Command|Description
-------|-----------
:LspCodeAction|Apply the code action supplied by the language server to the diagnostic in the current line.
+:LspCodeLens|Display a list of code lens commands and apply a selected code lens command to the current file.
: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.
lspserver.isCodeActionProvider = false
endif
+ # codeLensProvider
+ if lspserver.caps->has_key('codeLensProvider')
+ lspserver.isCodeLensProvider = true
+ if lspserver.caps.codeLensProvider->has_key('resolveProvider')
+ lspserver.isCodeLensResolveProvider = true
+ else
+ lspserver.isCodeLensResolveProvider = false
+ endif
+ else
+ lspserver.isCodeLensProvider = false
+ endif
+
# workspaceSymbolProvider
if lspserver.caps->has_key('workspaceSymbolProvider')
if lspserver.caps.workspaceSymbolProvider->type() == v:t_bool
CommandHandlers[cmd] = Handler
enddef
-def DoCommand(lspserver: dict<any>, cmd: dict<any>)
+export def DoCommand(lspserver: dict<any>, cmd: dict<any>)
if cmd->has_key('command') && CommandHandlers->has_key(cmd.command)
var CmdHandler: func = CommandHandlers[cmd.command]
- call CmdHandler(cmd)
+ try
+ call CmdHandler(cmd)
+ catch
+ util.ErrMsg($'Error: "{cmd.command}" handler raised exception {v:exception}')
+ endtry
else
lspserver.executeCommand(cmd)
endif
--- /dev/null
+vim9script
+
+import './codeaction.vim'
+
+# Functions related to handling LSP code lens
+
+export def ProcessCodeLens(lspserver: dict<any>, codeLensItems: list<dict<any>>)
+ var text: list<string> = []
+ for i in codeLensItems->len()->range()
+ var item = codeLensItems[i]
+ if !item->has_key('command')
+ # resolve the code lens
+ item = lspserver.resolveCodeLens(item)
+ if item->empty()
+ continue
+ endif
+ codeLensItems[i] = item
+ endif
+ text->add(printf("%d. %s\t| L%s:%s", i + 1, item.command.title,
+ item.range.start.line + 1,
+ getline(item.range.start.line + 1)))
+ endfor
+
+ var choice = inputlist(['Code Lens:'] + text)
+ if choice < 1 || choice > codeLensItems->len()
+ return
+ endif
+
+ codeaction.DoCommand(lspserver, codeLensItems[choice - 1].command)
+enddef
+
+# vim: tabstop=8 shiftwidth=2 softtabstop=2
lspserver.codeAction(fname, line1, line2, query)
enddef
+# Code lens
+# Uses LSP "textDocument/codeLens" request
+export def CodeLens()
+ var lspserver: dict<any> = buf.CurbufGetServerChecked()
+ if lspserver->empty()
+ return
+ endif
+
+ lspserver.codeLens(@%)
+enddef
+
# Perform a workspace wide symbol lookup
# Uses LSP "workspace/symbol" request
export def SymbolSearch(queryArg: string)
import './hover.vim'
import './signature.vim'
import './codeaction.vim'
+import './codelens.vim'
import './callhierarchy.vim' as callhier
import './typehierarchy.vim' as typehier
import './inlayhints.vim'
codeaction.ApplyCodeAction(lspserver, reply.result, query)
enddef
+# Request: "textDocument/codeLens"
+# Param: CodeLensParams
+def CodeLens(lspserver: dict<any>, fname: string)
+ # Check whether LSP server supports code lens operation
+ if !lspserver.isCodeLensProvider
+ util.ErrMsg('Error: LSP server does not support code lens operation')
+ return
+ endif
+
+ var params = {textDocument: {uri: util.LspFileToUri(fname)}}
+ var reply = lspserver.rpc('textDocument/codeLens', params)
+ if reply->empty() || reply.result->empty()
+ util.WarnMsg($'Error: No code lens actions found for the current file')
+ return
+ endif
+
+ codelens.ProcessCodeLens(lspserver, reply.result)
+enddef
+
+# Request: "codeLens/resolve"
+# Param: CodeLens
+def ResolveCodeLens(lspserver: dict<any>, codeLens: dict<any>): dict<any>
+ if !lspserver.isCodeLensResolveProvider
+ return {}
+ endif
+ var reply = lspserver.rpc('codeLens/resolve', codeLens)
+ if reply->empty()
+ return {}
+ endif
+ return reply.result
+enddef
+
# List project-wide symbols matching query string
# Request: "workspace/symbol"
# Param: WorkspaceSymbolParams
typeHierarchy: function(TypeHiearchy, [lspserver]),
renameSymbol: function(RenameSymbol, [lspserver]),
codeAction: function(CodeAction, [lspserver]),
+ codeLens: function(CodeLens, [lspserver]),
+ resolveCodeLens: function(ResolveCodeLens, [lspserver]),
workspaceQuery: function(WorkspaceQuerySymbols, [lspserver]),
addWorkspaceFolder: function(AddWorkspaceFolder, [lspserver]),
removeWorkspaceFolder: function(RemoveWorkspaceFolder, [lspserver]),
:LspCodeAction Apply the code action supplied by the language server
to the diagnostic in the current line.
+:LspCodeLens Display all the code lens commands available for the
+ current file and apply the selected command.
:LspDiagCurrent Display the diagnostic message for the current line.
:LspDiagFirst Jump to the first diagnostic message for the current
buffer.
When [query] is not given you will be prompted to select
one of the actions supplied by the language server.
+ *:LspCodeLens*
+:LspCodeLens Display a list of code lens commands available for the
+ current buffer and apply the selected code lens
+ command.
+
*:LspDiagCurrent*
:LspDiagCurrent Displays the diagnostic message (if any) for the
current line. If the option 'showDiagInPopup' is set
# LSP commands
command! -nargs=? -bar -range LspCodeAction lsp.CodeAction(<line1>, <line2>, <q-args>)
+command! -nargs=0 -bar LspCodeLens lsp.CodeLens()
command! -nargs=0 -bar -bang LspDiagCurrent lsp.LspShowCurrentDiag(<bang>false)
command! -nargs=0 -bar LspDiagFirst lsp.JumpToDiag('first')
command! -nargs=0 -bar LspDiagHighlightDisable lsp.DiagHighlightDisable()
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
command! -nargs=0 -bar LspSubTypeHierarchy lsp.TypeHierarchy(0)
command! -nargs=0 -bar LspSuperTypeHierarchy lsp.TypeHierarchy(1)
+# Clangd specifc extension to switch from one C/C++ source file to a
+# corresponding header file
command! -nargs=0 -bar LspSwitchSourceHeader lsp.SwitchSourceHeader()
command! -nargs=? -bar LspSymbolSearch lsp.SymbolSearch(<q-args>)
command! -nargs=1 -bar -complete=dir LspWorkspaceAddFolder lsp.AddWorkspaceFolder(<q-args>)