diff options
| author | Josh Rahm <joshuarahm@gmail.com> | 2024-11-25 19:15:05 +0000 |
|---|---|---|
| committer | Josh Rahm <joshuarahm@gmail.com> | 2024-11-25 19:27:38 +0000 |
| commit | c5d770d311841ea5230426cc4c868e8db27300a8 (patch) | |
| tree | dd21f70127b4b8b5f109baefc8ecc5016f507c91 /test/functional/plugin/lsp_spec.lua | |
| parent | 9be89f131f87608f224f0ee06d199fcd09d32176 (diff) | |
| parent | 081beb3659bd6d8efc3e977a160b1e72becbd8a2 (diff) | |
| download | rneovim-c5d770d311841ea5230426cc4c868e8db27300a8.tar.gz rneovim-c5d770d311841ea5230426cc4c868e8db27300a8.tar.bz2 rneovim-c5d770d311841ea5230426cc4c868e8db27300a8.zip | |
Merge remote-tracking branch 'upstream/master' into mix_20240309
Diffstat (limited to 'test/functional/plugin/lsp_spec.lua')
| -rw-r--r-- | test/functional/plugin/lsp_spec.lua | 149 |
1 files changed, 110 insertions, 39 deletions
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 9956fdf628..5222216faf 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) @@ -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 @@ -3519,6 +3481,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() @@ -5090,6 +5076,91 @@ 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, + 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) + 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() |