From 1da0f3494eb042c84ae5f00654878f7f8cedf3b7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 11 Mar 2024 22:23:14 +0800 Subject: test: correct order of arguments to eq() (#27816) --- test/functional/plugin/lsp/diagnostic_spec.lua | 10 +++++----- test/functional/plugin/lsp/inlay_hint_spec.lua | 14 +++++++------- test/functional/plugin/lsp_spec.lua | 14 +++++++------- 3 files changed, 19 insertions(+), 19 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp/diagnostic_spec.lua b/test/functional/plugin/lsp/diagnostic_spec.lua index 705c182df7..72531db021 100644 --- a/test/functional/plugin/lsp/diagnostic_spec.lua +++ b/test/functional/plugin/lsp/diagnostic_spec.lua @@ -257,7 +257,7 @@ describe('vim.lsp.diagnostic', function() }, {client_id=client_id}) return vim.fn.bufnr(vim.uri_to_fname("file:///fake/uri2")) ]] - eq(bufnr, -1) + eq(-1, bufnr) -- Create buffer on diagnostics bufnr = exec_lua [[ @@ -269,8 +269,8 @@ describe('vim.lsp.diagnostic', function() }, {client_id=client_id}) return vim.fn.bufnr(vim.uri_to_fname("file:///fake/uri2")) ]] - neq(bufnr, -1) - eq(exec_lua([[return #vim.diagnostic.get(...)]], bufnr), 1) + neq(-1, bufnr) + eq(1, exec_lua([[return #vim.diagnostic.get(...)]], bufnr)) -- Clear diagnostics after buffer was created bufnr = exec_lua [[ @@ -280,8 +280,8 @@ describe('vim.lsp.diagnostic', function() }, {client_id=client_id}) return vim.fn.bufnr(vim.uri_to_fname("file:///fake/uri2")) ]] - neq(bufnr, -1) - eq(exec_lua([[return #vim.diagnostic.get(...)]], bufnr), 0) + neq(-1, bufnr) + eq(0, exec_lua([[return #vim.diagnostic.get(...)]], bufnr)) end) end) diff --git a/test/functional/plugin/lsp/inlay_hint_spec.lua b/test/functional/plugin/lsp/inlay_hint_spec.lua index 192797b312..864394d7e0 100644 --- a/test/functional/plugin/lsp/inlay_hint_spec.lua +++ b/test/functional/plugin/lsp/inlay_hint_spec.lua @@ -169,12 +169,12 @@ describe('vim.lsp.inlay_hint', function() --- @type vim.lsp.inlay_hint.get.ret local res = exec_lua([[return vim.lsp.inlay_hint.get()]]) - eq(res, { + eq({ { bufnr = 1, client_id = 1, inlay_hint = expected[1] }, { bufnr = 1, client_id = 1, inlay_hint = expected[2] }, { bufnr = 1, client_id = 1, inlay_hint = expected[3] }, { bufnr = 1, client_id = 2, inlay_hint = expected2 }, - }) + }, res) --- @type vim.lsp.inlay_hint.get.ret res = exec_lua([[return vim.lsp.inlay_hint.get({ @@ -183,9 +183,9 @@ describe('vim.lsp.inlay_hint', function() ["end"] = { line = 2, character = 10 }, }, })]]) - eq(res, { + eq({ { bufnr = 1, client_id = 2, inlay_hint = expected2 }, - }) + }, res) --- @type vim.lsp.inlay_hint.get.ret res = exec_lua([[return vim.lsp.inlay_hint.get({ @@ -195,16 +195,16 @@ describe('vim.lsp.inlay_hint', function() ["end"] = { line = 5, character = 17 }, }, })]]) - eq(res, { + eq({ { bufnr = 1, client_id = 1, inlay_hint = expected[2] }, { bufnr = 1, client_id = 1, inlay_hint = expected[3] }, - }) + }, res) --- @type vim.lsp.inlay_hint.get.ret res = exec_lua([[return vim.lsp.inlay_hint.get({ bufnr = vim.api.nvim_get_current_buf() + 1, })]]) - eq(res, {}) + eq({}, res) end) end) end) diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 4826153edb..0cb2b88948 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -641,11 +641,11 @@ describe('LSP', function() vim.lsp.stop_client(client_id) return server.messages ]]) - eq(#messages, 4) - eq(messages[1].method, 'initialize') - eq(messages[2].method, 'initialized') - eq(messages[3].method, 'shutdown') - eq(messages[4].method, 'exit') + eq(4, #messages) + eq('initialize', messages[1].method) + eq('initialized', messages[2].method) + eq('shutdown', messages[3].method) + eq('exit', messages[4].method) end) it('BufWritePre sends willSave / willSaveWaitUntil, applies textEdits', function() @@ -4221,7 +4221,7 @@ describe('LSP', function() server:shutdown() return vim.json.decode(init) ]] - eq(result.method, 'initialize') + eq('initialize', result.method) end) it('can connect to lsp server via rpc.domain_socket_connect', function() local tmpfile @@ -4257,7 +4257,7 @@ describe('LSP', function() ]], tmpfile ) - eq(result.method, 'initialize') + eq('initialize', result.method) end) end) -- cgit From 542c910a1d3ffd29b59278b740abd7487315cb47 Mon Sep 17 00:00:00 2001 From: Caleb Marshall Date: Sat, 9 Mar 2024 14:23:25 -0600 Subject: fix(lsp): add missing LSP semantic token highlight links Added the following LSP semantic token types to be linked to highlight groups by default: * @lsp.type.event * @lsp.type.keyword * @lsp.type.modifier * @lsp.type.number * @lsp.type.operator * @lsp.type.regexp * @lsp.type.string --- .../functional/plugin/lsp/semantic_tokens_spec.lua | 75 +++++++++++++++++----- 1 file changed, 60 insertions(+), 15 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp/semantic_tokens_spec.lua b/test/functional/plugin/lsp/semantic_tokens_spec.lua index 77e39c81c8..ad09ab08b3 100644 --- a/test/functional/plugin/lsp/semantic_tokens_spec.lua +++ b/test/functional/plugin/lsp/semantic_tokens_spec.lua @@ -37,6 +37,8 @@ describe('semantic token highlighting', function() [7] = { bold = true, foreground = Screen.colors.DarkCyan }, [8] = { bold = true, foreground = Screen.colors.SlateBlue }, [9] = { bold = true, foreground = tonumber('0x6a0dad') }, + [10] = { bold = true, foreground = Screen.colors.Brown }, + [11] = { foreground = Screen.colors.Magenta1 }, } command([[ hi link @lsp.type.namespace Type ]]) command([[ hi link @lsp.type.function Special ]]) @@ -837,11 +839,13 @@ b = "as"]], { it = 'rust-analyzer', text = [[pub fn main() { - break rust; - /// what? + println!("Hello world!"); + break rust; + /// what? } ]], - response = [[{"data": [0, 0, 3, 1, 0, 0, 4, 2, 1, 0, 0, 3, 4, 14, 524290, 0, 4, 1, 45, 0, 0, 1, 1, 45, 0, 0, 2, 1, 26, 0, 1, 4, 5, 1, 8192, 0, 6, 4, 52, 0, 0, 4, 1, 48, 0, 1, 4, 9, 0, 1, 1, 0, 1, 26, 0], "resultId": "1"}]], + response = [[{"data": [0, 0, 3, 1, 0, 0, 4, 2, 1, 0, 0, 3, 4, 14, 524290, 0, 4, 1, 45, 0, 0, 1, 1, 45, 0, 0, 2, 1, 26, 0, 1, 4, 8, 17, 0, 0, 8, 1, 45, 0, 0, 1, 14, 2, 0, 0, 14, 1, 45, 0, 0, 1, 1, 48, 0, 1, 4, 5, 1, 8192, 0, 6, 4, 52, 0, 0, 4, 1, 48, 0, 1, 4, 9, 0, 1, 1, 0, 1, 26, 0 ], "resultId": "1"}]], + legend = [[{ "tokenTypes": [ "comment", "keyword", "string", "number", "regexp", "operator", "namespace", "type", "struct", "class", "interface", "enum", "enumMember", "typeParameter", "function", "method", "property", "macro", "variable", @@ -904,6 +908,46 @@ b = "as"]], }, { line = 1, + modifiers = {}, + start_col = 4, + end_col = 12, + type = 'macro', -- println! + marked = true, + }, + { + line = 1, + modifiers = {}, + start_col = 12, + end_col = 13, + type = 'parenthesis', + marked = true, + }, + { + line = 1, + modifiers = {}, + start_col = 13, + end_col = 27, + type = 'string', -- "Hello world!" + marked = true, + }, + { + line = 1, + modifiers = {}, + start_col = 27, + end_col = 28, + type = 'parenthesis', + marked = true, + }, + { + line = 1, + modifiers = {}, + start_col = 28, + end_col = 29, + type = 'semicolon', + marked = true, + }, + { + line = 2, modifiers = { controlFlow = true }, start_col = 4, end_col = 9, -- break @@ -911,31 +955,31 @@ b = "as"]], marked = true, }, { - line = 1, + line = 2, modifiers = {}, start_col = 10, - end_col = 13, -- rust + end_col = 14, -- rust type = 'unresolvedReference', marked = true, }, { - line = 1, + line = 2, modifiers = {}, - start_col = 13, - end_col = 13, + start_col = 14, + end_col = 15, type = 'semicolon', marked = true, }, { - line = 2, + line = 3, modifiers = { documentation = true }, start_col = 4, - end_col = 11, + end_col = 13, type = 'comment', -- /// what? marked = true, }, { - line = 3, + line = 4, modifiers = {}, start_col = 0, end_col = 1, @@ -946,12 +990,13 @@ b = "as"]], expected_screen = function() screen:expect { grid = [[ - pub fn {8:main}() { | - break rust; | - //{6:/ what?} | + {10:pub} {10:fn} {8:main}() { | + {5:println!}({11:"Hello world!"}); | + {10:break} rust; | + {6:/// what?} | } | ^ | - {1:~ }|*10 + {1:~ }|*9 | ]], } -- cgit From 77a9f3395bd1e7184f4d735c01e50285e30477ab Mon Sep 17 00:00:00 2001 From: Takuya Tokuda Date: Mon, 18 Mar 2024 05:04:59 +0900 Subject: fix(lsp): create codelens request parameters for each buffer (#27699) --- test/functional/plugin/lsp_spec.lua | 86 +++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 0cb2b88948..f2d8890dd5 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -3879,6 +3879,92 @@ describe('LSP', function() end, } end) + + it('refresh multiple buffers', function() + local lens_title_per_fake_uri = { + ['file:///fake/uri1'] = 'Lens1', + ['file:///fake/uri2'] = 'Lens2', + } + clear() + exec_lua(create_server_definition) + + -- setup lsp + exec_lua( + [[ + local lens_title_per_fake_uri = ... + local server = _create_server({ + capabilities = { + codeLensProvider = { + resolveProvider = true + }, + }, + handlers = { + ["textDocument/codeLens"] = function(method, params) + local lenses = { + { + range = { + start = { line = 0, character = 0 }, + ['end'] = { line = 0, character = 0 }, + }, + command = { + title = lens_title_per_fake_uri[params.textDocument.uri], + command = 'Dummy', + }, + }, + } + return lenses + end, + } + }) + + CLIENT_ID = vim.lsp.start({ + name = "dummy", + cmd = server.cmd, + }) + ]], + lens_title_per_fake_uri + ) + + -- create buffers and setup handler + exec_lua( + [[ + local lens_title_per_fake_uri = ... + local default_buf = vim.api.nvim_get_current_buf() + for fake_uri, _ in pairs(lens_title_per_fake_uri) do + local bufnr = vim.uri_to_bufnr(fake_uri) + vim.api.nvim_set_current_buf(bufnr) + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, {'Some contents'}) + vim.lsp.buf_attach_client(bufnr, CLIENT_ID) + end + vim.api.nvim_buf_delete(default_buf, {force = true}) + + REQUEST_COUNT = vim.tbl_count(lens_title_per_fake_uri) + RESPONSES = {} + local on_codelens = vim.lsp.codelens.on_codelens + vim.lsp.codelens.on_codelens = function (err, result, ctx, ...) + table.insert(RESPONSES, { err = err, result = result, ctx = ctx }) + return on_codelens(err, result, ctx, ...) + end + ]], + lens_title_per_fake_uri + ) + + -- call codelens refresh + local cmds = exec_lua([[ + RESPONSES = {} + vim.lsp.codelens.refresh() + vim.wait(100, function () return #RESPONSES >= REQUEST_COUNT end) + + local cmds = {} + for _, resp in ipairs(RESPONSES) do + local uri = resp.ctx.params.textDocument.uri + cmds[uri] = resp.result[1].command + end + return cmds + ]]) + eq({ command = 'Dummy', title = 'Lens1' }, cmds['file:///fake/uri1']) + eq({ command = 'Dummy', title = 'Lens2' }, cmds['file:///fake/uri2']) + end) end) describe('vim.lsp.buf.format', function() -- cgit From e34c23b7016aee5ac6483ab53fed1bce037cec5a Mon Sep 17 00:00:00 2001 From: En-En <39373446+En-En-Code@users.noreply.github.com> Date: Mon, 18 Mar 2024 11:19:20 +0000 Subject: fix(tutor): set a value for ":syntax iskeyword" (#27833) Problem: "NOTE"s, inline Vim script code, and links ending in digits may not be highlighted correctly within the :Tutor. Solution: set an explicit value for ":syntax iskeyword" that includes digits. Do it after ":syntax include"s, so the included syntax/sh.vim doesn't mess with the value. Increase screen test width so all text within the conclusion section is visible. Co-authored-by: Sean Dewar <6256228+seandewar@users.noreply.github.com> --- test/functional/plugin/tutor_spec.lua | 161 +++++++++++++++++++++------------- 1 file changed, 100 insertions(+), 61 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/tutor_spec.lua b/test/functional/plugin/tutor_spec.lua index 99538e1db0..c3caf5ff16 100644 --- a/test/functional/plugin/tutor_spec.lua +++ b/test/functional/plugin/tutor_spec.lua @@ -12,7 +12,7 @@ describe(':Tutor', function() clear({ args = { '--clean' } }) command('set cmdheight=0') command('Tutor') - screen = Screen.new(80, 30) + screen = Screen.new(81, 30) screen:set_default_attr_ids({ [0] = { foreground = Screen.colors.DarkBlue, background = Screen.colors.Gray }, [1] = { bold = true }, @@ -20,6 +20,7 @@ describe(':Tutor', function() [3] = { foreground = Screen.colors.SlateBlue }, [4] = { bold = true, foreground = Screen.colors.Brown }, [5] = { bold = true, foreground = Screen.colors.Magenta1 }, + [6] = { italic = true }, }) screen:attach() end) @@ -27,71 +28,109 @@ describe(':Tutor', function() it('applies {unix:…,win:…} transform', function() local expected = is_os('win') and [[ - {0: }^ | - {0: } 3. To verify that a file was retrieved, cursor back and notice that there | - {0: } are now two copies of Lesson 5.3, the original and the retrieved version. | - {0: } | - {0: }{1:NOTE}: You can also read the output of an external command. For example, | - {0: } | - {0: } :r {4:!}dir | - {0: } | - {0: } reads the output of the ls command and puts it below the cursor. | - {0: } | - {0: }{3:#}{5: Lesson 5 SUMMARY} | - {0: } | - {0: } 1. {2::!command} executes an external command. | - {0: } | - {0: } Some useful examples are: | - {0: } :{4:!}dir - shows a directory listing | - {0: } :{4:!}del FILENAME - removes file FILENAME | - {0: } | - {0: } 2. {2::w} FILENAME writes the current Neovim file to disk with | - {0: } name FILENAME. | - {0: } | - {0: } 3. {2:v} motion :w FILENAME saves the Visually selected lines in file | - {0: } FILENAME. | - {0: } | - {0: } 4. {2::r} FILENAME retrieves disk file FILENAME and puts it | - {0: } below the cursor position. | - {0: } | - {0: } 5. {2::r !dir} reads the output of the dir command and | - {0: } puts it below the cursor position. | - {0: } | + {0: }^ | + {0: } 3. To verify that a file was retrieved, cursor back and notice that there | + {0: } are now two copies of Lesson 5.3, the original and the retrieved version. | + {0: } | + {0: }{1:NOTE}: You can also read the output of an external command. For example, | + {0: } | + {0: } :r {4:!}dir | + {0: } | + {0: } reads the output of the ls command and puts it below the cursor. | + {0: } | + {0: }{3:#}{5: Lesson 5 SUMMARY} | + {0: } | + {0: } 1. {2::!command} executes an external command. | + {0: } | + {0: } Some useful examples are: | + {0: } :{4:!}dir - shows a directory listing | + {0: } :{4:!}del FILENAME - removes file FILENAME | + {0: } | + {0: } 2. {2::w} FILENAME writes the current Neovim file to disk with | + {0: } name FILENAME. | + {0: } | + {0: } 3. {2:v} motion :w FILENAME saves the Visually selected lines in file | + {0: } FILENAME. | + {0: } | + {0: } 4. {2::r} FILENAME retrieves disk file FILENAME and puts it | + {0: } below the cursor position. | + {0: } | + {0: } 5. {2::r !dir} reads the output of the dir command and | + {0: } puts it below the cursor position. | + {0: } | ]] or [[ - {0: }^ | - {0: } 3. To verify that a file was retrieved, cursor back and notice that there | - {0: } are now two copies of Lesson 5.3, the original and the retrieved version. | - {0: } | - {0: }{1:NOTE}: You can also read the output of an external command. For example, | - {0: } | - {0: } :r {4:!}ls | - {0: } | - {0: } reads the output of the ls command and puts it below the cursor. | - {0: } | - {0: }{3:#}{5: Lesson 5 SUMMARY} | - {0: } | - {0: } 1. {2::!command} executes an external command. | - {0: } | - {0: } Some useful examples are: | - {0: } :{4:!}ls - shows a directory listing | - {0: } :{4:!}rm FILENAME - removes file FILENAME | - {0: } | - {0: } 2. {2::w} FILENAME writes the current Neovim file to disk with | - {0: } name FILENAME. | - {0: } | - {0: } 3. {2:v} motion :w FILENAME saves the Visually selected lines in file | - {0: } FILENAME. | - {0: } | - {0: } 4. {2::r} FILENAME retrieves disk file FILENAME and puts it | - {0: } below the cursor position. | - {0: } | - {0: } 5. {2::r !ls} reads the output of the ls command and | - {0: } puts it below the cursor position. | - {0: } | + {0: }^ | + {0: } 3. To verify that a file was retrieved, cursor back and notice that there | + {0: } are now two copies of Lesson 5.3, the original and the retrieved version. | + {0: } | + {0: }{1:NOTE}: You can also read the output of an external command. For example, | + {0: } | + {0: } :r {4:!}ls | + {0: } | + {0: } reads the output of the ls command and puts it below the cursor. | + {0: } | + {0: }{3:#}{5: Lesson 5 SUMMARY} | + {0: } | + {0: } 1. {2::!command} executes an external command. | + {0: } | + {0: } Some useful examples are: | + {0: } :{4:!}ls - shows a directory listing | + {0: } :{4:!}rm FILENAME - removes file FILENAME | + {0: } | + {0: } 2. {2::w} FILENAME writes the current Neovim file to disk with | + {0: } name FILENAME. | + {0: } | + {0: } 3. {2:v} motion :w FILENAME saves the Visually selected lines in file | + {0: } FILENAME. | + {0: } | + {0: } 4. {2::r} FILENAME retrieves disk file FILENAME and puts it | + {0: } below the cursor position. | + {0: } | + {0: } 5. {2::r !ls} reads the output of the ls command and | + {0: } puts it below the cursor position. | + {0: } | ]] feed(':700zt') screen:expect(expected) end) + + it('applies hyperlink highlighting', function() + local expected = [[ + {0: }^ | + {0: }{3:#}{5: CONCLUSION} | + {0: } | + {0: }This was intended to give a brief overview of the Neovim editor, just enough to| + {0: }allow you to use it fairly easily. It is far from complete as Neovim has | + {0: }many many more commands. Consult the help often. | + {0: }There are also countless great tutorials and videos to be found online. | + {0: }Here's a bunch of them: | + {0: } | + {0: }- {6:Learn Vim Progressively}: | + {0: } {2:https://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/} | + {0: }- {6:Learning Vim in 2014}: | + {0: } {2:https://benmccormick.org/learning-vim-in-2014/} | + {0: }- {6:Vimcasts}: | + {0: } {2:http://vimcasts.org/} | + {0: }- {6:Vim Video-Tutorials by Derek Wyatt}: | + {0: } {2:http://derekwyatt.org/vim/tutorials/} | + {0: }- {6:Learn Vimscript the Hard Way}: | + {0: } {2:https://learnvimscriptthehardway.stevelosh.com/} | + {0: }- {6:7 Habits of Effective Text Editing}: | + {0: } {2:https://www.moolenaar.net/habits.html} | + {0: }- {6:vim-galore}: | + {0: } {2:https://github.com/mhinz/vim-galore} | + {0: } | + {0: }If you prefer a book, {6:Practical Vim} by Drew Neil is recommended often | + {0: }(the sequel, {6:Modern Vim}, includes material specific to Neovim). | + {0: } | + {0: }This tutorial was written by Michael C. Pierce and Robert K. Ware, Colorado | + {0: }School of Mines using ideas supplied by Charles Smith, Colorado State | + {0: }University. E-mail: {2:bware@mines.colorado.edu}. | + ]] + + feed(':960zt') + screen:expect(expected) + end) end) -- cgit From 5de0482d1abfdc0a4ede1b96f729dae38f1c7c56 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 18 Mar 2024 19:49:31 +0800 Subject: test(lsp): fix flaky basic_finish test (#27899) Problem: As mentioned in #23002 on_setup and on_init are run concurrently. However, in basic_finish tests on_setup must attach the client before on_init finishes. The other basic_finish test isn't flaky because it makes an RPC request in on_init. Solution: Don't use on_setup in basic_finish tests. --- test/functional/plugin/lsp_spec.lua | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index f2d8890dd5..d130c74aac 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -282,7 +282,8 @@ describe('LSP', function() local client test_rpc_server { test_name = 'basic_finish', - on_setup = function() + on_init = function(_client) + client = _client exec_lua [[ BUFFER = vim.api.nvim_create_buf(false, true) ]] @@ -291,9 +292,6 @@ describe('LSP', function() exec_lua [[ vim.api.nvim_command(BUFFER.."bwipeout") ]] - end, - on_init = function(_client) - client = _client client.notify('finish') end, on_exit = function(code, signal) @@ -1060,7 +1058,8 @@ describe('LSP', function() local client test_rpc_server { test_name = 'basic_finish', - on_setup = function() + on_init = function(_client) + client = _client exec_lua [[ BUFFER = vim.api.nvim_create_buf(false, true) vim.api.nvim_buf_set_lines(BUFFER, 0, -1, false, { @@ -1074,9 +1073,6 @@ describe('LSP', function() exec_lua [[ vim.api.nvim_command(BUFFER.."bwipeout") ]] - end, - on_init = function(_client) - client = _client local full_kind = exec_lua("return require'vim.lsp.protocol'.TextDocumentSyncKind.Full") eq(full_kind, client.server_capabilities().textDocumentSync.change) eq(true, client.server_capabilities().textDocumentSync.openClose) -- cgit From 0c59771e314d6faaad69676985cd2a11c157ee37 Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 22 Mar 2024 11:02:52 +0100 Subject: refactor(tests): all screen tests should use highlights This is the first installment of a multi-PR series significantly refactoring how highlights are being specified. The end goal is to have a base set of 20 ish most common highlights, and then specific files only need to add more groups to that as needed. As a complicating factor, we also want to migrate to the new default color scheme eventually. But by sharing a base set, that future PR will hopefully be a lot smaller since a lot of tests will be migrated just simply by updating the base set in place. As a first step, fix the anti-pattern than Screen defaults to ignoring highlights. Highlights are integral part of the screen state, not something "extra" which we only test "sometimes". For now, we still allow opt-out via the intentionally ugly screen._default_attr_ids = nil The end goal is to get rid of all of these eventually (which will be easier as part of the color scheme migration) --- test/functional/plugin/health_spec.lua | 61 ++++++++++++++++---------- test/functional/plugin/lsp/inlay_hint_spec.lua | 4 +- 2 files changed, 39 insertions(+), 26 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index 8564ec7c9b..9306180c40 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -166,11 +166,11 @@ describe('health.vim', function() screen:expect { grid = [[ ^ | - ──────────────────────────────────────────────────| - +WE 4 lines: foo: ·······························| - ──────────────────────────────────────────────────| - +-- 8 lines: test_plug.success1: require("test_pl| - ~ | + {14:──────────────────────────────────────────────────}| + {13:+WE 4 lines: foo: ·······························}| + {14:──────────────────────────────────────────────────}| + {13:+-- 8 lines: test_plug.success1: require("test_pl}| + {1:~ }| | ]], } @@ -218,6 +218,12 @@ describe(':checkhealth window', function() it('opens directly if no buffer created', function() local screen = Screen.new(50, 12) + screen:set_default_attr_ids { + [1] = { foreground = Screen.colors.Blue, bold = true }, + [14] = { foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGray }, + [31] = { foreground = tonumber('0x6a0dad') }, + [32] = { foreground = Screen.colors.PaleGreen2 }, + } screen:attach({ ext_multigrid = true }) command('checkhealth success1') screen:expect { @@ -227,16 +233,16 @@ describe(':checkhealth window', function() [3:--------------------------------------------------]| ## grid 2 ^ | - ──────────────────────────────────────────────────| - ──────────────────────────── | - test_plug.success1: require("test_plug.success1. | - health").check() | + {14:──────────────────────────────────────────────────}| + {14:────────────────────────────} | + {31:test_plug.success1: require("test_plug.success1. }| + {31:health").check()} | | - report 1 | - - OK everything is fine | + {31:report 1} | + - {32:OK} everything is fine | | - report 2 | - - OK nothing to see here | + {31:report 2} | + - {32:OK} nothing to see here | ## grid 3 | ]], @@ -245,6 +251,12 @@ describe(':checkhealth window', function() local function test_health_vsplit(left, emptybuf, mods) local screen = Screen.new(50, 20) + screen:set_default_attr_ids { + [1] = { foreground = Screen.colors.Blue, bold = true }, + [14] = { foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGray }, + [31] = { foreground = tonumber('0x6a0dad') }, + [32] = { foreground = Screen.colors.PaleGreen2 }, + } screen:attach({ ext_multigrid = true }) if not emptybuf then insert('hello') @@ -257,24 +269,24 @@ describe(':checkhealth window', function() [3:--------------------------------------------------]| ## grid 2 %s | - ~ |*18 + {1:~ }|*18 ## grid 3 | ## grid 4 ^ | - ─────────────────────────|*3 - ─── | - test_plug.success1: | - require("test_plug. | - success1.health").check()| + {14:─────────────────────────}|*3 + {14:───} | + {31:test_plug.success1: }| + {31:require("test_plug. }| + {31:success1.health").check()}| | - report 1 | - - OK everything is fine | + {31:report 1} | + - {32:OK} everything is fine | | - report 2 | - - OK nothing to see here | + {31:report 2} | + - {32:OK} nothing to see here | | - ~ |*4 + {1:~ }|*4 ]]):format( left and '[4:-------------------------]│[2:------------------------]|*19' or '[2:------------------------]│[4:-------------------------]|*19', @@ -304,6 +316,7 @@ describe(':checkhealth window', function() local function test_health_split(top, emptybuf, mods) local screen = Screen.new(50, 25) screen:attach({ ext_multigrid = true }) + screen._default_attr_ids = nil if not emptybuf then insert('hello') end diff --git a/test/functional/plugin/lsp/inlay_hint_spec.lua b/test/functional/plugin/lsp/inlay_hint_spec.lua index 864394d7e0..b046a2c509 100644 --- a/test/functional/plugin/lsp/inlay_hint_spec.lua +++ b/test/functional/plugin/lsp/inlay_hint_spec.lua @@ -41,12 +41,12 @@ local grid_without_inlay_hints = [[ ]] local grid_with_inlay_hints = [[ - auto add(int a, int b)-> int { return a + b; } | + auto add(int a, int b){1:-> int} { return a + b; } | | int main() { | int x = 1; | int y = 2; | - return add(a: x,b: y); | + return add({1:a:} x,{1:b:} y); | } | ^} | | -- cgit From 3f238b39cfdf27657b2d9452c6ffd28f8209c95f Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Thu, 21 Mar 2024 15:15:20 +0000 Subject: refactor(lsp): simplify client tracking - Remove: - uninitialized_clients - active_clients - all_buffer_active_clients - Add: - all_clients - Use `lsp.get_clients()` to get buffer clients. --- test/functional/plugin/lsp_spec.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index d130c74aac..a8e85bdc37 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -282,8 +282,7 @@ describe('LSP', function() local client test_rpc_server { test_name = 'basic_finish', - on_init = function(_client) - client = _client + on_setup = function() exec_lua [[ BUFFER = vim.api.nvim_create_buf(false, true) ]] @@ -292,6 +291,9 @@ describe('LSP', function() exec_lua [[ vim.api.nvim_command(BUFFER.."bwipeout") ]] + end, + on_init = function(_client) + client = _client client.notify('finish') end, on_exit = function(code, signal) @@ -806,14 +808,12 @@ describe('LSP', function() BUFFER = vim.api.nvim_get_current_buf() lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID) vim.lsp.handlers['textDocument/typeDefinition'] = function() end + vim.cmd(BUFFER.."bwipeout") ]=]) end, on_init = function(client) client.stop() exec_lua('vim.lsp.buf.type_definition()') - exec_lua [[ - vim.api.nvim_command(BUFFER.."bwipeout") - ]] end, on_exit = function(code, signal) eq(0, code, 'exit code') @@ -1058,8 +1058,7 @@ describe('LSP', function() local client test_rpc_server { test_name = 'basic_finish', - on_init = function(_client) - client = _client + on_setup = function() exec_lua [[ BUFFER = vim.api.nvim_create_buf(false, true) vim.api.nvim_buf_set_lines(BUFFER, 0, -1, false, { @@ -1073,6 +1072,9 @@ describe('LSP', function() exec_lua [[ vim.api.nvim_command(BUFFER.."bwipeout") ]] + end, + on_init = function(_client) + client = _client local full_kind = exec_lua("return require'vim.lsp.protocol'.TextDocumentSyncKind.Full") eq(full_kind, client.server_capabilities().textDocumentSync.change) eq(true, client.server_capabilities().textDocumentSync.openClose) -- cgit From 934f38682afd5925df675485b96ac9a2d3b8dd57 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 25 Mar 2024 20:16:42 +0000 Subject: Revert "refactor(lsp): simplify client tracking" This reverts commit 3f238b39cfdf27657b2d9452c6ffd28f8209c95f. --- test/functional/plugin/lsp_spec.lua | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index a8e85bdc37..d130c74aac 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -282,7 +282,8 @@ describe('LSP', function() local client test_rpc_server { test_name = 'basic_finish', - on_setup = function() + on_init = function(_client) + client = _client exec_lua [[ BUFFER = vim.api.nvim_create_buf(false, true) ]] @@ -291,9 +292,6 @@ describe('LSP', function() exec_lua [[ vim.api.nvim_command(BUFFER.."bwipeout") ]] - end, - on_init = function(_client) - client = _client client.notify('finish') end, on_exit = function(code, signal) @@ -808,12 +806,14 @@ describe('LSP', function() BUFFER = vim.api.nvim_get_current_buf() lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID) vim.lsp.handlers['textDocument/typeDefinition'] = function() end - vim.cmd(BUFFER.."bwipeout") ]=]) end, on_init = function(client) client.stop() exec_lua('vim.lsp.buf.type_definition()') + exec_lua [[ + vim.api.nvim_command(BUFFER.."bwipeout") + ]] end, on_exit = function(code, signal) eq(0, code, 'exit code') @@ -1058,7 +1058,8 @@ describe('LSP', function() local client test_rpc_server { test_name = 'basic_finish', - on_setup = function() + on_init = function(_client) + client = _client exec_lua [[ BUFFER = vim.api.nvim_create_buf(false, true) vim.api.nvim_buf_set_lines(BUFFER, 0, -1, false, { @@ -1072,9 +1073,6 @@ describe('LSP', function() exec_lua [[ vim.api.nvim_command(BUFFER.."bwipeout") ]] - end, - on_init = function(_client) - client = _client local full_kind = exec_lua("return require'vim.lsp.protocol'.TextDocumentSyncKind.Full") eq(full_kind, client.server_capabilities().textDocumentSync.change) eq(true, client.server_capabilities().textDocumentSync.openClose) -- cgit From a7bbda121d035d050b449b4dc63bd6ae027e248d Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 25 Mar 2024 19:06:28 +0000 Subject: fix(test): typing --- test/functional/plugin/editorconfig_spec.lua | 2 + test/functional/plugin/lsp/helpers.lua | 13 ++ test/functional/plugin/lsp_spec.lua | 230 +++++++++++++-------------- test/functional/plugin/man_spec.lua | 16 +- test/functional/plugin/matchparen_spec.lua | 2 +- test/functional/plugin/tutor_spec.lua | 2 +- test/functional/plugin/vim_syntax_spec.lua | 2 +- 7 files changed, 133 insertions(+), 134 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/editorconfig_spec.lua b/test/functional/plugin/editorconfig_spec.lua index 115c28fbf6..c8151d2005 100644 --- a/test/functional/plugin/editorconfig_spec.lua +++ b/test/functional/plugin/editorconfig_spec.lua @@ -9,6 +9,8 @@ local exec_lua = helpers.exec_lua local testdir = 'Xtest-editorconfig' +--- @param name string +--- @param expected table local function test_case(name, expected) local filename = testdir .. pathsep .. name command('edit ' .. filename) diff --git a/test/functional/plugin/lsp/helpers.lua b/test/functional/plugin/lsp/helpers.lua index 97fa108500..376de66c51 100644 --- a/test/functional/plugin/lsp/helpers.lua +++ b/test/functional/plugin/lsp/helpers.lua @@ -128,6 +128,18 @@ local function fake_lsp_server_setup(test_name, timeout_ms, options, settings) ) end +--- @class test.lsp.Config +--- @field test_name string +--- @field timeout_ms? integer +--- @field options? table +--- @field settings? table +--- +--- @field on_setup? fun() +--- @field on_init? fun(client: vim.lsp.Client, ...) +--- @field on_handler? fun(...) +--- @field on_exit? fun(code: integer, signal: integer) + +--- @param config test.lsp.Config function M.test_rpc_server(config) if config.test_name then M.clear_notrace() @@ -158,6 +170,7 @@ function M.test_rpc_server(config) end end, }) + --- @type integer, integer local code, signal local function on_request(method, args) if method == 'init' then diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index d130c74aac..4437c4aeaa 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -17,8 +17,8 @@ local fn = helpers.fn local retry = helpers.retry local stop = helpers.stop local NIL = vim.NIL -local read_file = require('test.helpers').read_file -local write_file = require('test.helpers').write_file +local read_file = helpers.read_file +local write_file = helpers.write_file local is_ci = helpers.is_ci local api = helpers.api local is_os = helpers.is_os @@ -279,7 +279,7 @@ describe('LSP', function() { NIL, {}, { method = 'shutdown', client_id = 1 } }, { NIL, {}, { method = 'finish', client_id = 1 } }, } - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'basic_finish', on_init = function(_client) @@ -310,7 +310,7 @@ describe('LSP', function() end) it('should fire autocommands on attach and detach', function() - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'basic_init', on_setup = function() @@ -347,7 +347,7 @@ describe('LSP', function() end) it('should set default options on attach', function() - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'set_defaults_all_capabilities', on_init = function(_client) @@ -395,7 +395,7 @@ describe('LSP', function() end) it('should overwrite options set by ftplugins', function() - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'set_defaults_all_capabilities', on_init = function(_client) @@ -435,7 +435,7 @@ describe('LSP', function() end) it('should not overwrite user-defined options', function() - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'set_defaults_all_capabilities', on_init = function(_client) @@ -506,7 +506,7 @@ describe('LSP', function() }, { NIL, {}, { method = 'start', client_id = 1 } }, } - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'check_workspace_configuration', on_init = function(_client) @@ -596,7 +596,7 @@ describe('LSP', function() { NIL, {}, { method = 'shutdown', client_id = 1 } }, { NIL, {}, { method = 'start', client_id = 1 } }, } - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'text_document_sync_save_bool', on_init = function(c) @@ -690,7 +690,7 @@ describe('LSP', function() { NIL, {}, { method = 'shutdown', client_id = 1 } }, { NIL, {}, { method = 'start', client_id = 1 } }, } - local client + local client --- @type vim.lsp.Client test_rpc_server({ test_name = 'text_document_save_did_open', on_init = function(c) @@ -730,7 +730,7 @@ describe('LSP', function() { NIL, {}, { method = 'shutdown', client_id = 1 } }, { NIL, {}, { method = 'start', client_id = 1 } }, } - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'text_document_sync_save_includeText', on_init = function(c) @@ -857,7 +857,7 @@ describe('LSP', function() local expected_handlers = { { NIL, {}, { method = 'finish', client_id = 1 } }, } - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'check_forward_request_cancelled', on_init = function(_client) @@ -883,7 +883,7 @@ describe('LSP', function() { NIL, {}, { method = 'finish', client_id = 1 } }, { { code = -32801 }, NIL, { method = 'error_code_test', bufnr = 1, client_id = 1 } }, } - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'check_forward_content_modified', on_init = function(_client) @@ -913,7 +913,7 @@ describe('LSP', function() { NIL, {}, { method = 'finish', client_id = 1 } }, { NIL, {}, { method = 'slow_request', bufnr = 1, client_id = 1 } }, } - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'check_pending_request_tracked', on_init = function(_client) @@ -947,7 +947,7 @@ describe('LSP', function() local expected_handlers = { { NIL, {}, { method = 'finish', client_id = 1 } }, } - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'check_cancel_request_tracked', on_init = function(_client) @@ -980,7 +980,7 @@ describe('LSP', function() { NIL, {}, { method = 'finish', client_id = 1 } }, { NIL, {}, { method = 'slow_request', bufnr = 1, client_id = 1 } }, } - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'check_tracked_requests_cleared', on_init = function(_client) @@ -1019,7 +1019,7 @@ describe('LSP', function() { NIL, {}, { method = 'finish', client_id = 1 } }, { NIL, {}, { method = 'slow_request', bufnr = 1, client_id = 1 } }, } - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'check_tracked_requests_cleared', on_init = function(_client) @@ -1055,7 +1055,7 @@ describe('LSP', function() { NIL, {}, { method = 'shutdown', client_id = 1 } }, { NIL, {}, { method = 'finish', client_id = 1 } }, } - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'basic_finish', on_init = function(_client) @@ -1097,7 +1097,7 @@ describe('LSP', function() { NIL, {}, { method = 'finish', client_id = 1 } }, { NIL, {}, { method = 'start', client_id = 1 } }, } - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'basic_check_buffer_open', on_setup = function() @@ -1143,7 +1143,7 @@ describe('LSP', function() { NIL, {}, { method = 'finish', client_id = 1 } }, { NIL, {}, { method = 'start', client_id = 1 } }, } - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'basic_check_buffer_open', on_setup = function() @@ -1186,7 +1186,7 @@ describe('LSP', function() { NIL, {}, { method = 'finish', client_id = 1 } }, { NIL, {}, { method = 'start', client_id = 1 } }, } - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'basic_check_buffer_open_and_change', on_setup = function() @@ -1234,7 +1234,7 @@ describe('LSP', function() { NIL, {}, { method = 'finish', client_id = 1 } }, { NIL, {}, { method = 'start', client_id = 1 } }, } - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'basic_check_buffer_open_and_change_noeol', on_setup = function() @@ -1301,7 +1301,7 @@ describe('LSP', function() }, { NIL, {}, { method = 'start', client_id = 1 } }, } - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'inlay_hint', on_setup = function() @@ -1348,7 +1348,7 @@ describe('LSP', function() { NIL, {}, { method = 'finish', client_id = 1 } }, { NIL, {}, { method = 'start', client_id = 1 } }, } - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'basic_check_buffer_open_and_change_incremental', options = { @@ -1399,7 +1399,7 @@ describe('LSP', function() { NIL, {}, { method = 'finish', client_id = 1 } }, { NIL, {}, { method = 'start', client_id = 1 } }, } - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'basic_check_buffer_open_and_change_incremental', options = { @@ -1453,7 +1453,7 @@ describe('LSP', function() { NIL, {}, { method = 'finish', client_id = 1 } }, { NIL, {}, { method = 'start', client_id = 1 } }, } - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'basic_check_buffer_open_and_change_incremental_editing', on_setup = function() @@ -1498,7 +1498,7 @@ describe('LSP', function() { NIL, {}, { method = 'finish', client_id = 1 } }, { NIL, {}, { method = 'start', client_id = 1 } }, } - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'basic_check_buffer_open_and_change_multi', on_setup = function() @@ -1549,7 +1549,7 @@ describe('LSP', function() { NIL, {}, { method = 'finish', client_id = 1 } }, { NIL, {}, { method = 'start', client_id = 1 } }, } - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'basic_check_buffer_open_and_change_multi_and_close', on_setup = function() @@ -1603,7 +1603,7 @@ describe('LSP', function() { NIL, {}, { method = 'finish', client_id = 1 } }, { NIL, {}, { method = 'start', client_id = 1 } }, } - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'invalid_header', on_setup = function() end, @@ -1636,7 +1636,7 @@ describe('LSP', function() }, { NIL, {}, { method = 'start', client_id = 1 } }, } - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'decode_nil', on_setup = function() @@ -1849,7 +1849,7 @@ describe('LSP', function() describe('cursor position', function() it("don't fix the cursor if the range contains the cursor", function() - fn.nvim_win_set_cursor(0, { 2, 6 }) + api.nvim_win_set_cursor(0, { 2, 6 }) local edits = { make_edit(1, 0, 1, 19, 'Second line of text'), } @@ -1861,11 +1861,11 @@ describe('LSP', function() 'Fourth line of text', 'å å ɧ 汉语 ↥ 🤦 🦄', }, buf_lines(1)) - eq({ 2, 6 }, fn.nvim_win_get_cursor(0)) + eq({ 2, 6 }, api.nvim_win_get_cursor(0)) end) it('fix the cursor to the valid col if the content was removed', function() - fn.nvim_win_set_cursor(0, { 2, 6 }) + api.nvim_win_set_cursor(0, { 2, 6 }) local edits = { make_edit(1, 0, 1, 6, ''), make_edit(1, 6, 1, 19, ''), @@ -1878,11 +1878,11 @@ describe('LSP', function() 'Fourth line of text', 'å å ɧ 汉语 ↥ 🤦 🦄', }, buf_lines(1)) - eq({ 2, 0 }, fn.nvim_win_get_cursor(0)) + eq({ 2, 0 }, api.nvim_win_get_cursor(0)) end) it('fix the cursor to the valid row if the content was removed', function() - fn.nvim_win_set_cursor(0, { 2, 6 }) + api.nvim_win_set_cursor(0, { 2, 6 }) local edits = { make_edit(1, 0, 1, 6, ''), make_edit(0, 18, 5, 0, ''), @@ -1891,11 +1891,11 @@ describe('LSP', function() eq({ 'First line of text', }, buf_lines(1)) - eq({ 1, 17 }, fn.nvim_win_get_cursor(0)) + eq({ 1, 17 }, api.nvim_win_get_cursor(0)) end) it('fix the cursor row', function() - fn.nvim_win_set_cursor(0, { 3, 0 }) + api.nvim_win_set_cursor(0, { 3, 0 }) local edits = { make_edit(1, 0, 2, 0, ''), } @@ -1906,14 +1906,14 @@ describe('LSP', function() 'Fourth line of text', 'å å ɧ 汉语 ↥ 🤦 🦄', }, buf_lines(1)) - eq({ 2, 0 }, fn.nvim_win_get_cursor(0)) + eq({ 2, 0 }, api.nvim_win_get_cursor(0)) end) it('fix the cursor col', function() -- append empty last line. See #22636 exec_lua('vim.api.nvim_buf_set_lines(...)', 1, -1, -1, true, { '' }) - fn.nvim_win_set_cursor(0, { 2, 11 }) + api.nvim_win_set_cursor(0, { 2, 11 }) local edits = { make_edit(1, 7, 1, 11, ''), } @@ -1926,11 +1926,11 @@ describe('LSP', function() 'å å ɧ 汉语 ↥ 🤦 🦄', '', }, buf_lines(1)) - eq({ 2, 7 }, fn.nvim_win_get_cursor(0)) + eq({ 2, 7 }, api.nvim_win_get_cursor(0)) end) it('fix the cursor row and col', function() - fn.nvim_win_set_cursor(0, { 2, 12 }) + api.nvim_win_set_cursor(0, { 2, 12 }) local edits = { make_edit(0, 11, 1, 12, ''), } @@ -1941,7 +1941,7 @@ describe('LSP', function() 'Fourth line of text', 'å å ɧ 汉语 ↥ 🤦 🦄', }, buf_lines(1)) - eq({ 1, 11 }, fn.nvim_win_get_cursor(0)) + eq({ 1, 11 }, api.nvim_win_get_cursor(0)) end) end) @@ -2017,7 +2017,7 @@ describe('LSP', function() end) describe('apply_text_document_edit', function() - local target_bufnr + local target_bufnr --- @type integer local text_document_edit = function(editVersion) return { edits = { @@ -2693,6 +2693,7 @@ describe('LSP', function() eq(expected, actual) end) end) + describe('lsp.util.symbols_to_items', function() describe('convert DocumentSymbol[] to items', function() it('DocumentSymbol has children', function() @@ -2967,7 +2968,7 @@ describe('LSP', function() end) describe('lsp.util.jump_to_location', function() - local target_bufnr + local target_bufnr --- @type integer before_each(function() target_bufnr = exec_lua [[ @@ -3027,21 +3028,21 @@ describe('LSP', function() end) it('adds current position to jumplist before jumping', function() - fn.nvim_win_set_buf(0, target_bufnr) - local mark = fn.nvim_buf_get_mark(target_bufnr, "'") + api.nvim_win_set_buf(0, target_bufnr) + local mark = api.nvim_buf_get_mark(target_bufnr, "'") eq({ 1, 0 }, mark) - fn.nvim_win_set_cursor(0, { 2, 3 }) + api.nvim_win_set_cursor(0, { 2, 3 }) jump(location(0, 9, 0, 9)) - mark = fn.nvim_buf_get_mark(target_bufnr, "'") + mark = api.nvim_buf_get_mark(target_bufnr, "'") eq({ 2, 3 }, mark) end) end) describe('lsp.util.show_document', function() - local target_bufnr - local target_bufnr2 + local target_bufnr --- @type integer + local target_bufnr2 --- @type integer before_each(function() target_bufnr = exec_lua([[ @@ -3128,101 +3129,101 @@ describe('LSP', function() end) it('does not add current position to jumplist if not focus', function() - fn.nvim_win_set_buf(0, target_bufnr) - local mark = fn.nvim_buf_get_mark(target_bufnr, "'") + api.nvim_win_set_buf(0, target_bufnr) + local mark = api.nvim_buf_get_mark(target_bufnr, "'") eq({ 1, 0 }, mark) - fn.nvim_win_set_cursor(0, { 2, 3 }) + api.nvim_win_set_cursor(0, { 2, 3 }) show_document(location(0, 9, 0, 9), false, true) show_document(location(0, 9, 0, 9, true), false, true) - mark = fn.nvim_buf_get_mark(target_bufnr, "'") + mark = api.nvim_buf_get_mark(target_bufnr, "'") eq({ 1, 0 }, mark) end) it('does not change cursor position if not focus and not reuse_win', function() - fn.nvim_win_set_buf(0, target_bufnr) - local cursor = fn.nvim_win_get_cursor(0) + api.nvim_win_set_buf(0, target_bufnr) + local cursor = api.nvim_win_get_cursor(0) show_document(location(0, 9, 0, 9), false, false) - eq(cursor, fn.nvim_win_get_cursor(0)) + eq(cursor, api.nvim_win_get_cursor(0)) end) it('does not change window if not focus', function() - fn.nvim_win_set_buf(0, target_bufnr) - local win = fn.nvim_get_current_win() + api.nvim_win_set_buf(0, target_bufnr) + local win = api.nvim_get_current_win() -- same document/bufnr show_document(location(0, 9, 0, 9), false, true) - eq(win, fn.nvim_get_current_win()) + eq(win, api.nvim_get_current_win()) -- different document/bufnr, new window/split show_document(location(0, 9, 0, 9, true), false, true) - eq(2, #fn.nvim_list_wins()) - eq(win, fn.nvim_get_current_win()) + eq(2, #api.nvim_list_wins()) + eq(win, api.nvim_get_current_win()) end) it("respects 'reuse_win' parameter", function() - fn.nvim_win_set_buf(0, target_bufnr) + api.nvim_win_set_buf(0, target_bufnr) -- does not create a new window if the buffer is already open show_document(location(0, 9, 0, 9), false, true) - eq(1, #fn.nvim_list_wins()) + eq(1, #api.nvim_list_wins()) -- creates a new window even if the buffer is already open show_document(location(0, 9, 0, 9), false, false) - eq(2, #fn.nvim_list_wins()) + eq(2, #api.nvim_list_wins()) end) it('correctly sets the cursor of the split if range is given without focus', function() - fn.nvim_win_set_buf(0, target_bufnr) + api.nvim_win_set_buf(0, target_bufnr) show_document(location(0, 9, 0, 9, true), false, true) - local wins = fn.nvim_list_wins() + local wins = api.nvim_list_wins() eq(2, #wins) table.sort(wins) - eq({ 1, 0 }, fn.nvim_win_get_cursor(wins[1])) - eq({ 1, 9 }, fn.nvim_win_get_cursor(wins[2])) + eq({ 1, 0 }, api.nvim_win_get_cursor(wins[1])) + eq({ 1, 9 }, api.nvim_win_get_cursor(wins[2])) end) it('does not change cursor of the split if not range and not focus', function() - fn.nvim_win_set_buf(0, target_bufnr) - fn.nvim_win_set_cursor(0, { 2, 3 }) + api.nvim_win_set_buf(0, target_bufnr) + api.nvim_win_set_cursor(0, { 2, 3 }) exec_lua([[vim.cmd.new()]]) - fn.nvim_win_set_buf(0, target_bufnr2) - fn.nvim_win_set_cursor(0, { 2, 3 }) + api.nvim_win_set_buf(0, target_bufnr2) + api.nvim_win_set_cursor(0, { 2, 3 }) show_document({ uri = 'file:///fake/uri2' }, false, true) - local wins = fn.nvim_list_wins() + local wins = api.nvim_list_wins() eq(2, #wins) - eq({ 2, 3 }, fn.nvim_win_get_cursor(wins[1])) - eq({ 2, 3 }, fn.nvim_win_get_cursor(wins[2])) + eq({ 2, 3 }, api.nvim_win_get_cursor(wins[1])) + eq({ 2, 3 }, api.nvim_win_get_cursor(wins[2])) end) it('respects existing buffers', function() - fn.nvim_win_set_buf(0, target_bufnr) - local win = fn.nvim_get_current_win() + api.nvim_win_set_buf(0, target_bufnr) + local win = api.nvim_get_current_win() exec_lua([[vim.cmd.new()]]) - fn.nvim_win_set_buf(0, target_bufnr2) - fn.nvim_win_set_cursor(0, { 2, 3 }) - local split = fn.nvim_get_current_win() + api.nvim_win_set_buf(0, target_bufnr2) + api.nvim_win_set_cursor(0, { 2, 3 }) + local split = api.nvim_get_current_win() -- reuse win for open document/bufnr if called from split show_document(location(0, 9, 0, 9, true), false, true) - eq({ 1, 9 }, fn.nvim_win_get_cursor(split)) - eq(2, #fn.nvim_list_wins()) + eq({ 1, 9 }, api.nvim_win_get_cursor(split)) + eq(2, #api.nvim_list_wins()) - fn.nvim_set_current_win(win) + api.nvim_set_current_win(win) -- reuse win for open document/bufnr if called outside the split show_document(location(0, 9, 0, 9, true), false, true) - eq({ 1, 9 }, fn.nvim_win_get_cursor(split)) - eq(2, #fn.nvim_list_wins()) + eq({ 1, 9 }, api.nvim_win_get_cursor(split)) + eq(2, #api.nvim_list_wins()) end) end) @@ -3500,7 +3501,7 @@ describe('LSP', function() }, }) do it(test.it, function() - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = test.name, on_init = function(_client) @@ -3550,7 +3551,7 @@ describe('LSP', function() describe('vim.lsp.buf.code_action', function() it('Calls client side command if available', function() - local client + local client --- @type vim.lsp.Client local expected_handlers = { { NIL, {}, { method = 'shutdown', client_id = 1 } }, { NIL, {}, { method = 'start', client_id = 1 } }, @@ -3588,7 +3589,7 @@ describe('LSP', function() } end) it('Calls workspace/executeCommand if no client side command', function() - local client + local client --- @type vim.lsp.Client local expected_handlers = { { NIL, {}, { method = 'shutdown', client_id = 1 } }, { @@ -3628,7 +3629,7 @@ describe('LSP', function() }) end) it('Filters and automatically applies action if requested', function() - local client + local client --- @type vim.lsp.Client local expected_handlers = { { NIL, {}, { method = 'shutdown', client_id = 1 } }, { NIL, {}, { method = 'start', client_id = 1 } }, @@ -3728,6 +3729,7 @@ describe('LSP', function() eq('command:1', result[5].params.command) end) end) + describe('vim.lsp.commands', function() it('Accepts only string keys', function() matches( @@ -3742,9 +3744,10 @@ describe('LSP', function() ) end) end) + describe('vim.lsp.codelens', function() it('uses client commands', function() - local client + local client --- @type vim.lsp.Client local expected_handlers = { { NIL, {}, { method = 'shutdown', client_id = 1 } }, { NIL, {}, { method = 'start', client_id = 1 } }, @@ -3798,7 +3801,7 @@ describe('LSP', function() end) it('releases buffer refresh lock', function() - local client + local client --- @type vim.lsp.Client local expected_handlers = { { NIL, {}, { method = 'shutdown', client_id = 1 } }, { NIL, {}, { method = 'start', client_id = 1 } }, @@ -3965,7 +3968,7 @@ describe('LSP', function() describe('vim.lsp.buf.format', function() it('Aborts with notify if no client matches filter', function() - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'basic_init', on_init = function(c) @@ -3994,7 +3997,7 @@ describe('LSP', function() { NIL, {}, { method = 'shutdown', client_id = 1 } }, { NIL, {}, { method = 'start', client_id = 1 } }, } - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'basic_formatting', on_init = function(c) @@ -4027,7 +4030,7 @@ describe('LSP', function() { NIL, {}, { method = 'shutdown', client_id = 1 } }, { NIL, {}, { method = 'start', client_id = 1 } }, } - local client + local client --- @type vim.lsp.Client test_rpc_server { test_name = 'basic_formatting', on_init = function(c) @@ -4150,6 +4153,9 @@ describe('LSP', function() end ]]) local fail_msg = '[LSP] Format request failed, no matching language servers.' + --- @param name string + --- @param formatting boolean + --- @param range_formatting boolean local function check_notify(name, formatting, range_formatting) local timeout_msg = '[LSP][' .. name .. '] timeout' exec_lua( @@ -4306,7 +4312,7 @@ describe('LSP', function() eq('initialize', result.method) end) it('can connect to lsp server via rpc.domain_socket_connect', function() - local tmpfile + local tmpfile --- @type string if is_os('win') then tmpfile = '\\\\.\\\\pipe\\pipe.test' else @@ -4761,14 +4767,7 @@ describe('LSP', function() ) local function watched_uri(fname) - return exec_lua( - [[ - local root_dir, fname = ... - return vim.uri_from_fname(root_dir .. '/' .. fname) - ]], - root_dir, - fname - ) + return vim.uri_from_fname(root_dir .. '/' .. fname) end eq(4, #result) @@ -4874,13 +4873,7 @@ describe('LSP', function() ) local function watched_uri(fname) - return exec_lua( - [[ - local fname = ... - return vim.uri_from_fname('/dir/' .. fname) - ]], - fname - ) + return vim.uri_from_fname('/dir/' .. fname) end eq(3, #result) @@ -5005,30 +4998,21 @@ describe('LSP', function() root_dir ) - local function watched_uri(fname) - return exec_lua( - [[ - return vim.uri_from_fname(...) - ]], - fname - ) - end - eq(3, #result) eq('workspace/didChangeWatchedFiles', result[3].method) eq({ changes = { { type = exec_lua([[return vim.lsp.protocol.FileChangeType.Created]]), - uri = watched_uri('file1'), + uri = vim.uri_from_fname('file1'), }, { type = exec_lua([[return vim.lsp.protocol.FileChangeType.Changed]]), - uri = watched_uri('file1'), + uri = vim.uri_from_fname('file1'), }, { type = exec_lua([[return vim.lsp.protocol.FileChangeType.Created]]), - uri = watched_uri('file2'), + uri = vim.uri_from_fname('file2'), }, }, }, result[3].params) diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua index 5bfa566729..34006d5906 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local command, rawfeed = helpers.command, helpers.rawfeed +local command, feed = helpers.command, helpers.feed local clear = helpers.clear local exec_lua = helpers.exec_lua local fn = helpers.fn @@ -44,7 +44,7 @@ describe(':Man', function() end) describe('man.lua: highlight_line()', function() - local screen + local screen --- @type test.functional.ui.screen before_each(function() command('syntax on') @@ -64,7 +64,7 @@ describe(':Man', function() end) it('clears backspaces from text and adds highlights', function() - rawfeed( + feed( [[ ithis iiss aa test with _o_v_e_r_s_t_r_u_c_k text]] @@ -90,7 +90,7 @@ describe(':Man', function() end) it('clears escape sequences from text and adds highlights', function() - rawfeed( + feed( [[ ithis [1mis [3ma [4mtest[0m [4mwith[24m [4mescaped[24m [4mtext[24m]] @@ -116,7 +116,7 @@ describe(':Man', function() end) it('highlights multibyte text', function() - rawfeed( + feed( [[ ithis iiss ああ test with _ö_v_e_r_s_t_r_u_̃_c_k te[3mxt¶[0m]] @@ -132,7 +132,7 @@ describe(':Man', function() end) it('highlights underscores based on context', function() - rawfeed( + feed( [[ i__bbeeggiinnss mmiidd__ddllee @@ -150,7 +150,7 @@ describe(':Man', function() end) it('highlights various bullet formats', function() - rawfeed([[ + feed([[ i· ·· +o ++oo double]]) @@ -166,7 +166,7 @@ describe(':Man', function() end) it('handles : characters in input', function() - rawfeed([[ + feed([[ i[40m 0 [41m 1 [42m 2 [43m 3 [44m 4 [45m 5 [46m 6 [47m 7 [100m 8 [101m 9 [102m 10 [103m 11 [104m 12 [105m 13 [106m 14 [107m 15 diff --git a/test/functional/plugin/matchparen_spec.lua b/test/functional/plugin/matchparen_spec.lua index 530afd16e4..619c43f2c9 100644 --- a/test/functional/plugin/matchparen_spec.lua +++ b/test/functional/plugin/matchparen_spec.lua @@ -8,7 +8,7 @@ local feed = helpers.feed local eq = helpers.eq describe('matchparen', function() - local screen + local screen --- @type test.functional.ui.screen before_each(function() clear { args = { '-u', 'NORC' } } diff --git a/test/functional/plugin/tutor_spec.lua b/test/functional/plugin/tutor_spec.lua index c3caf5ff16..46a117f298 100644 --- a/test/functional/plugin/tutor_spec.lua +++ b/test/functional/plugin/tutor_spec.lua @@ -6,7 +6,7 @@ local feed = helpers.feed local is_os = helpers.is_os describe(':Tutor', function() - local screen + local screen --- @type test.functional.ui.screen before_each(function() clear({ args = { '--clean' } }) diff --git a/test/functional/plugin/vim_syntax_spec.lua b/test/functional/plugin/vim_syntax_spec.lua index 9396bbce5c..c5858f8bc0 100644 --- a/test/functional/plugin/vim_syntax_spec.lua +++ b/test/functional/plugin/vim_syntax_spec.lua @@ -5,7 +5,7 @@ local exec = helpers.exec local api = helpers.api describe('Vimscript syntax highlighting', function() - local screen + local screen --- @type test.functional.ui.screen before_each(function() clear() -- cgit From 00e71d3da3464df2b4c4f33bfd5fac6d88e7c867 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Thu, 21 Mar 2024 15:15:20 +0000 Subject: refactor(lsp): simplify client tracking - Remove: - uninitialized_clients - active_clients - all_buffer_active_clients - Add: - all_clients - Use `lsp.get_clients()` to get buffer clients. --- test/functional/plugin/lsp_spec.lua | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 4437c4aeaa..eda4c95889 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -282,8 +282,7 @@ describe('LSP', function() local client --- @type vim.lsp.Client test_rpc_server { test_name = 'basic_finish', - on_init = function(_client) - client = _client + on_setup = function() exec_lua [[ BUFFER = vim.api.nvim_create_buf(false, true) ]] @@ -292,6 +291,9 @@ describe('LSP', function() exec_lua [[ vim.api.nvim_command(BUFFER.."bwipeout") ]] + end, + on_init = function(_client) + client = _client client.notify('finish') end, on_exit = function(code, signal) @@ -806,14 +808,12 @@ describe('LSP', function() BUFFER = vim.api.nvim_get_current_buf() lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID) vim.lsp.handlers['textDocument/typeDefinition'] = function() end + vim.cmd(BUFFER.."bwipeout") ]=]) end, on_init = function(client) client.stop() exec_lua('vim.lsp.buf.type_definition()') - exec_lua [[ - vim.api.nvim_command(BUFFER.."bwipeout") - ]] end, on_exit = function(code, signal) eq(0, code, 'exit code') @@ -1058,21 +1058,21 @@ describe('LSP', function() local client --- @type vim.lsp.Client test_rpc_server { test_name = 'basic_finish', - on_init = function(_client) - client = _client + on_setup = function() exec_lua [[ BUFFER = vim.api.nvim_create_buf(false, true) vim.api.nvim_buf_set_lines(BUFFER, 0, -1, false, { "testing"; "123"; }) + assert(TEST_RPC_CLIENT_ID == 1) + assert(lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)) + assert(lsp.buf_is_attached(BUFFER, TEST_RPC_CLIENT_ID)) + vim.cmd(BUFFER.."bwipeout") ]] - eq(1, exec_lua('return TEST_RPC_CLIENT_ID')) - eq(true, exec_lua('return lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)')) - eq(true, exec_lua('return lsp.buf_is_attached(BUFFER, TEST_RPC_CLIENT_ID)')) - exec_lua [[ - vim.api.nvim_command(BUFFER.."bwipeout") - ]] + end, + on_init = function(_client) + client = _client local full_kind = exec_lua("return require'vim.lsp.protocol'.TextDocumentSyncKind.Full") eq(full_kind, client.server_capabilities().textDocumentSync.change) eq(true, client.server_capabilities().textDocumentSync.openClose) -- cgit From 0c0be09eab66975e62c67522620fee10f82663d2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 26 Mar 2024 21:11:32 +0800 Subject: test(lsp): fix flaky basic_finish test again (#28041) Problem: LSP basic_finish test modified in #27899 is flaky again after #28030. Solution: Run on_setup() immediately after setup using a before_init callback. --- test/functional/plugin/lsp/helpers.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp/helpers.lua b/test/functional/plugin/lsp/helpers.lua index 376de66c51..375bff06af 100644 --- a/test/functional/plugin/lsp/helpers.lua +++ b/test/functional/plugin/lsp/helpers.lua @@ -105,6 +105,11 @@ local function fake_lsp_server_setup(test_name, timeout_ms, options, settings) uri = 'file://' .. vim.uv.cwd(), name = 'test_folder', }}; + before_init = function(params, config) + vim.schedule(function() + vim.rpcrequest(1, "setup") + end) + end, on_init = function(client, result) TEST_RPC_CLIENT = client vim.rpcrequest(1, "init", result) @@ -173,6 +178,12 @@ function M.test_rpc_server(config) --- @type integer, integer local code, signal local function on_request(method, args) + if method == 'setup' then + if config.on_setup then + config.on_setup() + end + return NIL + end if method == 'init' then if config.on_init then config.on_init(client, unpack(args)) @@ -193,8 +204,8 @@ function M.test_rpc_server(config) end end -- TODO specify timeout? - -- run(on_request, on_notify, config.on_setup, 1000) - run(on_request, on_notify, config.on_setup) + -- run(on_request, on_notify, nil, 1000) + run(on_request, on_notify, nil) if config.on_exit then config.on_exit(code, signal) end -- cgit From 4e56f7f0beafcd9db1775a76dcf2d2a4ef2867ba Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 29 Mar 2024 06:26:01 +0800 Subject: test: skip another flaky test on macOS (#28087) --- test/functional/plugin/lsp_spec.lua | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index eda4c95889..788cc8d6f8 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -4537,18 +4537,26 @@ describe('LSP', function() string.format('sends notifications when files change (watchfunc=%s)', watchfunc), function() if watchfunc == 'fswatch' then + skip(is_os('win'), 'not supported on windows') + skip(is_os('mac'), 'flaky test on mac') skip( not is_ci() and fn.executable('fswatch') == 0, 'fswatch not installed and not on CI' ) - skip(is_os('win'), 'not supported on windows') - skip(is_os('mac'), 'flaky') end - skip( - is_os('bsd'), - 'kqueue only reports events on watched folder itself, not contained files #26110' - ) + if watchfunc == 'watch' then + skip(is_os('mac'), 'flaky test on mac') + skip( + is_os('bsd'), + 'Stopped working on bsd after 3ca967387c49c754561c3b11a574797504d40f38' + ) + else + skip( + is_os('bsd'), + 'kqueue only reports events on watched folder itself, not contained files #26110' + ) + end local root_dir = tmpname() os.remove(root_dir) -- cgit From e016f5bee6293d126fde9e8d75a3f02f882e2c81 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 2 Apr 2024 15:45:19 +0200 Subject: test: reduce `exec_lua` calls `exec_lua` makes code slighly harder to read, so it's beneficial to remove it in cases where it's possible or convenient. Not all `exec_lua` calls should be removed even if the test passes as it changes the semantics of the test even if it happens to pass. From https://github.com/neovim/neovim/pull/28155#discussion_r1548185779: "Note for tests like this, which fundamentally are about conversion, you end up changing what conversion you are testing. Even if the result happens to be same (as they often are, as we like the rules to be consistent if possible), you are now testing the RPC conversion rules instead of the vim script to in-process lua conversion rules." From https://github.com/neovim/neovim/pull/28155#discussion_r1548190152: "A test like this specifies that the cursor is valid immediately and not after a separate cycle of normal (or an other input-processing) mode." --- test/functional/plugin/health_spec.lua | 7 ++- test/functional/plugin/lsp/helpers.lua | 3 +- test/functional/plugin/lsp/inlay_hint_spec.lua | 3 +- .../functional/plugin/lsp/semantic_tokens_spec.lua | 3 +- test/functional/plugin/lsp_spec.lua | 72 +++++++++++----------- 5 files changed, 46 insertions(+), 42 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index 9306180c40..8416f0e5f7 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -8,7 +8,8 @@ local eq, neq, matches = helpers.eq, helpers.neq, helpers.matches local getcompletion = helpers.fn.getcompletion local insert = helpers.insert local source = helpers.source -local exec_lua = helpers.exec_lua +local fn = helpers.fn +local api = helpers.api describe(':checkhealth', function() it('detects invalid $VIMRUNTIME', function() @@ -381,7 +382,7 @@ describe(':checkhealth window', function() it('opens in tab', function() -- create an empty buffer called "my_buff" - exec_lua 'vim.api.nvim_create_buf(false, true)' + api.nvim_create_buf(false, true) command('file my_buff') command('checkhealth success1') -- define a function that collects all buffers in each tab @@ -400,7 +401,7 @@ describe(':checkhealth window', function() return buffs endfunction ]]) - local buffers_per_tab = exec_lua('return vim.fn.CollectBuffersPerTab()') + local buffers_per_tab = fn.CollectBuffersPerTab() eq(buffers_per_tab, { tab1 = { 'my_buff' }, tab2 = { 'health://' } }) end) end) diff --git a/test/functional/plugin/lsp/helpers.lua b/test/functional/plugin/lsp/helpers.lua index 375bff06af..fb93746480 100644 --- a/test/functional/plugin/lsp/helpers.lua +++ b/test/functional/plugin/lsp/helpers.lua @@ -4,6 +4,7 @@ local clear = helpers.clear local exec_lua = helpers.exec_lua local run = helpers.run local stop = helpers.stop +local api = helpers.api local NIL = vim.NIL local M = {} @@ -211,7 +212,7 @@ function M.test_rpc_server(config) end stop() if config.test_name then - exec_lua("vim.api.nvim_exec_autocmds('VimLeavePre', { modeline = false })") + api.nvim_exec_autocmds('VimLeavePre', { modeline = false }) end end diff --git a/test/functional/plugin/lsp/inlay_hint_spec.lua b/test/functional/plugin/lsp/inlay_hint_spec.lua index b046a2c509..e9c347bcc5 100644 --- a/test/functional/plugin/lsp/inlay_hint_spec.lua +++ b/test/functional/plugin/lsp/inlay_hint_spec.lua @@ -6,6 +6,7 @@ local eq = helpers.eq local dedent = helpers.dedent local exec_lua = helpers.exec_lua local insert = helpers.insert +local api = helpers.api local clear_notrace = lsp_helpers.clear_notrace local create_server_definition = lsp_helpers.create_server_definition @@ -88,7 +89,7 @@ before_each(function() end) after_each(function() - exec_lua("vim.api.nvim_exec_autocmds('VimLeavePre', { modeline = false })") + api.nvim_exec_autocmds('VimLeavePre', { modeline = false }) end) describe('vim.lsp.inlay_hint', function() diff --git a/test/functional/plugin/lsp/semantic_tokens_spec.lua b/test/functional/plugin/lsp/semantic_tokens_spec.lua index ad09ab08b3..12f6e09e7e 100644 --- a/test/functional/plugin/lsp/semantic_tokens_spec.lua +++ b/test/functional/plugin/lsp/semantic_tokens_spec.lua @@ -10,6 +10,7 @@ local feed = helpers.feed local feed_command = helpers.feed_command local insert = helpers.insert local matches = helpers.matches +local api = helpers.api local clear_notrace = lsp_helpers.clear_notrace local create_server_definition = lsp_helpers.create_server_definition @@ -19,7 +20,7 @@ before_each(function() end) after_each(function() - exec_lua("vim.api.nvim_exec_autocmds('VimLeavePre', { modeline = false })") + api.nvim_exec_autocmds('VimLeavePre', { modeline = false }) end) describe('semantic token highlighting', function() diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 788cc8d6f8..c65cca6cb7 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -83,7 +83,7 @@ describe('LSP', function() end) after_each(function() - exec_lua("vim.api.nvim_exec_autocmds('VimLeavePre', { modeline = false })") + api.nvim_exec_autocmds('VimLeavePre', { modeline = false }) -- exec_lua("lsp.stop_all_clients(true)") end) @@ -146,7 +146,7 @@ describe('LSP', function() after_each(function() stop() exec_lua('lsp.stop_client(lsp.get_clients(), true)') - exec_lua("vim.api.nvim_exec_autocmds('VimLeavePre', { modeline = false })") + api.nvim_exec_autocmds('VimLeavePre', { modeline = false }) end) it('should run correctly', function() @@ -1803,7 +1803,7 @@ describe('LSP', function() make_edit(1, 0, 2, 5, 'foobar'), make_edit(4, 0, 5, 0, 'barfoo'), } - eq(true, exec_lua('return vim.api.nvim_buf_set_mark(1, "a", 2, 1, {})')) + eq(true, api.nvim_buf_set_mark(1, 'a', 2, 1, {})) exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-16') eq({ 'First line of text', @@ -1811,7 +1811,7 @@ describe('LSP', function() 'Fourth line of text', 'barfoo', }, buf_lines(1)) - local mark = exec_lua('return vim.api.nvim_buf_get_mark(1, "a")') + local mark = api.nvim_buf_get_mark(1, 'a') eq({ 2, 1 }, mark) end) @@ -1820,7 +1820,7 @@ describe('LSP', function() make_edit(1, 0, 2, 15, 'foobar'), make_edit(4, 0, 5, 0, 'barfoo'), } - eq(true, exec_lua('return vim.api.nvim_buf_set_mark(1, "a", 2, 10, {})')) + eq(true, api.nvim_buf_set_mark(1, 'a', 2, 10, {})) exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-16') eq({ 'First line of text', @@ -1828,7 +1828,7 @@ describe('LSP', function() 'Fourth line of text', 'barfoo', }, buf_lines(1)) - local mark = exec_lua('return vim.api.nvim_buf_get_mark(1, "a")') + local mark = api.nvim_buf_get_mark(1, 'a') eq({ 2, 9 }, mark) end) @@ -1837,13 +1837,13 @@ describe('LSP', function() make_edit(1, 0, 4, 5, 'foobar'), make_edit(4, 0, 5, 0, 'barfoo'), } - eq(true, exec_lua('return vim.api.nvim_buf_set_mark(1, "a", 4, 1, {})')) + eq(true, api.nvim_buf_set_mark(1, 'a', 4, 1, {})) exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1, 'utf-16') eq({ 'First line of text', 'foobaro', }, buf_lines(1)) - local mark = exec_lua('return vim.api.nvim_buf_get_mark(1, "a")') + local mark = api.nvim_buf_get_mark(1, 'a') eq({ 2, 1 }, mark) end) @@ -1911,7 +1911,7 @@ describe('LSP', function() it('fix the cursor col', function() -- append empty last line. See #22636 - exec_lua('vim.api.nvim_buf_set_lines(...)', 1, -1, -1, true, { '' }) + api.nvim_buf_set_lines(1, -1, -1, true, { '' }) api.nvim_win_set_cursor(0, { 2, 11 }) local edits = { @@ -2263,7 +2263,7 @@ describe('LSP', function() }, } exec_lua('vim.lsp.util.apply_workspace_edit(...)', edit, 'utf-16') - eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', tmpfile)) + eq(true, vim.uv.fs_stat(tmpfile) ~= nil) end) it( 'Supports file creation in folder that needs to be created with CreateFile payload', @@ -2281,7 +2281,7 @@ describe('LSP', function() }, } exec_lua('vim.lsp.util.apply_workspace_edit(...)', edit, 'utf-16') - eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', tmpfile)) + eq(true, vim.uv.fs_stat(tmpfile) ~= nil) end ) it('createFile does not touch file if it exists and ignoreIfExists is set', function() @@ -2300,7 +2300,7 @@ describe('LSP', function() }, } exec_lua('vim.lsp.util.apply_workspace_edit(...)', edit, 'utf-16') - eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', tmpfile)) + eq(true, vim.uv.fs_stat(tmpfile) ~= nil) eq('Dummy content', read_file(tmpfile)) end) it('createFile overrides file if overwrite is set', function() @@ -2320,7 +2320,7 @@ describe('LSP', function() }, } exec_lua('vim.lsp.util.apply_workspace_edit(...)', edit, 'utf-16') - eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', tmpfile)) + eq(true, vim.uv.fs_stat(tmpfile) ~= nil) eq('', read_file(tmpfile)) end) it('DeleteFile delete file and buffer', function() @@ -2344,8 +2344,8 @@ describe('LSP', function() }, } eq(true, pcall(exec_lua, 'vim.lsp.util.apply_workspace_edit(...)', edit, 'utf-16')) - eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', tmpfile)) - eq(false, exec_lua('return vim.api.nvim_buf_is_loaded(vim.fn.bufadd(...))', tmpfile)) + eq(false, vim.uv.fs_stat(tmpfile) ~= nil) + eq(false, api.nvim_buf_is_loaded(fn.bufadd(tmpfile))) end) it('DeleteFile fails if file does not exist and ignoreIfNotExists is false', function() local tmpfile = tmpname() @@ -2363,7 +2363,7 @@ describe('LSP', function() }, } eq(false, pcall(exec_lua, 'vim.lsp.util.apply_workspace_edit(...)', edit)) - eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', tmpfile)) + eq(false, vim.uv.fs_stat(tmpfile) ~= nil) end) end) @@ -2391,9 +2391,9 @@ describe('LSP', function() new ) eq({ 'Test content' }, lines) - local exists = exec_lua('return vim.uv.fs_stat(...) ~= nil', old) + local exists = vim.uv.fs_stat(old) ~= nil eq(false, exists) - exists = exec_lua('return vim.uv.fs_stat(...) ~= nil', new) + exists = vim.uv.fs_stat(new) ~= nil eq(true, exists) os.remove(new) end) @@ -2429,9 +2429,9 @@ describe('LSP', function() file ) eq({ 'Test content' }, lines) - eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', old_dir)) - eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', new_dir)) - eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', new_dir .. pathsep .. file)) + eq(false, vim.uv.fs_stat(old_dir) ~= nil) + eq(true, vim.uv.fs_stat(new_dir) ~= nil) + eq(true, vim.uv.fs_stat(new_dir .. pathsep .. file) ~= nil) os.remove(new_dir) end) @@ -2495,7 +2495,7 @@ describe('LSP', function() new ) - eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', old)) + eq(true, vim.uv.fs_stat(old) ~= nil) eq('New file', read_file(new)) exec_lua( @@ -2509,7 +2509,7 @@ describe('LSP', function() new ) - eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', old)) + eq(true, vim.uv.fs_stat(old) ~= nil) eq('New file', read_file(new)) end ) @@ -2539,8 +2539,8 @@ describe('LSP', function() old, new ) - eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', old)) - eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', new)) + eq(false, vim.uv.fs_stat(old) ~= nil) + eq(true, vim.uv.fs_stat(new) ~= nil) eq(true, undo_kept) end) it('Maintains undo information for unloaded buffer', function() @@ -2566,8 +2566,8 @@ describe('LSP', function() old, new ) - eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', old)) - eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', new)) + eq(false, vim.uv.fs_stat(old) ~= nil) + eq(true, vim.uv.fs_stat(new) ~= nil) eq(true, undo_kept) end) it('Does not rename file when it conflicts with a buffer without file', function() @@ -2611,8 +2611,8 @@ describe('LSP', function() new ) - eq(false, exec_lua('return vim.uv.fs_stat(...) ~= nil', old)) - eq(true, exec_lua('return vim.uv.fs_stat(...) ~= nil', new)) + eq(false, vim.uv.fs_stat(old) ~= nil) + eq(true, vim.uv.fs_stat(new) ~= nil) eq('Old file', read_file(new)) end) end) @@ -2991,10 +2991,10 @@ describe('LSP', function() local jump = function(msg) eq(true, exec_lua('return vim.lsp.util.jump_to_location(...)', msg, 'utf-16')) - eq(target_bufnr, exec_lua [[return vim.fn.bufnr('%')]]) + eq(target_bufnr, fn.bufnr('%')) return { - line = exec_lua [[return vim.fn.line('.')]], - col = exec_lua [[return vim.fn.col('.')]], + line = fn.line('.'), + col = fn.col('.'), } end @@ -3024,7 +3024,7 @@ describe('LSP', function() local pos = jump(location(1, 2, 1, 2)) eq(2, pos.line) eq(4, pos.col) - eq('å', exec_lua [[return vim.fn.expand('')]]) + eq('å', fn.expand('')) end) it('adds current position to jumplist before jumping', function() @@ -3081,11 +3081,11 @@ describe('LSP', function() ) ) if focus == true or focus == nil then - eq(target_bufnr, exec_lua([[return vim.fn.bufnr('%')]])) + eq(target_bufnr, fn.bufnr('%')) end return { - line = exec_lua([[return vim.fn.line('.')]]), - col = exec_lua([[return vim.fn.col('.')]]), + line = fn.line('.'), + col = fn.col('.'), } end -- cgit From 7035125b2b26aa68fcfb7cda39377ac79926a0f9 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 8 Apr 2024 11:03:20 +0200 Subject: test: improve test conventions Work on https://github.com/neovim/neovim/issues/27004. --- test/functional/plugin/ccomplete_spec.lua | 14 +- test/functional/plugin/cfilter_spec.lua | 10 +- test/functional/plugin/editorconfig_spec.lua | 30 +-- test/functional/plugin/health_spec.lua | 32 +-- test/functional/plugin/lsp/codelens_spec.lua | 10 +- test/functional/plugin/lsp/completion_spec.lua | 8 +- test/functional/plugin/lsp/diagnostic_spec.lua | 14 +- test/functional/plugin/lsp/handler_spec.lua | 10 +- test/functional/plugin/lsp/helpers.lua | 219 --------------------- .../plugin/lsp/incremental_sync_spec.lua | 12 +- test/functional/plugin/lsp/inlay_hint_spec.lua | 18 +- .../functional/plugin/lsp/semantic_tokens_spec.lua | 28 +-- test/functional/plugin/lsp/snippet_spec.lua | 10 +- test/functional/plugin/lsp/testutil.lua | 219 +++++++++++++++++++++ test/functional/plugin/lsp/utils_spec.lua | 12 +- test/functional/plugin/lsp_spec.lua | 72 +++---- test/functional/plugin/man_spec.lua | 24 +-- test/functional/plugin/matchparen_spec.lua | 12 +- test/functional/plugin/msgpack_spec.lua | 16 +- test/functional/plugin/shada_spec.lua | 16 +- test/functional/plugin/tohtml_spec.lua | 16 +- test/functional/plugin/tutor_spec.lua | 10 +- test/functional/plugin/vim_syntax_spec.lua | 10 +- 23 files changed, 411 insertions(+), 411 deletions(-) delete mode 100644 test/functional/plugin/lsp/helpers.lua create mode 100644 test/functional/plugin/lsp/testutil.lua (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/ccomplete_spec.lua b/test/functional/plugin/ccomplete_spec.lua index 903f16fc73..2133f28a2e 100644 --- a/test/functional/plugin/ccomplete_spec.lua +++ b/test/functional/plugin/ccomplete_spec.lua @@ -1,10 +1,10 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local eval = helpers.eval -local feed = helpers.feed -local write_file = helpers.write_file +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local command = t.command +local eq = t.eq +local eval = t.eval +local feed = t.feed +local write_file = t.write_file describe('ccomplete#Complete', function() setup(function() diff --git a/test/functional/plugin/cfilter_spec.lua b/test/functional/plugin/cfilter_spec.lua index 37261d59df..917e666ab0 100644 --- a/test/functional/plugin/cfilter_spec.lua +++ b/test/functional/plugin/cfilter_spec.lua @@ -1,8 +1,8 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local fn = helpers.fn +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local command = t.command +local eq = t.eq +local fn = t.fn describe('cfilter.lua', function() before_each(function() diff --git a/test/functional/plugin/editorconfig_spec.lua b/test/functional/plugin/editorconfig_spec.lua index c8151d2005..cd524373da 100644 --- a/test/functional/plugin/editorconfig_spec.lua +++ b/test/functional/plugin/editorconfig_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local command = helpers.command -local eq = helpers.eq -local pathsep = helpers.get_pathsep() -local fn = helpers.fn -local api = helpers.api -local exec_lua = helpers.exec_lua +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local command = t.command +local eq = t.eq +local pathsep = t.get_pathsep() +local fn = t.fn +local api = t.api +local exec_lua = t.exec_lua local testdir = 'Xtest-editorconfig' @@ -20,8 +20,8 @@ local function test_case(name, expected) end setup(function() - helpers.mkdir_p(testdir) - helpers.write_file( + t.mkdir_p(testdir) + t.write_file( testdir .. pathsep .. '.editorconfig', [[ root = true @@ -96,7 +96,7 @@ setup(function() end) teardown(function() - helpers.rmdir(testdir) + t.rmdir(testdir) end) describe('editorconfig', function() @@ -178,18 +178,18 @@ But not this one -- luacheck: pop local trimmed = untrimmed:gsub('%s+\n', '\n') - helpers.write_file(filename, untrimmed) + t.write_file(filename, untrimmed) command('edit ' .. filename) command('write') command('bdelete') - eq(trimmed, helpers.read_file(filename)) + eq(trimmed, t.read_file(filename)) filename = testdir .. pathsep .. 'no_trim.txt' - helpers.write_file(filename, untrimmed) + t.write_file(filename, untrimmed) command('edit ' .. filename) command('write') command('bdelete') - eq(untrimmed, helpers.read_file(filename)) + eq(untrimmed, t.read_file(filename)) end) it('sets textwidth', function() diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index 8416f0e5f7..3fe9102886 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local curbuf_contents = helpers.curbuf_contents -local command = helpers.command -local eq, neq, matches = helpers.eq, helpers.neq, helpers.matches -local getcompletion = helpers.fn.getcompletion -local insert = helpers.insert -local source = helpers.source -local fn = helpers.fn -local api = helpers.api +local clear = t.clear +local curbuf_contents = t.curbuf_contents +local command = t.command +local eq, neq, matches = t.eq, t.neq, t.matches +local getcompletion = t.fn.getcompletion +local insert = t.insert +local source = t.source +local fn = t.fn +local api = t.api describe(':checkhealth', function() it('detects invalid $VIMRUNTIME', function() @@ -53,7 +53,7 @@ describe('health.vim', function() describe(':checkhealth', function() it('functions report_*() render correctly', function() command('checkhealth full_render') - helpers.expect([[ + t.expect([[ ============================================================================== test_plug.full_render: require("test_plug.full_render.health").check() @@ -76,7 +76,7 @@ describe('health.vim', function() it('concatenates multiple reports', function() command('checkhealth success1 success2 test_plug') - helpers.expect([[ + t.expect([[ ============================================================================== test_plug: require("test_plug.health").check() @@ -106,7 +106,7 @@ describe('health.vim', function() it('lua plugins submodules', function() command('checkhealth test_plug.submodule') - helpers.expect([[ + t.expect([[ ============================================================================== test_plug.submodule: require("test_plug.submodule.health").check() @@ -121,7 +121,7 @@ describe('health.vim', function() it('... including empty reports', function() command('checkhealth test_plug.submodule_empty') - helpers.expect([[ + t.expect([[ ============================================================================== test_plug.submodule_empty: require("test_plug.submodule_empty.health").check() @@ -180,7 +180,7 @@ describe('health.vim', function() it('gracefully handles invalid healthcheck', function() command('checkhealth non_existent_healthcheck') -- luacheck: ignore 613 - helpers.expect([[ + t.expect([[ ============================================================================== non_existent_healthcheck: @@ -192,7 +192,7 @@ describe('health.vim', function() it('does not use vim.health as a healtcheck', function() -- vim.health is not a healthcheck command('checkhealth vim') - helpers.expect([[ + t.expect([[ ERROR: No healthchecks found.]]) end) end) diff --git a/test/functional/plugin/lsp/codelens_spec.lua b/test/functional/plugin/lsp/codelens_spec.lua index 29daf7a066..a618854e2f 100644 --- a/test/functional/plugin/lsp/codelens_spec.lua +++ b/test/functional/plugin/lsp/codelens_spec.lua @@ -1,14 +1,14 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local exec_lua = helpers.exec_lua -local eq = helpers.eq +local exec_lua = t.exec_lua +local eq = t.eq describe('vim.lsp.codelens', function() before_each(function() - helpers.clear() + t.clear() exec_lua('require("vim.lsp")') end) - after_each(helpers.clear) + after_each(t.clear) it('on_codelens_stores_and_displays_lenses', function() local fake_uri = 'file:///fake/uri' diff --git a/test/functional/plugin/lsp/completion_spec.lua b/test/functional/plugin/lsp/completion_spec.lua index 655eb76be6..fd29a11ead 100644 --- a/test/functional/plugin/lsp/completion_spec.lua +++ b/test/functional/plugin/lsp/completion_spec.lua @@ -1,7 +1,7 @@ ---@diagnostic disable: no-unknown -local helpers = require('test.functional.helpers')(after_each) -local eq = helpers.eq -local exec_lua = helpers.exec_lua +local t = require('test.functional.testutil')(after_each) +local eq = t.eq +local exec_lua = t.exec_lua --- Convert completion results. --- @@ -41,7 +41,7 @@ local function complete(line, candidates, lnum) end describe('vim.lsp._completion', function() - before_each(helpers.clear) + before_each(t.clear) -- https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion it('prefers textEdit over label as word', function() diff --git a/test/functional/plugin/lsp/diagnostic_spec.lua b/test/functional/plugin/lsp/diagnostic_spec.lua index 72531db021..ffff677ad6 100644 --- a/test/functional/plugin/lsp/diagnostic_spec.lua +++ b/test/functional/plugin/lsp/diagnostic_spec.lua @@ -1,12 +1,12 @@ -local helpers = require('test.functional.helpers')(after_each) -local lsp_helpers = require('test.functional.plugin.lsp.helpers') +local t = require('test.functional.testutil')(after_each) +local t_lsp = require('test.functional.plugin.lsp.testutil') -local clear = helpers.clear -local exec_lua = helpers.exec_lua -local eq = helpers.eq -local neq = require('test.helpers').neq +local clear = t.clear +local exec_lua = t.exec_lua +local eq = t.eq +local neq = t.neq -local create_server_definition = lsp_helpers.create_server_definition +local create_server_definition = t_lsp.create_server_definition describe('vim.lsp.diagnostic', function() local fake_uri diff --git a/test/functional/plugin/lsp/handler_spec.lua b/test/functional/plugin/lsp/handler_spec.lua index 56e29e7337..04e4fc8b8e 100644 --- a/test/functional/plugin/lsp/handler_spec.lua +++ b/test/functional/plugin/lsp/handler_spec.lua @@ -1,9 +1,9 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local eq = helpers.eq -local exec_lua = helpers.exec_lua -local pcall_err = helpers.pcall_err -local matches = helpers.matches +local eq = t.eq +local exec_lua = t.exec_lua +local pcall_err = t.pcall_err +local matches = t.matches describe('lsp-handlers', function() describe('vim.lsp._with_extend', function() diff --git a/test/functional/plugin/lsp/helpers.lua b/test/functional/plugin/lsp/helpers.lua deleted file mode 100644 index fb93746480..0000000000 --- a/test/functional/plugin/lsp/helpers.lua +++ /dev/null @@ -1,219 +0,0 @@ -local helpers = require('test.functional.helpers')(nil) - -local clear = helpers.clear -local exec_lua = helpers.exec_lua -local run = helpers.run -local stop = helpers.stop -local api = helpers.api -local NIL = vim.NIL - -local M = {} - -function M.clear_notrace() - -- problem: here be dragons - -- solution: don't look too closely for dragons - clear { - env = { - NVIM_LUA_NOTRACK = '1', - NVIM_APPNAME = 'nvim_lsp_test', - VIMRUNTIME = os.getenv 'VIMRUNTIME', - }, - } -end - -M.create_server_definition = [[ - function _create_server(opts) - opts = opts or {} - local server = {} - server.messages = {} - - function server.cmd(dispatchers) - local closing = false - local handlers = opts.handlers or {} - local srv = {} - - function srv.request(method, params, callback) - table.insert(server.messages, { - method = method, - params = params, - }) - local handler = handlers[method] - if handler then - local response, err = handler(method, params) - callback(err, response) - elseif method == 'initialize' then - callback(nil, { - capabilities = opts.capabilities or {} - }) - elseif method == 'shutdown' then - callback(nil, nil) - end - local request_id = #server.messages - return true, request_id - end - - function srv.notify(method, params) - table.insert(server.messages, { - method = method, - params = params - }) - if method == 'exit' then - dispatchers.on_exit(0, 15) - end - end - - function srv.is_closing() - return closing - end - - function srv.terminate() - closing = true - end - - return srv - end - - return server - end -]] - --- Fake LSP server. -M.fake_lsp_code = 'test/functional/fixtures/fake-lsp-server.lua' -M.fake_lsp_logfile = 'Xtest-fake-lsp.log' - -local function fake_lsp_server_setup(test_name, timeout_ms, options, settings) - exec_lua( - [=[ - lsp = require('vim.lsp') - local test_name, fake_lsp_code, fake_lsp_logfile, timeout, options, settings = ... - TEST_RPC_CLIENT_ID = lsp.start_client { - cmd_env = { - NVIM_LOG_FILE = fake_lsp_logfile; - NVIM_LUA_NOTRACK = "1"; - NVIM_APPNAME = "nvim_lsp_test"; - }; - cmd = { - vim.v.progpath, '-l', fake_lsp_code, test_name, tostring(timeout), - }; - handlers = setmetatable({}, { - __index = function(t, method) - return function(...) - return vim.rpcrequest(1, 'handler', ...) - end - end; - }); - workspace_folders = {{ - uri = 'file://' .. vim.uv.cwd(), - name = 'test_folder', - }}; - before_init = function(params, config) - vim.schedule(function() - vim.rpcrequest(1, "setup") - end) - end, - on_init = function(client, result) - TEST_RPC_CLIENT = client - vim.rpcrequest(1, "init", result) - end; - flags = { - allow_incremental_sync = options.allow_incremental_sync or false; - debounce_text_changes = options.debounce_text_changes or 0; - }; - settings = settings; - on_exit = function(...) - vim.rpcnotify(1, "exit", ...) - end; - } - ]=], - test_name, - M.fake_lsp_code, - M.fake_lsp_logfile, - timeout_ms or 1e3, - options or {}, - settings or {} - ) -end - ---- @class test.lsp.Config ---- @field test_name string ---- @field timeout_ms? integer ---- @field options? table ---- @field settings? table ---- ---- @field on_setup? fun() ---- @field on_init? fun(client: vim.lsp.Client, ...) ---- @field on_handler? fun(...) ---- @field on_exit? fun(code: integer, signal: integer) - ---- @param config test.lsp.Config -function M.test_rpc_server(config) - if config.test_name then - M.clear_notrace() - fake_lsp_server_setup( - config.test_name, - config.timeout_ms or 1e3, - config.options, - config.settings - ) - end - local client = setmetatable({}, { - __index = function(_, name) - -- Workaround for not being able to yield() inside __index for Lua 5.1 :( - -- Otherwise I would just return the value here. - return function(...) - return exec_lua( - [=[ - local name = ... - if type(TEST_RPC_CLIENT[name]) == 'function' then - return TEST_RPC_CLIENT[name](select(2, ...)) - else - return TEST_RPC_CLIENT[name] - end - ]=], - name, - ... - ) - end - end, - }) - --- @type integer, integer - local code, signal - local function on_request(method, args) - if method == 'setup' then - if config.on_setup then - config.on_setup() - end - return NIL - end - if method == 'init' then - if config.on_init then - config.on_init(client, unpack(args)) - end - return NIL - end - if method == 'handler' then - if config.on_handler then - config.on_handler(unpack(args)) - end - end - return NIL - end - local function on_notify(method, args) - if method == 'exit' then - code, signal = unpack(args) - return stop() - end - end - -- TODO specify timeout? - -- run(on_request, on_notify, nil, 1000) - run(on_request, on_notify, nil) - if config.on_exit then - config.on_exit(code, signal) - end - stop() - if config.test_name then - api.nvim_exec_autocmds('VimLeavePre', { modeline = false }) - end -end - -return M diff --git a/test/functional/plugin/lsp/incremental_sync_spec.lua b/test/functional/plugin/lsp/incremental_sync_spec.lua index bd1842ceb5..eed182150e 100644 --- a/test/functional/plugin/lsp/incremental_sync_spec.lua +++ b/test/functional/plugin/lsp/incremental_sync_spec.lua @@ -1,11 +1,11 @@ -- Test suite for testing interactions with the incremental sync algorithms powering the LSP client -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local api = helpers.api -local clear = helpers.clear -local eq = helpers.eq -local exec_lua = helpers.exec_lua -local feed = helpers.feed +local api = t.api +local clear = t.clear +local eq = t.eq +local exec_lua = t.exec_lua +local feed = t.feed before_each(function() clear() diff --git a/test/functional/plugin/lsp/inlay_hint_spec.lua b/test/functional/plugin/lsp/inlay_hint_spec.lua index e9c347bcc5..dceaf45bca 100644 --- a/test/functional/plugin/lsp/inlay_hint_spec.lua +++ b/test/functional/plugin/lsp/inlay_hint_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) -local lsp_helpers = require('test.functional.plugin.lsp.helpers') +local t = require('test.functional.testutil')(after_each) +local t_lsp = require('test.functional.plugin.lsp.testutil') local Screen = require('test.functional.ui.screen') -local eq = helpers.eq -local dedent = helpers.dedent -local exec_lua = helpers.exec_lua -local insert = helpers.insert -local api = helpers.api +local eq = t.eq +local dedent = t.dedent +local exec_lua = t.exec_lua +local insert = t.insert +local api = t.api -local clear_notrace = lsp_helpers.clear_notrace -local create_server_definition = lsp_helpers.create_server_definition +local clear_notrace = t_lsp.clear_notrace +local create_server_definition = t_lsp.create_server_definition local text = dedent([[ auto add(int a, int b) { return a + b; } diff --git a/test/functional/plugin/lsp/semantic_tokens_spec.lua b/test/functional/plugin/lsp/semantic_tokens_spec.lua index 12f6e09e7e..82450e404e 100644 --- a/test/functional/plugin/lsp/semantic_tokens_spec.lua +++ b/test/functional/plugin/lsp/semantic_tokens_spec.lua @@ -1,19 +1,19 @@ -local helpers = require('test.functional.helpers')(after_each) -local lsp_helpers = require('test.functional.plugin.lsp.helpers') +local t = require('test.functional.testutil')(after_each) +local t_lsp = require('test.functional.plugin.lsp.testutil') local Screen = require('test.functional.ui.screen') -local command = helpers.command -local dedent = helpers.dedent -local eq = helpers.eq -local exec_lua = helpers.exec_lua -local feed = helpers.feed -local feed_command = helpers.feed_command -local insert = helpers.insert -local matches = helpers.matches -local api = helpers.api - -local clear_notrace = lsp_helpers.clear_notrace -local create_server_definition = lsp_helpers.create_server_definition +local command = t.command +local dedent = t.dedent +local eq = t.eq +local exec_lua = t.exec_lua +local feed = t.feed +local feed_command = t.feed_command +local insert = t.insert +local matches = t.matches +local api = t.api + +local clear_notrace = t_lsp.clear_notrace +local create_server_definition = t_lsp.create_server_definition before_each(function() clear_notrace() diff --git a/test/functional/plugin/lsp/snippet_spec.lua b/test/functional/plugin/lsp/snippet_spec.lua index ba8bc7fe04..d62e188dab 100644 --- a/test/functional/plugin/lsp/snippet_spec.lua +++ b/test/functional/plugin/lsp/snippet_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local snippet = require('vim.lsp._snippet_grammar') local type = snippet.NodeType -local eq = helpers.eq -local exec_lua = helpers.exec_lua +local eq = t.eq +local exec_lua = t.exec_lua describe('vim.lsp._snippet_grammar', function() - before_each(helpers.clear) - after_each(helpers.clear) + before_each(t.clear) + after_each(t.clear) local parse = function(...) local res = exec_lua('return require("vim.lsp._snippet_grammar").parse(...)', ...) diff --git a/test/functional/plugin/lsp/testutil.lua b/test/functional/plugin/lsp/testutil.lua new file mode 100644 index 0000000000..7dc7bd9925 --- /dev/null +++ b/test/functional/plugin/lsp/testutil.lua @@ -0,0 +1,219 @@ +local t = require('test.functional.testutil')(nil) + +local clear = t.clear +local exec_lua = t.exec_lua +local run = t.run +local stop = t.stop +local api = t.api +local NIL = vim.NIL + +local M = {} + +function M.clear_notrace() + -- problem: here be dragons + -- solution: don't look too closely for dragons + clear { + env = { + NVIM_LUA_NOTRACK = '1', + NVIM_APPNAME = 'nvim_lsp_test', + VIMRUNTIME = os.getenv 'VIMRUNTIME', + }, + } +end + +M.create_server_definition = [[ + function _create_server(opts) + opts = opts or {} + local server = {} + server.messages = {} + + function server.cmd(dispatchers) + local closing = false + local handlers = opts.handlers or {} + local srv = {} + + function srv.request(method, params, callback) + table.insert(server.messages, { + method = method, + params = params, + }) + local handler = handlers[method] + if handler then + local response, err = handler(method, params) + callback(err, response) + elseif method == 'initialize' then + callback(nil, { + capabilities = opts.capabilities or {} + }) + elseif method == 'shutdown' then + callback(nil, nil) + end + local request_id = #server.messages + return true, request_id + end + + function srv.notify(method, params) + table.insert(server.messages, { + method = method, + params = params + }) + if method == 'exit' then + dispatchers.on_exit(0, 15) + end + end + + function srv.is_closing() + return closing + end + + function srv.terminate() + closing = true + end + + return srv + end + + return server + end +]] + +-- Fake LSP server. +M.fake_lsp_code = 'test/functional/fixtures/fake-lsp-server.lua' +M.fake_lsp_logfile = 'Xtest-fake-lsp.log' + +local function fake_lsp_server_setup(test_name, timeout_ms, options, settings) + exec_lua( + [=[ + lsp = require('vim.lsp') + local test_name, fake_lsp_code, fake_lsp_logfile, timeout, options, settings = ... + TEST_RPC_CLIENT_ID = lsp.start_client { + cmd_env = { + NVIM_LOG_FILE = fake_lsp_logfile; + NVIM_LUA_NOTRACK = "1"; + NVIM_APPNAME = "nvim_lsp_test"; + }; + cmd = { + vim.v.progpath, '-l', fake_lsp_code, test_name, tostring(timeout), + }; + handlers = setmetatable({}, { + __index = function(t, method) + return function(...) + return vim.rpcrequest(1, 'handler', ...) + end + end; + }); + workspace_folders = {{ + uri = 'file://' .. vim.uv.cwd(), + name = 'test_folder', + }}; + before_init = function(params, config) + vim.schedule(function() + vim.rpcrequest(1, "setup") + end) + end, + on_init = function(client, result) + TEST_RPC_CLIENT = client + vim.rpcrequest(1, "init", result) + end; + flags = { + allow_incremental_sync = options.allow_incremental_sync or false; + debounce_text_changes = options.debounce_text_changes or 0; + }; + settings = settings; + on_exit = function(...) + vim.rpcnotify(1, "exit", ...) + end; + } + ]=], + test_name, + M.fake_lsp_code, + M.fake_lsp_logfile, + timeout_ms or 1e3, + options or {}, + settings or {} + ) +end + +--- @class test.lsp.Config +--- @field test_name string +--- @field timeout_ms? integer +--- @field options? table +--- @field settings? table +--- +--- @field on_setup? fun() +--- @field on_init? fun(client: vim.lsp.Client, ...) +--- @field on_handler? fun(...) +--- @field on_exit? fun(code: integer, signal: integer) + +--- @param config test.lsp.Config +function M.test_rpc_server(config) + if config.test_name then + M.clear_notrace() + fake_lsp_server_setup( + config.test_name, + config.timeout_ms or 1e3, + config.options, + config.settings + ) + end + local client = setmetatable({}, { + __index = function(_, name) + -- Workaround for not being able to yield() inside __index for Lua 5.1 :( + -- Otherwise I would just return the value here. + return function(...) + return exec_lua( + [=[ + local name = ... + if type(TEST_RPC_CLIENT[name]) == 'function' then + return TEST_RPC_CLIENT[name](select(2, ...)) + else + return TEST_RPC_CLIENT[name] + end + ]=], + name, + ... + ) + end + end, + }) + --- @type integer, integer + local code, signal + local function on_request(method, args) + if method == 'setup' then + if config.on_setup then + config.on_setup() + end + return NIL + end + if method == 'init' then + if config.on_init then + config.on_init(client, unpack(args)) + end + return NIL + end + if method == 'handler' then + if config.on_handler then + config.on_handler(unpack(args)) + end + end + return NIL + end + local function on_notify(method, args) + if method == 'exit' then + code, signal = unpack(args) + return stop() + end + end + -- TODO specify timeout? + -- run(on_request, on_notify, nil, 1000) + run(on_request, on_notify, nil) + if config.on_exit then + config.on_exit(code, signal) + end + stop() + if config.test_name then + api.nvim_exec_autocmds('VimLeavePre', { modeline = false }) + end +end + +return M diff --git a/test/functional/plugin/lsp/utils_spec.lua b/test/functional/plugin/lsp/utils_spec.lua index bb9cdb8390..c7b874d443 100644 --- a/test/functional/plugin/lsp/utils_spec.lua +++ b/test/functional/plugin/lsp/utils_spec.lua @@ -1,12 +1,12 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local feed = helpers.feed +local feed = t.feed -local eq = helpers.eq -local exec_lua = helpers.exec_lua +local eq = t.eq +local exec_lua = t.exec_lua describe('vim.lsp.util', function() - before_each(helpers.clear) + before_each(t.clear) describe('stylize_markdown', function() local stylize_markdown = function(content, opts) @@ -142,7 +142,7 @@ describe('vim.lsp.util', function() local screen before_each(function() - helpers.clear() + t.clear() screen = Screen.new(80, 80) screen:attach() feed('79i') -- fill screen with empty lines diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index c65cca6cb7..a7dd0537c3 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -1,36 +1,36 @@ -local helpers = require('test.functional.helpers')(after_each) -local lsp_helpers = require('test.functional.plugin.lsp.helpers') - -local assert_log = helpers.assert_log -local buf_lines = helpers.buf_lines -local clear = helpers.clear -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 t = require('test.functional.testutil')(after_each) +local t_lsp = require('test.functional.plugin.lsp.testutil') + +local assert_log = t.assert_log +local buf_lines = t.buf_lines +local clear = t.clear +local command = t.command +local dedent = t.dedent +local exec_lua = t.exec_lua +local eq = t.eq +local eval = t.eval +local matches = t.matches +local pcall_err = t.pcall_err local pesc = vim.pesc -local insert = helpers.insert -local fn = helpers.fn -local retry = helpers.retry -local stop = helpers.stop +local insert = t.insert +local fn = t.fn +local retry = t.retry +local stop = t.stop local NIL = vim.NIL -local read_file = helpers.read_file -local write_file = helpers.write_file -local is_ci = helpers.is_ci -local api = helpers.api -local is_os = helpers.is_os -local skip = helpers.skip -local mkdir = helpers.mkdir -local tmpname = helpers.tmpname - -local clear_notrace = lsp_helpers.clear_notrace -local create_server_definition = lsp_helpers.create_server_definition -local fake_lsp_code = lsp_helpers.fake_lsp_code -local fake_lsp_logfile = lsp_helpers.fake_lsp_logfile -local test_rpc_server = lsp_helpers.test_rpc_server +local read_file = t.read_file +local write_file = t.write_file +local is_ci = t.is_ci +local api = t.api +local is_os = t.is_os +local skip = t.skip +local mkdir = t.mkdir +local tmpname = t.tmpname + +local clear_notrace = t_lsp.clear_notrace +local create_server_definition = t_lsp.create_server_definition +local fake_lsp_code = t_lsp.fake_lsp_code +local fake_lsp_logfile = t_lsp.fake_lsp_logfile +local test_rpc_server = t_lsp.test_rpc_server local function get_buf_option(name, bufnr) bufnr = bufnr or 'BUFFER' @@ -249,7 +249,7 @@ describe('LSP', function() if is_ci() then pending('hangs the build on CI #14028, re-enable with freeze timeout #14204') return - elseif helpers.skip_fragile(pending) then + elseif t.skip_fragile(pending) then return end local expected_handlers = { @@ -1481,7 +1481,7 @@ describe('LSP', function() end, on_handler = function(err, result, ctx) if ctx.method == 'start' then - helpers.command('normal! 1Go') + t.command('normal! 1Go') client.notify('finish') end eq(table.remove(expected_handlers), { err, result, ctx }, 'expected handler') @@ -2368,7 +2368,7 @@ describe('LSP', function() end) describe('lsp.util.rename', function() - local pathsep = helpers.get_pathsep() + local pathsep = t.get_pathsep() it('Can rename an existing file', function() local old = tmpname() @@ -2404,7 +2404,7 @@ describe('LSP', function() os.remove(old_dir) os.remove(new_dir) - helpers.mkdir_p(old_dir) + t.mkdir_p(old_dir) local file = 'file.txt' write_file(old_dir .. pathsep .. file, 'Test content') @@ -2440,7 +2440,7 @@ describe('LSP', function() local new = tmpname() os.remove(old) os.remove(new) - helpers.mkdir_p(old) + t.mkdir_p(old) local result = exec_lua( [[ diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua index 34006d5906..862cb13146 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -1,17 +1,17 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local command, feed = helpers.command, helpers.feed -local clear = helpers.clear -local exec_lua = helpers.exec_lua -local fn = helpers.fn -local nvim_prog = helpers.nvim_prog -local matches = helpers.matches -local write_file = helpers.write_file -local tmpname = helpers.tmpname -local eq = helpers.eq +local command, feed = t.command, t.feed +local clear = t.clear +local exec_lua = t.exec_lua +local fn = t.fn +local nvim_prog = t.nvim_prog +local matches = t.matches +local write_file = t.write_file +local tmpname = t.tmpname +local eq = t.eq local pesc = vim.pesc -local skip = helpers.skip -local is_ci = helpers.is_ci +local skip = t.skip +local is_ci = t.is_ci -- Collects all names passed to find_path() after attempting ":Man foo". local function get_search_history(name) diff --git a/test/functional/plugin/matchparen_spec.lua b/test/functional/plugin/matchparen_spec.lua index 619c43f2c9..93d747519a 100644 --- a/test/functional/plugin/matchparen_spec.lua +++ b/test/functional/plugin/matchparen_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local command = helpers.command -local api = helpers.api -local feed = helpers.feed -local eq = helpers.eq +local clear = t.clear +local command = t.command +local api = t.api +local feed = t.feed +local eq = t.eq describe('matchparen', function() local screen --- @type test.functional.ui.screen diff --git a/test/functional/plugin/msgpack_spec.lua b/test/functional/plugin/msgpack_spec.lua index 8511e6c703..76feca7911 100644 --- a/test/functional/plugin/msgpack_spec.lua +++ b/test/functional/plugin/msgpack_spec.lua @@ -1,11 +1,11 @@ -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local api = helpers.api -local eq = helpers.eq -local nvim_eval = helpers.eval -local nvim_command = helpers.command -local exc_exec = helpers.exc_exec -local ok = helpers.ok +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local api = t.api +local eq = t.eq +local nvim_eval = t.eval +local nvim_command = t.command +local exc_exec = t.exc_exec +local ok = t.ok local NIL = vim.NIL describe('autoload/msgpack.vim', function() diff --git a/test/functional/plugin/shada_spec.lua b/test/functional/plugin/shada_spec.lua index 1c20548321..9312f1f2f0 100644 --- a/test/functional/plugin/shada_spec.lua +++ b/test/functional/plugin/shada_spec.lua @@ -1,13 +1,13 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear +local clear = t.clear local eq, api, nvim_eval, nvim_command, exc_exec, fn, nvim_feed = - helpers.eq, helpers.api, helpers.eval, helpers.command, helpers.exc_exec, helpers.fn, helpers.feed -local neq = helpers.neq -local read_file = helpers.read_file + t.eq, t.api, t.eval, t.command, t.exc_exec, t.fn, t.feed +local neq = t.neq +local read_file = t.read_file -local shada_helpers = require('test.functional.shada.helpers') -local get_shada_rw = shada_helpers.get_shada_rw +local t_shada = require('test.functional.shada.testutil') +local get_shada_rw = t_shada.get_shada_rw local function reset(shada_file) clear { args = { '-u', 'NORC', '-i', shada_file or 'NONE' } } @@ -2612,7 +2612,7 @@ end) describe('plugin/shada.vim', function() local epoch = os.date('%Y-%m-%dT%H:%M:%S', 0) - local eol = helpers.is_os('win') and '\r\n' or '\n' + local eol = t.is_os('win') and '\r\n' or '\n' before_each(function() -- Note: reset() is called explicitly in each test. os.remove(fname) diff --git a/test/functional/plugin/tohtml_spec.lua b/test/functional/plugin/tohtml_spec.lua index 2ac0fe1fa3..9d947fe44a 100644 --- a/test/functional/plugin/tohtml_spec.lua +++ b/test/functional/plugin/tohtml_spec.lua @@ -1,13 +1,13 @@ local Screen = require('test.functional.ui.screen') -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local clear = helpers.clear -local exec = helpers.exec -local exec_lua = helpers.exec_lua -local eq = helpers.eq -local fn = helpers.fn -local api = helpers.api -local insert = helpers.insert +local clear = t.clear +local exec = t.exec +local exec_lua = t.exec_lua +local eq = t.eq +local fn = t.fn +local api = t.api +local insert = t.insert local function html_syntax_match() local styles = diff --git a/test/functional/plugin/tutor_spec.lua b/test/functional/plugin/tutor_spec.lua index 46a117f298..d9ba8365d6 100644 --- a/test/functional/plugin/tutor_spec.lua +++ b/test/functional/plugin/tutor_spec.lua @@ -1,9 +1,9 @@ local Screen = require('test.functional.ui.screen') -local helpers = require('test.functional.helpers')(after_each) -local clear = helpers.clear -local command = helpers.command -local feed = helpers.feed -local is_os = helpers.is_os +local t = require('test.functional.testutil')(after_each) +local clear = t.clear +local command = t.command +local feed = t.feed +local is_os = t.is_os describe(':Tutor', function() local screen --- @type test.functional.ui.screen diff --git a/test/functional/plugin/vim_syntax_spec.lua b/test/functional/plugin/vim_syntax_spec.lua index c5858f8bc0..c07c5646a6 100644 --- a/test/functional/plugin/vim_syntax_spec.lua +++ b/test/functional/plugin/vim_syntax_spec.lua @@ -1,15 +1,15 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') -local clear = helpers.clear -local exec = helpers.exec -local api = helpers.api +local clear = t.clear +local exec = t.exec +local api = t.api describe('Vimscript syntax highlighting', function() local screen --- @type test.functional.ui.screen before_each(function() clear() - helpers.add_builddir_to_rtp() + t.add_builddir_to_rtp() exec([[ setfiletype vim syntax on -- cgit From 81fc27124b9e1b375e0ce9605ae69c3c2a2d9222 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 9 Apr 2024 12:26:16 +0100 Subject: refactor(test): inject after_each differently --- test/functional/plugin/ccomplete_spec.lua | 2 +- test/functional/plugin/cfilter_spec.lua | 2 +- test/functional/plugin/editorconfig_spec.lua | 2 +- test/functional/plugin/health_spec.lua | 2 +- test/functional/plugin/lsp/codelens_spec.lua | 2 +- test/functional/plugin/lsp/completion_spec.lua | 2 +- test/functional/plugin/lsp/diagnostic_spec.lua | 2 +- test/functional/plugin/lsp/handler_spec.lua | 2 +- test/functional/plugin/lsp/incremental_sync_spec.lua | 2 +- test/functional/plugin/lsp/inlay_hint_spec.lua | 2 +- test/functional/plugin/lsp/semantic_tokens_spec.lua | 2 +- test/functional/plugin/lsp/snippet_spec.lua | 2 +- test/functional/plugin/lsp/utils_spec.lua | 2 +- test/functional/plugin/lsp_spec.lua | 2 +- test/functional/plugin/man_spec.lua | 2 +- test/functional/plugin/matchparen_spec.lua | 2 +- test/functional/plugin/msgpack_spec.lua | 2 +- test/functional/plugin/shada_spec.lua | 2 +- test/functional/plugin/tohtml_spec.lua | 2 +- test/functional/plugin/tutor_spec.lua | 2 +- test/functional/plugin/vim_syntax_spec.lua | 2 +- 21 files changed, 21 insertions(+), 21 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/ccomplete_spec.lua b/test/functional/plugin/ccomplete_spec.lua index 2133f28a2e..bb9b28d300 100644 --- a/test/functional/plugin/ccomplete_spec.lua +++ b/test/functional/plugin/ccomplete_spec.lua @@ -1,4 +1,4 @@ -local t = require('test.functional.testutil')(after_each) +local t = require('test.functional.testutil')() local clear = t.clear local command = t.command local eq = t.eq diff --git a/test/functional/plugin/cfilter_spec.lua b/test/functional/plugin/cfilter_spec.lua index 917e666ab0..d421c5fc14 100644 --- a/test/functional/plugin/cfilter_spec.lua +++ b/test/functional/plugin/cfilter_spec.lua @@ -1,4 +1,4 @@ -local t = require('test.functional.testutil')(after_each) +local t = require('test.functional.testutil')() local clear = t.clear local command = t.command local eq = t.eq diff --git a/test/functional/plugin/editorconfig_spec.lua b/test/functional/plugin/editorconfig_spec.lua index cd524373da..d108f325e1 100644 --- a/test/functional/plugin/editorconfig_spec.lua +++ b/test/functional/plugin/editorconfig_spec.lua @@ -1,4 +1,4 @@ -local t = require('test.functional.testutil')(after_each) +local t = require('test.functional.testutil')() local clear = t.clear local command = t.command local eq = t.eq diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index 3fe9102886..ef86dcf31e 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -1,4 +1,4 @@ -local t = require('test.functional.testutil')(after_each) +local t = require('test.functional.testutil')() local Screen = require('test.functional.ui.screen') local clear = t.clear diff --git a/test/functional/plugin/lsp/codelens_spec.lua b/test/functional/plugin/lsp/codelens_spec.lua index a618854e2f..20e850eeee 100644 --- a/test/functional/plugin/lsp/codelens_spec.lua +++ b/test/functional/plugin/lsp/codelens_spec.lua @@ -1,4 +1,4 @@ -local t = require('test.functional.testutil')(after_each) +local t = require('test.functional.testutil')() local exec_lua = t.exec_lua local eq = t.eq diff --git a/test/functional/plugin/lsp/completion_spec.lua b/test/functional/plugin/lsp/completion_spec.lua index fd29a11ead..18f123a979 100644 --- a/test/functional/plugin/lsp/completion_spec.lua +++ b/test/functional/plugin/lsp/completion_spec.lua @@ -1,5 +1,5 @@ ---@diagnostic disable: no-unknown -local t = require('test.functional.testutil')(after_each) +local t = require('test.functional.testutil')() local eq = t.eq local exec_lua = t.exec_lua diff --git a/test/functional/plugin/lsp/diagnostic_spec.lua b/test/functional/plugin/lsp/diagnostic_spec.lua index ffff677ad6..27b0da1f3d 100644 --- a/test/functional/plugin/lsp/diagnostic_spec.lua +++ b/test/functional/plugin/lsp/diagnostic_spec.lua @@ -1,4 +1,4 @@ -local t = require('test.functional.testutil')(after_each) +local t = require('test.functional.testutil')() local t_lsp = require('test.functional.plugin.lsp.testutil') local clear = t.clear diff --git a/test/functional/plugin/lsp/handler_spec.lua b/test/functional/plugin/lsp/handler_spec.lua index 04e4fc8b8e..0ce7479c49 100644 --- a/test/functional/plugin/lsp/handler_spec.lua +++ b/test/functional/plugin/lsp/handler_spec.lua @@ -1,4 +1,4 @@ -local t = require('test.functional.testutil')(after_each) +local t = require('test.functional.testutil')() local eq = t.eq local exec_lua = t.exec_lua diff --git a/test/functional/plugin/lsp/incremental_sync_spec.lua b/test/functional/plugin/lsp/incremental_sync_spec.lua index eed182150e..a44b861ca1 100644 --- a/test/functional/plugin/lsp/incremental_sync_spec.lua +++ b/test/functional/plugin/lsp/incremental_sync_spec.lua @@ -1,5 +1,5 @@ -- Test suite for testing interactions with the incremental sync algorithms powering the LSP client -local t = require('test.functional.testutil')(after_each) +local t = require('test.functional.testutil')() local api = t.api local clear = t.clear diff --git a/test/functional/plugin/lsp/inlay_hint_spec.lua b/test/functional/plugin/lsp/inlay_hint_spec.lua index dceaf45bca..64c65b74c3 100644 --- a/test/functional/plugin/lsp/inlay_hint_spec.lua +++ b/test/functional/plugin/lsp/inlay_hint_spec.lua @@ -1,4 +1,4 @@ -local t = require('test.functional.testutil')(after_each) +local t = require('test.functional.testutil')() local t_lsp = require('test.functional.plugin.lsp.testutil') local Screen = require('test.functional.ui.screen') diff --git a/test/functional/plugin/lsp/semantic_tokens_spec.lua b/test/functional/plugin/lsp/semantic_tokens_spec.lua index 82450e404e..a9d8592eb0 100644 --- a/test/functional/plugin/lsp/semantic_tokens_spec.lua +++ b/test/functional/plugin/lsp/semantic_tokens_spec.lua @@ -1,4 +1,4 @@ -local t = require('test.functional.testutil')(after_each) +local t = require('test.functional.testutil')() local t_lsp = require('test.functional.plugin.lsp.testutil') local Screen = require('test.functional.ui.screen') diff --git a/test/functional/plugin/lsp/snippet_spec.lua b/test/functional/plugin/lsp/snippet_spec.lua index d62e188dab..0f4304868b 100644 --- a/test/functional/plugin/lsp/snippet_spec.lua +++ b/test/functional/plugin/lsp/snippet_spec.lua @@ -1,4 +1,4 @@ -local t = require('test.functional.testutil')(after_each) +local t = require('test.functional.testutil')() local snippet = require('vim.lsp._snippet_grammar') local type = snippet.NodeType diff --git a/test/functional/plugin/lsp/utils_spec.lua b/test/functional/plugin/lsp/utils_spec.lua index c7b874d443..8e57ace449 100644 --- a/test/functional/plugin/lsp/utils_spec.lua +++ b/test/functional/plugin/lsp/utils_spec.lua @@ -1,4 +1,4 @@ -local t = require('test.functional.testutil')(after_each) +local t = require('test.functional.testutil')() local Screen = require('test.functional.ui.screen') local feed = t.feed diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index a7dd0537c3..1ff29bf74f 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -1,4 +1,4 @@ -local t = require('test.functional.testutil')(after_each) +local t = require('test.functional.testutil')() local t_lsp = require('test.functional.plugin.lsp.testutil') local assert_log = t.assert_log diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua index 862cb13146..19d279afbf 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -1,4 +1,4 @@ -local t = require('test.functional.testutil')(after_each) +local t = require('test.functional.testutil')() local Screen = require('test.functional.ui.screen') local command, feed = t.command, t.feed local clear = t.clear diff --git a/test/functional/plugin/matchparen_spec.lua b/test/functional/plugin/matchparen_spec.lua index 93d747519a..ae343b9555 100644 --- a/test/functional/plugin/matchparen_spec.lua +++ b/test/functional/plugin/matchparen_spec.lua @@ -1,4 +1,4 @@ -local t = require('test.functional.testutil')(after_each) +local t = require('test.functional.testutil')() local Screen = require('test.functional.ui.screen') local clear = t.clear diff --git a/test/functional/plugin/msgpack_spec.lua b/test/functional/plugin/msgpack_spec.lua index 76feca7911..9b70c12fc7 100644 --- a/test/functional/plugin/msgpack_spec.lua +++ b/test/functional/plugin/msgpack_spec.lua @@ -1,4 +1,4 @@ -local t = require('test.functional.testutil')(after_each) +local t = require('test.functional.testutil')() local clear = t.clear local api = t.api local eq = t.eq diff --git a/test/functional/plugin/shada_spec.lua b/test/functional/plugin/shada_spec.lua index 9312f1f2f0..270eacc653 100644 --- a/test/functional/plugin/shada_spec.lua +++ b/test/functional/plugin/shada_spec.lua @@ -1,4 +1,4 @@ -local t = require('test.functional.testutil')(after_each) +local t = require('test.functional.testutil')() local Screen = require('test.functional.ui.screen') local clear = t.clear local eq, api, nvim_eval, nvim_command, exc_exec, fn, nvim_feed = diff --git a/test/functional/plugin/tohtml_spec.lua b/test/functional/plugin/tohtml_spec.lua index 9d947fe44a..f06d4d9c54 100644 --- a/test/functional/plugin/tohtml_spec.lua +++ b/test/functional/plugin/tohtml_spec.lua @@ -1,5 +1,5 @@ local Screen = require('test.functional.ui.screen') -local t = require('test.functional.testutil')(after_each) +local t = require('test.functional.testutil')() local clear = t.clear local exec = t.exec diff --git a/test/functional/plugin/tutor_spec.lua b/test/functional/plugin/tutor_spec.lua index d9ba8365d6..b8d5dc9399 100644 --- a/test/functional/plugin/tutor_spec.lua +++ b/test/functional/plugin/tutor_spec.lua @@ -1,5 +1,5 @@ local Screen = require('test.functional.ui.screen') -local t = require('test.functional.testutil')(after_each) +local t = require('test.functional.testutil')() local clear = t.clear local command = t.command local feed = t.feed diff --git a/test/functional/plugin/vim_syntax_spec.lua b/test/functional/plugin/vim_syntax_spec.lua index c07c5646a6..d31d6ad2f2 100644 --- a/test/functional/plugin/vim_syntax_spec.lua +++ b/test/functional/plugin/vim_syntax_spec.lua @@ -1,4 +1,4 @@ -local t = require('test.functional.testutil')(after_each) +local t = require('test.functional.testutil')() local Screen = require('test.functional.ui.screen') local clear = t.clear local exec = t.exec -- cgit From 4528a69c8772a5fe182fb293b929dfcfad112abc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 11 Apr 2024 08:51:06 +0800 Subject: test: remove unnecessary nil argument to testutil (#28270) --- test/functional/plugin/lsp/testutil.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp/testutil.lua b/test/functional/plugin/lsp/testutil.lua index 7dc7bd9925..c51ccf3097 100644 --- a/test/functional/plugin/lsp/testutil.lua +++ b/test/functional/plugin/lsp/testutil.lua @@ -1,4 +1,4 @@ -local t = require('test.functional.testutil')(nil) +local t = require('test.functional.testutil')() local clear = t.clear local exec_lua = t.exec_lua -- cgit From 66220d164a40791a5131d4660e6ffbee431070d5 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 8 Apr 2024 10:57:37 +0200 Subject: revert: "feat(health): fold successful healthchecks #22866" This reverts commit 4382d2ed564b80944345785d780cf1b19fb23ba8. The story for this feature was left in an incomplete state. It was never the intention to unilaterally fold all information, only the ones that did not contain relevant information. This feature does more harm than good in its incomplete state. --- test/functional/plugin/health_spec.lua | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index ef86dcf31e..529d182603 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -159,24 +159,6 @@ describe('health.vim', function() } end) - it('fold healthchecks', function() - local screen = Screen.new(50, 7) - screen:attach() - command('checkhealth foo success1') - command('set nowrap laststatus=0') - screen:expect { - grid = [[ - ^ | - {14:──────────────────────────────────────────────────}| - {13:+WE 4 lines: foo: ·······························}| - {14:──────────────────────────────────────────────────}| - {13:+-- 8 lines: test_plug.success1: require("test_pl}| - {1:~ }| - | - ]], - } - end) - it('gracefully handles invalid healthcheck', function() command('checkhealth non_existent_healthcheck') -- luacheck: ignore 613 -- cgit From 97323d821be97deeb1a5797b4ca534156b9e9b0c Mon Sep 17 00:00:00 2001 From: Mathias Fußenegger Date: Thu, 18 Apr 2024 15:34:10 +0200 Subject: refactor(lsp): merge rpc.domain_socket_connect into rpc.connect (#28398) See discussion in https://github.com/neovim/neovim/pull/26850 --- test/functional/plugin/lsp_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 1ff29bf74f..feca31c01b 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -4311,7 +4311,7 @@ describe('LSP', function() ]] eq('initialize', result.method) end) - it('can connect to lsp server via rpc.domain_socket_connect', function() + it('can connect to lsp server via pipe or domain_socket', function() local tmpfile --- @type string if is_os('win') then tmpfile = '\\\\.\\\\pipe\\pipe.test' @@ -4336,7 +4336,7 @@ describe('LSP', function() client:close() end)) end) - vim.lsp.start({ name = "dummy", cmd = vim.lsp.rpc.domain_socket_connect(SOCK) }) + vim.lsp.start({ name = "dummy", cmd = vim.lsp.rpc.connect(SOCK) }) vim.wait(1000, function() return init ~= nil end) assert(init, "server must receive `initialize` request") server:close() -- cgit From f1dfe32bf5552197e0068298b0527526a4f918b1 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 18 Apr 2024 07:57:58 -0700 Subject: feat(lua): enable(enable:boolean, filter:table) #28374 Problem: We need to establish a pattern for `enable()`. Solution: - First `enable()` parameter is always `enable:boolean`. - Update `vim.diagnostic.enable()` - Update `vim.lsp.inlay_hint.enable()`. - It was not released yet, so no deprecation is needed. But to help HEAD users, it will show an informative error. - vim.deprecate(): - Improve message when the "removal version" is a *current or older* version. --- test/functional/plugin/lsp/inlay_hint_spec.lua | 33 ++++++++++++++++++++------ test/functional/plugin/lsp_spec.lua | 2 +- 2 files changed, 27 insertions(+), 8 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp/inlay_hint_spec.lua b/test/functional/plugin/lsp/inlay_hint_spec.lua index 64c65b74c3..24c93fcbe0 100644 --- a/test/functional/plugin/lsp/inlay_hint_spec.lua +++ b/test/functional/plugin/lsp/inlay_hint_spec.lua @@ -84,7 +84,7 @@ before_each(function() ) insert(text) - exec_lua([[vim.lsp.inlay_hint.enable(bufnr)]]) + exec_lua([[vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })]]) screen:expect({ grid = grid_with_inlay_hints }) end) @@ -111,7 +111,7 @@ describe('vim.lsp.inlay_hint', function() } }) client2 = vim.lsp.start({ name = 'dummy2', cmd = server2.cmd }) - vim.lsp.inlay_hint.enable(bufnr) + vim.lsp.inlay_hint.enable(true, { bufnr = bufnr }) ]]) exec_lua([[ vim.lsp.stop_client(client2) ]]) @@ -119,17 +119,36 @@ describe('vim.lsp.inlay_hint', function() end) describe('enable()', function() + it('validation', function() + t.matches( + 'enable: expected boolean, got table', + t.pcall_err(exec_lua, [[vim.lsp.inlay_hint.enable({}, { bufnr = bufnr })]]) + ) + t.matches( + 'filter: expected table, got number', + t.pcall_err(exec_lua, [[vim.lsp.inlay_hint.enable(true, 42)]]) + ) + + exec_lua [[vim.notify = function() end]] + t.matches( + 'see %:help vim%.lsp%.inlay_hint%.enable', + t.pcall_err(exec_lua, [[vim.lsp.inlay_hint.enable(42)]]) + ) + end) + it('clears/applies inlay hints when passed false/true/nil', function() - exec_lua([[vim.lsp.inlay_hint.enable(bufnr, false)]]) + exec_lua([[vim.lsp.inlay_hint.enable(false, { bufnr = bufnr })]]) screen:expect({ grid = grid_without_inlay_hints, unchanged = true }) - exec_lua([[vim.lsp.inlay_hint.enable(bufnr, true)]]) + exec_lua([[vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })]]) screen:expect({ grid = grid_with_inlay_hints, unchanged = true }) - exec_lua([[vim.lsp.inlay_hint.enable(bufnr, not vim.lsp.inlay_hint.is_enabled(bufnr))]]) + exec_lua( + [[vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled(bufnr), { bufnr = bufnr })]] + ) screen:expect({ grid = grid_without_inlay_hints, unchanged = true }) - exec_lua([[vim.lsp.inlay_hint.enable(bufnr)]]) + exec_lua([[vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })]]) screen:expect({ grid = grid_with_inlay_hints, unchanged = true }) end) end) @@ -163,7 +182,7 @@ describe('vim.lsp.inlay_hint', function() } }) client2 = vim.lsp.start({ name = 'dummy2', cmd = server2.cmd }) - vim.lsp.inlay_hint.enable(bufnr) + vim.lsp.inlay_hint.enable(true, { bufnr = bufnr }) ]], expected2 ) diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index feca31c01b..5b90e6de6c 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -1328,7 +1328,7 @@ describe('LSP', function() on_handler = function(err, result, ctx) if ctx.method == 'start' then exec_lua [[ - vim.lsp.inlay_hint.enable(BUFFER) + vim.lsp.inlay_hint.enable(true, { bufnr = BUFFER }) ]] end if ctx.method == 'textDocument/inlayHint' then -- cgit From f190f758ac58d9cc955368e047b070e0a2261033 Mon Sep 17 00:00:00 2001 From: Yinzuo Jiang Date: Sat, 20 Apr 2024 21:40:01 +0800 Subject: feat(lsp): add vim.lsp.buf.subtypes(), vim.lsp.buf.supertypes() (#28388) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mathias Fußenegger Co-authored-by: Maria José Solano --- test/functional/plugin/lsp_spec.lua | 436 ++++++++++++++++++++++++++++++++++++ 1 file changed, 436 insertions(+) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 5b90e6de6c..d471aadf9c 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -3461,6 +3461,442 @@ describe('LSP', function() end) end) + describe('vim.lsp.buf.subtypes', function() + it('does nothing for an empty response', function() + local qflist_count = exec_lua([=[ + require'vim.lsp.handlers'['typeHierarchy/subtypes'](nil, nil, {}) + return #vim.fn.getqflist() + ]=]) + eq(0, qflist_count) + end) + + it('opens the quickfix list with the right subtypes', function() + clear() + exec_lua(create_server_definition) + local qflist = exec_lua([=[ + local clangd_response = { { + data = { + parents = { { + parents = { { + parents = { { + parents = {}, + symbolID = "62B3D268A01B9978" + } }, + symbolID = "DC9B0AD433B43BEC" + } }, + symbolID = "06B5F6A19BA9F6A8" + } }, + symbolID = "EDC336589C09ABB2" + }, + kind = 5, + name = "D2", + range = { + ["end"] = { + character = 8, + line = 9 + }, + start = { + character = 6, + line = 9 + } + }, + selectionRange = { + ["end"] = { + character = 8, + line = 9 + }, + start = { + character = 6, + line = 9 + } + }, + uri = "file:///home/jiangyinzuo/hello.cpp" + }, { + data = { + parents = { { + parents = { { + parents = { { + parents = {}, + symbolID = "62B3D268A01B9978" + } }, + symbolID = "DC9B0AD433B43BEC" + } }, + symbolID = "06B5F6A19BA9F6A8" + } }, + symbolID = "AFFCAED15557EF08" + }, + kind = 5, + name = "D1", + range = { + ["end"] = { + character = 8, + line = 8 + }, + start = { + character = 6, + line = 8 + } + }, + selectionRange = { + ["end"] = { + character = 8, + line = 8 + }, + start = { + character = 6, + line = 8 + } + }, + uri = "file:///home/jiangyinzuo/hello.cpp" + } } + + local server = _create_server({ + capabilities = { + positionEncoding = "utf-8" + }, + }) + local client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd }) + local handler = require'vim.lsp.handlers'['typeHierarchy/subtypes'] + handler(nil, clangd_response, { client_id = client_id, bufnr = 1 }) + return vim.fn.getqflist() + ]=]) + + local expected = { + { + bufnr = 2, + col = 7, + end_col = 0, + end_lnum = 0, + lnum = 10, + module = '', + nr = 0, + pattern = '', + text = 'D2', + type = '', + valid = 1, + vcol = 0, + }, + { + bufnr = 2, + col = 7, + end_col = 0, + end_lnum = 0, + lnum = 9, + module = '', + nr = 0, + pattern = '', + text = 'D1', + type = '', + valid = 1, + vcol = 0, + }, + } + + eq(expected, qflist) + end) + + it('opens the quickfix list with the right subtypes and details', function() + clear() + exec_lua(create_server_definition) + local qflist = exec_lua([=[ + local jdtls_response = { + { + data = { element = '=hello-java_ed323c3c/_<{Main.java[Main[A' }, + detail = '', + kind = 5, + name = 'A', + range = { + ['end'] = { character = 26, line = 3 }, + start = { character = 1, line = 3 }, + }, + selectionRange = { + ['end'] = { character = 8, line = 3 }, + start = { character = 7, line = 3 }, + }, + tags = {}, + uri = 'file:///home/jiangyinzuo/hello-java/Main.java', + }, + { + data = { element = '=hello-java_ed323c3c/_ Date: Mon, 22 Apr 2024 19:35:02 +0800 Subject: fix(completion): check that healthcheck name is string (#28458) --- test/functional/plugin/health_spec.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index 529d182603..9c17e74e19 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -6,6 +6,8 @@ local curbuf_contents = t.curbuf_contents local command = t.command local eq, neq, matches = t.eq, t.neq, t.matches local getcompletion = t.fn.getcompletion +local exec_lua = t.exec_lua +local assert_alive = t.assert_alive local insert = t.insert local source = t.source local fn = t.fn @@ -20,6 +22,7 @@ describe(':checkhealth', function() eq(false, status) eq('Invalid $VIMRUNTIME: bogus', string.match(err, 'Invalid.*')) end) + it("detects invalid 'runtimepath'", function() clear() command('set runtimepath=bogus') @@ -27,6 +30,7 @@ describe(':checkhealth', function() eq(false, status) eq("Invalid 'runtimepath'", string.match(err, 'Invalid.*')) end) + it('detects invalid $VIM', function() clear() -- Do this after startup, otherwise it just breaks $VIMRUNTIME. @@ -34,6 +38,7 @@ describe(':checkhealth', function() command('checkhealth nvim') matches('ERROR $VIM .* zub', curbuf_contents()) end) + it('completions can be listed via getcompletion()', function() clear() eq('nvim', getcompletion('nvim', 'checkhealth')[1]) @@ -41,6 +46,15 @@ describe(':checkhealth', function() eq('vim.lsp', getcompletion('vim.ls', 'checkhealth')[1]) neq('vim', getcompletion('^vim', 'checkhealth')[1]) -- should not complete vim.health end) + + it('completion checks for vim.health._complete() return type #28456', function() + clear() + exec_lua([[vim.health._complete = function() return 1 end]]) + eq({}, getcompletion('', 'checkhealth')) + exec_lua([[vim.health._complete = function() return { 1 } end]]) + eq({}, getcompletion('', 'checkhealth')) + assert_alive() + end) end) describe('health.vim', function() -- cgit From 052498ed42780a76daea589d063cd8947a894673 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 20 Apr 2024 17:44:13 +0200 Subject: test: improve test conventions Specifically, functions that are run in the context of the test runner are put in module `test/testutil.lua` while the functions that are run in the context of the test session are put in `test/functional/testnvim.lua`. Closes https://github.com/neovim/neovim/issues/27004. --- test/functional/plugin/ccomplete_spec.lua | 12 ++++---- test/functional/plugin/cfilter_spec.lua | 10 ++++--- test/functional/plugin/editorconfig_spec.lua | 20 +++++++------ test/functional/plugin/health_spec.lua | 35 +++++++++++----------- test/functional/plugin/lsp/codelens_spec.lua | 9 +++--- test/functional/plugin/lsp/completion_spec.lua | 8 +++-- test/functional/plugin/lsp/diagnostic_spec.lua | 8 +++-- test/functional/plugin/lsp/handler_spec.lua | 5 ++-- .../plugin/lsp/incremental_sync_spec.lua | 11 +++---- test/functional/plugin/lsp/inlay_hint_spec.lua | 11 +++---- .../functional/plugin/lsp/semantic_tokens_spec.lua | 17 ++++++----- test/functional/plugin/lsp/snippet_spec.lua | 10 ++++--- test/functional/plugin/lsp/testutil.lua | 12 ++++---- test/functional/plugin/lsp/utils_spec.lua | 11 +++---- test/functional/plugin/lsp_spec.lua | 30 ++++++++++--------- test/functional/plugin/man_spec.lua | 14 +++++---- test/functional/plugin/matchparen_spec.lua | 11 +++---- test/functional/plugin/msgpack_spec.lua | 14 +++++---- test/functional/plugin/shada_spec.lua | 10 ++++--- test/functional/plugin/tohtml_spec.lua | 15 +++++----- test/functional/plugin/tutor_spec.lua | 10 ++++--- test/functional/plugin/vim_syntax_spec.lua | 11 +++---- 22 files changed, 163 insertions(+), 131 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/ccomplete_spec.lua b/test/functional/plugin/ccomplete_spec.lua index bb9b28d300..4c4c5e9444 100644 --- a/test/functional/plugin/ccomplete_spec.lua +++ b/test/functional/plugin/ccomplete_spec.lua @@ -1,9 +1,11 @@ -local t = require('test.functional.testutil')() -local clear = t.clear -local command = t.command +local t = require('test.testutil') +local n = require('test.functional.testnvim')() + +local clear = n.clear +local command = n.command local eq = t.eq -local eval = t.eval -local feed = t.feed +local eval = n.eval +local feed = n.feed local write_file = t.write_file describe('ccomplete#Complete', function() diff --git a/test/functional/plugin/cfilter_spec.lua b/test/functional/plugin/cfilter_spec.lua index d421c5fc14..220404a934 100644 --- a/test/functional/plugin/cfilter_spec.lua +++ b/test/functional/plugin/cfilter_spec.lua @@ -1,8 +1,10 @@ -local t = require('test.functional.testutil')() -local clear = t.clear -local command = t.command +local t = require('test.testutil') +local n = require('test.functional.testnvim')() + +local clear = n.clear +local command = n.command local eq = t.eq -local fn = t.fn +local fn = n.fn describe('cfilter.lua', function() before_each(function() diff --git a/test/functional/plugin/editorconfig_spec.lua b/test/functional/plugin/editorconfig_spec.lua index d108f325e1..839a723405 100644 --- a/test/functional/plugin/editorconfig_spec.lua +++ b/test/functional/plugin/editorconfig_spec.lua @@ -1,11 +1,13 @@ -local t = require('test.functional.testutil')() -local clear = t.clear -local command = t.command +local t = require('test.testutil') +local n = require('test.functional.testnvim')() + +local clear = n.clear +local command = n.command local eq = t.eq -local pathsep = t.get_pathsep() -local fn = t.fn -local api = t.api -local exec_lua = t.exec_lua +local pathsep = n.get_pathsep() +local fn = n.fn +local api = n.api +local exec_lua = n.exec_lua local testdir = 'Xtest-editorconfig' @@ -20,7 +22,7 @@ local function test_case(name, expected) end setup(function() - t.mkdir_p(testdir) + n.mkdir_p(testdir) t.write_file( testdir .. pathsep .. '.editorconfig', [[ @@ -96,7 +98,7 @@ setup(function() end) teardown(function() - t.rmdir(testdir) + n.rmdir(testdir) end) describe('editorconfig', function() diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index 9c17e74e19..78cffd07fb 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -1,17 +1,18 @@ -local t = require('test.functional.testutil')() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local clear = t.clear -local curbuf_contents = t.curbuf_contents -local command = t.command +local clear = n.clear +local curbuf_contents = n.curbuf_contents +local command = n.command local eq, neq, matches = t.eq, t.neq, t.matches -local getcompletion = t.fn.getcompletion -local exec_lua = t.exec_lua -local assert_alive = t.assert_alive -local insert = t.insert -local source = t.source -local fn = t.fn -local api = t.api +local getcompletion = n.fn.getcompletion +local insert = n.insert +local exec_lua = n.exec_lua +local source = n.source +local assert_alive = n.assert_alive +local fn = n.fn +local api = n.api describe(':checkhealth', function() it('detects invalid $VIMRUNTIME', function() @@ -67,7 +68,7 @@ describe('health.vim', function() describe(':checkhealth', function() it('functions report_*() render correctly', function() command('checkhealth full_render') - t.expect([[ + n.expect([[ ============================================================================== test_plug.full_render: require("test_plug.full_render.health").check() @@ -90,7 +91,7 @@ describe('health.vim', function() it('concatenates multiple reports', function() command('checkhealth success1 success2 test_plug') - t.expect([[ + n.expect([[ ============================================================================== test_plug: require("test_plug.health").check() @@ -120,7 +121,7 @@ describe('health.vim', function() it('lua plugins submodules', function() command('checkhealth test_plug.submodule') - t.expect([[ + n.expect([[ ============================================================================== test_plug.submodule: require("test_plug.submodule.health").check() @@ -135,7 +136,7 @@ describe('health.vim', function() it('... including empty reports', function() command('checkhealth test_plug.submodule_empty') - t.expect([[ + n.expect([[ ============================================================================== test_plug.submodule_empty: require("test_plug.submodule_empty.health").check() @@ -176,7 +177,7 @@ describe('health.vim', function() it('gracefully handles invalid healthcheck', function() command('checkhealth non_existent_healthcheck') -- luacheck: ignore 613 - t.expect([[ + n.expect([[ ============================================================================== non_existent_healthcheck: @@ -188,7 +189,7 @@ describe('health.vim', function() it('does not use vim.health as a healtcheck', function() -- vim.health is not a healthcheck command('checkhealth vim') - t.expect([[ + n.expect([[ ERROR: No healthchecks found.]]) end) end) diff --git a/test/functional/plugin/lsp/codelens_spec.lua b/test/functional/plugin/lsp/codelens_spec.lua index 20e850eeee..cd20e95dd1 100644 --- a/test/functional/plugin/lsp/codelens_spec.lua +++ b/test/functional/plugin/lsp/codelens_spec.lua @@ -1,14 +1,15 @@ -local t = require('test.functional.testutil')() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() -local exec_lua = t.exec_lua +local exec_lua = n.exec_lua local eq = t.eq describe('vim.lsp.codelens', function() before_each(function() - t.clear() + n.clear() exec_lua('require("vim.lsp")') end) - after_each(t.clear) + after_each(n.clear) it('on_codelens_stores_and_displays_lenses', function() local fake_uri = 'file:///fake/uri' diff --git a/test/functional/plugin/lsp/completion_spec.lua b/test/functional/plugin/lsp/completion_spec.lua index 18f123a979..2798d57381 100644 --- a/test/functional/plugin/lsp/completion_spec.lua +++ b/test/functional/plugin/lsp/completion_spec.lua @@ -1,7 +1,9 @@ ---@diagnostic disable: no-unknown -local t = require('test.functional.testutil')() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() + local eq = t.eq -local exec_lua = t.exec_lua +local exec_lua = n.exec_lua --- Convert completion results. --- @@ -41,7 +43,7 @@ local function complete(line, candidates, lnum) end describe('vim.lsp._completion', function() - before_each(t.clear) + before_each(n.clear) -- https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion it('prefers textEdit over label as word', function() diff --git a/test/functional/plugin/lsp/diagnostic_spec.lua b/test/functional/plugin/lsp/diagnostic_spec.lua index 27b0da1f3d..c5e14ffdc2 100644 --- a/test/functional/plugin/lsp/diagnostic_spec.lua +++ b/test/functional/plugin/lsp/diagnostic_spec.lua @@ -1,8 +1,10 @@ -local t = require('test.functional.testutil')() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() + local t_lsp = require('test.functional.plugin.lsp.testutil') -local clear = t.clear -local exec_lua = t.exec_lua +local clear = n.clear +local exec_lua = n.exec_lua local eq = t.eq local neq = t.neq diff --git a/test/functional/plugin/lsp/handler_spec.lua b/test/functional/plugin/lsp/handler_spec.lua index 0ce7479c49..013a5fb5e7 100644 --- a/test/functional/plugin/lsp/handler_spec.lua +++ b/test/functional/plugin/lsp/handler_spec.lua @@ -1,7 +1,8 @@ -local t = require('test.functional.testutil')() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local eq = t.eq -local exec_lua = t.exec_lua +local exec_lua = n.exec_lua local pcall_err = t.pcall_err local matches = t.matches diff --git a/test/functional/plugin/lsp/incremental_sync_spec.lua b/test/functional/plugin/lsp/incremental_sync_spec.lua index a44b861ca1..238b90b57d 100644 --- a/test/functional/plugin/lsp/incremental_sync_spec.lua +++ b/test/functional/plugin/lsp/incremental_sync_spec.lua @@ -1,11 +1,12 @@ -- Test suite for testing interactions with the incremental sync algorithms powering the LSP client -local t = require('test.functional.testutil')() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() -local api = t.api -local clear = t.clear +local api = n.api +local clear = n.clear local eq = t.eq -local exec_lua = t.exec_lua -local feed = t.feed +local exec_lua = n.exec_lua +local feed = n.feed before_each(function() clear() diff --git a/test/functional/plugin/lsp/inlay_hint_spec.lua b/test/functional/plugin/lsp/inlay_hint_spec.lua index 24c93fcbe0..0aaf94d6da 100644 --- a/test/functional/plugin/lsp/inlay_hint_spec.lua +++ b/test/functional/plugin/lsp/inlay_hint_spec.lua @@ -1,12 +1,13 @@ -local t = require('test.functional.testutil')() -local t_lsp = require('test.functional.plugin.lsp.testutil') +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') +local t_lsp = require('test.functional.plugin.lsp.testutil') local eq = t.eq local dedent = t.dedent -local exec_lua = t.exec_lua -local insert = t.insert -local api = t.api +local exec_lua = n.exec_lua +local insert = n.insert +local api = n.api local clear_notrace = t_lsp.clear_notrace local create_server_definition = t_lsp.create_server_definition diff --git a/test/functional/plugin/lsp/semantic_tokens_spec.lua b/test/functional/plugin/lsp/semantic_tokens_spec.lua index a9d8592eb0..013393095e 100644 --- a/test/functional/plugin/lsp/semantic_tokens_spec.lua +++ b/test/functional/plugin/lsp/semantic_tokens_spec.lua @@ -1,16 +1,17 @@ -local t = require('test.functional.testutil')() -local t_lsp = require('test.functional.plugin.lsp.testutil') +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') +local t_lsp = require('test.functional.plugin.lsp.testutil') -local command = t.command +local command = n.command local dedent = t.dedent local eq = t.eq -local exec_lua = t.exec_lua -local feed = t.feed -local feed_command = t.feed_command -local insert = t.insert +local exec_lua = n.exec_lua +local feed = n.feed +local feed_command = n.feed_command +local insert = n.insert local matches = t.matches -local api = t.api +local api = n.api local clear_notrace = t_lsp.clear_notrace local create_server_definition = t_lsp.create_server_definition diff --git a/test/functional/plugin/lsp/snippet_spec.lua b/test/functional/plugin/lsp/snippet_spec.lua index 0f4304868b..e60c36cd23 100644 --- a/test/functional/plugin/lsp/snippet_spec.lua +++ b/test/functional/plugin/lsp/snippet_spec.lua @@ -1,13 +1,15 @@ -local t = require('test.functional.testutil')() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() + local snippet = require('vim.lsp._snippet_grammar') local type = snippet.NodeType local eq = t.eq -local exec_lua = t.exec_lua +local exec_lua = n.exec_lua describe('vim.lsp._snippet_grammar', function() - before_each(t.clear) - after_each(t.clear) + before_each(n.clear) + after_each(n.clear) local parse = function(...) local res = exec_lua('return require("vim.lsp._snippet_grammar").parse(...)', ...) diff --git a/test/functional/plugin/lsp/testutil.lua b/test/functional/plugin/lsp/testutil.lua index c51ccf3097..4d14752f2a 100644 --- a/test/functional/plugin/lsp/testutil.lua +++ b/test/functional/plugin/lsp/testutil.lua @@ -1,10 +1,10 @@ -local t = require('test.functional.testutil')() +local n = require('test.functional.testnvim')() -local clear = t.clear -local exec_lua = t.exec_lua -local run = t.run -local stop = t.stop -local api = t.api +local clear = n.clear +local exec_lua = n.exec_lua +local run = n.run +local stop = n.stop +local api = n.api local NIL = vim.NIL local M = {} diff --git a/test/functional/plugin/lsp/utils_spec.lua b/test/functional/plugin/lsp/utils_spec.lua index 8e57ace449..6c6dec0667 100644 --- a/test/functional/plugin/lsp/utils_spec.lua +++ b/test/functional/plugin/lsp/utils_spec.lua @@ -1,12 +1,13 @@ -local t = require('test.functional.testutil')() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local feed = t.feed +local feed = n.feed local eq = t.eq -local exec_lua = t.exec_lua +local exec_lua = n.exec_lua describe('vim.lsp.util', function() - before_each(t.clear) + before_each(n.clear) describe('stylize_markdown', function() local stylize_markdown = function(content, opts) @@ -142,7 +143,7 @@ describe('vim.lsp.util', function() local screen before_each(function() - t.clear() + n.clear() screen = Screen.new(80, 80) screen:attach() feed('79i') -- fill screen with empty lines diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index d471aadf9c..8d3e141944 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -1,26 +1,28 @@ -local t = require('test.functional.testutil')() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() + local t_lsp = require('test.functional.plugin.lsp.testutil') local assert_log = t.assert_log -local buf_lines = t.buf_lines -local clear = t.clear -local command = t.command +local buf_lines = n.buf_lines +local clear = n.clear +local command = n.command local dedent = t.dedent -local exec_lua = t.exec_lua +local exec_lua = n.exec_lua local eq = t.eq -local eval = t.eval +local eval = n.eval local matches = t.matches local pcall_err = t.pcall_err local pesc = vim.pesc -local insert = t.insert -local fn = t.fn +local insert = n.insert +local fn = n.fn local retry = t.retry -local stop = t.stop +local stop = n.stop local NIL = vim.NIL local read_file = t.read_file local write_file = t.write_file local is_ci = t.is_ci -local api = t.api +local api = n.api local is_os = t.is_os local skip = t.skip local mkdir = t.mkdir @@ -1481,7 +1483,7 @@ describe('LSP', function() end, on_handler = function(err, result, ctx) if ctx.method == 'start' then - t.command('normal! 1Go') + n.command('normal! 1Go') client.notify('finish') end eq(table.remove(expected_handlers), { err, result, ctx }, 'expected handler') @@ -2368,7 +2370,7 @@ describe('LSP', function() end) describe('lsp.util.rename', function() - local pathsep = t.get_pathsep() + local pathsep = n.get_pathsep() it('Can rename an existing file', function() local old = tmpname() @@ -2404,7 +2406,7 @@ describe('LSP', function() os.remove(old_dir) os.remove(new_dir) - t.mkdir_p(old_dir) + n.mkdir_p(old_dir) local file = 'file.txt' write_file(old_dir .. pathsep .. file, 'Test content') @@ -2440,7 +2442,7 @@ describe('LSP', function() local new = tmpname() os.remove(old) os.remove(new) - t.mkdir_p(old) + n.mkdir_p(old) local result = exec_lua( [[ diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua index 19d279afbf..e9500bf920 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -1,10 +1,12 @@ -local t = require('test.functional.testutil')() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local command, feed = t.command, t.feed -local clear = t.clear -local exec_lua = t.exec_lua -local fn = t.fn -local nvim_prog = t.nvim_prog + +local command, feed = n.command, n.feed +local clear = n.clear +local exec_lua = n.exec_lua +local fn = n.fn +local nvim_prog = n.nvim_prog local matches = t.matches local write_file = t.write_file local tmpname = t.tmpname diff --git a/test/functional/plugin/matchparen_spec.lua b/test/functional/plugin/matchparen_spec.lua index ae343b9555..ae718ac1bd 100644 --- a/test/functional/plugin/matchparen_spec.lua +++ b/test/functional/plugin/matchparen_spec.lua @@ -1,10 +1,11 @@ -local t = require('test.functional.testutil')() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local clear = t.clear -local command = t.command -local api = t.api -local feed = t.feed +local clear = n.clear +local command = n.command +local api = n.api +local feed = n.feed local eq = t.eq describe('matchparen', function() diff --git a/test/functional/plugin/msgpack_spec.lua b/test/functional/plugin/msgpack_spec.lua index 9b70c12fc7..1d5d20ec02 100644 --- a/test/functional/plugin/msgpack_spec.lua +++ b/test/functional/plugin/msgpack_spec.lua @@ -1,10 +1,12 @@ -local t = require('test.functional.testutil')() -local clear = t.clear -local api = t.api +local t = require('test.testutil') +local n = require('test.functional.testnvim')() + +local clear = n.clear +local api = n.api local eq = t.eq -local nvim_eval = t.eval -local nvim_command = t.command -local exc_exec = t.exc_exec +local nvim_eval = n.eval +local nvim_command = n.command +local exc_exec = n.exc_exec local ok = t.ok local NIL = vim.NIL diff --git a/test/functional/plugin/shada_spec.lua b/test/functional/plugin/shada_spec.lua index 270eacc653..1c2bcbd497 100644 --- a/test/functional/plugin/shada_spec.lua +++ b/test/functional/plugin/shada_spec.lua @@ -1,12 +1,14 @@ -local t = require('test.functional.testutil')() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local clear = t.clear +local t_shada = require('test.functional.shada.testutil') + +local clear = n.clear local eq, api, nvim_eval, nvim_command, exc_exec, fn, nvim_feed = - t.eq, t.api, t.eval, t.command, t.exc_exec, t.fn, t.feed + t.eq, n.api, n.eval, n.command, n.exc_exec, n.fn, n.feed local neq = t.neq local read_file = t.read_file -local t_shada = require('test.functional.shada.testutil') local get_shada_rw = t_shada.get_shada_rw local function reset(shada_file) diff --git a/test/functional/plugin/tohtml_spec.lua b/test/functional/plugin/tohtml_spec.lua index f06d4d9c54..200a5f34b2 100644 --- a/test/functional/plugin/tohtml_spec.lua +++ b/test/functional/plugin/tohtml_spec.lua @@ -1,13 +1,14 @@ +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local t = require('test.functional.testutil')() -local clear = t.clear -local exec = t.exec -local exec_lua = t.exec_lua +local clear = n.clear +local exec = n.exec +local exec_lua = n.exec_lua local eq = t.eq -local fn = t.fn -local api = t.api -local insert = t.insert +local fn = n.fn +local api = n.api +local insert = n.insert local function html_syntax_match() local styles = diff --git a/test/functional/plugin/tutor_spec.lua b/test/functional/plugin/tutor_spec.lua index b8d5dc9399..9f381d45db 100644 --- a/test/functional/plugin/tutor_spec.lua +++ b/test/functional/plugin/tutor_spec.lua @@ -1,8 +1,10 @@ +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local t = require('test.functional.testutil')() -local clear = t.clear -local command = t.command -local feed = t.feed + +local clear = n.clear +local command = n.command +local feed = n.feed local is_os = t.is_os describe(':Tutor', function() diff --git a/test/functional/plugin/vim_syntax_spec.lua b/test/functional/plugin/vim_syntax_spec.lua index d31d6ad2f2..d99a69eab9 100644 --- a/test/functional/plugin/vim_syntax_spec.lua +++ b/test/functional/plugin/vim_syntax_spec.lua @@ -1,15 +1,16 @@ -local t = require('test.functional.testutil')() +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local clear = t.clear -local exec = t.exec -local api = t.api + +local clear = n.clear +local exec = n.exec +local api = n.api describe('Vimscript syntax highlighting', function() local screen --- @type test.functional.ui.screen before_each(function() clear() - t.add_builddir_to_rtp() + n.add_builddir_to_rtp() exec([[ setfiletype vim syntax on -- cgit From c81b7849a0f677164c01cf84ecfb25c1f47acf21 Mon Sep 17 00:00:00 2001 From: Mathias Fußenegger Date: Tue, 23 Apr 2024 19:05:01 +0200 Subject: refactor(lsp): merge subtypes and supertypes into typehierarchy (#28467) Both methods had pretty much the same documentation and shared the implementation. --- test/functional/plugin/lsp_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 8d3e141944..0432d3fc94 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -3463,7 +3463,7 @@ describe('LSP', function() end) end) - describe('vim.lsp.buf.subtypes', function() + describe('vim.lsp.buf.typehierarchy subtypes', function() it('does nothing for an empty response', function() local qflist_count = exec_lua([=[ require'vim.lsp.handlers'['typeHierarchy/subtypes'](nil, nil, {}) @@ -3681,7 +3681,7 @@ describe('LSP', function() end) end) - describe('vim.lsp.buf.supertypes', function() + describe('vim.lsp.buf.typehierarchy supertypes', function() it('does nothing for an empty response', function() local qflist_count = exec_lua([=[ require'vim.lsp.handlers'['typeHierarchy/supertypes'](nil, nil, {}) -- cgit From 3a7c30dc93b9b903ff8591c43689c3bdcb4761de Mon Sep 17 00:00:00 2001 From: Brian Cao <75100021+RandomChugokujin@users.noreply.github.com> Date: Fri, 26 Apr 2024 14:14:45 -0400 Subject: fix(man.vim): q quits after jump to different tag in MANPAGER modified (#28495) --- test/functional/plugin/man_spec.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua index e9500bf920..978178191c 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -192,6 +192,7 @@ describe(':Man', function() '--headless', '+autocmd VimLeave * echo "quit works!!"', '+Man!', + '+tag ls', '+call nvim_input("q")', } matches('quit works!!', fn.system(args, { 'manpage contents' })) -- cgit From d5063f4b290e1c4262f7ced6d425ff2d7a2e2045 Mon Sep 17 00:00:00 2001 From: Yi Ming Date: Thu, 2 May 2024 21:16:20 +0800 Subject: feat(lsp): vim.lsp.inlay_hint.enable(nil) applies to all buffers #28543 Problem: Inlay hints `enable()` does not fully implement the `:help dev-lua` guidelines: Interface conventions ~ - When accepting a buffer id, etc., 0 means "current buffer", nil means "all buffers". Likewise for window id, tabpage id, etc. - Examples: |vim.lsp.codelens.clear()| |vim.diagnostic.enable()| Solution: Implement globally enabling inlay hints. * refactor(lsp): do not rely on `enable` to create autocmds * refactor(lsp): make `bufstates` a defaulttable * refactor(lsp): make `bufstate` inherit values from `globalstate` * feat(lsp): `vim.lsp.inlay_hints` now take effect on all buffers by default * test(lsp): add basic tests for enable inlay hints for all buffers * test(lsp): add test cases cover more than one buffer --- test/functional/plugin/lsp/inlay_hint_spec.lua | 53 ++++++++++++++++++++------ 1 file changed, 42 insertions(+), 11 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp/inlay_hint_spec.lua b/test/functional/plugin/lsp/inlay_hint_spec.lua index 0aaf94d6da..94e7fbb97c 100644 --- a/test/functional/plugin/lsp/inlay_hint_spec.lua +++ b/test/functional/plugin/lsp/inlay_hint_spec.lua @@ -137,20 +137,51 @@ describe('vim.lsp.inlay_hint', function() ) end) - it('clears/applies inlay hints when passed false/true/nil', function() - exec_lua([[vim.lsp.inlay_hint.enable(false, { bufnr = bufnr })]]) - screen:expect({ grid = grid_without_inlay_hints, unchanged = true }) + describe('clears/applies inlay hints when passed false/true/nil', function() + before_each(function() + exec_lua([[ + bufnr2 = vim.api.nvim_create_buf(true, false) + vim.lsp.buf_attach_client(bufnr2, client_id) + vim.api.nvim_win_set_buf(0, bufnr2) + ]]) + insert(text) + exec_lua([[vim.lsp.inlay_hint.enable(true, { bufnr = bufnr2 })]]) + exec_lua([[vim.api.nvim_win_set_buf(0, bufnr)]]) + screen:expect({ grid = grid_with_inlay_hints }) + end) - exec_lua([[vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })]]) - screen:expect({ grid = grid_with_inlay_hints, unchanged = true }) + it('for one single buffer', function() + exec_lua([[ + vim.lsp.inlay_hint.enable(false, { bufnr = bufnr }) + vim.api.nvim_win_set_buf(0, bufnr2) + ]]) + screen:expect({ grid = grid_with_inlay_hints, unchanged = true }) + exec_lua([[vim.api.nvim_win_set_buf(0, bufnr)]]) + screen:expect({ grid = grid_without_inlay_hints, unchanged = true }) - exec_lua( - [[vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled(bufnr), { bufnr = bufnr })]] - ) - screen:expect({ grid = grid_without_inlay_hints, unchanged = true }) + exec_lua([[vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })]]) + screen:expect({ grid = grid_with_inlay_hints, unchanged = true }) + + exec_lua( + [[vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled(bufnr), { bufnr = bufnr })]] + ) + screen:expect({ grid = grid_without_inlay_hints, unchanged = true }) + + exec_lua([[vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })]]) + screen:expect({ grid = grid_with_inlay_hints, unchanged = true }) + end) + + it('for all buffers', function() + exec_lua([[vim.lsp.inlay_hint.enable(false)]]) + screen:expect({ grid = grid_without_inlay_hints, unchanged = true }) + exec_lua([[vim.api.nvim_win_set_buf(0, bufnr2)]]) + screen:expect({ grid = grid_without_inlay_hints, unchanged = true }) - exec_lua([[vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })]]) - screen:expect({ grid = grid_with_inlay_hints, unchanged = true }) + exec_lua([[vim.lsp.inlay_hint.enable(true)]]) + screen:expect({ grid = grid_with_inlay_hints, unchanged = true }) + exec_lua([[vim.api.nvim_win_set_buf(0, bufnr)]]) + screen:expect({ grid = grid_with_inlay_hints, unchanged = true }) + end) end) end) -- cgit From 350d81856473b45100d6b0e5920b757df1b4ad27 Mon Sep 17 00:00:00 2001 From: Yi Ming Date: Thu, 2 May 2024 22:26:07 +0800 Subject: feat(lsp): inlay_hint.is_enabled({filter}) #28523 vim.diagnostic.enable and vim.diagnostic.is_enabled() use the same pattern. --- test/functional/plugin/lsp/inlay_hint_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp/inlay_hint_spec.lua b/test/functional/plugin/lsp/inlay_hint_spec.lua index 94e7fbb97c..4a8d9669c5 100644 --- a/test/functional/plugin/lsp/inlay_hint_spec.lua +++ b/test/functional/plugin/lsp/inlay_hint_spec.lua @@ -163,7 +163,7 @@ describe('vim.lsp.inlay_hint', function() screen:expect({ grid = grid_with_inlay_hints, unchanged = true }) exec_lua( - [[vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled(bufnr), { bufnr = bufnr })]] + [[vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = bufnr }), { bufnr = bufnr })]] ) screen:expect({ grid = grid_without_inlay_hints, unchanged = true }) -- cgit From c1a95d9653f39c5e118d030270e4b77ebd20139e Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 10 May 2024 13:47:30 +0100 Subject: fix(lsp): disable didChangeWatchedFiles on Linux Problem: The file watcher backends for Linux have too many limitations and doesn't work reliably. Solution: disable didChangeWatchedFiles on Linux Ref: #27807, #28058, #23291, #26520 --- test/functional/plugin/lsp_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 0432d3fc94..3bbb5c0971 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -5521,7 +5521,7 @@ describe('LSP', function() ) end - eq(true, check_registered(nil)) -- start{_client}() defaults to make_client_capabilities(). + eq(is_os('mac') or is_os('win'), check_registered(nil)) -- start{_client}() defaults to make_client_capabilities(). eq(false, check_registered(vim.empty_dict())) eq( false, -- cgit From e3ec974324bd73b63f54503480a4e48d1887f8d9 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 13 May 2024 05:00:39 -0700 Subject: refactor(lua): remove deprecated features #28725 --- test/functional/plugin/lsp/inlay_hint_spec.lua | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp/inlay_hint_spec.lua b/test/functional/plugin/lsp/inlay_hint_spec.lua index 4a8d9669c5..3d0fcc31ff 100644 --- a/test/functional/plugin/lsp/inlay_hint_spec.lua +++ b/test/functional/plugin/lsp/inlay_hint_spec.lua @@ -126,14 +126,12 @@ describe('vim.lsp.inlay_hint', function() t.pcall_err(exec_lua, [[vim.lsp.inlay_hint.enable({}, { bufnr = bufnr })]]) ) t.matches( - 'filter: expected table, got number', - t.pcall_err(exec_lua, [[vim.lsp.inlay_hint.enable(true, 42)]]) + 'enable: expected boolean, got number', + t.pcall_err(exec_lua, [[vim.lsp.inlay_hint.enable(42)]]) ) - - exec_lua [[vim.notify = function() end]] t.matches( - 'see %:help vim%.lsp%.inlay_hint%.enable', - t.pcall_err(exec_lua, [[vim.lsp.inlay_hint.enable(42)]]) + 'filter: expected table, got number', + t.pcall_err(exec_lua, [[vim.lsp.inlay_hint.enable(true, 42)]]) ) end) -- cgit From 0f4f7d32ce5d6d3b751b0b01455770f3b72531b9 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 18 May 2024 18:35:26 +0200 Subject: refactor!: remove `nvim` and `provider` module for checkhealth The namespacing for healthchecks for neovim modules is inconsistent and confusing. The completion for `:checkhealth` with `--clean` gives ``` nvim provider.clipboard provider.node provider.perl provider.python provider.ruby vim.lsp vim.treesitter ``` There are now three top-level module names for nvim: `nvim`, `provider` and `vim` with no signs of stopping. The `nvim` name is especially confusing as it does not contain all neovim checkhealths, which makes it almost a decoy healthcheck. The confusion only worsens if you add plugins to the mix: ``` lazy mason nvim nvim-treesitter provider.clipboard provider.node provider.perl provider.python provider.ruby telescope vim.lsp vim.treesitter ``` Another problem with the current approach is that it's not easy to run nvim-only healthchecks since they don't share the same namespace. The current approach would be to run `:che nvim vim.* provider.*` and would also require the user to know these are the neovim modules. Instead, use this alternative structure: ``` vim.health vim.lsp vim.provider.clipboard vim.provider.node vim.provider.perl vim.provider.python vim.provider.ruby vim.treesitter ``` and ``` lazy mason nvim-treesitter telescope vim.health vim.lsp vim.provider.clipboard vim.provider.node vim.provider.perl vim.provider.python vim.provider.ruby vim.treesitter ``` Now, the entries are properly sorted and running nvim-only healthchecks requires running only `:che vim.*`. --- test/functional/plugin/health_spec.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index 78cffd07fb..327b5759c7 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -5,7 +5,7 @@ local Screen = require('test.functional.ui.screen') local clear = n.clear local curbuf_contents = n.curbuf_contents local command = n.command -local eq, neq, matches = t.eq, t.neq, t.matches +local eq, matches = t.eq, t.matches local getcompletion = n.fn.getcompletion local insert = n.insert local exec_lua = n.exec_lua @@ -36,16 +36,15 @@ describe(':checkhealth', function() clear() -- Do this after startup, otherwise it just breaks $VIMRUNTIME. command("let $VIM='zub'") - command('checkhealth nvim') + command('checkhealth vim.health') matches('ERROR $VIM .* zub', curbuf_contents()) end) it('completions can be listed via getcompletion()', function() clear() - eq('nvim', getcompletion('nvim', 'checkhealth')[1]) - eq('provider.clipboard', getcompletion('prov', 'checkhealth')[1]) + eq('vim.health', getcompletion('vim', 'checkhealth')[1]) + eq('vim.provider.clipboard', getcompletion('vim.prov', 'checkhealth')[1]) eq('vim.lsp', getcompletion('vim.ls', 'checkhealth')[1]) - neq('vim', getcompletion('^vim', 'checkhealth')[1]) -- should not complete vim.health end) it('completion checks for vim.health._complete() return type #28456', function() -- cgit From a108852b008b2cb1fe38b1f66cffd78b33bd9a70 Mon Sep 17 00:00:00 2001 From: Riley Bruins Date: Tue, 21 May 2024 09:25:54 -0700 Subject: fix(lsp): semantic token functions allow "0" bufnr #28849 aligns with ":help dev-patterns" --- .../functional/plugin/lsp/semantic_tokens_spec.lua | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp/semantic_tokens_spec.lua b/test/functional/plugin/lsp/semantic_tokens_spec.lua index 013393095e..60f02b0521 100644 --- a/test/functional/plugin/lsp/semantic_tokens_spec.lua +++ b/test/functional/plugin/lsp/semantic_tokens_spec.lua @@ -273,6 +273,63 @@ describe('semantic token highlighting', function() end ) + it('highlights start and stop when using "0" for current buffer', function() + exec_lua([[ + bufnr = vim.api.nvim_get_current_buf() + vim.api.nvim_win_set_buf(0, bufnr) + client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd }) + ]]) + + insert(text) + + exec_lua([[ + vim.notify = function() end + vim.lsp.semantic_tokens.stop(0, client_id) + ]]) + + screen:expect { + grid = [[ + #include | + | + int main() | + { | + int x; | + #ifdef __cplusplus | + std::cout << x << "\n"; | + #else | + printf("%d\n", x); | + #endif | + } | + ^} | + {1:~ }|*3 + | + ]], + } + + exec_lua([[ + vim.lsp.semantic_tokens.start(0, client_id) + ]]) + + screen:expect { + grid = [[ + #include | + | + int {8:main}() | + { | + int {7:x}; | + #ifdef {5:__cplusplus} | + {4:std}::{2:cout} << {2:x} << "\n"; | + {6:#else} | + {6: printf("%d\n", x);} | + {6:#endif} | + } | + ^} | + {1:~ }|*3 + | + ]], + } + end) + it('buffer is re-highlighted when force refreshed', function() exec_lua([[ bufnr = vim.api.nvim_get_current_buf() -- cgit From 01b4da65c229f05ccb26c55db4e0d30ed9bac10b Mon Sep 17 00:00:00 2001 From: dundargoc Date: Wed, 22 May 2024 20:40:20 +0200 Subject: fix: merge all provider healthchecks into a single health.lua This will help manage the overly granular checkhealth completion to go from ``` vim.health vim.lsp vim.provider.clipboard vim.provider.node vim.provider.perl vim.provider.python vim.provider.ruby vim.treesitter ``` to ``` vim.health vim.lsp vim.provider vim.treesitter ``` --- test/functional/plugin/health_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index 327b5759c7..7aa5c99a60 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -43,7 +43,7 @@ describe(':checkhealth', function() it('completions can be listed via getcompletion()', function() clear() eq('vim.health', getcompletion('vim', 'checkhealth')[1]) - eq('vim.provider.clipboard', getcompletion('vim.prov', 'checkhealth')[1]) + eq('vim.provider', getcompletion('vim.prov', 'checkhealth')[1]) eq('vim.lsp', getcompletion('vim.ls', 'checkhealth')[1]) end) -- cgit From 5ac8db10f0428c976dfc9a4935a74d0fe160995c Mon Sep 17 00:00:00 2001 From: Andre Toerien <49614525+AThePeanut4@users.noreply.github.com> Date: Thu, 23 May 2024 12:03:47 +0200 Subject: fix(lsp): trigger LspDetach on buffer delete (#28795) Co-authored-by: Mathias Fussenegger --- test/functional/plugin/lsp_spec.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 3bbb5c0971..8358a1b9ec 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -475,6 +475,12 @@ describe('LSP', function() local server = _create_server() local bufnr = vim.api.nvim_create_buf(false, true) vim.api.nvim_set_current_buf(bufnr) + local detach_called = false + vim.api.nvim_create_autocmd("LspDetach", { + callback = function() + detach_called = true + end + }) local client_id = vim.lsp.start({ name = 'detach-dummy', cmd = server.cmd }) assert(client_id, "lsp.start must return client_id") local client = vim.lsp.get_client_by_id(client_id) @@ -486,11 +492,13 @@ describe('LSP', function() client_id = client_id, num_attached_before = num_attached_before, num_attached_after = num_attached_after, + detach_called = detach_called, } ]]) eq(true, result ~= nil, 'exec_lua must return result') eq(1, result.num_attached_before) eq(0, result.num_attached_after) + eq(true, result.detach_called) end) it('client should return settings via workspace/configuration handler', function() -- cgit From af200c10cf9d117a14ebf9f2e9c666721a1090d6 Mon Sep 17 00:00:00 2001 From: Ilia Choly Date: Thu, 23 May 2024 09:17:53 -0400 Subject: fix(lsp): check if buffer was detached in on_init callback (#28914) Co-authored-by: Jongwook Choi --- test/functional/plugin/lsp/inlay_hint_spec.lua | 12 ++--- .../functional/plugin/lsp/semantic_tokens_spec.lua | 34 ++++++------- test/functional/plugin/lsp/testutil.lua | 3 +- test/functional/plugin/lsp_spec.lua | 57 ++++++++++++++++------ 4 files changed, 67 insertions(+), 39 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp/inlay_hint_spec.lua b/test/functional/plugin/lsp/inlay_hint_spec.lua index 3d0fcc31ff..d3b5ae0e4e 100644 --- a/test/functional/plugin/lsp/inlay_hint_spec.lua +++ b/test/functional/plugin/lsp/inlay_hint_spec.lua @@ -70,8 +70,8 @@ before_each(function() inlayHintProvider = true, }, handlers = { - ['textDocument/inlayHint'] = function() - return vim.json.decode(response) + ['textDocument/inlayHint'] = function(_, _, callback) + callback(nil, vim.json.decode(response)) end, } }) @@ -106,8 +106,8 @@ describe('vim.lsp.inlay_hint', function() inlayHintProvider = true, }, handlers = { - ['textDocument/inlayHint'] = function() - return {} + ['textDocument/inlayHint'] = function(_, _, callback) + callback(nil, {}) end, } }) @@ -206,8 +206,8 @@ describe('vim.lsp.inlay_hint', function() inlayHintProvider = true, }, handlers = { - ['textDocument/inlayHint'] = function() - return { expected2 } + ['textDocument/inlayHint'] = function(_, _, callback) + callback(nil, { expected2 }) end, } }) diff --git a/test/functional/plugin/lsp/semantic_tokens_spec.lua b/test/functional/plugin/lsp/semantic_tokens_spec.lua index 60f02b0521..7908c5d2e7 100644 --- a/test/functional/plugin/lsp/semantic_tokens_spec.lua +++ b/test/functional/plugin/lsp/semantic_tokens_spec.lua @@ -95,11 +95,11 @@ describe('semantic token highlighting', function() }, }, handlers = { - ['textDocument/semanticTokens/full'] = function() - return vim.fn.json_decode(response) + ['textDocument/semanticTokens/full'] = function(_, _, callback) + callback(nil, vim.fn.json_decode(response)) end, - ['textDocument/semanticTokens/full/delta'] = function() - return vim.fn.json_decode(edit_response) + ['textDocument/semanticTokens/full/delta'] = function(_, _, callback) + callback(nil, vim.fn.json_decode(edit_response)) end, } }) @@ -560,11 +560,11 @@ describe('semantic token highlighting', function() }, }, handlers = { - ['textDocument/semanticTokens/full'] = function() - return nil + ['textDocument/semanticTokens/full'] = function(_, _, callback) + callback(nil, nil) end, ['textDocument/semanticTokens/full/delta'] = function() - return nil + callback(nil, nil) end, } }) @@ -608,11 +608,11 @@ describe('semantic token highlighting', function() }, }, handlers = { - ['textDocument/semanticTokens/full'] = function() - return vim.fn.json_decode(response) + ['textDocument/semanticTokens/full'] = function(_, _, callback) + callback(nil, vim.fn.json_decode(response)) end, - ['textDocument/semanticTokens/full/delta'] = function() - return vim.fn.json_decode(edit_response) + ['textDocument/semanticTokens/full/delta'] = function(_, _, callback) + callback(nil, vim.fn.json_decode(edit_response)) end, } }) @@ -1075,8 +1075,8 @@ b = "as"]], }, }, handlers = { - ['textDocument/semanticTokens/full'] = function() - return vim.fn.json_decode(resp) + ['textDocument/semanticTokens/full'] = function(_, _, callback) + callback(nil, vim.fn.json_decode(resp)) end, } }) @@ -1461,11 +1461,11 @@ int main() }, }, handlers = { - ['textDocument/semanticTokens/full'] = function() - return vim.fn.json_decode(resp1) + ['textDocument/semanticTokens/full'] = function(_, _, callback) + callback(nil, vim.fn.json_decode(resp1)) end, - ['textDocument/semanticTokens/full/delta'] = function() - return vim.fn.json_decode(resp2) + ['textDocument/semanticTokens/full/delta'] = function(_, _, callback) + callback(nil, vim.fn.json_decode(resp2)) end, } }) diff --git a/test/functional/plugin/lsp/testutil.lua b/test/functional/plugin/lsp/testutil.lua index 4d14752f2a..3430a1e1a3 100644 --- a/test/functional/plugin/lsp/testutil.lua +++ b/test/functional/plugin/lsp/testutil.lua @@ -39,8 +39,7 @@ M.create_server_definition = [[ }) local handler = handlers[method] if handler then - local response, err = handler(method, params) - callback(err, response) + handler(method, params, callback) elseif method == 'initialize' then callback(nil, { capabilities = opts.capabilities or {} diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 8358a1b9ec..c95a96baca 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -501,6 +501,35 @@ describe('LSP', function() eq(true, result.detach_called) end) + it('should not re-attach buffer if it was deleted in on_init #28575', function() + clear() + exec_lua(create_server_definition) + exec_lua([[ + local server = _create_server({ + handlers = { + initialize = function(method, params, callback) + vim.schedule(function() + callback(nil, { capabilities = {} }) + end) + end + } + }) + local bufnr = vim.api.nvim_create_buf(false, true) + local on_init_called = false + local client_id = vim.lsp.start({ + name = 'detach-dummy', + cmd = server.cmd, + on_init = function() + vim.api.nvim_buf_delete(bufnr, {}) + on_init_called = true + end + }) + vim.lsp.buf_attach_client(bufnr, client_id) + local ok = vim.wait(1000, function() return on_init_called end) + assert(ok, "on_init was not called") + ]]) + end) + it('client should return settings via workspace/configuration handler', function() local expected_handlers = { { NIL, {}, { method = 'shutdown', client_id = 1 } }, @@ -670,7 +699,7 @@ describe('LSP', function() } }, handlers = { - ['textDocument/willSaveWaitUntil'] = function() + ['textDocument/willSaveWaitUntil'] = function(_, _, callback) local text_edit = { range = { start = { line = 0, character = 0 }, @@ -678,7 +707,7 @@ describe('LSP', function() }, newText = 'Hello' } - return { text_edit, } + callback(nil, { text_edit, }) end }, }) @@ -4144,8 +4173,8 @@ describe('LSP', function() } }, handlers = { - ["textDocument/codeAction"] = function() - return { + ["textDocument/codeAction"] = function(_, _, callback) + callback(nil, { { title = "Code Action 1", command = { @@ -4153,10 +4182,10 @@ describe('LSP', function() command = "command:1", } } - } + }) end, - ["codeAction/resolve"] = function() - return nil, "resolve failed" + ["codeAction/resolve"] = function(_, _, callback) + callback("resolve failed", nil) end, } }) @@ -4344,7 +4373,7 @@ describe('LSP', function() }, }, handlers = { - ["textDocument/codeLens"] = function(method, params) + ["textDocument/codeLens"] = function(method, params, callback) local lenses = { { range = { @@ -4357,7 +4386,7 @@ describe('LSP', function() }, }, } - return lenses + callback(nil, lenses) end, } }) @@ -4665,13 +4694,13 @@ describe('LSP', function() }, handlers = { ---@return lsp.Location[] - ['textDocument/definition'] = function() - return { _G.mock_locations[1] } + ['textDocument/definition'] = function(_, _, callback) + callback(nil, { _G.mock_locations[1] }) end, ---@return lsp.WorkspaceSymbol[] - ['workspace/symbol'] = function(_, request) + ['workspace/symbol'] = function(_, request, callback) assert(request.query == 'foobar') - return { + callback(nil, { { name = 'foobar', kind = 13, ---@type lsp.SymbolKind @@ -4682,7 +4711,7 @@ describe('LSP', function() kind = 12, ---@type lsp.SymbolKind location = _G.mock_locations[2], } - } + }) end, }, }) -- cgit From d123202ae6ef3f046d5b6579c194dca82ddb8a8f Mon Sep 17 00:00:00 2001 From: dundargoc Date: Thu, 16 May 2024 18:33:09 +0200 Subject: fix: change deprecation presentation Deprecation with vim.deprecate is currently too noisy. Show the following warning instead: [function] is deprecated. Run ":checkhealth vim.deprecated" for more information. The important part is that the full message needs to be short enough to fit in one line in order to not trigger the "Press ENTER or type command to continue" prompt. The full information and stack trace for the deprecated functions will be shown in the new healthcheck `vim.deprecated`. --- test/functional/plugin/health_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index 7aa5c99a60..9c7c953fb0 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -42,7 +42,7 @@ describe(':checkhealth', function() it('completions can be listed via getcompletion()', function() clear() - eq('vim.health', getcompletion('vim', 'checkhealth')[1]) + eq('vim.deprecated', getcompletion('vim', 'checkhealth')[1]) eq('vim.provider', getcompletion('vim.prov', 'checkhealth')[1]) eq('vim.lsp', getcompletion('vim.ls', 'checkhealth')[1]) end) -- cgit