diff options
author | Yinzuo Jiang <jiangyinzuo@foxmail.com> | 2024-04-20 21:40:01 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-20 15:40:01 +0200 |
commit | f190f758ac58d9cc955368e047b070e0a2261033 (patch) | |
tree | 01b942694411b6d2852cff8a9123068ebe27a7ad /test/functional/plugin/lsp_spec.lua | |
parent | fd085d90820149caecf213b299f19e46305043ee (diff) | |
download | rneovim-f190f758ac58d9cc955368e047b070e0a2261033.tar.gz rneovim-f190f758ac58d9cc955368e047b070e0a2261033.tar.bz2 rneovim-f190f758ac58d9cc955368e047b070e0a2261033.zip |
feat(lsp): add vim.lsp.buf.subtypes(), vim.lsp.buf.supertypes() (#28388)
Co-authored-by: Mathias Fußenegger <mfussenegger@users.noreply.github.com>
Co-authored-by: Maria José Solano <majosolano99@gmail.com>
Diffstat (limited to 'test/functional/plugin/lsp_spec.lua')
-rw-r--r-- | test/functional/plugin/lsp_spec.lua | 436 |
1 files changed, 436 insertions, 0 deletions
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/_<mylist{MyList.java[MyList[Inner' }, + detail = 'mylist', + kind = 5, + name = 'MyList$Inner', + range = { + ['end'] = { character = 37, line = 3 }, + start = { character = 1, line = 3 }, + }, + selectionRange = { + ['end'] = { character = 19, line = 3 }, + start = { character = 14, line = 3 }, + }, + tags = {}, + uri = 'file:///home/jiangyinzuo/hello-java/mylist/MyList.java', + }, + } + + 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, jdtls_response, { client_id = client_id, bufnr = 1 }) + return vim.fn.getqflist() + ]=]) + + local expected = { + { + bufnr = 2, + col = 2, + end_col = 0, + end_lnum = 0, + lnum = 4, + module = '', + nr = 0, + pattern = '', + text = 'A', + type = '', + valid = 1, + vcol = 0, + }, + { + bufnr = 3, + col = 2, + end_col = 0, + end_lnum = 0, + lnum = 4, + module = '', + nr = 0, + pattern = '', + text = 'MyList$Inner mylist', + type = '', + valid = 1, + vcol = 0, + }, + } + eq(expected, qflist) + end) + end) + + describe('vim.lsp.buf.supertypes', function() + it('does nothing for an empty response', function() + local qflist_count = exec_lua([=[ + require'vim.lsp.handlers'['typeHierarchy/supertypes'](nil, nil, {}) + return #vim.fn.getqflist() + ]=]) + eq(0, qflist_count) + end) + + it('opens the quickfix list with the right supertypes', 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/supertypes'] + 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 supertypes 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/_<mylist{MyList.java[MyList[Inner' }, + detail = 'mylist', + kind = 5, + name = 'MyList$Inner', + range = { + ['end'] = { character = 37, line = 3 }, + start = { character = 1, line = 3 }, + }, + selectionRange = { + ['end'] = { character = 19, line = 3 }, + start = { character = 14, line = 3 }, + }, + tags = {}, + uri = 'file:///home/jiangyinzuo/hello-java/mylist/MyList.java', + }, + } + + 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/supertypes'] + handler(nil, jdtls_response, { client_id = client_id, bufnr = 1 }) + return vim.fn.getqflist() + ]=]) + + local expected = { + { + bufnr = 2, + col = 2, + end_col = 0, + end_lnum = 0, + lnum = 4, + module = '', + nr = 0, + pattern = '', + text = 'A', + type = '', + valid = 1, + vcol = 0, + }, + { + bufnr = 3, + col = 2, + end_col = 0, + end_lnum = 0, + lnum = 4, + module = '', + nr = 0, + pattern = '', + text = 'MyList$Inner mylist', + type = '', + valid = 1, + vcol = 0, + }, + } + eq(expected, qflist) + end) + end) + describe('vim.lsp.buf.rename', function() for _, test in ipairs({ { |