autoload/lsp.vim | 10 ++++++++++ autoload/lspserver.vim | 12 +++++++++++- doc/lsp.txt | 9 +++++++++ plugin/lsp.vim | 1 + test/unit_tests.vim | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/autoload/lsp.vim b/autoload/lsp.vim index 39bd1097cff8332992486ff07b62a1ece50a0d91..772da603016cf563bbfb570bd86996ecf3c4001e 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 e4b2b3763124c431844d883102292f4a7820a379..3b943730bed867365998144811044d87057fc293 100644 --- a/autoload/lspserver.vim +++ b/autoload/lspserver.vim @@ -860,6 +860,15 @@ req.params->extend(cmd) 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 @@ addWorkspaceFolder: function('s:addWorkspaceFolder', [lspserver]), 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 fe45b479c4d14f68d9dbc9202e5b026b698da330..486c5e54dc8a597ab7f005afb6ae50bc66f4b60d 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -123,6 +123,8 @@ :LspWorkspaceRemoveFolder {folder} 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* @@ -466,6 +468,13 @@ *:LspWorkspaceListFolders* :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 aa84149672810a26839f06ea5c75c71d7bd77f93..6029d967aff2c69a93143f594d4a22f68301295e 100644 --- a/plugin/lsp.vim +++ b/plugin/lsp.vim @@ -32,6 +32,7 @@ # autocmd VimLeavePre * call lsp#stopAllServers() # 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 10a70f917c1ce58b738c56aae10a975b154ca7ad..89337098f0051892214e60060caf15b29e1ceb45 100644 --- a/test/unit_tests.vim +++ b/test/unit_tests.vim @@ -164,6 +164,15 @@ } } 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 @@ :sleep 500m 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 @@ cursor(4, 1) :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 @@ count = 5; } 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 @@ redraw! 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 @@ sleep 1 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