From: Yegappan Lakshmanan Date: Sat, 22 Jan 2022 05:04:29 +0000 (-0800) Subject: Add a command to display LSP server capabilities. Add additional test X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=2b51dc9f61d348f6bc079859f93fe101fd5a56c3;p=vim-lsp.git Add a command to display LSP server capabilities. Add additional test --- diff --git a/autoload/lsp.vim b/autoload/lsp.vim index 39bd109..772da60 100644 --- a/autoload/lsp.vim +++ b/autoload/lsp.vim @@ -886,4 +886,14 @@ def lsp#diagHighlightDisable() diag.DiagsHighlightDisable() enddef +# Display the LSP server capabilities +def lsp#showServerCapabilities() + var lspserver: dict = s:curbufGetServerChecked() + if lspserver->empty() + return + endif + + lspserver.showCapabilities() +enddef + # vim: shiftwidth=2 softtabstop=2 diff --git a/autoload/lspserver.vim b/autoload/lspserver.vim index e4b2b37..3b94373 100644 --- a/autoload/lspserver.vim +++ b/autoload/lspserver.vim @@ -860,6 +860,15 @@ def s:executeCommand(lspserver: dict, cmd: dict) lspserver.sendMessage(req) enddef +# Display the LSP server capabilities (received during the initialization +# stage). +def s:showCapabilities(lspserver: dict) + echo "Capabilities of '" .. lspserver.path .. "' LSP server:" + for k in lspserver.caps->keys()->sort() + echo k .. ": " .. lspserver.caps[k]->string() + endfor +enddef + export def NewLspServer(path: string, args: list): dict var lspserver: dict = { path: path, @@ -921,7 +930,8 @@ export def NewLspServer(path: string, args: list): dict removeWorkspaceFolder: function('s:removeWorkspaceFolder', [lspserver]), selectionRange: function('s:selectionRange', [lspserver]), foldRange: function('s:foldRange', [lspserver]), - executeCommand: function('s:executeCommand', [lspserver]) + executeCommand: function('s:executeCommand', [lspserver]), + showCapabilities: function('s:showCapabilities', [lspserver]) }) return lspserver diff --git a/doc/lsp.txt b/doc/lsp.txt index fe45b47..486c5e5 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -123,6 +123,8 @@ The following commands are provided: Remove a folder from the workspace :LspWorkspaceListFolders Show the list of folders in the workspace +:LspShowServerCapabilities + Display the list of capabilities of a LSP server. ============================================================================== 4. Configuration *lsp-configuration* @@ -467,6 +469,13 @@ diagnostic messages, you can add the following line to your .vimrc file: :LspWorkspaceListFolders Show the list of folders in the workspace. + *:LspShowServerCapabilities* +:LspShowServerCapabilities + Display the list of capabilities of a LSP server. + The server capabilities are described in the LSP + protocol specification under the "ServerCapabilities" + interface. + ============================================================================== 6. Insert mode completion diff --git a/plugin/lsp.vim b/plugin/lsp.vim index aa84149..6029d96 100644 --- a/plugin/lsp.vim +++ b/plugin/lsp.vim @@ -32,6 +32,7 @@ augroup END # LSP commands command! -nargs=0 -bar LspShowServers call lsp#showServers() +command! -nargs=0 -bar LspShowServerCapabilities call lsp#showServerCapabilities() command! -nargs=1 -bar LspSetTrace call lsp#setTraceServer() command! -nargs=0 -bar LspGotoDefinition call lsp#gotoDefinition(v:false) command! -nargs=0 -bar LspGotoDeclaration call lsp#gotoDeclaration(v:false) diff --git a/test/unit_tests.vim b/test/unit_tests.vim index 10a70f9..8933709 100644 --- a/test/unit_tests.vim +++ b/test/unit_tests.vim @@ -164,6 +164,15 @@ def Test_lsp_formatting() } END assert_equal(expected, getline(1, '$')) + bw! + + # empty file + assert_equal('', execute('LspFormat')) + + # file without an LSP server + edit a.b + assert_equal(['Error: LSP server for "a.b" is not found'], + execute('LspFormat')->split("\n")) :%bw! enddef @@ -206,6 +215,15 @@ def Test_lsp_show_references() WaitForAssert(() => assert_equal(1, getloclist(0)->len())) qfl = getloclist(0) assert_equal([1, 5], [qfl[0].lnum, qfl[0].col]) + bw! + + # empty file + assert_equal('', execute('LspShowReferences')) + + # file without an LSP server + edit a.b + assert_equal(['Error: LSP server for "a.b" is not found'], + execute('LspShowReferences')->split("\n")) :%bw! enddef @@ -302,6 +320,15 @@ def Test_lsp_codeaction() :LspCodeAction sleep 500m WaitForAssert(() => assert_equal("\tcount = 20;", getline(4))) + bw! + + # empty file + assert_equal('', execute('LspCodeAction')) + + # file without an LSP server + edit a.b + assert_equal(['Error: LSP server for "a.b" is not found'], + execute('LspCodeAction')->split("\n")) :%bw! enddef @@ -345,6 +372,16 @@ def Test_lsp_rename() } END WaitForAssert(() => assert_equal(expected, getline(1, '$'))) + bw! + + # empty file + assert_equal('', execute('LspRename')) + + # file without an LSP server + edit a.b + assert_equal(['Error: LSP server for "a.b" is not found'], + execute('LspRename')->split("\n")) + :%bw! enddef @@ -386,6 +423,16 @@ def Test_lsp_selection() normal! y assert_equal('v', visualmode()) assert_equal([4, 5, 6, 5], [line("'<"), col("'<"), line("'>"), col("'>")]) + bw! + + # empty file + assert_equal('', execute('LspSelectionRange')) + + # file without an LSP server + edit a.b + assert_equal(['Error: LSP server for "a.b" is not found'], + execute('LspSelectionRange')->split("\n")) + :%bw! enddef @@ -456,6 +503,22 @@ def Test_lsp_goto_definition() m = execute('messages')->split("\n") assert_equal('Error: implementation is not found', m[1]) endif + bw! + + # empty file + assert_equal('', execute('LspGotoDefinition')) + assert_equal('', execute('LspGotoDeclaration')) + assert_equal('', execute('LspGotoImpl')) + + # file without an LSP server + edit a.b + assert_equal(['Error: LSP server for "a.b" is not found'], + execute('LspGotoDefinition')->split("\n")) + assert_equal(['Error: LSP server for "a.b" is not found'], + execute('LspGotoDeclaration')->split("\n")) + assert_equal(['Error: LSP server for "a.b" is not found'], + execute('LspGotoImpl')->split("\n")) + :%bw! enddef