]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Add a command to display LSP server capabilities. Add additional test
authorYegappan Lakshmanan <yegappan@yahoo.com>
Sat, 22 Jan 2022 05:04:29 +0000 (21:04 -0800)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Sat, 22 Jan 2022 05:04:29 +0000 (21:04 -0800)
autoload/lsp.vim
autoload/lspserver.vim
doc/lsp.txt
plugin/lsp.vim
test/unit_tests.vim

index 39bd1097cff8332992486ff07b62a1ece50a0d91..772da603016cf563bbfb570bd86996ecf3c4001e 100644 (file)
@@ -886,4 +886,14 @@ def lsp#diagHighlightDisable()
   diag.DiagsHighlightDisable()
 enddef
 
+# Display the LSP server capabilities
+def lsp#showServerCapabilities()
+  var lspserver: dict<any> = s:curbufGetServerChecked()
+  if lspserver->empty()
+    return
+  endif
+
+  lspserver.showCapabilities()
+enddef
+
 # vim: shiftwidth=2 softtabstop=2
index e4b2b3763124c431844d883102292f4a7820a379..3b943730bed867365998144811044d87057fc293 100644 (file)
@@ -860,6 +860,15 @@ def s:executeCommand(lspserver: dict<any>, cmd: dict<any>)
   lspserver.sendMessage(req)
 enddef
 
+# Display the LSP server capabilities (received during the initialization
+# stage).
+def s:showCapabilities(lspserver: dict<any>)
+  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<string>): dict<any>
   var lspserver: dict<any> = {
     path: path,
@@ -921,7 +930,8 @@ export def NewLspServer(path: string, args: list<string>): dict<any>
     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
index fe45b479c4d14f68d9dbc9202e5b026b698da330..486c5e54dc8a597ab7f005afb6ae50bc66f4b60d 100644 (file)
@@ -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
 
index aa84149672810a26839f06ea5c75c71d7bd77f93..6029d967aff2c69a93143f594d4a22f68301295e 100644 (file)
@@ -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(<q-args>)
 command! -nargs=0 -bar LspGotoDefinition call lsp#gotoDefinition(v:false)
 command! -nargs=0 -bar LspGotoDeclaration call lsp#gotoDeclaration(v:false)
index 10a70f917c1ce58b738c56aae10a975b154ca7ad..89337098f0051892214e60060caf15b29e1ceb45 100644 (file)
@@ -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