Skip to content

Commit b9c17e7

Browse files
committed
Suppport nvim -d and fix test
1 parent feb5ca5 commit b9c17e7

3 files changed

Lines changed: 32 additions & 23 deletions

File tree

lua/common/arg_parse.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ local parameters_map = {
1010
["-o"] = "split",
1111
["-O"] = "vsplit",
1212
["-p"] = "tab",
13+
["-d"] = "diff",
1314
}
1415

1516
local function detect_parameters(str)
@@ -66,7 +67,7 @@ local function parse_line_number(arg, state)
6667
state.files[index] = {}
6768
end
6869

69-
state.files[index].line = line
70+
state.files[index].line = tonumber(line)
7071

7172
return true
7273
end

lua/server/server_functions.lua

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,33 +88,41 @@ local open_methods_table = {
8888
vsplit = "vsplit",
8989
tab = "tabnew",
9090
argadd = "argadd",
91+
diff = "diff",
9192
}
9293

9394
local function unception_detect_open_method(options)
9495
local open_method = open_methods_table[options.multi_file_open_method]
9596
if open_method == nil then
9697
print("unception can't find multi_file_open_method fall back to tab")
9798
open_method = "tabnew"
99+
elseif open_method == "diff" then
100+
-- For now net's assume that the only way to view diff is via vsplit
101+
open_method = "vsplit"
102+
options.diff = true
98103
end
99104
return open_method
100105
end
101106

102-
local function unception_open_file(open_method, file)
107+
local function unception_open_file(open_method, file, diff)
103108
if file.line then
104109
vim.cmd(("%s +%d %s"):format(open_method, file.line, file.path))
105110
else
106111
vim.cmd(("%s %s"):format(open_method, file.path))
107112
end
113+
if diff then
114+
vim.cmd.diffthis()
115+
end
108116
end
109117

110118
local function unception_open_file_other(file_args, options, open_method)
111119
if options.open_in_new_tab and open_method ~= "tabnew" then
112120
vim.cmd("tabnew")
113-
unception_open_file("edit", file_args[1])
121+
unception_open_file("edit", file_args[1], options.diff)
114122
table.remove(file_args, 1)
115123
end
116124
for _, file in ipairs(file_args) do
117-
unception_open_file(open_method, file)
125+
unception_open_file(open_method, file, options.diff)
118126
end
119127
end
120128

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,44 @@ require "common.arg_parse"
88
describe("unception nvim tests", function()
99
describe("argument parser", function()
1010
local tests_list = {
11-
-- { -- NYI
12-
-- argv = { "file", "\\+32" },
13-
-- output = { { file = "open" }, { file = "+32" } }
14-
-- },
1511
{
1612
argv = { "/usr/bin/nvim", "file", "+5", "-p" },
17-
output = { { path = "file", line = "5" } },
18-
option = { multi_file_open_method="tab" }
13+
output = { file = 5 },
14+
option = { multi_file_open_method = "tab" }
1915
},
2016
{
2117
argv = { "/usr/bin/dontcare", "file", "file2", "+32" },
22-
output = { { path = "file" }, { path = "file2", line = "32" } },
23-
option = { }
18+
output = { file2 = 32 },
19+
option = {}
2420
},
2521
{
26-
argv = { "/usr/bin/dontcare", "--ignored-option-long", "-i", "file", "file2", "+32" },
27-
output = { { path = "file" }, { path = "file2", line = "32" } },
28-
option = { }
22+
argv = { "/usr/bin/dontcare", "--ignored-option-long", "-i", "file2", "+32" },
23+
output = { file2 = 32 },
24+
option = {}
2925
},
3026
-- { -- NYI
3127
-- argv = { "/usr/bin/dontcare", "\\- file starting with dash" },
3228
-- output = { { file = "- file starting with dash" } }
3329
-- },
3430
{
35-
argv = { "/usr/bin/dontcare", "--", "- file starting with dash" },
36-
output = { { path = "- file starting with dash" } },
37-
option = { }
31+
argv = { "/usr/bin/dontcare", "+15", "--", "- file starting with dash" },
32+
output = { ["- file starting with dash"] = 15 },
33+
option = {}
3834
},
3935
{
4036
argv = { "/usr/bin/nvim", "file", "+5", "-o" },
41-
output = { { path = "file", line = "5" } },
42-
option = { multi_file_open_method="split" }
37+
output = { file = 5 },
38+
option = { multi_file_open_method = "split" }
4339
},
4440
{
4541
argv = { "/usr/bin/nvim", "file", "+5", "-O" },
46-
output = { { path = "file", line = "5" } },
47-
option = { multi_file_open_method="vsplit" }
42+
output = { file = 5 },
43+
option = { multi_file_open_method = "vsplit" }
44+
},
45+
{
46+
argv = { "/usr/bin/nvim", "file", "file2", "+3", "-d" },
47+
output = { file2 = 3 },
48+
option = { multi_file_open_method = "diff" }
4849
},
4950
}
5051
for i, test in ipairs(tests_list) do
@@ -55,6 +56,5 @@ describe("unception nvim tests", function()
5556
assert.are.same(options, test.option)
5657
end)
5758
end
58-
5959
end)
6060
end)

0 commit comments

Comments
 (0)