From 8450752f46e1482bf34b7f05e484cca740f61075 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 9 Oct 2024 08:15:14 +0800 Subject: vim-patch:9.1.0771: completion attribute hl_group is confusing Problem: Currently completion attribute hl_group is combined with all items, which is redundant and confusing with kind_hlgroup Solution: Renamed to abbr_hlgroup and combine it only with the abbr item (glepnir). closes: vim/vim#15818 https://github.com/vim/vim/commit/0fe17f8ffbd2588ecd2bf42dced556897bc64f89 Co-authored-by: glepnir --- test/functional/plugin/lsp/completion_spec.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp/completion_spec.lua b/test/functional/plugin/lsp/completion_spec.lua index 4df8d77d44..cb49526f56 100644 --- a/test/functional/plugin/lsp/completion_spec.lua +++ b/test/functional/plugin/lsp/completion_spec.lua @@ -320,7 +320,7 @@ describe('vim.lsp.completion: item conversion', function() info = '', kind = 'Module', menu = '', - hl_group = '', + abbr_hlgroup = '', word = 'this_thread', } local result = complete(' std::this|', completion_list) @@ -376,7 +376,7 @@ describe('vim.lsp.completion: item conversion', function() info = '', kind = 'Module', menu = '', - hl_group = '', + abbr_hlgroup = '', word = 'this_thread', } local result = complete(' std::this|is', completion_list) @@ -570,7 +570,7 @@ describe('vim.lsp.completion: protocol', function() info = '', kind = 'Unknown', menu = '', - hl_group = '', + abbr_hlgroup = '', user_data = { nvim = { lsp = { @@ -591,7 +591,7 @@ describe('vim.lsp.completion: protocol', function() info = '', kind = 'Unknown', menu = '', - hl_group = 'DiagnosticDeprecated', + abbr_hlgroup = 'DiagnosticDeprecated', user_data = { nvim = { lsp = { @@ -613,7 +613,7 @@ describe('vim.lsp.completion: protocol', function() info = '', kind = 'Unknown', menu = '', - hl_group = 'DiagnosticDeprecated', + abbr_hlgroup = 'DiagnosticDeprecated', user_data = { nvim = { lsp = { -- cgit From b3109084c2c3675aa886bf16ff15f50025f30096 Mon Sep 17 00:00:00 2001 From: Tomasz N Date: Thu, 10 Oct 2024 11:40:03 +0200 Subject: fix(lsp): fix cursor position after snippet expansion (#30659) Problem: on `CompleteDone` cursor can jump to the end of line instead of the end of the completed word. Solution: remove only inserted word for snippet expansion instead of everything until eol. Fixes #30656 Co-authored-by: Mathias Fussenegger Co-authored-by: Justin M. Keyes --- test/functional/plugin/lsp/completion_spec.lua | 121 ++++++++++++++++++------- 1 file changed, 88 insertions(+), 33 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp/completion_spec.lua b/test/functional/plugin/lsp/completion_spec.lua index cb49526f56..ec2f88ec32 100644 --- a/test/functional/plugin/lsp/completion_spec.lua +++ b/test/functional/plugin/lsp/completion_spec.lua @@ -471,6 +471,39 @@ describe('vim.lsp.completion: item conversion', function() ) end) +--- @param completion_result lsp.CompletionList +--- @return integer +local function create_server(completion_result) + return exec_lua(function() + local server = _G._create_server({ + capabilities = { + completionProvider = { + triggerCharacters = { '.' }, + }, + }, + handlers = { + ['textDocument/completion'] = function(_, _, callback) + callback(nil, completion_result) + end, + }, + }) + + local bufnr = vim.api.nvim_get_current_buf() + vim.api.nvim_win_set_buf(0, bufnr) + return vim.lsp.start({ + name = 'dummy', + cmd = server.cmd, + on_attach = function(client, bufnr0) + vim.lsp.completion.enable(true, client.id, bufnr0, { + convert = function(item) + return { abbr = item.label:gsub('%b()', '') } + end, + }) + end, + }) + end) +end + describe('vim.lsp.completion: protocol', function() before_each(function() clear() @@ -487,39 +520,6 @@ describe('vim.lsp.completion: protocol', function() after_each(clear) - --- @param completion_result lsp.CompletionList - --- @return integer - local function create_server(completion_result) - return exec_lua(function() - local server = _G._create_server({ - capabilities = { - completionProvider = { - triggerCharacters = { '.' }, - }, - }, - handlers = { - ['textDocument/completion'] = function(_, _, callback) - callback(nil, completion_result) - end, - }, - }) - - local bufnr = vim.api.nvim_get_current_buf() - vim.api.nvim_win_set_buf(0, bufnr) - return vim.lsp.start({ - name = 'dummy', - cmd = server.cmd, - on_attach = function(client, bufnr0) - vim.lsp.completion.enable(true, client.id, bufnr0, { - convert = function(item) - return { abbr = item.label:gsub('%b()', '') } - end, - }) - end, - }) - end) - end - local function assert_matches(fn) retry(nil, nil, function() fn(exec_lua('return _G.capture.matches')) @@ -726,3 +726,58 @@ describe('vim.lsp.completion: protocol', function() end) end) end) + +describe('vim.lsp.completion: integration', function() + before_each(function() + clear() + exec_lua(create_server_definition) + exec_lua(function() + vim.fn.complete = vim.schedule_wrap(vim.fn.complete) + end) + end) + + after_each(clear) + + it('puts cursor at the end of completed word', function() + local completion_list = { + isIncomplete = false, + items = { + { + label = 'hello', + insertText = '${1:hello} friends', + insertTextFormat = 2, + }, + }, + } + exec_lua(function() + vim.o.completeopt = 'menuone,noselect' + end) + create_server(completion_list) + feed('i world0ih') + retry(nil, nil, function() + eq( + 1, + exec_lua(function() + return vim.fn.pumvisible() + end) + ) + end) + feed('') + eq( + { true, { 'hello friends world' } }, + exec_lua(function() + return { + vim.snippet.active({ direction = 1 }), + vim.api.nvim_buf_get_lines(0, 0, -1, true), + } + end) + ) + feed('') + eq( + #'hello friends', + exec_lua(function() + return vim.api.nvim_win_get_cursor(0)[2] + end) + ) + end) +end) -- cgit From e0a5c3bb581752569df4490b48cb54e7c1ab0613 Mon Sep 17 00:00:00 2001 From: Maria José Solano Date: Tue, 15 Oct 2024 02:36:04 -0700 Subject: fix(lsp): handle multiline signature help labels #30460 --- test/functional/plugin/lsp_spec.lua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 9956fdf628..0ab384a032 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -3519,6 +3519,30 @@ describe('LSP', function() local expected = { '```cs', 'TestEntity.TestEntity()', '```', 'some doc' } eq(expected, result) end) + + it('highlights active parameters in multiline signature labels', function() + local _, hl = exec_lua(function() + local signature_help = { + activeSignature = 0, + signatures = { + { + activeParameter = 1, + label = 'fn bar(\n _: void,\n _: void,\n) void', + parameters = { + { label = '_: void' }, + { label = '_: void' }, + }, + }, + }, + } + return vim.lsp.util.convert_signature_help_to_markdown_lines(signature_help, 'zig', { '(' }) + end) + -- Note that although the higlight positions below are 0-indexed, the 2nd parameter + -- corresponds to the 3rd line because the first line is the ``` from the + -- Markdown block. + local expected = { 3, 4, 3, 11 } + eq(expected, hl) + end) end) describe('lsp.util.get_effective_tabstop', function() -- cgit From f0973d42272e9474c758c87697e3803e1796d17c Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 16 Oct 2024 09:58:10 +0100 Subject: feat(lsp.util): refactor symbols_to_items() - Remove the trivial function vim.lsp.util._get_symbol_kind_name() and its tests. --- test/functional/plugin/lsp_spec.lua | 38 ------------------------------------- 1 file changed, 38 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 0ab384a032..5309e1967c 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -3134,44 +3134,6 @@ describe('LSP', function() end) end) - describe('lsp.util._get_symbol_kind_name', function() - it('returns the name specified by protocol', function() - eq( - 'File', - exec_lua(function() - return vim.lsp.util._get_symbol_kind_name(1) - end) - ) - eq( - 'TypeParameter', - exec_lua(function() - return vim.lsp.util._get_symbol_kind_name(26) - end) - ) - end) - - it('returns the name not specified by protocol', function() - eq( - 'Unknown', - exec_lua(function() - return vim.lsp.util._get_symbol_kind_name(nil) - end) - ) - eq( - 'Unknown', - exec_lua(function() - return vim.lsp.util._get_symbol_kind_name(vim.NIL) - end) - ) - eq( - 'Unknown', - exec_lua(function() - return vim.lsp.util._get_symbol_kind_name(1000) - end) - ) - end) - end) - describe('lsp.util.jump_to_location', function() local target_bufnr --- @type integer -- cgit From acbc6a7f91d15fe5f59df08227d196156fafedb4 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 16 Oct 2024 13:17:10 +0100 Subject: fix(lsp.util): inconsistent handling of offset_encoding --- 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 5309e1967c..6cd433b975 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -2586,7 +2586,7 @@ describe('LSP', function() }, }, } - eq(false, pcall(exec_lua, 'vim.lsp.util.apply_workspace_edit(...)', edit)) + eq(false, pcall(exec_lua, 'vim.lsp.util.apply_workspace_edit(...)', edit, 'utf-16')) eq(false, vim.uv.fs_stat(tmpfile) ~= nil) end) end) -- cgit From 0083e03d6fa7586d0d6360b40b52b0cab0d2e7ba Mon Sep 17 00:00:00 2001 From: Mathias Fußenegger Date: Sun, 20 Oct 2024 23:40:44 +0200 Subject: feat(lsp)!: support multiple clients in goto methods (#30877) Relates to: - https://github.com/neovim/neovim/issues/30034 - https://github.com/neovim/neovim/issues/17712 - https://github.com/neovim/neovim/issues/16363 Closes: - https://github.com/neovim/neovim/issues/26936 (but only provides bufnr and method) - https://github.com/neovim/neovim/issues/22318 Might fix: https://github.com/neovim/neovim/issues/30737 --- test/functional/plugin/lsp_spec.lua | 80 +++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 6cd433b975..eaca413e89 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -5076,6 +5076,86 @@ describe('LSP', function() end) end) + describe('lsp.buf.definition', function() + it('jumps to single location', function() + exec_lua(create_server_definition) + local result = exec_lua(function() + local bufnr = vim.api.nvim_get_current_buf() + local server = _G._create_server({ + capabilities = { + definitionProvider = true, + }, + handlers = { + ['textDocument/definition'] = function(_, _, callback) + local location = { + range = { + start = { line = 0, character = 0 }, + ['end'] = { line = 0, character = 0 }, + }, + uri = vim.uri_from_bufnr(bufnr), + } + callback(nil, location) + end, + }, + }) + local win = vim.api.nvim_get_current_win() + vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, { 'local x = 10', '', 'print(x)' }) + vim.api.nvim_win_set_cursor(win, { 3, 6 }) + local client_id = assert(vim.lsp.start({ name = 'dummy', cmd = server.cmd })) + vim.lsp.buf.definition() + vim.lsp.stop_client(client_id) + return { + cursor = vim.api.nvim_win_get_cursor(win), + messages = server.messages, + } + end) + eq('textDocument/definition', result.messages[3].method) + eq({ 1, 0 }, result.cursor) + end) + it('merges results from multiple servers', function() + exec_lua(create_server_definition) + local result = exec_lua(function() + local bufnr = vim.api.nvim_get_current_buf() + local function serveropts(character) + return { + capabilities = { + definitionProvider = true, + }, + handlers = { + ['textDocument/definition'] = function(_, _, callback) + local location = { + range = { + start = { line = 0, character = character }, + ['end'] = { line = 0, character = character }, + }, + uri = vim.uri_from_bufnr(bufnr), + } + callback(nil, location) + end, + }, + } + end + local server1 = _G._create_server(serveropts(0)) + local server2 = _G._create_server(serveropts(7)) + local win = vim.api.nvim_get_current_win() + vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, { 'local x = 10', '', 'print(x)' }) + vim.api.nvim_win_set_cursor(win, { 3, 6 }) + local client_id1 = assert(vim.lsp.start({ name = 'dummy', cmd = server1.cmd })) + local client_id2 = assert(vim.lsp.start({ name = 'dummy', cmd = server2.cmd })) + local response + vim.lsp.buf.definition({ + on_list = function(r) + response = r + end, + }) + vim.lsp.stop_client(client_id1) + vim.lsp.stop_client(client_id2) + return response + end) + eq(2, #result.items) + end) + end) + describe('vim.lsp.tagfunc', function() before_each(function() clear() -- cgit From 3c51058d7611ef235a23ae77f994403480237700 Mon Sep 17 00:00:00 2001 From: Mathias Fussenegger Date: Thu, 24 Oct 2024 10:22:38 +0200 Subject: fix(lsp): set tagstack on jump via goto methods Follow up to https://github.com/neovim/neovim/pull/30877 Fixes https://github.com/neovim/neovim/issues/30926 --- test/functional/plugin/lsp_spec.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index eaca413e89..5222216faf 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -5107,10 +5107,15 @@ describe('LSP', function() return { cursor = vim.api.nvim_win_get_cursor(win), messages = server.messages, + tagstack = vim.fn.gettagstack(win), } end) eq('textDocument/definition', result.messages[3].method) eq({ 1, 0 }, result.cursor) + eq(1, #result.tagstack.items) + eq('x', result.tagstack.items[1].tagname) + eq(3, result.tagstack.items[1].from[2]) + eq(7, result.tagstack.items[1].from[3]) end) it('merges results from multiple servers', function() exec_lua(create_server_definition) -- cgit From 25b53b593ef6f229fbec5b3dc205a7539579d13a Mon Sep 17 00:00:00 2001 From: Tristan Knight Date: Sat, 26 Oct 2024 15:38:25 +0100 Subject: refactor(lsp): drop str_byteindex/str_utfindex wrappers #30915 * deprecate old signatures * move to new str_byteindex/str_utfindex signature * use single-underscore name (double-underscore is reserved for Lua itself) --- test/functional/plugin/lsp/diagnostic_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 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 78c684083b..b7e292cad0 100644 --- a/test/functional/plugin/lsp/diagnostic_spec.lua +++ b/test/functional/plugin/lsp/diagnostic_spec.lua @@ -219,13 +219,13 @@ describe('vim.lsp.diagnostic', function() eq(1, #result) eq( exec_lua(function() - return vim.str_byteindex(line, 7, true) + return vim.str_byteindex(line, 'utf-16', 7) end), result[1].col ) eq( exec_lua(function() - return vim.str_byteindex(line, 8, true) + return vim.str_byteindex(line, 'utf-16', 8) end), result[1].end_col ) -- cgit From 9b357e30fdd0a575480182872331fdb87e9cc331 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 29 Oct 2024 09:36:02 +0000 Subject: feat(lsp)!: remove client-server handlers from vim.lsp.handlers - Partition the handlers in vim.lsp.handlers as: - client to server response handlers (RCS) - server to client request handlers (RSC) - server to client notification handlers (NSC) Note use string indexes instead of protocol.methods for improved typing in LuaLS (tip: use hover on RCS, RSC or NSC). --- test/functional/plugin/lsp/diagnostic_spec.lua | 107 ------------------------- 1 file changed, 107 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 b7e292cad0..5afbe22793 100644 --- a/test/functional/plugin/lsp/diagnostic_spec.lua +++ b/test/functional/plugin/lsp/diagnostic_spec.lua @@ -120,85 +120,6 @@ describe('vim.lsp.diagnostic', function() end) describe('vim.lsp.diagnostic.on_publish_diagnostics', function() - it('allows configuring the virtual text via vim.lsp.with', function() - local expected_spacing = 10 - local extmarks = exec_lua(function() - _G.PublishDiagnostics = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { - virtual_text = { - spacing = expected_spacing, - }, - }) - - _G.PublishDiagnostics(nil, { - uri = fake_uri, - diagnostics = { - _G.make_error('Delayed Diagnostic', 4, 4, 4, 4), - }, - }, { client_id = client_id }) - - return _G.get_extmarks(diagnostic_bufnr, client_id) - end) - - local spacing = extmarks[1][4].virt_text[1][1] - - eq(expected_spacing, #spacing) - end) - - it('allows configuring the virtual text via vim.lsp.with using a function', function() - local expected_spacing = 10 - local extmarks = exec_lua(function() - _G.PublishDiagnostics = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { - virtual_text = function() - return { - spacing = expected_spacing, - } - end, - }) - - _G.PublishDiagnostics(nil, { - uri = fake_uri, - diagnostics = { - _G.make_error('Delayed Diagnostic', 4, 4, 4, 4), - }, - }, { client_id = client_id }) - - return _G.get_extmarks(diagnostic_bufnr, client_id) - end) - - local spacing = extmarks[1][4].virt_text[1][1] - - eq(expected_spacing, #spacing) - end) - - it('allows filtering via severity limit', function() - local get_extmark_count_with_severity = function(severity_limit) - return exec_lua(function() - _G.PublishDiagnostics = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { - underline = false, - virtual_text = { - severity = { min = severity_limit }, - }, - }) - - _G.PublishDiagnostics(nil, { - uri = fake_uri, - diagnostics = { - _G.make_warning('Delayed Diagnostic', 4, 4, 4, 4), - }, - }, { client_id = client_id }) - - return #_G.get_extmarks(diagnostic_bufnr, client_id) - end, client_id, fake_uri, severity_limit) - end - - -- No messages with Error or higher - eq(0, get_extmark_count_with_severity('ERROR')) - - -- But now we don't filter it - eq(1, get_extmark_count_with_severity('WARN')) - eq(1, get_extmark_count_with_severity('HINT')) - end) - it('correctly handles UTF-16 offsets', function() local line = 'All 💼 and no 🎉 makes Jack a dull 👦' local result = exec_lua(function() @@ -380,34 +301,6 @@ describe('vim.lsp.diagnostic', function() eq(1, diagnostics[1].severity) end) - it('allows configuring the virtual text via vim.lsp.with', function() - local expected_spacing = 10 - local extmarks = exec_lua(function() - _G.Diagnostic = vim.lsp.with(vim.lsp.diagnostic.on_diagnostic, { - virtual_text = { - spacing = expected_spacing, - }, - }) - - _G.Diagnostic(nil, { - kind = 'full', - items = { - _G.make_error('Pull Diagnostic', 4, 4, 4, 4), - }, - }, { - params = { - textDocument = { uri = fake_uri }, - }, - uri = fake_uri, - client_id = client_id, - }, {}) - - return _G.get_extmarks(diagnostic_bufnr, client_id) - end) - eq(2, #extmarks) - eq(expected_spacing, #extmarks[1][4].virt_text[1][1]) - end) - it('clears diagnostics when client detaches', function() exec_lua(function() vim.lsp.diagnostic.on_diagnostic(nil, { -- cgit From 33d10db5b7a7cd03b22e3ba401cb3bc74640f522 Mon Sep 17 00:00:00 2001 From: Kristijan Husak Date: Wed, 13 Nov 2024 16:18:29 +0100 Subject: fix(lsp): filter completion candidates based on completeopt (#30945) --- test/functional/plugin/lsp/completion_spec.lua | 266 ++++++++++++++++++++++++- 1 file changed, 263 insertions(+), 3 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/lsp/completion_spec.lua b/test/functional/plugin/lsp/completion_spec.lua index ec2f88ec32..39b6ddc105 100644 --- a/test/functional/plugin/lsp/completion_spec.lua +++ b/test/functional/plugin/lsp/completion_spec.lua @@ -134,10 +134,14 @@ describe('vim.lsp.completion: item conversion', function() eq(expected, result) end) - it('filters on label if filterText is missing', function() + it('does not filter if there is a textEdit', function() + local range0 = { + start = { line = 0, character = 0 }, + ['end'] = { line = 0, character = 0 }, + } local completion_list = { - { label = 'foo' }, - { label = 'bar' }, + { label = 'foo', textEdit = { newText = 'foo', range = range0 } }, + { label = 'bar', textEdit = { newText = 'bar', range = range0 } }, } local result = complete('fo|', completion_list) local expected = { @@ -145,6 +149,10 @@ describe('vim.lsp.completion: item conversion', function() abbr = 'foo', word = 'foo', }, + { + abbr = 'bar', + word = 'bar', + }, } result = vim.tbl_map(function(x) return { @@ -152,9 +160,261 @@ describe('vim.lsp.completion: item conversion', function() word = x.word, } end, result.items) + local sorter = function(a, b) + return a.word > b.word + end + table.sort(expected, sorter) + table.sort(result, sorter) eq(expected, result) end) + ---@param prefix string + ---@param items lsp.CompletionItem[] + ---@param expected table[] + local assert_completion_matches = function(prefix, items, expected) + local result = complete(prefix .. '|', items) + result = vim.tbl_map(function(x) + return { + abbr = x.abbr, + word = x.word, + } + end, result.items) + local sorter = function(a, b) + return a.word > b.word + end + table.sort(expected, sorter) + table.sort(result, sorter) + eq(expected, result) + end + + describe('when completeopt has fuzzy matching enabled', function() + before_each(function() + exec_lua(function() + vim.opt.completeopt:append('fuzzy') + end) + end) + after_each(function() + exec_lua(function() + vim.opt.completeopt:remove('fuzzy') + end) + end) + + it('fuzzy matches on filterText', function() + assert_completion_matches('fo', { + { label = '?.foo', filterText = 'foo' }, + { label = 'faz other', filterText = 'faz other' }, + { label = 'bar', filterText = 'bar' }, + }, { + { + abbr = 'faz other', + word = 'faz other', + }, + { + abbr = '?.foo', + word = '?.foo', + }, + }) + end) + + it('fuzzy matches on label when filterText is missing', function() + assert_completion_matches('fo', { + { label = 'foo' }, + { label = 'faz other' }, + { label = 'bar' }, + }, { + { + abbr = 'faz other', + word = 'faz other', + }, + { + abbr = 'foo', + word = 'foo', + }, + }) + end) + end) + + describe('when smartcase is enabled', function() + before_each(function() + exec_lua(function() + vim.opt.smartcase = true + end) + end) + after_each(function() + exec_lua(function() + vim.opt.smartcase = false + end) + end) + + it('matches filterText case sensitively', function() + assert_completion_matches('Fo', { + { label = 'foo', filterText = 'foo' }, + { label = '?.Foo', filterText = 'Foo' }, + { label = 'Faz other', filterText = 'Faz other' }, + { label = 'faz other', filterText = 'faz other' }, + { label = 'bar', filterText = 'bar' }, + }, { + { + abbr = '?.Foo', + word = '?.Foo', + }, + }) + end) + + it('matches label case sensitively when filterText is missing', function() + assert_completion_matches('Fo', { + { label = 'foo' }, + { label = 'Foo' }, + { label = 'Faz other' }, + { label = 'faz other' }, + { label = 'bar' }, + }, { + { + abbr = 'Foo', + word = 'Foo', + }, + }) + end) + + describe('when ignorecase is enabled', function() + before_each(function() + exec_lua(function() + vim.opt.ignorecase = true + end) + end) + after_each(function() + exec_lua(function() + vim.opt.ignorecase = false + end) + end) + + it('matches filterText case insensitively if prefix is lowercase', function() + assert_completion_matches('fo', { + { label = '?.foo', filterText = 'foo' }, + { label = '?.Foo', filterText = 'Foo' }, + { label = 'Faz other', filterText = 'Faz other' }, + { label = 'faz other', filterText = 'faz other' }, + { label = 'bar', filterText = 'bar' }, + }, { + { + abbr = '?.Foo', + word = '?.Foo', + }, + { + abbr = '?.foo', + word = '?.foo', + }, + }) + end) + + it( + 'matches label case insensitively if prefix is lowercase and filterText is missing', + function() + assert_completion_matches('fo', { + { label = 'foo' }, + { label = 'Foo' }, + { label = 'Faz other' }, + { label = 'faz other' }, + { label = 'bar' }, + }, { + { + abbr = 'Foo', + word = 'Foo', + }, + { + abbr = 'foo', + word = 'foo', + }, + }) + end + ) + + it('matches filterText case sensitively if prefix has uppercase letters', function() + assert_completion_matches('Fo', { + { label = 'foo', filterText = 'foo' }, + { label = '?.Foo', filterText = 'Foo' }, + { label = 'Faz other', filterText = 'Faz other' }, + { label = 'faz other', filterText = 'faz other' }, + { label = 'bar', filterText = 'bar' }, + }, { + { + abbr = '?.Foo', + word = '?.Foo', + }, + }) + end) + + it( + 'matches label case sensitively if prefix has uppercase letters and filterText is missing', + function() + assert_completion_matches('Fo', { + { label = 'foo' }, + { label = 'Foo' }, + { label = 'Faz other' }, + { label = 'faz other' }, + { label = 'bar' }, + }, { + { + abbr = 'Foo', + word = 'Foo', + }, + }) + end + ) + end) + end) + + describe('when ignorecase is enabled', function() + before_each(function() + exec_lua(function() + vim.opt.ignorecase = true + end) + end) + after_each(function() + exec_lua(function() + vim.opt.ignorecase = false + end) + end) + + it('matches filterText case insensitively', function() + assert_completion_matches('Fo', { + { label = '?.foo', filterText = 'foo' }, + { label = '?.Foo', filterText = 'Foo' }, + { label = 'Faz other', filterText = 'Faz other' }, + { label = 'faz other', filterText = 'faz other' }, + { label = 'bar', filterText = 'bar' }, + }, { + { + abbr = '?.Foo', + word = '?.Foo', + }, + { + abbr = '?.foo', + word = '?.foo', + }, + }) + end) + + it('matches label case insensitively when filterText is missing', function() + assert_completion_matches('Fo', { + { label = 'foo' }, + { label = 'Foo' }, + { label = 'Faz other' }, + { label = 'faz other' }, + { label = 'bar' }, + }, { + { + abbr = 'Foo', + word = 'Foo', + }, + { + abbr = 'foo', + word = 'foo', + }, + }) + end) + end) + it('works on non word prefix', function() local completion_list = { { label = ' foo', insertText = '->foo' }, -- cgit From e61228a214ebda9845db9462dad0a8c362d3963f Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 11 Nov 2024 22:15:19 +0100 Subject: fix(tests): needing two calls to setup a screen is cringe Before calling "attach" a screen object is just a dummy container for (row, col) values whose purpose is to be sent as part of the "attach" function call anyway. Just create the screen in an attached state directly. Keep the complete (row, col, options) config together. It is still completely valid to later detach and re-attach as needed, including to another session. --- test/functional/plugin/health_spec.lua | 10 +++------- test/functional/plugin/lsp/inlay_hint_spec.lua | 2 -- test/functional/plugin/lsp/semantic_tokens_spec.lua | 1 - test/functional/plugin/lsp/utils_spec.lua | 4 +--- test/functional/plugin/man_spec.lua | 1 - test/functional/plugin/matchparen_spec.lua | 1 - test/functional/plugin/shada_spec.lua | 1 - test/functional/plugin/tohtml_spec.lua | 3 +-- test/functional/plugin/tutor_spec.lua | 1 - test/functional/plugin/vim_syntax_spec.lua | 1 - 10 files changed, 5 insertions(+), 20 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index 7089313303..753da64522 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -155,7 +155,6 @@ describe('vim.health', function() it('highlights OK, ERROR', function() local screen = Screen.new(50, 12) - screen:attach() screen:set_default_attr_ids({ h1 = { reverse = true }, h2 = { foreground = tonumber('0x6a0dad') }, @@ -222,7 +221,7 @@ describe(':checkhealth window', function() end) it('opens directly if no buffer created', function() - local screen = Screen.new(50, 12) + local screen = Screen.new(50, 12, { ext_multigrid = true }) screen:set_default_attr_ids { h1 = { reverse = true }, h2 = { foreground = tonumber('0x6a0dad') }, @@ -230,7 +229,6 @@ describe(':checkhealth window', function() [14] = { foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGray }, [32] = { foreground = Screen.colors.PaleGreen2 }, } - screen:attach({ ext_multigrid = true }) command('checkhealth success1') screen:expect { grid = [[ @@ -256,7 +254,7 @@ describe(':checkhealth window', function() end) local function test_health_vsplit(left, emptybuf, mods) - local screen = Screen.new(50, 20) + local screen = Screen.new(50, 20, { ext_multigrid = true }) screen:set_default_attr_ids { h1 = { reverse = true }, h2 = { foreground = tonumber('0x6a0dad') }, @@ -264,7 +262,6 @@ describe(':checkhealth window', function() [14] = { foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGray }, [32] = { foreground = Screen.colors.PaleGreen2 }, } - screen:attach({ ext_multigrid = true }) if not emptybuf then insert('hello') end @@ -322,8 +319,7 @@ describe(':checkhealth window', function() end local function test_health_split(top, emptybuf, mods) - local screen = Screen.new(50, 25) - screen:attach({ ext_multigrid = true }) + local screen = Screen.new(50, 25, { ext_multigrid = true }) screen._default_attr_ids = nil if not emptybuf then insert('hello') diff --git a/test/functional/plugin/lsp/inlay_hint_spec.lua b/test/functional/plugin/lsp/inlay_hint_spec.lua index 471f2cc3e8..fc6c3f46f7 100644 --- a/test/functional/plugin/lsp/inlay_hint_spec.lua +++ b/test/functional/plugin/lsp/inlay_hint_spec.lua @@ -67,7 +67,6 @@ int main() { before_each(function() clear_notrace() screen = Screen.new(50, 9) - screen:attach() bufnr = n.api.nvim_get_current_buf() exec_lua(create_server_definition) @@ -339,7 +338,6 @@ test text before_each(function() clear_notrace() screen = Screen.new(50, 3) - screen:attach() exec_lua(create_server_definition) bufnr = n.api.nvim_get_current_buf() diff --git a/test/functional/plugin/lsp/semantic_tokens_spec.lua b/test/functional/plugin/lsp/semantic_tokens_spec.lua index f72aab7e0b..280bd27207 100644 --- a/test/functional/plugin/lsp/semantic_tokens_spec.lua +++ b/test/functional/plugin/lsp/semantic_tokens_spec.lua @@ -28,7 +28,6 @@ describe('semantic token highlighting', function() local screen --- @type test.functional.ui.screen before_each(function() screen = Screen.new(40, 16) - screen:attach() screen:set_default_attr_ids { [1] = { bold = true, foreground = Screen.colors.Blue1 }, [2] = { foreground = Screen.colors.DarkCyan }, diff --git a/test/functional/plugin/lsp/utils_spec.lua b/test/functional/plugin/lsp/utils_spec.lua index 64d58eeffd..813b8de812 100644 --- a/test/functional/plugin/lsp/utils_spec.lua +++ b/test/functional/plugin/lsp/utils_spec.lua @@ -181,11 +181,9 @@ describe('vim.lsp.util', function() eq(expected_anchor, string.sub(opts.anchor, 1, 1)) end - local screen --- @type test.functional.ui.screen before_each(function() n.clear() - screen = Screen.new(80, 80) - screen:attach() + local _ = Screen.new(80, 80) feed('79i') -- fill screen with empty lines end) diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua index 6f0eeff748..8906e60dce 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -60,7 +60,6 @@ describe(':Man', function() c = { foreground = Screen.colors.Blue }, -- control chars eob = { bold = true, foreground = Screen.colors.Blue }, -- empty line '~'s }) - screen:attach() end) it('clears backspaces from text and adds highlights', function() diff --git a/test/functional/plugin/matchparen_spec.lua b/test/functional/plugin/matchparen_spec.lua index ae718ac1bd..b2bbdb2ef6 100644 --- a/test/functional/plugin/matchparen_spec.lua +++ b/test/functional/plugin/matchparen_spec.lua @@ -14,7 +14,6 @@ describe('matchparen', function() before_each(function() clear { args = { '-u', 'NORC' } } screen = Screen.new(20, 5) - screen:attach() screen:set_default_attr_ids({ [0] = { bold = true, foreground = 255 }, [1] = { bold = true }, diff --git a/test/functional/plugin/shada_spec.lua b/test/functional/plugin/shada_spec.lua index c9d49f7d01..f33819f364 100644 --- a/test/functional/plugin/shada_spec.lua +++ b/test/functional/plugin/shada_spec.lua @@ -3053,7 +3053,6 @@ describe('syntax/shada.vim', function() [7] = { bold = true, reverse = true }, [8] = { bold = true, foreground = Screen.colors.Blue }, } - screen:attach() api.nvim_buf_set_lines(0, 0, 1, true, { 'Header with timestamp ' .. epoch .. ':', diff --git a/test/functional/plugin/tohtml_spec.lua b/test/functional/plugin/tohtml_spec.lua index 1d05f4d6b4..afd4169006 100644 --- a/test/functional/plugin/tohtml_spec.lua +++ b/test/functional/plugin/tohtml_spec.lua @@ -185,8 +185,7 @@ describe(':TOhtml', function() local screen before_each(function() clear({ args = { '--clean' } }) - screen = Screen.new(80, 80) - screen:attach({ term_name = 'xterm' }) + screen = Screen.new(80, 80, { term_name = 'xterm' }) exec('colorscheme default') end) diff --git a/test/functional/plugin/tutor_spec.lua b/test/functional/plugin/tutor_spec.lua index 9f381d45db..09cd22ab6c 100644 --- a/test/functional/plugin/tutor_spec.lua +++ b/test/functional/plugin/tutor_spec.lua @@ -24,7 +24,6 @@ describe(':Tutor', function() [5] = { bold = true, foreground = Screen.colors.Magenta1 }, [6] = { italic = true }, }) - screen:attach() end) it('applies {unix:…,win:…} transform', function() diff --git a/test/functional/plugin/vim_syntax_spec.lua b/test/functional/plugin/vim_syntax_spec.lua index d99a69eab9..bdb4534cba 100644 --- a/test/functional/plugin/vim_syntax_spec.lua +++ b/test/functional/plugin/vim_syntax_spec.lua @@ -21,7 +21,6 @@ describe('Vimscript syntax highlighting', function() [1] = { foreground = Screen.colors.Brown, bold = true }, [2] = { foreground = tonumber('0x6a0dad') }, }) - screen:attach() end) it('prefixed boolean options are highlighted properly', function() -- cgit