aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/api/buffer_spec.lua18
-rw-r--r--test/functional/api/server_requests_spec.lua9
-rw-r--r--test/functional/api/vim_spec.lua161
-rw-r--r--test/functional/core/channels_spec.lua10
-rw-r--r--test/functional/core/startup_spec.lua5
-rw-r--r--test/functional/fixtures/fake-lsp-server.lua63
-rw-r--r--test/functional/helpers.lua11
-rw-r--r--test/functional/lua/diagnostic_spec.lua276
-rw-r--r--test/functional/lua/luaeval_spec.lua6
-rw-r--r--test/functional/lua/mpack_spec.lua8
-rw-r--r--test/functional/lua/vim_spec.lua64
-rw-r--r--test/functional/plugin/lsp/codelens_spec.lua27
-rw-r--r--test/functional/plugin/lsp/diagnostic_spec.lua807
-rw-r--r--test/functional/plugin/lsp_spec.lua213
-rw-r--r--test/functional/ui/decorations_spec.lua11
-rw-r--r--test/functional/ui/diff_spec.lua23
-rw-r--r--test/functional/vimscript/executable_spec.lua6
-rw-r--r--test/functional/vimscript/exepath_spec.lua3
-rw-r--r--test/functional/vimscript/has_spec.lua7
-rw-r--r--test/functional/vimscript/null_spec.lua2
-rw-r--r--test/unit/api/private_helpers_spec.lua2
-rw-r--r--test/unit/marktree_spec.lua4
22 files changed, 838 insertions, 898 deletions
diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua
index 01fcfab543..a0c97804b7 100644
--- a/test/functional/api/buffer_spec.lua
+++ b/test/functional/api/buffer_spec.lua
@@ -711,46 +711,46 @@ describe('api/buf', function()
describe('nvim_buf_set_mark', function()
it('works with buffer local marks', function()
curbufmeths.set_lines(-1, -1, true, {'a', 'bit of', 'text'})
- eq(true, curbufmeths.set_mark('z', 1, 1))
+ eq(true, curbufmeths.set_mark('z', 1, 1, {}))
eq({1, 1}, curbufmeths.get_mark('z'))
end)
it('works with file/uppercase marks', function()
curbufmeths.set_lines(-1, -1, true, {'a', 'bit of', 'text'})
- eq(true, curbufmeths.set_mark('Z', 3, 1))
+ eq(true, curbufmeths.set_mark('Z', 3, 1, {}))
eq({3, 1}, curbufmeths.get_mark('Z'))
end)
it('fails when invalid marks names are used', function()
- eq(false, pcall(curbufmeths.set_mark, '!', 1, 0))
- eq(false, pcall(curbufmeths.set_mark, 'fail', 1, 0))
+ eq(false, pcall(curbufmeths.set_mark, '!', 1, 0, {}))
+ eq(false, pcall(curbufmeths.set_mark, 'fail', 1, 0, {}))
end)
it('fails when invalid buffer number is used', function()
- eq(false, pcall(meths.buf_set_mark, 99, 'a', 1, 1))
+ eq(false, pcall(meths.buf_set_mark, 99, 'a', 1, 1, {}))
end)
end)
describe('nvim_buf_del_mark', function()
it('works with buffer local marks', function()
curbufmeths.set_lines(-1, -1, true, {'a', 'bit of', 'text'})
- curbufmeths.set_mark('z', 3, 1)
+ curbufmeths.set_mark('z', 3, 1, {})
eq(true, curbufmeths.del_mark('z'))
eq({0, 0}, curbufmeths.get_mark('z'))
end)
it('works with file/uppercase marks', function()
curbufmeths.set_lines(-1, -1, true, {'a', 'bit of', 'text'})
- curbufmeths.set_mark('Z', 3, 3)
+ curbufmeths.set_mark('Z', 3, 3, {})
eq(true, curbufmeths.del_mark('Z'))
eq({0, 0}, curbufmeths.get_mark('Z'))
end)
it('returns false in marks not set in this buffer', function()
local abuf = meths.create_buf(false,true)
bufmeths.set_lines(abuf, -1, -1, true, {'a', 'bit of', 'text'})
- bufmeths.set_mark(abuf, 'A', 2, 2)
+ bufmeths.set_mark(abuf, 'A', 2, 2, {})
eq(false, curbufmeths.del_mark('A'))
eq({2, 2}, bufmeths.get_mark(abuf, 'A'))
end)
it('returns false if mark was not deleted', function()
curbufmeths.set_lines(-1, -1, true, {'a', 'bit of', 'text'})
- curbufmeths.set_mark('z', 3, 1)
+ curbufmeths.set_mark('z', 3, 1, {})
eq(true, curbufmeths.del_mark('z'))
eq(false, curbufmeths.del_mark('z')) -- Mark was already deleted
end)
diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua
index e408890906..309d9084c8 100644
--- a/test/functional/api/server_requests_spec.lua
+++ b/test/functional/api/server_requests_spec.lua
@@ -278,8 +278,9 @@ describe('server -> client', function()
local nvim_argv = merge_args(helpers.nvim_argv, {'--headless'})
local function connect_test(server, mode, address)
local serverpid = funcs.getpid()
- local client = spawn(nvim_argv)
- set_session(client, true)
+ local client = spawn(nvim_argv, false, nil, true)
+ set_session(client)
+
local clientpid = funcs.getpid()
neq(serverpid, clientpid)
local id = funcs.sockconnect(mode, address, {rpc=true})
@@ -288,7 +289,7 @@ describe('server -> client', function()
funcs.rpcrequest(id, 'nvim_set_current_line', 'hello')
local client_id = funcs.rpcrequest(id, 'nvim_get_api_info')[1]
- set_session(server, true)
+ set_session(server)
eq(serverpid, funcs.getpid())
eq('hello', meths.get_current_line())
@@ -296,7 +297,7 @@ describe('server -> client', function()
funcs.rpcrequest(client_id, 'nvim_set_current_line', 'howdy!')
eq(id, funcs.rpcrequest(client_id, 'nvim_get_api_info')[1])
- set_session(client, true)
+ set_session(client)
eq(clientpid, funcs.getpid())
eq('howdy!', meths.get_current_line())
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index d8914a3ab7..21de4925b5 100644
--- a/test/functional/api/vim_spec.lua
+++ b/test/functional/api/vim_spec.lua
@@ -22,6 +22,7 @@ local source = helpers.source
local next_msg = helpers.next_msg
local tmpname = helpers.tmpname
local write_file = helpers.write_file
+local exec_lua = helpers.exec_lua
local pcall_err = helpers.pcall_err
local format_string = helpers.format_string
@@ -1689,7 +1690,7 @@ describe('API', function()
end)
local it_maybe_pending = it
- if (helpers.isCI('appveyor') and os.getenv('CONFIGURATION') == 'MSVC_32') then
+ if helpers.isCI() and os.getenv('CONFIGURATION') == 'MSVC_32' then
-- For "works with &opt" (flaky on MSVC_32), but not easy to skip alone. #10241
it_maybe_pending = pending
end
@@ -2264,6 +2265,9 @@ describe('API', function()
[2] = {background = tonumber('0xffff40'), bg_indexed = true};
[3] = {background = Screen.colors.Plum1, fg_indexed = true, foreground = tonumber('0x00e000')};
[4] = {bold = true, reverse = true, background = Screen.colors.Plum1};
+ [5] = {foreground = Screen.colors.Blue, background = Screen.colors.LightMagenta, bold = true};
+ [6] = {bold = true};
+ [7] = {reverse = true, background = Screen.colors.LightMagenta};
})
end)
@@ -2311,13 +2315,81 @@ describe('API', function()
|
]]}
end)
+
+ it('can handle input', function()
+ screen:try_resize(50, 10)
+ eq({3, 2}, exec_lua [[
+ buf = vim.api.nvim_create_buf(1,1)
+
+ stream = ''
+ do_the_echo = false
+ function input(_,t1,b1,data)
+ stream = stream .. data
+ _G.vals = {t1, b1}
+ if do_the_echo then
+ vim.api.nvim_chan_send(t1, data)
+ end
+ end
+
+ term = vim.api.nvim_open_term(buf, {on_input=input})
+ vim.api.nvim_open_win(buf, true, {width=40, height=5, row=1, col=1, relative='editor'})
+ return {term, buf}
+ ]])
+
+ screen:expect{grid=[[
+ |
+ {0:~}{1:^ }{0: }|
+ {0:~}{1: }{0: }|
+ {0:~}{1: }{0: }|
+ {0:~}{1: }{0: }|
+ {0:~}{1: }{0: }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ |
+ ]]}
+
+ feed 'iba<c-x>bla'
+ screen:expect{grid=[[
+ |
+ {0:~}{7: }{1: }{0: }|
+ {0:~}{1: }{0: }|
+ {0:~}{1: }{0: }|
+ {0:~}{1: }{0: }|
+ {0:~}{1: }{0: }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {6:-- TERMINAL --} |
+ ]]}
+
+ eq('ba\024bla', exec_lua [[ return stream ]])
+ eq({3,2}, exec_lua [[ return vals ]])
+
+ exec_lua [[ do_the_echo = true ]]
+ feed 'herrejösses!'
+
+ screen:expect{grid=[[
+ |
+ {0:~}{1:herrejösses!}{7: }{1: }{0: }|
+ {0:~}{1: }{0: }|
+ {0:~}{1: }{0: }|
+ {0:~}{1: }{0: }|
+ {0:~}{1: }{0: }|
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ {6:-- TERMINAL --} |
+ ]]}
+ eq('ba\024blaherrejösses!', exec_lua [[ return stream ]])
+ end)
end)
describe('nvim_del_mark', function()
it('works', function()
local buf = meths.create_buf(false,true)
meths.buf_set_lines(buf, -1, -1, true, {'a', 'bit of', 'text'})
- eq(true, meths.buf_set_mark(buf, 'F', 2, 2))
+ eq(true, meths.buf_set_mark(buf, 'F', 2, 2, {}))
eq(true, meths.del_mark('F'))
eq({0, 0}, meths.buf_get_mark(buf, 'F'))
end)
@@ -2331,9 +2403,9 @@ describe('API', function()
it('works', function()
local buf = meths.create_buf(false,true)
meths.buf_set_lines(buf, -1, -1, true, {'a', 'bit of', 'text'})
- meths.buf_set_mark(buf, 'F', 2, 2)
+ meths.buf_set_mark(buf, 'F', 2, 2, {})
meths.buf_set_name(buf, "mybuf")
- local mark = meths.get_mark('F')
+ local mark = meths.get_mark('F', {})
-- Compare the path tail ony
assert(string.find(mark[4], "mybuf$"))
eq({2, 2, buf.id, mark[4]}, mark)
@@ -2345,7 +2417,7 @@ describe('API', function()
end)
it('returns the expected when mark is not set', function()
eq(true, meths.del_mark('A'))
- eq({0, 0, 0, ''}, meths.get_mark('A'))
+ eq({0, 0, 0, ''}, meths.get_mark('A', {}))
end)
it('works with deleted buffers', function()
local fname = tmpname()
@@ -2353,12 +2425,12 @@ describe('API', function()
nvim("command", "edit " .. fname)
local buf = meths.get_current_buf()
- meths.buf_set_mark(buf, 'F', 2, 2)
+ meths.buf_set_mark(buf, 'F', 2, 2, {})
nvim("command", "new") -- Create new buf to avoid :bd failing
nvim("command", "bd! " .. buf.id)
os.remove(fname)
- local mark = meths.get_mark('F')
+ local mark = meths.get_mark('F', {})
-- To avoid comparing relative vs absolute path
local mfname = mark[4]
local tail_patt = [[[\/][^\/]*$]]
@@ -2367,4 +2439,79 @@ describe('API', function()
eq({2, 2, buf.id, mark[4]}, mark)
end)
end)
+ describe('nvim_eval_statusline', function()
+ it('works', function()
+ eq({
+ str = '%StatusLineStringWithHighlights',
+ width = 31
+ },
+ meths.eval_statusline(
+ '%%StatusLineString%#WarningMsg#WithHighlights',
+ {}))
+ end)
+ it('doesn\'t exceed maxwidth', function()
+ eq({
+ str = 'Should be trun>',
+ width = 15
+ },
+ meths.eval_statusline(
+ 'Should be truncated%<',
+ { maxwidth = 15 }))
+ end)
+ describe('highlight parsing', function()
+ it('works', function()
+ eq({
+ str = "TextWithWarningHighlightTextWithUserHighlight",
+ width = 45,
+ highlights = {
+ { start = 0, group = 'WarningMsg' },
+ { start = 24, group = 'User1' }
+ },
+ },
+ meths.eval_statusline(
+ '%#WarningMsg#TextWithWarningHighlight%1*TextWithUserHighlight',
+ { highlights = true }))
+ end)
+ it('works with no highlight', function()
+ eq({
+ str = "TextWithNoHighlight",
+ width = 19,
+ highlights = {
+ { start = 0, group = 'StatusLine' },
+ },
+ },
+ meths.eval_statusline(
+ 'TextWithNoHighlight',
+ { highlights = true }))
+ end)
+ it('works with inactive statusline', function()
+ command('split')
+
+ eq({
+ str = 'TextWithNoHighlightTextWithWarningHighlight',
+ width = 43,
+ highlights = {
+ { start = 0, group = 'StatusLineNC' },
+ { start = 19, group = 'WarningMsg' }
+ }
+ },
+ meths.eval_statusline(
+ 'TextWithNoHighlight%#WarningMsg#TextWithWarningHighlight',
+ { winid = meths.list_wins()[2].id, highlights = true }))
+ end)
+ it('works with tabline', function()
+ eq({
+ str = 'TextWithNoHighlightTextWithWarningHighlight',
+ width = 43,
+ highlights = {
+ { start = 0, group = 'TabLineFill' },
+ { start = 19, group = 'WarningMsg' }
+ }
+ },
+ meths.eval_statusline(
+ 'TextWithNoHighlight%#WarningMsg#TextWithWarningHighlight',
+ { use_tabline = true, highlights = true }))
+ end)
+ end)
+ end)
end)
diff --git a/test/functional/core/channels_spec.lua b/test/functional/core/channels_spec.lua
index 6efa4f9b80..93dec9fb35 100644
--- a/test/functional/core/channels_spec.lua
+++ b/test/functional/core/channels_spec.lua
@@ -29,11 +29,11 @@ describe('channels', function()
end)
pending('can connect to socket', function()
- local server = spawn(nvim_argv)
+ local server = spawn(nvim_argv, nil, nil, true)
set_session(server)
local address = funcs.serverlist()[1]
- local client = spawn(nvim_argv)
- set_session(client, true)
+ local client = spawn(nvim_argv, nil, nil, true)
+ set_session(client)
source(init)
meths.set_var('address', address)
@@ -42,11 +42,11 @@ describe('channels', function()
ok(id > 0)
command("call chansend(g:id, msgpackdump([[2,'nvim_set_var',['code',23]]]))")
- set_session(server, true)
+ set_session(server)
retry(nil, 1000, function()
eq(23, meths.get_var('code'))
end)
- set_session(client, true)
+ set_session(client)
command("call chansend(g:id, msgpackdump([[0,0,'nvim_eval',['2+3']]]))")
diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua
index cc6e2c8067..d1dce0f8da 100644
--- a/test/functional/core/startup_spec.lua
+++ b/test/functional/core/startup_spec.lua
@@ -414,6 +414,11 @@ describe('startup', function()
eq({'ordinary', 'funky!', 'FANCY', 'mittel', 'FANCY after', 'ordinary after'}, exec_lua [[ return _G.test_loadorder ]])
eq({'ordinary', 'funky!', 'mittel', 'ordinary after'}, exec_lua [[ return _G.nested_order ]])
end)
+
+ it("handles the correct order when prepending packpath", function()
+ clear{args={'--cmd', 'set packpath^=test/functional/fixtures', '--cmd', [[ lua _G.test_loadorder = {} vim.cmd "runtime! filen.lua" ]]}, env={XDG_CONFIG_HOME='test/functional/fixtures/'}}
+ eq({'ordinary', 'FANCY', 'FANCY after', 'ordinary after'}, exec_lua [[ return _G.test_loadorder ]])
+ end)
end)
describe('sysinit', function()
diff --git a/test/functional/fixtures/fake-lsp-server.lua b/test/functional/fixtures/fake-lsp-server.lua
index 9abf478070..5c0de50731 100644
--- a/test/functional/fixtures/fake-lsp-server.lua
+++ b/test/functional/fixtures/fake-lsp-server.lua
@@ -275,6 +275,55 @@ function tests.check_forward_content_modified()
}
end
+function tests.check_pending_request_tracked()
+ skeleton {
+ on_init = function(_)
+ return { capabilities = {} }
+ end;
+ body = function()
+ local msg = read_message()
+ assert_eq('slow_request', msg.method)
+ expect_notification('release')
+ respond(msg.id, nil, {})
+ expect_notification('finish')
+ notify('finish')
+ end;
+ }
+end
+
+function tests.check_cancel_request_tracked()
+ skeleton {
+ on_init = function(_)
+ return { capabilities = {} }
+ end;
+ body = function()
+ local msg = read_message()
+ assert_eq('slow_request', msg.method)
+ expect_notification('$/cancelRequest', {id=msg.id})
+ expect_notification('release')
+ respond(msg.id, {code = -32800}, nil)
+ notify('finish')
+ end;
+ }
+end
+
+function tests.check_tracked_requests_cleared()
+ skeleton {
+ on_init = function(_)
+ return { capabilities = {} }
+ end;
+ body = function()
+ local msg = read_message()
+ assert_eq('slow_request', msg.method)
+ expect_notification('$/cancelRequest', {id=msg.id})
+ expect_notification('release')
+ respond(msg.id, nil, {})
+ expect_notification('finish')
+ notify('finish')
+ end;
+ }
+end
+
function tests.basic_finish()
skeleton {
on_init = function(params)
@@ -622,6 +671,20 @@ function tests.code_action_with_resolve()
}
end
+function tests.clientside_commands()
+ skeleton {
+ on_init = function()
+ return {
+ capabilities = {}
+ }
+ end;
+ body = function()
+ notify('start')
+ notify('shutdown')
+ end;
+ }
+end
+
-- Tests will be indexed by TEST_NAME
local kill_timer = vim.loop.new_timer()
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index a26e883370..f152a487af 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -96,10 +96,7 @@ function module.get_session()
return session
end
-function module.set_session(s, keep)
- if session and not keep then
- session:close()
- end
+function module.set_session(s)
session = s
end
@@ -366,7 +363,11 @@ local function remove_args(args, args_rm)
return new_args
end
-function module.spawn(argv, merge, env)
+function module.spawn(argv, merge, env, keep)
+ if session and not keep then
+ session:close()
+ end
+
local child_stream = ChildProcessStream.spawn(
merge and module.merge_args(prepend_argv, argv) or argv,
env)
diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua
index 33469597a1..00011687a9 100644
--- a/test/functional/lua/diagnostic_spec.lua
+++ b/test/functional/lua/diagnostic_spec.lua
@@ -6,6 +6,8 @@ local clear = helpers.clear
local exec_lua = helpers.exec_lua
local eq = helpers.eq
local nvim = helpers.nvim
+local matches = helpers.matches
+local pcall_err = helpers.pcall_err
describe('vim.diagnostic', function()
before_each(function()
@@ -47,7 +49,21 @@ describe('vim.diagnostic', function()
end
function count_extmarks(bufnr, namespace)
- return #vim.api.nvim_buf_get_extmarks(bufnr, namespace, 0, -1, {})
+ local ns = vim.diagnostic.get_namespace(namespace)
+ local extmarks = 0
+ if ns.user_data.virt_text_ns then
+ extmarks = extmarks + #vim.api.nvim_buf_get_extmarks(bufnr, ns.user_data.virt_text_ns, 0, -1, {})
+ end
+ if ns.user_data.underline_ns then
+ extmarks = extmarks + #vim.api.nvim_buf_get_extmarks(bufnr, ns.user_data.underline_ns, 0, -1, {})
+ end
+ return extmarks
+ end
+
+ function get_virt_text_extmarks(ns)
+ local ns = vim.diagnostic.get_namespace(ns)
+ local virt_text_ns = ns.user_data.virt_text_ns
+ return vim.api.nvim_buf_get_extmarks(diagnostic_bufnr, virt_text_ns, 0, -1, {details = true})
end
]]
@@ -567,7 +583,7 @@ describe('vim.diagnostic', function()
]]
eq(1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]])
- eq(1, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]])
+ -- eq(1, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]])
end)
it('allows filtering by severity', function()
@@ -615,7 +631,7 @@ describe('vim.diagnostic', function()
severity_sort = severity_sort,
})
- local virt_text = vim.api.nvim_buf_get_extmarks(diagnostic_bufnr, diagnostic_ns, 0, -1, {details = true})[1][4].virt_text
+ local virt_text = get_virt_text_extmarks(diagnostic_ns)[1][4].virt_text
local virt_texts = {}
for i = 2, #virt_text do
@@ -661,7 +677,7 @@ describe('vim.diagnostic', function()
}
})
- local extmarks = vim.api.nvim_buf_get_extmarks(diagnostic_bufnr, diagnostic_ns, 0, -1, {details = true})
+ local extmarks = get_virt_text_extmarks(diagnostic_ns)
local virt_text = extmarks[1][4].virt_text[2][1]
return virt_text
]]
@@ -676,7 +692,7 @@ describe('vim.diagnostic', function()
}
}, diagnostic_ns)
- local extmarks = vim.api.nvim_buf_get_extmarks(diagnostic_bufnr, diagnostic_ns, 0, -1, {details = true})
+ local extmarks = get_virt_text_extmarks(diagnostic_ns)
local virt_text = extmarks[1][4].virt_text[2][1]
return virt_text
]]
@@ -696,7 +712,7 @@ describe('vim.diagnostic', function()
}
})
- local extmarks = vim.api.nvim_buf_get_extmarks(diagnostic_bufnr, diagnostic_ns, 0, -1, {details = true})
+ local extmarks = get_virt_text_extmarks(diagnostic_ns)
local virt_text = {extmarks[1][4].virt_text[2][1], extmarks[2][4].virt_text[2][1]}
return virt_text
]]
@@ -724,7 +740,7 @@ describe('vim.diagnostic', function()
make_error('Error', 1, 0, 1, 0),
})
- local extmarks = vim.api.nvim_buf_get_extmarks(diagnostic_bufnr, diagnostic_ns, 0, -1, {details = true})
+ local extmarks = get_virt_text_extmarks(diagnostic_ns)
return {extmarks[1][4].virt_text, extmarks[2][4].virt_text}
]]
eq(" 👀 Warning", result[1][2][1])
@@ -752,7 +768,7 @@ describe('vim.diagnostic', function()
make_error('Error', 1, 0, 1, 0, 'another_linter'),
})
- local extmarks = vim.api.nvim_buf_get_extmarks(diagnostic_bufnr, diagnostic_ns, 0, -1, {details = true})
+ local extmarks = get_virt_text_extmarks(diagnostic_ns)
return {extmarks[1][4].virt_text, extmarks[2][4].virt_text}
]]
eq(" some_linter: 👀 Warning", result[1][2][1])
@@ -800,13 +816,11 @@ describe('vim.diagnostic', function()
virtual_text = true,
})
- -- Count how many times we call display.
- SetVirtualTextOriginal = vim.diagnostic._set_virtual_text
-
DisplayCount = 0
- vim.diagnostic._set_virtual_text = function(...)
+ local set_virtual_text = vim.diagnostic.handlers.virtual_text.show
+ vim.diagnostic.handlers.virtual_text.show = function(...)
DisplayCount = DisplayCount + 1
- return SetVirtualTextOriginal(...)
+ return set_virtual_text(...)
end
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
@@ -850,13 +864,12 @@ describe('vim.diagnostic', function()
virtual_text = false,
})
- -- Count how many times we call display.
- SetVirtualTextOriginal = vim.diagnostic._set_virtual_text
DisplayCount = 0
- vim.diagnostic._set_virtual_text = function(...)
+ local set_virtual_text = vim.diagnostic.handlers.virtual_text.show
+ vim.diagnostic.handlers.virtual_text.show = function(...)
DisplayCount = DisplayCount + 1
- return SetVirtualTextOriginal(...)
+ return set_virtual_text(...)
end
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
@@ -968,8 +981,102 @@ describe('vim.diagnostic', function()
end)
end)
- describe('show_line_diagnostics()', function()
- it('creates floating window and returns popup bufnr and winnr if current line contains diagnostics', function()
+ describe('open_float()', function()
+ it('can show diagnostics from the whole buffer', function()
+ eq({'1. Syntax error', '2. Some warning'}, exec_lua [[
+ local diagnostics = {
+ make_error("Syntax error", 0, 1, 0, 3),
+ make_warning("Some warning", 1, 1, 1, 3),
+ }
+ vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
+ local float_bufnr, winnr = vim.diagnostic.open_float(0, {show_header = false})
+ local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
+ vim.api.nvim_win_close(winnr, true)
+ return lines
+ ]])
+ end)
+
+ it('can show diagnostics from a single line', function()
+ -- Using cursor position
+ eq({'1. Some warning'}, exec_lua [[
+ local diagnostics = {
+ make_error("Syntax error", 0, 1, 0, 3),
+ make_warning("Some warning", 1, 1, 1, 3),
+ }
+ vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
+ vim.api.nvim_win_set_cursor(0, {2, 1})
+ local float_bufnr, winnr = vim.diagnostic.open_float(0, {show_header=false, scope="line"})
+ local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
+ vim.api.nvim_win_close(winnr, true)
+ return lines
+ ]])
+
+ -- With specified position
+ eq({'1. Some warning'}, exec_lua [[
+ local diagnostics = {
+ make_error("Syntax error", 0, 1, 0, 3),
+ make_warning("Some warning", 1, 1, 1, 3),
+ }
+ vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
+ vim.api.nvim_win_set_cursor(0, {1, 1})
+ local float_bufnr, winnr = vim.diagnostic.open_float(0, {show_header=false, scope="line", pos=1})
+ local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
+ vim.api.nvim_win_close(winnr, true)
+ return lines
+ ]])
+ end)
+
+ it('can show diagnostics from a specific position', function()
+ -- Using cursor position
+ eq({'1. Syntax error'}, exec_lua [[
+ local diagnostics = {
+ make_error("Syntax error", 1, 1, 1, 2),
+ make_warning("Some warning", 1, 3, 1, 4),
+ }
+ vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
+ vim.api.nvim_win_set_cursor(0, {2, 2})
+ local float_bufnr, winnr = vim.diagnostic.open_float(0, {show_header=false, scope="cursor"})
+ local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
+ vim.api.nvim_win_close(winnr, true)
+ return lines
+ ]])
+
+ -- With specified position
+ eq({'1. Some warning'}, exec_lua [[
+ local diagnostics = {
+ make_error("Syntax error", 1, 1, 1, 2),
+ make_warning("Some warning", 1, 3, 1, 4),
+ }
+ vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
+ vim.api.nvim_win_set_cursor(0, {1, 1})
+ local float_bufnr, winnr = vim.diagnostic.open_float(0, {show_header=false, scope="cursor", pos={1,3}})
+ local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
+ vim.api.nvim_win_close(winnr, true)
+ return lines
+ ]])
+
+ -- With column position past the end of the line. #16062
+ eq({'1. Syntax error'}, exec_lua [[
+ local first_line_len = #vim.api.nvim_buf_get_lines(diagnostic_bufnr, 0, 1, true)[1]
+ local diagnostics = {
+ make_error("Syntax error", 0, first_line_len + 1, 1, 0),
+ }
+ vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
+ vim.api.nvim_win_set_cursor(0, {1, 1})
+ local float_bufnr, winnr = vim.diagnostic.open_float(0, {show_header=false, scope="cursor", pos={0,first_line_len}})
+ local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
+ vim.api.nvim_win_close(winnr, true)
+ return lines
+ ]])
+ end)
+
+ it('creates floating window and returns float bufnr and winnr if current line contains diagnostics', function()
-- Two lines:
-- Diagnostic:
-- 1. <msg>
@@ -979,8 +1086,10 @@ describe('vim.diagnostic', function()
}
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
- local popup_bufnr, winnr = vim.diagnostic.show_line_diagnostics()
- return #vim.api.nvim_buf_get_lines(popup_bufnr, 0, -1, false)
+ local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, {scope="line"})
+ local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
+ vim.api.nvim_win_close(winnr, true)
+ return #lines
]])
end)
@@ -996,8 +1105,10 @@ describe('vim.diagnostic', function()
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, buf_1_diagnostics)
vim.diagnostic.set(other_ns, other_bufnr, buf_2_diagnostics)
- local popup_bufnr, winnr = vim.diagnostic.show_line_diagnostics()
- return #vim.api.nvim_buf_get_lines(popup_bufnr, 0, -1, false)
+ local float_bufnr, winnr = vim.diagnostic.open_float()
+ local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
+ vim.api.nvim_win_close(winnr, true)
+ return #lines
]])
end)
@@ -1012,12 +1123,14 @@ describe('vim.diagnostic', function()
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, ns_1_diagnostics)
vim.diagnostic.set(other_ns, diagnostic_bufnr, ns_2_diagnostics)
- local popup_bufnr, winnr = vim.diagnostic.show_line_diagnostics({namespace = diagnostic_ns})
- return #vim.api.nvim_buf_get_lines(popup_bufnr, 0, -1, false)
+ local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, {namespace = diagnostic_ns})
+ local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
+ vim.api.nvim_win_close(winnr, true)
+ return #lines
]])
end)
- it('creates floating window and returns popup bufnr and winnr without header, if requested', function()
+ it('creates floating window and returns float bufnr and winnr without header, if requested', function()
-- One line (since no header):
-- 1. <msg>
eq(1, exec_lua [[
@@ -1026,8 +1139,10 @@ describe('vim.diagnostic', function()
}
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
- local popup_bufnr, winnr = vim.diagnostic.show_line_diagnostics {show_header = false}
- return #vim.api.nvim_buf_get_lines(popup_bufnr, 0, -1, false)
+ local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, {show_header = false})
+ local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
+ vim.api.nvim_win_close(winnr, true)
+ return #lines
]])
end)
@@ -1038,8 +1153,10 @@ describe('vim.diagnostic', function()
}
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
- local popup_bufnr, winnr = vim.diagnostic.show_line_diagnostics({show_header = false}, diagnostic_bufnr, 5)
- return #vim.api.nvim_buf_get_lines(popup_bufnr, 0, -1, false)
+ local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, {show_header = false, scope = "line", pos = 5})
+ local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
+ vim.api.nvim_win_close(winnr, true)
+ return #lines
]])
end)
@@ -1051,21 +1168,21 @@ describe('vim.diagnostic', function()
make_error("Syntax error", 0, 1, 0, 3, "source x"),
}
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
- local popup_bufnr, winnr = vim.diagnostic.show_line_diagnostics {
+ local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, {
show_header = false,
source = "if_many",
- }
- local lines = vim.api.nvim_buf_get_lines(popup_bufnr, 0, -1, false)
+ })
+ local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
vim.api.nvim_win_close(winnr, true)
return lines
]])
eq({"1. source x: Syntax error"}, exec_lua [[
- local popup_bufnr, winnr = vim.diagnostic.show_line_diagnostics {
+ local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, {
show_header = false,
source = "always",
- }
- local lines = vim.api.nvim_buf_get_lines(popup_bufnr, 0, -1, false)
+ })
+ local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
vim.api.nvim_win_close(winnr, true)
return lines
]])
@@ -1076,11 +1193,11 @@ describe('vim.diagnostic', function()
make_error("Another error", 0, 1, 0, 3, "source y"),
}
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics)
- local popup_bufnr, winnr = vim.diagnostic.show_line_diagnostics {
+ local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, {
show_header = false,
source = "if_many",
- }
- local lines = vim.api.nvim_buf_get_lines(popup_bufnr, 0, -1, false)
+ })
+ local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
vim.api.nvim_win_close(winnr, true)
return lines
]])
@@ -1101,24 +1218,24 @@ describe('vim.diagnostic', function()
vim.diagnostic.config({severity_sort = false})
- local popup_bufnr, winnr = vim.diagnostic.show_line_diagnostics { show_header = false }
- local lines = vim.api.nvim_buf_get_lines(popup_bufnr, 0, -1, false)
+ local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, { show_header = false })
+ local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
vim.api.nvim_win_close(winnr, true)
return lines
]])
eq({"1. Syntax error", "2. Error", "3. Warning", "4. Info"}, exec_lua [[
vim.diagnostic.config({severity_sort = true})
- local popup_bufnr, winnr = vim.diagnostic.show_line_diagnostics { show_header = false }
- local lines = vim.api.nvim_buf_get_lines(popup_bufnr, 0, -1, false)
+ local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, { show_header = false })
+ local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
vim.api.nvim_win_close(winnr, true)
return lines
]])
eq({"1. Info", "2. Warning", "3. Error", "4. Syntax error"}, exec_lua [[
vim.diagnostic.config({severity_sort = { reverse = true } })
- local popup_bufnr, winnr = vim.diagnostic.show_line_diagnostics { show_header = false }
- local lines = vim.api.nvim_buf_get_lines(popup_bufnr, 0, -1, false)
+ local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, { show_header = false })
+ local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false)
vim.api.nvim_win_close(winnr, true)
return lines
]])
@@ -1243,4 +1360,73 @@ describe('vim.diagnostic', function()
eq(result[1], result[2])
end)
end)
+
+ describe('handlers', function()
+ it('checks that a new handler is a table', function()
+ matches([[.*handler: expected table, got string.*]], pcall_err(exec_lua, [[ vim.diagnostic.handlers.foo = "bar" ]]))
+ matches([[.*handler: expected table, got function.*]], pcall_err(exec_lua, [[ vim.diagnostic.handlers.foo = function() end ]]))
+ end)
+
+ it('can add new handlers', function()
+ eq(true, exec_lua [[
+ local handler_called = false
+ vim.diagnostic.handlers.test = {
+ show = function(namespace, bufnr, diagnostics, opts)
+ assert(namespace == diagnostic_ns)
+ assert(bufnr == diagnostic_bufnr)
+ assert(#diagnostics == 1)
+ assert(opts.test.some_opt == 42)
+ handler_called = true
+ end,
+ }
+
+ vim.diagnostic.config({test = {some_opt = 42}})
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
+ make_warning("Warning", 0, 0, 0, 0),
+ })
+ return handler_called
+ ]])
+ end)
+
+ it('can disable handlers by setting the corresponding option to false', function()
+ eq(false, exec_lua [[
+ local handler_called = false
+ vim.diagnostic.handlers.test = {
+ show = function(namespace, bufnr, diagnostics, opts)
+ handler_called = true
+ end,
+ }
+
+ vim.diagnostic.config({test = false})
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
+ make_warning("Warning", 0, 0, 0, 0),
+ })
+ return handler_called
+ ]])
+ end)
+
+ it('always calls a handler\'s hide function if defined', function()
+ eq({false, true}, exec_lua [[
+ local hide_called = false
+ local show_called = false
+ vim.diagnostic.handlers.test = {
+ show = function(namespace, bufnr, diagnostics, opts)
+ show_called = true
+ end,
+ hide = function(namespace, bufnr)
+ assert(namespace == diagnostic_ns)
+ assert(bufnr == diagnostic_bufnr)
+ hide_called = true
+ end,
+ }
+
+ vim.diagnostic.config({test = false})
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
+ make_warning("Warning", 0, 0, 0, 0),
+ })
+ vim.diagnostic.hide(diagnostic_ns, diagnostic_bufnr)
+ return {show_called, hide_called}
+ ]])
+ end)
+ end)
end)
diff --git a/test/functional/lua/luaeval_spec.lua b/test/functional/lua/luaeval_spec.lua
index 0675ec9abd..ab76e71a12 100644
--- a/test/functional/lua/luaeval_spec.lua
+++ b/test/functional/lua/luaeval_spec.lua
@@ -527,6 +527,12 @@ describe('v:lua', function()
]]}
end)
+ it('supports packages', function()
+ command('set pp+=test/functional/fixtures')
+ eq('\tbadval', eval("v:lua.require'leftpad'('badval')"))
+ eq(9003, eval("v:lua.require'bar'.doit()"))
+ end)
+
it('throw errors for invalid use', function()
eq('Vim(let):E15: Invalid expression: v:lua.func', pcall_err(command, "let g:Func = v:lua.func"))
eq('Vim(let):E15: Invalid expression: v:lua', pcall_err(command, "let g:Func = v:lua"))
diff --git a/test/functional/lua/mpack_spec.lua b/test/functional/lua/mpack_spec.lua
index ef693f01f3..cc788ed8bb 100644
--- a/test/functional/lua/mpack_spec.lua
+++ b/test/functional/lua/mpack_spec.lua
@@ -7,16 +7,16 @@ local exec_lua = helpers.exec_lua
describe('lua vim.mpack', function()
before_each(clear)
- it('can pack vim.NIL', function()
+ it('encodes vim.NIL', function()
eq({true, true, true, true}, exec_lua [[
- local var = vim.mpack.unpack(vim.mpack.pack({33, vim.NIL, 77}))
+ local var = vim.mpack.decode(vim.mpack.encode({33, vim.NIL, 77}))
return {var[1]==33, var[2]==vim.NIL, var[3]==77, var[4]==nil}
]])
end)
- it('can pack vim.empty_dict()', function()
+ it('encodes vim.empty_dict()', function()
eq({{{}, "foo", {}}, true, false}, exec_lua [[
- local var = vim.mpack.unpack(vim.mpack.pack({{}, "foo", vim.empty_dict()}))
+ local var = vim.mpack.decode(vim.mpack.encode({{}, "foo", vim.empty_dict()}))
return {var, vim.tbl_islist(var[1]), vim.tbl_islist(var[3])}
]])
end)
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua
index a739992611..5f903e7d5f 100644
--- a/test/functional/lua/vim_spec.lua
+++ b/test/functional/lua/vim_spec.lua
@@ -179,6 +179,37 @@ describe('lua stdlib', function()
end
end)
+ it("vim.str_utf_start", function()
+ exec_lua([[_G.test_text = "xy åäö ɧ 汉语 ↥ 🤦x🦄 å بِيَّ"]])
+ local expected_positions = {0,0,0,0,-1,0,-1,0,-1,0,0,-1,0,0,-1,-2,0,-1,-2,0,0,-1,-2,0,0,-1,-2,-3,0,0,-1,-2,-3,0,0,0,-1,0,0,-1,0,-1,0,-1,0,-1,0,-1}
+ eq(expected_positions, exec_lua([[
+ local start_codepoint_positions = {}
+ for idx = 1, #_G.test_text do
+ table.insert(start_codepoint_positions, vim.str_utf_start(_G.test_text, idx))
+ end
+ return start_codepoint_positions
+ ]]))
+ end)
+
+ it("vim.str_utf_end", function()
+ exec_lua([[_G.test_text = "xy åäö ɧ 汉语 ↥ 🤦x🦄 å بِيَّ"]])
+ local expected_positions = {0,0,0,1,0,1,0,1,0,0,1,0,0,2,1,0,2,1,0,0,2,1,0,0,3,2,1,0,0,3,2,1,0,0,0,1,0,0,1,0,1,0,1,0,1,0,1,0 }
+ eq(expected_positions, exec_lua([[
+ local end_codepoint_positions = {}
+ for idx = 1, #_G.test_text do
+ table.insert(end_codepoint_positions, vim.str_utf_end(_G.test_text, idx))
+ end
+ return end_codepoint_positions
+ ]]))
+ end)
+
+
+ it("vim.str_utf_pos", function()
+ exec_lua([[_G.test_text = "xy åäö ɧ 汉语 ↥ 🤦x🦄 å بِيَّ"]])
+ local expected_positions = { 1,2,3,4,6,8,10,11,13,14,17,20,21,24,25,29,30,34,35,36,38,39,41,43,45,47 }
+ eq(expected_positions, exec_lua("return vim.str_utf_pos(_G.test_text)"))
+ end)
+
it("vim.schedule", function()
exec_lua([[
test_table = {}
@@ -996,6 +1027,9 @@ describe('lua stdlib', function()
vim.g.to_delete = nil
]]
eq(NIL, funcs.luaeval "vim.g.to_delete")
+
+ matches([[^Error executing lua: .*: attempt to index .* nil value]],
+ pcall_err(exec_lua, 'return vim.g[0].testing'))
end)
it('vim.b', function()
@@ -1005,18 +1039,25 @@ describe('lua stdlib', function()
vim.api.nvim_buf_set_var(0, "floaty", 5120.1)
vim.api.nvim_buf_set_var(0, "nullvar", vim.NIL)
vim.api.nvim_buf_set_var(0, "to_delete", {hello="world"})
+ BUF = vim.api.nvim_create_buf(false, true)
+ vim.api.nvim_buf_set_var(BUF, "testing", "bye")
]]
eq('hi', funcs.luaeval "vim.b.testing")
+ eq('bye', funcs.luaeval "vim.b[BUF].testing")
eq(123, funcs.luaeval "vim.b.other")
eq(5120.1, funcs.luaeval "vim.b.floaty")
eq(NIL, funcs.luaeval "vim.b.nonexistant")
+ eq(NIL, funcs.luaeval "vim.b[BUF].nonexistant")
eq(NIL, funcs.luaeval "vim.b.nullvar")
-- lost over RPC, so test locally:
eq({false, true}, exec_lua [[
return {vim.b.nonexistant == vim.NIL, vim.b.nullvar == vim.NIL}
]])
+ matches([[^Error executing lua: .*: attempt to index .* nil value]],
+ pcall_err(exec_lua, 'return vim.b[BUF][0].testing'))
+
eq({hello="world"}, funcs.luaeval "vim.b.to_delete")
exec_lua [[
vim.b.to_delete = nil
@@ -1037,11 +1078,22 @@ describe('lua stdlib', function()
vim.api.nvim_win_set_var(0, "testing", "hi")
vim.api.nvim_win_set_var(0, "other", 123)
vim.api.nvim_win_set_var(0, "to_delete", {hello="world"})
+ BUF = vim.api.nvim_create_buf(false, true)
+ WIN = vim.api.nvim_open_win(BUF, false, {
+ width=10, height=10,
+ relative='win', row=0, col=0
+ })
+ vim.api.nvim_win_set_var(WIN, "testing", "bye")
]]
eq('hi', funcs.luaeval "vim.w.testing")
+ eq('bye', funcs.luaeval "vim.w[WIN].testing")
eq(123, funcs.luaeval "vim.w.other")
eq(NIL, funcs.luaeval "vim.w.nonexistant")
+ eq(NIL, funcs.luaeval "vim.w[WIN].nonexistant")
+
+ matches([[^Error executing lua: .*: attempt to index .* nil value]],
+ pcall_err(exec_lua, 'return vim.w[WIN][0].testing'))
eq({hello="world"}, funcs.luaeval "vim.w.to_delete")
exec_lua [[
@@ -1068,6 +1120,12 @@ describe('lua stdlib', function()
eq('hi', funcs.luaeval "vim.t.testing")
eq(123, funcs.luaeval "vim.t.other")
eq(NIL, funcs.luaeval "vim.t.nonexistant")
+ eq('hi', funcs.luaeval "vim.t[0].testing")
+ eq(123, funcs.luaeval "vim.t[0].other")
+ eq(NIL, funcs.luaeval "vim.t[0].nonexistant")
+
+ matches([[^Error executing lua: .*: attempt to index .* nil value]],
+ pcall_err(exec_lua, 'return vim.t[0][0].testing'))
eq({hello="world"}, funcs.luaeval "vim.t.to_delete")
exec_lua [[
@@ -1096,6 +1154,8 @@ describe('lua stdlib', function()
eq(funcs.luaeval "vim.api.nvim_get_vvar('progpath')", funcs.luaeval "vim.v.progpath")
eq(false, funcs.luaeval "vim.v['false']")
eq(NIL, funcs.luaeval "vim.v.null")
+ matches([[^Error executing lua: .*: attempt to index .* nil value]],
+ pcall_err(exec_lua, 'return vim.v[0].progpath'))
end)
it('vim.bo', function()
@@ -2030,6 +2090,8 @@ describe('lua stdlib', function()
-- Would wait ten seconds if results blocked.
wait_result = vim.wait(10000, function() return vim.g.timer_result end)
+ timer:close()
+
return {
time = (start_time + 5) > get_time(),
wait_result = wait_result,
@@ -2049,6 +2111,8 @@ describe('lua stdlib', function()
wait_result = vim.wait(300, function() return vim.g.timer_result end, nil, true)
+ timer:close()
+
return {
wait_result = wait_result,
}
diff --git a/test/functional/plugin/lsp/codelens_spec.lua b/test/functional/plugin/lsp/codelens_spec.lua
index c8b75e65fc..ecc2f579b8 100644
--- a/test/functional/plugin/lsp/codelens_spec.lua
+++ b/test/functional/plugin/lsp/codelens_spec.lua
@@ -60,31 +60,4 @@ describe('vim.lsp.codelens', function()
eq({[1] = {'Lens1', 'LspCodeLens'}}, virtual_text_chunks)
end)
- it('codelens uses client commands', function()
- local fake_uri = "file:///fake/uri"
- local cmd = exec_lua([[
- fake_uri = ...
- local bufnr = vim.uri_to_bufnr(fake_uri)
- vim.fn.bufload(bufnr)
- vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, {'One line'})
- local lenses = {
- {
- range = {
- start = { line = 0, character = 0, },
- ['end'] = { line = 0, character = 8 }
- },
- command = { title = 'Lens1', command = 'Dummy' }
- },
- }
- vim.lsp.codelens.on_codelens(nil, lenses, {method='textDocument/codeLens', client_id=1, bufnr=bufnr})
- local cmd_called = nil
- vim.lsp.commands['Dummy'] = function(command)
- cmd_called = command
- end
- vim.api.nvim_set_current_buf(bufnr)
- vim.lsp.codelens.run()
- return cmd_called
- ]], fake_uri)
- eq({ command = 'Dummy', title = 'Lens1' }, cmd)
- end)
end)
diff --git a/test/functional/plugin/lsp/diagnostic_spec.lua b/test/functional/plugin/lsp/diagnostic_spec.lua
index 243ad6bdb8..1269a2350c 100644
--- a/test/functional/plugin/lsp/diagnostic_spec.lua
+++ b/test/functional/plugin/lsp/diagnostic_spec.lua
@@ -3,7 +3,6 @@ local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
local exec_lua = helpers.exec_lua
local eq = helpers.eq
-local nvim = helpers.nvim
describe('vim.lsp.diagnostic', function()
local fake_uri
@@ -45,11 +44,32 @@ describe('vim.lsp.diagnostic', function()
}
end
- count_of_extmarks_for_client = function(bufnr, client_id)
- return #vim.api.nvim_buf_get_extmarks(
- bufnr, vim.lsp.diagnostic.get_namespace(client_id), 0, -1, {}
- )
+ function get_extmarks(bufnr, client_id)
+ local namespace = vim.lsp.diagnostic.get_namespace(client_id)
+ local ns = vim.diagnostic.get_namespace(namespace)
+ local extmarks = {}
+ if ns.user_data.virt_text_ns then
+ for _, e in pairs(vim.api.nvim_buf_get_extmarks(bufnr, ns.user_data.virt_text_ns, 0, -1, {details=true})) do
+ table.insert(extmarks, e)
+ end
+ end
+ if ns.user_data.underline_ns then
+ for _, e in pairs(vim.api.nvim_buf_get_extmarks(bufnr, ns.user_data.underline_ns, 0, -1, {details=true})) do
+ table.insert(extmarks, e)
+ end
+ end
+ return extmarks
end
+
+ client_id = vim.lsp.start_client {
+ cmd_env = {
+ NVIM_LUA_NOTRACK = "1";
+ };
+ cmd = {
+ vim.v.progpath, '-es', '-u', 'NONE', '--headless'
+ };
+ offset_encoding = "utf-16";
+ }
]]
fake_uri = "file:///fake/uri"
@@ -69,366 +89,6 @@ describe('vim.lsp.diagnostic', function()
end)
describe('vim.lsp.diagnostic', function()
- describe('handle_publish_diagnostics', function()
- it('should be able to retrieve diagnostics from all buffers and clients', function()
- local result = exec_lua [[
- vim.lsp.diagnostic.save(
- {
- make_error('Diagnostic #1', 1, 1, 1, 1),
- make_error('Diagnostic #2', 2, 1, 2, 1),
- }, 1, 1
- )
- vim.lsp.diagnostic.save(
- {
- make_error('Diagnostic #3', 3, 1, 3, 1),
- }, 2, 2
- )
- return vim.lsp.diagnostic.get_all()
- ]]
- eq(2, #result)
- eq(2, #result[1])
- eq('Diagnostic #1', result[1][1].message)
- end)
- it('should be able to save and count a single client error', function()
- eq(1, exec_lua [[
- vim.lsp.diagnostic.save(
- {
- make_error('Diagnostic #1', 1, 1, 1, 1),
- }, 0, 1
- )
- return vim.lsp.diagnostic.get_count(0, "Error", 1)
- ]])
- end)
-
- it('should be able to save and count from two clients', function()
- eq(2, exec_lua [[
- vim.lsp.diagnostic.save(
- {
- make_error('Diagnostic #1', 1, 1, 1, 1),
- make_error('Diagnostic #2', 2, 1, 2, 1),
- }, 0, 1
- )
- return vim.lsp.diagnostic.get_count(0, "Error", 1)
- ]])
- end)
-
- it('should be able to save and count from multiple clients', function()
- eq({1, 1, 2}, exec_lua [[
- vim.lsp.diagnostic.save(
- {
- make_error('Diagnostic From Server 1', 1, 1, 1, 1),
- }, 0, 1
- )
- vim.lsp.diagnostic.save(
- {
- make_error('Diagnostic From Server 2', 1, 1, 1, 1),
- }, 0, 2
- )
- return {
- -- Server 1
- vim.lsp.diagnostic.get_count(0, "Error", 1),
- -- Server 2
- vim.lsp.diagnostic.get_count(0, "Error", 2),
- -- All servers
- vim.lsp.diagnostic.get_count(0, "Error", nil),
- }
- ]])
- end)
-
- it('should be able to save and count from multiple clients with respect to severity', function()
- eq({3, 0, 3}, exec_lua [[
- vim.lsp.diagnostic.save(
- {
- make_error('Diagnostic From Server 1:1', 1, 1, 1, 1),
- make_error('Diagnostic From Server 1:2', 2, 2, 2, 2),
- make_error('Diagnostic From Server 1:3', 2, 3, 3, 2),
- }, 0, 1
- )
- vim.lsp.diagnostic.save(
- {
- make_warning('Warning From Server 2', 3, 3, 3, 3),
- }, 0, 2
- )
- return {
- -- Server 1
- vim.lsp.diagnostic.get_count(0, "Error", 1),
- -- Server 2
- vim.lsp.diagnostic.get_count(0, "Error", 2),
- -- All servers
- vim.lsp.diagnostic.get_count(0, "Error", nil),
- }
- ]])
- end)
- it('should handle one server clearing highlights while the other still has highlights', function()
- -- 1 Error (1)
- -- 1 Warning (2)
- -- 1 Warning (2) + 1 Warning (1)
- -- 2 highlights and 2 underlines (since error)
- -- 1 highlight + 1 underline
- local all_highlights = {1, 1, 2, 4, 2}
- eq(all_highlights, exec_lua [[
- local server_1_diags = {
- make_error("Error 1", 1, 1, 1, 5),
- make_warning("Warning on Server 1", 2, 1, 2, 5),
- }
- local server_2_diags = {
- make_warning("Warning 1", 2, 1, 2, 5),
- }
-
- vim.lsp.diagnostic.on_publish_diagnostics(nil, { uri = fake_uri, diagnostics = server_1_diags }, {client_id=1})
- vim.lsp.diagnostic.on_publish_diagnostics(nil, { uri = fake_uri, diagnostics = server_2_diags }, {client_id=2})
- return {
- vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Error", 1),
- vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Warning", 2),
- vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Warning", nil),
- count_of_extmarks_for_client(diagnostic_bufnr, 1),
- count_of_extmarks_for_client(diagnostic_bufnr, 2),
- }
- ]])
-
- -- Clear diagnostics from server 1, and make sure we have the right amount of stuff for client 2
- eq({1, 1, 2, 0, 2}, exec_lua [[
- vim.lsp.diagnostic.disable(diagnostic_bufnr, 1)
- return {
- vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Error", 1),
- vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Warning", 2),
- vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Warning", nil),
- count_of_extmarks_for_client(diagnostic_bufnr, 1),
- count_of_extmarks_for_client(diagnostic_bufnr, 2),
- }
- ]])
-
- -- Show diagnostics from server 1 again
- eq(all_highlights, exec_lua([[
- vim.lsp.diagnostic.enable(diagnostic_bufnr, 1)
- return {
- vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Error", 1),
- vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Warning", 2),
- vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Warning", nil),
- count_of_extmarks_for_client(diagnostic_bufnr, 1),
- count_of_extmarks_for_client(diagnostic_bufnr, 2),
- }
- ]]))
- end)
-
- it('should not display diagnostics when disabled', function()
- eq({0, 2}, exec_lua [[
- local server_1_diags = {
- make_error("Error 1", 1, 1, 1, 5),
- make_warning("Warning on Server 1", 2, 1, 2, 5),
- }
- local server_2_diags = {
- make_warning("Warning 1", 2, 1, 2, 5),
- }
-
- vim.lsp.diagnostic.on_publish_diagnostics(nil, { uri = fake_uri, diagnostics = server_1_diags }, {client_id=1})
- vim.lsp.diagnostic.on_publish_diagnostics(nil, { uri = fake_uri, diagnostics = server_2_diags }, {client_id=2})
-
- vim.lsp.diagnostic.disable(diagnostic_bufnr, 1)
-
- return {
- count_of_extmarks_for_client(diagnostic_bufnr, 1),
- count_of_extmarks_for_client(diagnostic_bufnr, 2),
- }
- ]])
-
- eq({4, 0}, exec_lua [[
- vim.lsp.diagnostic.enable(diagnostic_bufnr, 1)
- vim.lsp.diagnostic.disable(diagnostic_bufnr, 2)
-
- return {
- count_of_extmarks_for_client(diagnostic_bufnr, 1),
- count_of_extmarks_for_client(diagnostic_bufnr, 2),
- }
- ]])
- end)
-
- describe('reset', function()
- it('diagnostic count is 0 and displayed diagnostics are 0 after call', function()
- -- 1 Error (1)
- -- 1 Warning (2)
- -- 1 Warning (2) + 1 Warning (1)
- -- 2 highlights and 2 underlines (since error)
- -- 1 highlight + 1 underline
- local all_highlights = {1, 1, 2, 4, 2}
- eq(all_highlights, exec_lua [[
- local server_1_diags = {
- make_error("Error 1", 1, 1, 1, 5),
- make_warning("Warning on Server 1", 2, 1, 2, 5),
- }
- local server_2_diags = {
- make_warning("Warning 1", 2, 1, 2, 5),
- }
-
- vim.lsp.diagnostic.on_publish_diagnostics(nil, { uri = fake_uri, diagnostics = server_1_diags }, {client_id=1})
- vim.lsp.diagnostic.on_publish_diagnostics(nil, { uri = fake_uri, diagnostics = server_2_diags }, {client_id=2})
- return {
- vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Error", 1),
- vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Warning", 2),
- vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Warning", nil),
- count_of_extmarks_for_client(diagnostic_bufnr, 1),
- count_of_extmarks_for_client(diagnostic_bufnr, 2),
- }
- ]])
-
- -- Reset diagnostics from server 1
- exec_lua([[ vim.lsp.diagnostic.reset(1, { [ diagnostic_bufnr ] = { [ 1 ] = true ; [ 2 ] = true } } )]])
-
- -- Make sure we have the right diagnostic count
- eq({0, 1, 1, 0, 2} , exec_lua [[
- local diagnostic_count = {}
- vim.wait(100, function () diagnostic_count = {
- vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Error", 1),
- vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Warning", 2),
- vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Warning", nil),
- count_of_extmarks_for_client(diagnostic_bufnr, 1),
- count_of_extmarks_for_client(diagnostic_bufnr, 2),
- } end )
- return diagnostic_count
- ]])
-
- -- Reset diagnostics from server 2
- exec_lua([[ vim.lsp.diagnostic.reset(2, { [ diagnostic_bufnr ] = { [ 1 ] = true ; [ 2 ] = true } } )]])
-
- -- Make sure we have the right diagnostic count
- eq({0, 0, 0, 0, 0}, exec_lua [[
- local diagnostic_count = {}
- vim.wait(100, function () diagnostic_count = {
- vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Error", 1),
- vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Warning", 2),
- vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Warning", nil),
- count_of_extmarks_for_client(diagnostic_bufnr, 1),
- count_of_extmarks_for_client(diagnostic_bufnr, 2),
- } end )
- return diagnostic_count
- ]])
-
- end)
- end)
-
- describe('get_next_diagnostic_pos', function()
- it('can find the next pos with only one client', function()
- eq({1, 1}, exec_lua [[
- vim.lsp.diagnostic.save(
- {
- make_error('Diagnostic #1', 1, 1, 1, 1),
- }, diagnostic_bufnr, 1
- )
- vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
- return vim.lsp.diagnostic.get_next_pos()
- ]])
- end)
-
- it('can find next pos with two errors', function()
- eq({4, 4}, exec_lua [[
- vim.lsp.diagnostic.save(
- {
- make_error('Diagnostic #1', 1, 1, 1, 1),
- make_error('Diagnostic #2', 4, 4, 4, 4),
- }, diagnostic_bufnr, 1
- )
- vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
- vim.api.nvim_win_set_cursor(0, {3, 1})
- return vim.lsp.diagnostic.get_next_pos { client_id = 1 }
- ]])
- end)
-
- it('can cycle when position is past error', function()
- eq({1, 1}, exec_lua [[
- vim.lsp.diagnostic.save(
- {
- make_error('Diagnostic #1', 1, 1, 1, 1),
- }, diagnostic_bufnr, 1
- )
- vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
- vim.api.nvim_win_set_cursor(0, {3, 1})
- return vim.lsp.diagnostic.get_next_pos { client_id = 1 }
- ]])
- end)
-
- it('will not cycle when wrap is off', function()
- eq(false, exec_lua [[
- vim.lsp.diagnostic.save(
- {
- make_error('Diagnostic #1', 1, 1, 1, 1),
- }, diagnostic_bufnr, 1
- )
- vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
- vim.api.nvim_win_set_cursor(0, {3, 1})
- return vim.lsp.diagnostic.get_next_pos { client_id = 1, wrap = false }
- ]])
- end)
-
- it('can cycle even from the last line', function()
- eq({4, 4}, exec_lua [[
- vim.lsp.diagnostic.save(
- {
- make_error('Diagnostic #2', 4, 4, 4, 4),
- }, diagnostic_bufnr, 1
- )
- vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
- vim.api.nvim_win_set_cursor(0, {vim.api.nvim_buf_line_count(0), 1})
- return vim.lsp.diagnostic.get_prev_pos { client_id = 1 }
- ]])
- end)
- end)
-
- describe('get_prev_diagnostic_pos', function()
- it('can find the prev pos with only one client', function()
- eq({1, 1}, exec_lua [[
- vim.lsp.diagnostic.save(
- {
- make_error('Diagnostic #1', 1, 1, 1, 1),
- }, diagnostic_bufnr, 1
- )
- vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
- vim.api.nvim_win_set_cursor(0, {3, 1})
- return vim.lsp.diagnostic.get_prev_pos()
- ]])
- end)
-
- it('can find prev pos with two errors', function()
- eq({1, 1}, exec_lua [[
- vim.lsp.diagnostic.save(
- {
- make_error('Diagnostic #1', 1, 1, 1, 1),
- make_error('Diagnostic #2', 4, 4, 4, 4),
- }, diagnostic_bufnr, 1
- )
- vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
- vim.api.nvim_win_set_cursor(0, {3, 1})
- return vim.lsp.diagnostic.get_prev_pos { client_id = 1 }
- ]])
- end)
-
- it('can cycle when position is past error', function()
- eq({4, 4}, exec_lua [[
- vim.lsp.diagnostic.save(
- {
- make_error('Diagnostic #2', 4, 4, 4, 4),
- }, diagnostic_bufnr, 1
- )
- vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
- vim.api.nvim_win_set_cursor(0, {3, 1})
- return vim.lsp.diagnostic.get_prev_pos { client_id = 1 }
- ]])
- end)
-
- it('respects wrap parameter', function()
- eq(false, exec_lua [[
- vim.lsp.diagnostic.save(
- {
- make_error('Diagnostic #2', 4, 4, 4, 4),
- }, diagnostic_bufnr, 1
- )
- vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
- vim.api.nvim_win_set_cursor(0, {3, 1})
- return vim.lsp.diagnostic.get_prev_pos { client_id = 1, wrap = false}
- ]])
- end)
- end)
- end)
-
it('maintains LSP information when translating diagnostics', function()
local result = exec_lua [[
local diagnostics = {
@@ -442,7 +102,7 @@ describe('vim.lsp.diagnostic', function()
vim.lsp.diagnostic.on_publish_diagnostics(nil, {
uri = fake_uri,
diagnostics = diagnostics,
- }, {client_id=1})
+ }, {client_id=client_id})
return {
vim.diagnostic.get(diagnostic_bufnr, {lnum=1})[1],
@@ -456,246 +116,7 @@ describe('vim.lsp.diagnostic', function()
end)
end)
- describe("vim.lsp.diagnostic.get_line_diagnostics", function()
- it('should return an empty table when no diagnostics are present', function()
- eq({}, exec_lua [[return vim.lsp.diagnostic.get_line_diagnostics(diagnostic_bufnr, 1)]])
- end)
-
- it('should return all diagnostics when no severity is supplied', function()
- eq(2, exec_lua [[
- vim.lsp.diagnostic.on_publish_diagnostics(nil, {
- uri = fake_uri,
- diagnostics = {
- make_error("Error 1", 1, 1, 1, 5),
- make_warning("Warning on Server 1", 1, 1, 2, 5),
- make_error("Error On Other Line", 2, 1, 1, 5),
- }
- }, {client_id=1})
-
- return #vim.lsp.diagnostic.get_line_diagnostics(diagnostic_bufnr, 1)
- ]])
- end)
-
- it('should return only requested diagnostics when severity_limit is supplied', function()
- eq(2, exec_lua [[
- vim.lsp.diagnostic.on_publish_diagnostics(nil, {
- uri = fake_uri,
- diagnostics = {
- make_error("Error 1", 1, 1, 1, 5),
- make_warning("Warning on Server 1", 1, 1, 2, 5),
- make_information("Ignored information", 1, 1, 2, 5),
- make_error("Error On Other Line", 2, 1, 1, 5),
- }
- }, {client_id=1})
-
- return #vim.lsp.diagnostic.get_line_diagnostics(diagnostic_bufnr, 1, { severity_limit = "Warning" })
- ]])
- end)
- end)
-
describe("vim.lsp.diagnostic.on_publish_diagnostics", function()
- it('can use functions for config values', function()
- exec_lua [[
- vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
- virtual_text = function() return true end,
- })(nil, {
- uri = fake_uri,
- diagnostics = {
- make_error('Delayed Diagnostic', 4, 4, 4, 4),
- }
- }, {client_id=1}
- )
- ]]
-
- eq(1, exec_lua [[return vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Error", 1)]])
- eq(2, exec_lua [[return count_of_extmarks_for_client(diagnostic_bufnr, 1)]])
-
- -- Now, don't enable virtual text.
- -- We should have one less extmark displayed.
- exec_lua [[
- vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
- virtual_text = function() return false end,
- })(nil, {
- uri = fake_uri,
- diagnostics = {
- make_error('Delayed Diagnostic', 4, 4, 4, 4),
- }
- }, {client_id=1}
- )
- ]]
-
- eq(1, exec_lua [[return vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Error", 1)]])
- eq(1, exec_lua [[return count_of_extmarks_for_client(diagnostic_bufnr, 1)]])
- end)
-
- it('can perform updates after insert_leave', function()
- exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]]
- nvim("input", "o")
- eq({mode='i', blocking=false}, nvim("get_mode"))
-
- -- Save the diagnostics
- exec_lua [[
- vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
- update_in_insert = false,
- })(nil, {
- uri = fake_uri,
- diagnostics = {
- make_error('Delayed Diagnostic', 4, 4, 4, 4),
- }
- }, {client_id=1}
- )
- ]]
-
- -- No diagnostics displayed yet.
- eq({mode='i', blocking=false}, nvim("get_mode"))
- eq(1, exec_lua [[return vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Error", 1)]])
- eq(0, exec_lua [[return count_of_extmarks_for_client(diagnostic_bufnr, 1)]])
-
- nvim("input", "<esc>")
- eq({mode='n', blocking=false}, nvim("get_mode"))
-
- eq(1, exec_lua [[return vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Error", 1)]])
- eq(2, exec_lua [[return count_of_extmarks_for_client(diagnostic_bufnr, 1)]])
- end)
-
- it('does not perform updates when not needed', function()
- exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]]
- nvim("input", "o")
- eq({mode='i', blocking=false}, nvim("get_mode"))
-
- -- Save the diagnostics
- exec_lua [[
- PublishDiagnostics = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
- update_in_insert = false,
- virtual_text = true,
- })
-
- -- Count how many times we call display.
- SetVirtualTextOriginal = vim.diagnostic._set_virtual_text
-
- DisplayCount = 0
- vim.diagnostic._set_virtual_text = function(...)
- DisplayCount = DisplayCount + 1
- return SetVirtualTextOriginal(...)
- end
-
- PublishDiagnostics(nil, {
- uri = fake_uri,
- diagnostics = {
- make_error('Delayed Diagnostic', 4, 4, 4, 4),
- }
- }, {client_id=1}
- )
- ]]
-
- -- No diagnostics displayed yet.
- eq({mode='i', blocking=false}, nvim("get_mode"))
- eq(1, exec_lua [[return vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Error", 1)]])
- eq(0, exec_lua [[return count_of_extmarks_for_client(diagnostic_bufnr, 1)]])
- eq(0, exec_lua [[return DisplayCount]])
-
- nvim("input", "<esc>")
- eq({mode='n', blocking=false}, nvim("get_mode"))
-
- eq(1, exec_lua [[return vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Error", 1)]])
- eq(2, exec_lua [[return count_of_extmarks_for_client(diagnostic_bufnr, 1)]])
- eq(1, exec_lua [[return DisplayCount]])
-
- -- Go in and out of insert mode one more time.
- nvim("input", "o")
- eq({mode='i', blocking=false}, nvim("get_mode"))
-
- nvim("input", "<esc>")
- eq({mode='n', blocking=false}, nvim("get_mode"))
-
- -- Should not have set the virtual text again.
- eq(1, exec_lua [[return DisplayCount]])
- end)
-
- it('never sets virtual text, in combination with insert leave', function()
- exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]]
- nvim("input", "o")
- eq({mode='i', blocking=false}, nvim("get_mode"))
-
- -- Save the diagnostics
- exec_lua [[
- PublishDiagnostics = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
- update_in_insert = false,
- virtual_text = false,
- })
-
- -- Count how many times we call display.
- SetVirtualTextOriginal = vim.lsp.diagnostic.set_virtual_text
-
- DisplayCount = 0
- vim.lsp.diagnostic.set_virtual_text = function(...)
- DisplayCount = DisplayCount + 1
- return SetVirtualTextOriginal(...)
- end
-
- PublishDiagnostics(nil, {
- uri = fake_uri,
- diagnostics = {
- make_error('Delayed Diagnostic', 4, 4, 4, 4),
- }
- }, {client_id=1}
- )
- ]]
-
- -- No diagnostics displayed yet.
- eq({mode='i', blocking=false}, nvim("get_mode"))
- eq(1, exec_lua [[return vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Error", 1)]])
- eq(0, exec_lua [[return count_of_extmarks_for_client(diagnostic_bufnr, 1)]])
- eq(0, exec_lua [[return DisplayCount]])
-
- nvim("input", "<esc>")
- eq({mode='n', blocking=false}, nvim("get_mode"))
-
- eq(1, exec_lua [[return vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Error", 1)]])
- eq(1, exec_lua [[return count_of_extmarks_for_client(diagnostic_bufnr, 1)]])
- eq(0, exec_lua [[return DisplayCount]])
-
- -- Go in and out of insert mode one more time.
- nvim("input", "o")
- eq({mode='i', blocking=false}, nvim("get_mode"))
-
- nvim("input", "<esc>")
- eq({mode='n', blocking=false}, nvim("get_mode"))
-
- -- Should not have set the virtual text still.
- eq(0, exec_lua [[return DisplayCount]])
- end)
-
- it('can perform updates while in insert mode, if desired', function()
- exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]]
- nvim("input", "o")
- eq({mode='i', blocking=false}, nvim("get_mode"))
-
- -- Save the diagnostics
- exec_lua [[
- vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
- update_in_insert = true,
- })(nil, {
- uri = fake_uri,
- diagnostics = {
- make_error('Delayed Diagnostic', 4, 4, 4, 4),
- }
- }, {client_id=1}
- )
- ]]
-
- -- Diagnostics are displayed, because the user wanted them that way!
- eq({mode='i', blocking=false}, nvim("get_mode"))
- eq(1, exec_lua [[return vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Error", 1)]])
- eq(2, exec_lua [[return count_of_extmarks_for_client(diagnostic_bufnr, 1)]])
-
- nvim("input", "<esc>")
- eq({mode='n', blocking=false}, nvim("get_mode"))
-
- eq(1, exec_lua [[return vim.lsp.diagnostic.get_count(diagnostic_bufnr, "Error", 1)]])
- eq(2, exec_lua [[return count_of_extmarks_for_client(diagnostic_bufnr, 1)]])
- end)
-
it('allows configuring the virtual text via vim.lsp.with', function()
local expected_spacing = 10
local extmarks = exec_lua([[
@@ -710,16 +131,10 @@ describe('vim.lsp.diagnostic', function()
diagnostics = {
make_error('Delayed Diagnostic', 4, 4, 4, 4),
}
- }, {client_id=1}
+ }, {client_id=client_id}
)
- return vim.api.nvim_buf_get_extmarks(
- diagnostic_bufnr,
- vim.lsp.diagnostic.get_namespace(1),
- 0,
- -1,
- { details = true }
- )
+ return get_extmarks(diagnostic_bufnr, client_id)
]], expected_spacing)
local virt_text = extmarks[1][4].virt_text
@@ -728,7 +143,6 @@ describe('vim.lsp.diagnostic', function()
eq(expected_spacing, #spacing)
end)
-
it('allows configuring the virtual text via vim.lsp.with using a function', function()
local expected_spacing = 10
local extmarks = exec_lua([[
@@ -747,16 +161,10 @@ describe('vim.lsp.diagnostic', function()
diagnostics = {
make_error('Delayed Diagnostic', 4, 4, 4, 4),
}
- }, {client_id=1}
+ }, {client_id=client_id}
)
- return vim.api.nvim_buf_get_extmarks(
- diagnostic_bufnr,
- vim.lsp.diagnostic.get_namespace(1),
- 0,
- -1,
- { details = true }
- )
+ return get_extmarks(diagnostic_bufnr, client_id)
]], expected_spacing)
local virt_text = extmarks[1][4].virt_text
@@ -780,10 +188,10 @@ describe('vim.lsp.diagnostic', function()
diagnostics = {
make_warning('Delayed Diagnostic', 4, 4, 4, 4),
}
- }, {client_id=1}
+ }, {client_id=client_id}
)
- return count_of_extmarks_for_client(diagnostic_bufnr, 1)
+ return #get_extmarks(diagnostic_bufnr, client_id)
]], severity_limit)
end
@@ -799,16 +207,6 @@ describe('vim.lsp.diagnostic', function()
local line = "All 💼 and no 🎉 makes Jack a dull 👦"
local result = exec_lua([[
local line = ...
- local client_id = vim.lsp.start_client {
- cmd_env = {
- NVIM_LUA_NOTRACK = "1";
- };
- cmd = {
- vim.v.progpath, '-es', '-u', 'NONE', '--headless'
- };
- offset_encoding = "utf-16";
- }
-
vim.api.nvim_buf_set_lines(diagnostic_bufnr, 0, -1, false, {line})
vim.lsp.diagnostic.on_publish_diagnostics(nil, {
@@ -829,145 +227,4 @@ describe('vim.lsp.diagnostic', function()
eq(exec_lua([[return vim.str_byteindex(..., 8, true)]], line), result[1].end_col)
end)
end)
-
- describe('lsp.util.show_line_diagnostics', function()
- it('creates floating window and returns popup bufnr and winnr if current line contains diagnostics', function()
- -- Two lines:
- -- Diagnostic:
- -- 1. <msg>
- eq(2, exec_lua [[
- local buffer = vim.api.nvim_create_buf(false, true)
- vim.api.nvim_buf_set_lines(buffer, 0, -1, false, {
- "testing";
- "123";
- })
- local diagnostics = {
- {
- range = {
- start = { line = 0; character = 1; };
- ["end"] = { line = 0; character = 3; };
- };
- severity = vim.lsp.protocol.DiagnosticSeverity.Error;
- message = "Syntax error";
- },
- }
- vim.api.nvim_win_set_buf(0, buffer)
- vim.lsp.diagnostic.save(diagnostics, buffer, 1)
- local popup_bufnr, winnr = vim.lsp.diagnostic.show_line_diagnostics()
- return #vim.api.nvim_buf_get_lines(popup_bufnr, 0, -1, false)
- ]])
- end)
-
- it('creates floating window and returns popup bufnr and winnr without header, if requested', function()
- -- One line (since no header):
- -- 1. <msg>
- eq(1, exec_lua [[
- local buffer = vim.api.nvim_create_buf(false, true)
- vim.api.nvim_buf_set_lines(buffer, 0, -1, false, {
- "testing";
- "123";
- })
- local diagnostics = {
- {
- range = {
- start = { line = 0; character = 1; };
- ["end"] = { line = 0; character = 3; };
- };
- severity = vim.lsp.protocol.DiagnosticSeverity.Error;
- message = "Syntax error";
- },
- }
- vim.api.nvim_win_set_buf(0, buffer)
- vim.lsp.diagnostic.save(diagnostics, buffer, 1)
- local popup_bufnr, winnr = vim.lsp.diagnostic.show_line_diagnostics { show_header = false }
- return #vim.api.nvim_buf_get_lines(popup_bufnr, 0, -1, false)
- ]])
- end)
- end)
-
- describe('set_signs', function()
- -- TODO(tjdevries): Find out why signs are not displayed when set from Lua...??
- pending('sets signs by default', function()
- exec_lua [[
- PublishDiagnostics = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
- update_in_insert = true,
- signs = true,
- })
-
- local diagnostics = {
- make_error('Delayed Diagnostic', 1, 1, 1, 2),
- make_error('Delayed Diagnostic', 3, 3, 3, 3),
- }
-
- vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
- vim.lsp.diagnostic.on_publish_diagnostics(nil, {
- uri = fake_uri,
- diagnostics = diagnostics
- }, {client_id=1}
- )
-
- vim.lsp.diagnostic.set_signs(diagnostics, diagnostic_bufnr, 1)
- -- return vim.fn.sign_getplaced()
- ]]
-
- nvim("input", "o")
- nvim("input", "<esc>")
-
- -- TODO(tjdevries): Find a way to get the signs to display in the test...
- eq(nil, exec_lua [[
- return im.fn.sign_getplaced()[1].signs
- ]])
- end)
- end)
-
- describe('set_loclist()', function()
- it('sets diagnostics in lnum order', function()
- local loc_list = exec_lua [[
- vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
-
- vim.lsp.diagnostic.on_publish_diagnostics(nil, {
- uri = fake_uri,
- diagnostics = {
- make_error('Farther Diagnostic', 4, 4, 4, 4),
- make_error('Lower Diagnostic', 1, 1, 1, 1),
- }
- }, {client_id=1}
- )
-
- vim.lsp.diagnostic.set_loclist()
-
- return vim.fn.getloclist(0)
- ]]
-
- assert(loc_list[1].lnum < loc_list[2].lnum)
- end)
-
- it('sets diagnostics in lnum order, regardless of client', function()
- local loc_list = exec_lua [[
- vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
-
- vim.lsp.diagnostic.on_publish_diagnostics(nil, {
- uri = fake_uri,
- diagnostics = {
- make_error('Lower Diagnostic', 1, 1, 1, 1),
- }
- }, {client_id=1}
- )
-
- vim.lsp.diagnostic.on_publish_diagnostics(nil, {
- uri = fake_uri,
- diagnostics = {
- make_warning('Farther Diagnostic', 4, 4, 4, 4),
- }
- }, {client_id=2}
- )
-
- vim.lsp.diagnostic.set_loclist()
-
- return vim.fn.getloclist(0)
- ]]
-
- assert(loc_list[1].lnum < loc_list[2].lnum)
- end)
- end)
end)
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua
index 81ef8a9733..37fba02e0e 100644
--- a/test/functional/plugin/lsp_spec.lua
+++ b/test/functional/plugin/lsp_spec.lua
@@ -3,9 +3,11 @@ local helpers = require('test.functional.helpers')(after_each)
local assert_log = helpers.assert_log
local clear = helpers.clear
local buf_lines = helpers.buf_lines
+local command = helpers.command
local dedent = helpers.dedent
local exec_lua = helpers.exec_lua
local eq = helpers.eq
+local eval = helpers.eval
local matches = helpers.matches
local pcall_err = helpers.pcall_err
local pesc = helpers.pesc
@@ -272,7 +274,7 @@ describe('LSP', function()
return
end
local expected_handlers = {
- {NIL, {}, {method="shutdown", client_id=1}};
+ {NIL, {}, {method="shutdown", bufnr=1, client_id=1}};
{NIL, {}, {method="test", client_id=1}};
}
test_rpc_server {
@@ -486,7 +488,7 @@ describe('LSP', function()
it('should forward ContentModified to callback', function()
local expected_handlers = {
{NIL, {}, {method="finish", client_id=1}};
- {{code = -32801}, NIL, {method = "error_code_test", client_id=1}};
+ {{code = -32801}, NIL, {method = "error_code_test", bufnr=1, client_id=1}};
}
local client
test_rpc_server {
@@ -509,6 +511,140 @@ describe('LSP', function()
}
end)
+ it('should track pending requests to the language server', function()
+ local expected_handlers = {
+ {NIL, {}, {method="finish", client_id=1}};
+ {NIL, {}, {method="slow_request", bufnr=1, client_id=1}};
+ }
+ local client
+ test_rpc_server {
+ test_name = "check_pending_request_tracked";
+ on_init = function(_client)
+ client = _client
+ client.request("slow_request")
+ local request = exec_lua([=[ return TEST_RPC_CLIENT.requests[2] ]=])
+ eq("slow_request", request.method)
+ eq("pending", request.type)
+ client.notify("release")
+ end;
+ on_exit = function(code, signal)
+ eq(0, code, "exit code", fake_lsp_logfile)
+ eq(0, signal, "exit signal", fake_lsp_logfile)
+ eq(0, #expected_handlers, "did not call expected handler")
+ end;
+ on_handler = function(err, _, ctx)
+ eq(table.remove(expected_handlers), {err, {}, ctx}, "expected handler")
+ if ctx.method == 'slow_request' then
+ local request = exec_lua([=[ return TEST_RPC_CLIENT.requests[2] ]=])
+ eq(NIL, request)
+ client.notify("finish")
+ end
+ if ctx.method == 'finish' then client.stop() end
+ end;
+ }
+ end)
+
+ it('should track cancel requests to the language server', function()
+ local expected_handlers = {
+ {NIL, {}, {method="finish", client_id=1}};
+ }
+ local client
+ test_rpc_server {
+ test_name = "check_cancel_request_tracked";
+ on_init = function(_client)
+ client = _client
+ client.request("slow_request")
+ client.cancel_request(2)
+ local request = exec_lua([=[ return TEST_RPC_CLIENT.requests[2] ]=])
+ eq("slow_request", request.method)
+ eq("cancel", request.type)
+ client.notify("release")
+ end;
+ on_exit = function(code, signal)
+ eq(0, code, "exit code", fake_lsp_logfile)
+ eq(0, signal, "exit signal", fake_lsp_logfile)
+ eq(0, #expected_handlers, "did not call expected handler")
+ end;
+ on_handler = function(err, _, ctx)
+ eq(table.remove(expected_handlers), {err, {}, ctx}, "expected handler")
+ local request = exec_lua([=[ return TEST_RPC_CLIENT.requests[2] ]=])
+ eq(NIL, request)
+ if ctx.method == 'finish' then client.stop() end
+ end;
+ }
+ end)
+
+ it('should clear pending and cancel requests on reply', function()
+ local expected_handlers = {
+ {NIL, {}, {method="finish", client_id=1}};
+ {NIL, {}, {method="slow_request", bufnr=1, client_id=1}};
+ }
+ local client
+ test_rpc_server {
+ test_name = "check_tracked_requests_cleared";
+ on_init = function(_client)
+ client = _client
+ client.request("slow_request")
+ local request = exec_lua([=[ return TEST_RPC_CLIENT.requests[2] ]=])
+ eq("slow_request", request.method)
+ eq("pending", request.type)
+ client.cancel_request(2)
+ request = exec_lua([=[ return TEST_RPC_CLIENT.requests[2] ]=])
+ eq("slow_request", request.method)
+ eq("cancel", request.type)
+ client.notify("release")
+ end;
+ on_exit = function(code, signal)
+ eq(0, code, "exit code", fake_lsp_logfile)
+ eq(0, signal, "exit signal", fake_lsp_logfile)
+ eq(0, #expected_handlers, "did not call expected handler")
+ end;
+ on_handler = function(err, _, ctx)
+ eq(table.remove(expected_handlers), {err, {}, ctx}, "expected handler")
+ if ctx.method == 'slow_request' then
+ local request = exec_lua([=[ return TEST_RPC_CLIENT.requests[2] ]=])
+ eq(NIL, request)
+ client.notify("finish")
+ end
+ if ctx.method == 'finish' then client.stop() end
+ end;
+ }
+ end)
+
+ it('should trigger LspRequest autocmd when requests table changes', function()
+ local expected_handlers = {
+ {NIL, {}, {method="finish", client_id=1}};
+ {NIL, {}, {method="slow_request", bufnr=1, client_id=1}};
+ }
+ local client
+ test_rpc_server {
+ test_name = "check_tracked_requests_cleared";
+ on_init = function(_client)
+ command('let g:requests = 0')
+ command('autocmd User LspRequest let g:requests+=1')
+ client = _client
+ client.request("slow_request")
+ eq(1, eval('g:requests'))
+ client.cancel_request(2)
+ eq(2, eval('g:requests'))
+ client.notify("release")
+ end;
+ on_exit = function(code, signal)
+ eq(0, code, "exit code", fake_lsp_logfile)
+ eq(0, signal, "exit signal", fake_lsp_logfile)
+ eq(0, #expected_handlers, "did not call expected handler")
+ eq(3, eval('g:requests'))
+ end;
+ on_handler = function(err, _, ctx)
+ eq(table.remove(expected_handlers), {err, {}, ctx}, "expected handler")
+ if ctx.method == 'slow_request' then
+ client.notify("finish")
+ end
+ if ctx.method == 'finish' then client.stop() end
+ end;
+ }
+ end)
+
it('should not send didOpen if the buffer closes before init', function()
local expected_handlers = {
{NIL, {}, {method="shutdown", client_id=1}};
@@ -790,7 +926,7 @@ describe('LSP', function()
-- TODO(askhan) we don't support full for now, so we can disable these tests.
pending('should check the body and didChange incremental normal mode editing', function()
local expected_handlers = {
- {NIL, {}, {method="shutdown", client_id=1}};
+ {NIL, {}, {method="shutdown", bufnr=1, client_id=1}};
{NIL, {}, {method="finish", client_id=1}};
{NIL, {}, {method="start", client_id=1}};
}
@@ -1164,10 +1300,11 @@ describe('LSP', function()
eq({ 2, 6 }, funcs.nvim_win_get_cursor(0))
end)
- it('fix the cursor to the valid column if the content was removed', function()
+ it('fix the cursor to the valid col if the content was removed', function()
funcs.nvim_win_set_cursor(0, { 2, 6 })
local edits = {
- make_edit(1, 0, 1, 19, '')
+ make_edit(1, 0, 1, 6, ''),
+ make_edit(1, 6, 1, 19, '')
}
exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1)
eq({
@@ -1180,6 +1317,19 @@ describe('LSP', function()
eq({ 2, 0 }, funcs.nvim_win_get_cursor(0))
end)
+ it('fix the cursor to the valid row if the content was removed', function()
+ funcs.nvim_win_set_cursor(0, { 2, 6 })
+ local edits = {
+ make_edit(1, 0, 1, 6, ''),
+ make_edit(0, 18, 5, 0, '')
+ }
+ exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1)
+ eq({
+ 'First line of text';
+ }, buf_lines(1))
+ eq({ 1, 6 }, funcs.nvim_win_get_cursor(0))
+ end)
+
it('fix the cursor row', function()
funcs.nvim_win_set_cursor(0, { 3, 0 })
local edits = {
@@ -2381,4 +2531,57 @@ describe('LSP', function()
)
end)
end)
+ describe('vim.lsp.codelens', function()
+ it('uses client commands', function()
+ local client
+ local expected_handlers = {
+ {NIL, {}, {method="shutdown", client_id=1}};
+ {NIL, {}, {method="start", client_id=1}};
+ }
+ test_rpc_server {
+ test_name = 'clientside_commands',
+ on_init = function(client_)
+ client = client_
+ end,
+ on_setup = function()
+ end,
+ on_exit = function(code, signal)
+ eq(0, code, "exit code", fake_lsp_logfile)
+ eq(0, signal, "exit signal", fake_lsp_logfile)
+ end,
+ on_handler = function(err, result, ctx)
+ eq(table.remove(expected_handlers), {err, result, ctx})
+ if ctx.method == 'start' then
+ local fake_uri = "file:///fake/uri"
+ local cmd = exec_lua([[
+ fake_uri = ...
+ local bufnr = vim.uri_to_bufnr(fake_uri)
+ vim.fn.bufload(bufnr)
+ vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, {'One line'})
+ local lenses = {
+ {
+ range = {
+ start = { line = 0, character = 0, },
+ ['end'] = { line = 0, character = 8 }
+ },
+ command = { title = 'Lens1', command = 'Dummy' }
+ },
+ }
+ vim.lsp.codelens.on_codelens(nil, lenses, {method='textDocument/codeLens', client_id=1, bufnr=bufnr})
+ local cmd_called = nil
+ vim.lsp.commands['Dummy'] = function(command)
+ cmd_called = command
+ end
+ vim.api.nvim_set_current_buf(bufnr)
+ vim.lsp.codelens.run()
+ return cmd_called
+ ]], fake_uri)
+ eq({ command = 'Dummy', title = 'Lens1' }, cmd)
+ elseif ctx.method == 'shutdown' then
+ client.stop()
+ end
+ end
+ }
+ end)
+ end)
end)
diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua
index 8074f91215..dce6384b9b 100644
--- a/test/functional/ui/decorations_spec.lua
+++ b/test/functional/ui/decorations_spec.lua
@@ -901,15 +901,15 @@ if (h->n_buckets < new_n_buckets) { // expand
screen:expect{grid=[[
if (h->n_buckets < new_n_buckets) { // expand |
khkey_t *new_keys = (khkey_t *) |
+ {1:>> }{2:krealloc}: change the size of an allocation |
{3:krealloc}((void *)h->keys, new_n_buckets * sizeof(k|
hkey_t)); |
h->keys = new_keys; |
if (kh_is_map && val_size) { |
- char *new_vals = {3:krealloc}( h->vals_buf, new_n_|
- buck^ets * val_size); |
+ ^char *new_vals = {3:krealloc}( h->vals_buf, new_n_|
+ buckets * val_size); |
{5:^^ REVIEW:}{6: new_vals variable seems unneccesary?} |
h->vals_buf = new_vals; |
- } |
|
]]}
@@ -992,7 +992,7 @@ if (h->n_buckets < new_n_buckets) { // expand
]]}
end)
- it('works with text et the end of the buffer', function()
+ it('works with text at the end of the buffer', function()
insert(example_text)
feed 'G'
@@ -1213,7 +1213,7 @@ if (h->n_buckets < new_n_buckets) { // expand
|
]]}
- meths.buf_set_extmark(0, ns, 2, 0, {
+ local markid = meths.buf_set_extmark(0, ns, 2, 0, {
virt_lines={
{{"Some special", "Special"}};
{{"remark about codes", "Comment"}};
@@ -1241,6 +1241,7 @@ if (h->n_buckets < new_n_buckets) { // expand
{{"remark about codes", "Comment"}};
};
virt_lines_leftcol=true;
+ id=markid;
})
screen:expect{grid=[[
{8: }{9: 1 }^if (h->n_buckets < new_n_buckets) { // expan|
diff --git a/test/functional/ui/diff_spec.lua b/test/functional/ui/diff_spec.lua
index df750a1a68..13949b0756 100644
--- a/test/functional/ui/diff_spec.lua
+++ b/test/functional/ui/diff_spec.lua
@@ -1196,4 +1196,27 @@ it('Align the filler lines when changing text in diff mode', function()
{8:[No Name] [+] }{3:[No Name] [+] }|
|
]]}
+ feed('<C-W>lay<Esc>')
+ screen:expect{grid=[[
+ {1: }{2:-----------------}{3:│}{1: }{4:6 }|
+ {1: }{2:-----------------}{3:│}{1: }{4:7 }|
+ {1: }{2:-----------------}{3:│}{1: }{4:8 }|
+ {1: }9 {3:│}{1: }9 |
+ {1: }10 {3:│}{1: }10 |
+ {1: }11 {3:│}{1: }11 |
+ {1: }12 {3:│}{1: }12 |
+ {1: }13 {3:│}{1: }13 |
+ {1: }14 {3:│}{1: }14 |
+ {1: }{5:15}{6:x}{5: }{3:│}{1: }{5:15}{6:^y}{5: }|
+ {7:~ }{3:│}{7:~ }|
+ {7:~ }{3:│}{7:~ }|
+ {7:~ }{3:│}{7:~ }|
+ {7:~ }{3:│}{7:~ }|
+ {7:~ }{3:│}{7:~ }|
+ {7:~ }{3:│}{7:~ }|
+ {7:~ }{3:│}{7:~ }|
+ {7:~ }{3:│}{7:~ }|
+ {3:[No Name] [+] }{8:[No Name] [+] }|
+ |
+ ]]}
end)
diff --git a/test/functional/vimscript/executable_spec.lua b/test/functional/vimscript/executable_spec.lua
index 28aefb72e5..048a65188d 100644
--- a/test/functional/vimscript/executable_spec.lua
+++ b/test/functional/vimscript/executable_spec.lua
@@ -18,7 +18,7 @@ describe('executable()', function()
end)
it('fails for invalid values', function()
- for _, input in ipairs({'""', 'v:null', 'v:true', 'v:false', '{}', '[]'}) do
+ for _, input in ipairs({'v:null', 'v:true', 'v:false', '{}', '[]'}) do
eq('Vim(call):E928: String required', exc_exec('call executable('..input..')'))
end
command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")')
@@ -27,6 +27,10 @@ describe('executable()', function()
end
end)
+ it('returns 0 for empty strings', function()
+ eq(0, call('executable', '""'))
+ end)
+
it('returns 0 for non-existent files', function()
eq(0, call('executable', 'no_such_file_exists_209ufq23f'))
end)
diff --git a/test/functional/vimscript/exepath_spec.lua b/test/functional/vimscript/exepath_spec.lua
index 08d2c59af8..bbca954511 100644
--- a/test/functional/vimscript/exepath_spec.lua
+++ b/test/functional/vimscript/exepath_spec.lua
@@ -20,9 +20,10 @@ describe('exepath()', function()
end)
it('fails for invalid values', function()
- for _, input in ipairs({'""', 'v:null', 'v:true', 'v:false', '{}', '[]'}) do
+ for _, input in ipairs({'v:null', 'v:true', 'v:false', '{}', '[]'}) do
eq('Vim(call):E928: String required', exc_exec('call exepath('..input..')'))
end
+ eq('Vim(call):E1142: Non-empty string required', exc_exec('call exepath("")'))
command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")')
for _, input in ipairs({'v:null', 'v:true', 'v:false'}) do
eq('Vim(call):E928: String required', exc_exec('call exepath('..input..')'))
diff --git a/test/functional/vimscript/has_spec.lua b/test/functional/vimscript/has_spec.lua
index a3af2d1a20..c03fd13e0c 100644
--- a/test/functional/vimscript/has_spec.lua
+++ b/test/functional/vimscript/has_spec.lua
@@ -59,7 +59,12 @@ describe('has()', function()
end)
it('"wsl"', function()
- if 1 == funcs.has('win32') or 1 == funcs.has('mac') then
+ local luv = require('luv')
+ local is_wsl =
+ luv.os_uname()['release']:lower():match('microsoft') and true or false
+ if is_wsl then
+ eq(1, funcs.has('wsl'))
+ else
eq(0, funcs.has('wsl'))
end
end)
diff --git a/test/functional/vimscript/null_spec.lua b/test/functional/vimscript/null_spec.lua
index 7ecbcd2fd6..f23f00bcc5 100644
--- a/test/functional/vimscript/null_spec.lua
+++ b/test/functional/vimscript/null_spec.lua
@@ -161,7 +161,7 @@ describe('NULL', function()
null_test('does not crash :echomsg', 'echomsg S', 0)
null_test('does not crash :execute', 'execute S', 0)
null_expr_test('does not crash execute()', 'execute(S)', 0, '')
- null_expr_test('makes executable() error out', 'executable(S)', 'E928: String required', 0)
+ null_expr_test('does not crash executable()', 'executable(S)', 0, 0)
null_expr_test('makes timer_start() error out', 'timer_start(0, S)', 'E921: Invalid callback argument', -1)
null_expr_test('does not crash filereadable()', 'filereadable(S)', 0, 0)
null_expr_test('does not crash filewritable()', 'filewritable(S)', 0, 0)
diff --git a/test/unit/api/private_helpers_spec.lua b/test/unit/api/private_helpers_spec.lua
index a534d83165..dbb4b3ae5a 100644
--- a/test/unit/api/private_helpers_spec.lua
+++ b/test/unit/api/private_helpers_spec.lua
@@ -18,7 +18,7 @@ local type_key = api_helpers.type_key
local obj2lua = api_helpers.obj2lua
local func_type = api_helpers.func_type
-local api = cimport('./src/nvim/api/private/helpers.h')
+local api = cimport('./src/nvim/api/private/helpers.h', './src/nvim/api/private/converter.h')
describe('vim_to_object', function()
local vim_to_object = function(l)
diff --git a/test/unit/marktree_spec.lua b/test/unit/marktree_spec.lua
index cd9c7bef13..10d02d2eb4 100644
--- a/test/unit/marktree_spec.lua
+++ b/test/unit/marktree_spec.lua
@@ -97,7 +97,7 @@ describe('marktree', function()
for i = 1,100 do
for j = 1,100 do
local gravitate = (i%2) > 0
- local id = tonumber(lib.marktree_put(tree, j, i, gravitate))
+ local id = tonumber(lib.marktree_put(tree, j, i, gravitate, 0))
ok(id > 0)
eq(nil, shadow[id])
shadow[id] = {j,i,gravitate}
@@ -191,7 +191,7 @@ describe('marktree', function()
-- https://github.com/neovim/neovim/pull/14719
lib.marktree_clear(tree)
for i = 1,20 do
- lib.marktree_put(tree, i, i, false)
+ lib.marktree_put(tree, i, i, false, 0)
end
lib.marktree_itr_get(tree, 10, 10, iter)