From 5b812b62430aeea8e6f8010b0732272ba95dffae Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Sun, 26 Mar 2023 20:07:36 -0700 Subject: [PATCH] Add commands to display information about language server --- README.md | 55 ++++++++++++++++++----------------- autoload/lsp/lsp.vim | 63 +++++++++++++++++++++++++++++++++++----- autoload/lsp/options.vim | 2 +- doc/lsp.txt | 30 +++++++++++++------ plugin/lsp.vim | 3 +- 5 files changed, 107 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index c7d8aae..2fea0de 100644 --- a/README.md +++ b/README.md @@ -147,22 +147,22 @@ The following commands are provided to use the LSP features. Command|Description -------|----------- :LspCodeAction|Apply the code action supplied by the language server to the diagnostic in the current line. -:LspDiagCurrent|Display the diagnostic message for the current line -:LspDiagFirst|Jump to the first diagnostic message for the current buffer -:LspDiagHere|Jump to the next diagnostic message in the current line -:LspDiagHighlightDisable|Disable diagnostic message highlights -:LspDiagHighlightEnable|Enable diagnostic message highlights -:LspDiagNext|Jump to the next diagnostic message after the current position -:LspDiagPrev|Jump to the previous diagnostic message before the current position +:LspDiagCurrent|Display the diagnostic message for the current line. +:LspDiagFirst|Jump to the first diagnostic message for the current buffer. +:LspDiagHere|Jump to the next diagnostic message in the current line. +:LspDiagHighlightDisable|Disable diagnostic message highlights. +:LspDiagHighlightEnable|Enable diagnostic message highlights. +:LspDiagNext|Jump to the next diagnostic message after the current position. +:LspDiagPrev|Jump to the previous diagnostic message before the current position. :LspDiagShow|Display the diagnostics messages from the language server for the current buffer in a new location list. -:LspFold|Fold the current file +:LspFold|Fold the current file. :LspFormat|Format a range of lines in the current file using the language server. The **shiftwidth** and **expandtab** values set for the current buffer are used when format is applied. The default range is the entire file. -:LspGotoDeclaration|Go to the declaration of the keyword under cursor -:LspGotoDefinition|Go to the definition of the keyword under cursor -:LspGotoImpl|Go to the implementation of the keyword under cursor -:LspGotoTypeDef|Go to the type definition of the keyword under cursor -:LspHighlight|Highlight all the matches for the keyword under cursor -:LspHighlightClear|Clear all the matches highlighted by :LspHighlight +:LspGotoDeclaration|Go to the declaration of the keyword under cursor. +:LspGotoDefinition|Go to the definition of the keyword under cursor. +:LspGotoImpl|Go to the implementation of the keyword under cursor. +:LspGotoTypeDef|Go to the type definition of the keyword under cursor. +:LspHighlight|Highlight all the matches for the keyword under cursor. +:LspHighlightClear|Clear all the matches highlighted by :LspHighlight. :LspHover|Show the documentation for the symbol under the cursor in a popup window. :LspIncomingCalls|Display the list of symbols calling the current symbol. :LspOutgoingCalls|Display the list of symbols called by the current symbol. @@ -172,21 +172,22 @@ Command|Description :LspPeekImpl|Open the implementation of the symbol under cursor in the preview window. :LspPeekReferences|Display the list of references to the keyword under cursor in a location list associated with the preview window. :LspPeekTypeDef|Open the type definition of the symbol under cursor in the preview window. -:LspRename|Rename the current symbol -:LspSelectionExpand|Expand the current symbol range visual selection -:LspSelectionShrink|Shrink the current symbol range visual selection -:LspServerRestart|Restart the language server for the current buffer +:LspRename|Rename the current symbol. +:LspSelectionExpand|Expand the current symbol range visual selection. +:LspSelectionShrink|Shrink the current symbol range visual selection. +:LspShowAllServers|Display information about all the registered language servers. +:LspServerRestart|Restart the language server for the current buffer. :LspShowReferences|Display the list of references to the keyword under cursor in a new location list. -:LspShowServers|Display the list of registered language servers -:LspShowServerCapabilities|Display the language server capabilities for the current buffer -:LspShowSignature|Display the signature of the keyword under cursor -:LspSubTypeHierarchy|Display the sub type hierarchy in a popup window -:LspSuperTypeHierarchy|Display the super type hierarchy in a popup window +:LspShowServer|Display the language server status for the current buffer. +:LspShowServerCapabilities|Display the language server capabilities for the current buffer. +:LspShowSignature|Display the signature of the keyword under cursor. +:LspSubTypeHierarchy|Display the sub type hierarchy in a popup window. +:LspSuperTypeHierarchy|Display the super type hierarchy in a popup window. :LspSwitchSourceHeader|Switch between a source and a header file. -:LspSymbolSearch|Perform a workspace wide search for a symbol -:LspWorkspaceAddFolder `{folder}`| Add a folder to the workspace -:LspWorkspaceListFolders|Show the list of folders in the workspace -:LspWorkspaceRemoveFolder `{folder}`|Remove a folder from the workspace +:LspSymbolSearch|Perform a workspace wide search for a symbol. +:LspWorkspaceAddFolder `{folder}`| Add a folder to the workspace. +:LspWorkspaceListFolders|Show the list of folders in the workspace. +:LspWorkspaceRemoveFolder `{folder}`|Remove a folder from the workspace. ## Similar Vim LSP Plugins diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index 097ba56..c6fc4b2 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -79,17 +79,64 @@ export def ServerDebug(arg: string) enddef # Show information about all the LSP servers -export def ShowServers() +export def ShowAllServers() + var lines = [] + # Add filetype to server mapping information + lines->add('Filetype Information') + lines->add('====================') for [ftype, lspserver] in ftypeServerMap->items() - var msg = $'{ftype} ' - if lspserver.running - msg ..= 'running' - else - msg ..= 'not running' + lines->add($"Filetype: '{ftype}'") + lines->add($"Server Path: '{lspserver.path}'") + lines->add($"Status: {lspserver.running ? 'Running' : 'Not running'}") + lines->add('') + endfor + + # Add buffer to server mapping information + lines->add('Buffer Information') + lines->add('==================') + for bnr in range(1, bufnr('$')) + if buf.BufHasLspServer(bnr) + lines->add($"Buffer: '{bufname(bnr)}'") + var lspserver = buf.BufLspServerGet(bnr) + lines->add($"Server Path: '{lspserver.path}'") + lines->add($"Status: {lspserver.running ? 'Running' : 'Not running'}") + lines->add('') endif - msg ..= $' {lspserver.path}' - :echomsg msg endfor + + var wid = bufwinid('Language-Servers') + if wid != -1 + wid->win_gotoid() + :setlocal modifiable + :silent! :%d _ + else + :new Language-Servers + :setlocal buftype=nofile + :setlocal bufhidden=wipe + :setlocal noswapfile + :setlocal nonumber nornu + :setlocal fdc=0 signcolumn=no + endif + setline(1, lines) + :setlocal nomodified + :setlocal nomodifiable +enddef + +# Show the status of the LSP server for the current buffer +export def ShowServer() + var lspserver: dict = buf.CurbufGetServerChecked() + if lspserver->empty() + :echomsg "LSP Server not found" + return + endif + + var msg = $"LSP server '{lspserver.path}' is " + if lspserver.running + msg ..= 'running' + else + msg ..= 'not running' + endif + :echomsg msg enddef # Get LSP server running status for filetype 'ftype' diff --git a/autoload/lsp/options.vim b/autoload/lsp/options.vim index dea03a8..3d3440f 100644 --- a/autoload/lsp/options.vim +++ b/autoload/lsp/options.vim @@ -35,7 +35,7 @@ export var lspOptions: dict = { # Make diagnostics show in a popup instead of echoing showDiagInPopup: true, # Default diagnostic highlight on lines - diagLineHL: 'Cursor', + diagLineHL: 'DiffAdd', # Don't print message when a configured language server is missing. ignoreMissingServer: false, # Use a floating menu to show the code action menu instead of asking for input diff --git a/doc/lsp.txt b/doc/lsp.txt index 65baf36..bb41fd9 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -119,12 +119,15 @@ The following commands are provided: :LspServerDebug Enable or disable the language server debug messages. :LspServerRestart Restart the language server for the current buffer. :LspServerTrace Set the language server debug trace value. +:LspShowAllServers Display the status of all the registered language + servers. :LspShowReferences Display the list of references to the keyword under cursor in a new location list. :LspShowServerCapabilities Display the language server capabilities for the current buffer. -:LspShowServers Display the list of registered language servers +:LspShowServer Display the status of the language server for the + current buffer. :LspShowSignature Display the signature of the symbol under cursor. :LspSubTypeHierarchy Display the sub type hierarchy in a popup window. :LspSuperTypeHierarchy Display the super type hierarchy in a popup window. @@ -284,8 +287,9 @@ autoHighlightDiags |Boolean| option. Automatically place signs on the autoPopulateDiags |Boolean| option. Automatically populate the location list with diagnostics from the language server. By default this is set to false. -diagLineHL |String| option. Highlight used for diagnostic line. - By default uses "Cursor". Use "NONE" to disable. +diagLineHL |String| option. The highlight group used for a line + with one or more diagnostics. By default uses + "DiffAdd". Use "NONE" to disable. echoSignature |Boolean| option. In insert mode, echo the current symbol signature instead of showing it in a popup. By default this is set to false. @@ -617,6 +621,16 @@ can map these commands to keys and make it easier to invoke them. :LspServerTrace { off | messages | verbose } *:LspServerTrace* Set the language server debug trace value. + *:LspShowAllServers* +:LspShowAllServers Displays the list of registered language servers and + their status. The language servers are registered + using the LspAddServer() function. The output is + displayed in a scratch buffer. The output shows the + Vim file type, the corresponding language server + status and the path to the language server executable. + The language server information for each buffer is + also shown. + *:LspShowReferences* :LspShowReferences Creates a new location list with the list of locations where the symbol under the cursor is referenced and @@ -628,12 +642,10 @@ can map these commands to keys and make it easier to invoke them. described in the LSP protocol specification under the "ServerCapabilities" interface. - *:LspShowServers* -:LspShowServers Displays the list of registered language servers and - their status. The language servers are registered - using the LspAddServer() function. The output shows - the Vim file type, the corresponding language server - status and the path to the language server executable. + *:LspShowServer* +:LspShowServer Displays the language server status for the current + buffer. The output shows the path to the language + server executable and the server status. *:LspShowSignature* :LspShowSignature Displays the signature of the symbol (e.g. a function diff --git a/plugin/lsp.vim b/plugin/lsp.vim index 51e9f8b..18b04b4 100644 --- a/plugin/lsp.vim +++ b/plugin/lsp.vim @@ -111,7 +111,8 @@ command! -nargs=0 -bar LspServerRestart lsp.RestartServer() command! -nargs=1 -complete=customlist,LspServerTraceComplete -bar LspServerTrace lsp.ServerTraceSet() command! -nargs=0 -bar LspShowReferences lsp.ShowReferences(v:false) command! -nargs=0 -bar LspShowServerCapabilities lsp.ShowServerCapabilities() -command! -nargs=0 -bar LspShowServers lsp.ShowServers() +command! -nargs=0 -bar LspShowServer lsp.ShowServer() +command! -nargs=0 -bar LspShowAllServers lsp.ShowAllServers() command! -nargs=0 -bar LspShowSignature call LspShowSignature() # Clangd specifc extension to switch from one C/C++ source file to a # corresponding header file -- 2.48.1