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/lsp_spec.lua') 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/lsp_spec.lua') 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/lsp_spec.lua') 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/lsp_spec.lua') 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/lsp_spec.lua') 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