autoload/lsp/capabilities.vim | 106 ++++++++++++++++++++++++++++++++++++++++++----------- autoload/lsp/inlayhints.vim | 6 +++--- autoload/lsp/lsp.vim | 24 +++++++++++++----------- autoload/lsp/lspserver.vim | 8 +++++++- autoload/lsp/options.vim | 14 ++++++++------ autoload/lsp/signature.vim | 3 +-- doc/lsp.txt | 7 +++++-- plugin/lsp.vim | 2 +- diff --git a/autoload/lsp/capabilities.vim b/autoload/lsp/capabilities.vim index f29f250f64f0c95d9c6af207d5fa70c61526335f..9186a9b0a3616e0e2debe08f777d008d7b24b47b 100644 --- a/autoload/lsp/capabilities.vim +++ b/autoload/lsp/capabilities.vim @@ -294,10 +294,12 @@ # Return all the LSP client capabilities export def GetClientCaps(): dict # client capabilities (ClientCapabilities) var clientCaps: dict = { - workspace: { - workspaceFolders: true, - applyEdit: true, - configuration: true + general: { + # Currently we always send character count as position offset, + # which meanas only utf-32 is supported. + # Adding utf-16 simply for good mesure, as I'm scared some servers will + # give up if they don't support utf-32 only. + positionEncodings: ['utf-32', 'utf-16'] }, textDocument: { callHierarchy: { @@ -322,43 +324,105 @@ completion: { dynamicRegistration: false, completionItem: { documentationFormat: ['markdown', 'plaintext'], - resolveSupport: {properties: ['detail', 'documentation']}, + resolveSupport: { + properties: ['detail', 'documentation'] + }, snippetSupport: opt.lspOptions.snippetSupport, insertReplaceSupport: false }, - completionItemKind: {valueSet: range(1, 25)} + completionItemKind: { + valueSet: range(1, 25) + } + }, + declaration: { + dynamicRegistration: false, + linkSupport: true + }, + definition: { + dynamicRegistration: false, + linkSupport: true + }, + documentHighlight: { + dynamicRegistration: false }, documentSymbol: { dynamicRegistration: false, + symbolKind: { + valueSet: range(1, 25) + }, hierarchicalDocumentSymbolSupport: true, - symbolKind: {valueSet: range(1, 25)} + labelSupport: false + }, + foldingRange: { + dynamicRegistration: false, + rangeLimit: 5000, + lineFoldingOnly: true, + foldingRangeKind: { + valueSet: ['comment', 'imports', 'region'] + }, + foldingRange: { + collapsedText: true + } + }, + formatting: { + dynamicRegistration: false }, hover: { + dynamicRegistration: false, contentFormat: ['markdown', 'plaintext'] }, - foldingRange: {lineFoldingOnly: true}, - inlayHint: {dynamicRegistration: false}, - synchronization: { - didSave: true + implementation: { + dynamicRegistration: false, + linkSupport: true }, - declaration: {linkSupport: true}, - definition: {linkSupport: true}, - typeDefinition: {linkSupport: true}, - implementation: {linkSupport: true}, + inlayHint: { + dynamicRegistration: false + }, + publishDiagnostics: { + relatedInformation: false, + versionSupport: true, + codeDescriptionSupport: true, + dataSupport: true + }, + rangeFormatting: { + dynamicRegistration: false + }, + references: { + dynamicRegistration: false + }, + rename: { + dynamicRegistration: false, + prepareSupport: false, + }, signatureHelp: { + dynamicRegistration: false, signatureInformation: { documentationFormat: ['markdown', 'plaintext'], activeParameterSupport: true } + }, + synchronization: { + dynamicRegistration: false, + didSave: true, + willSave: false, + WillSaveWaitUntil: false + }, + typeDefinition: { + dynamicRegistration: false, + linkSupport: true + }, + typeHierarchy: { + dynamicRegistration: false, } }, window: {}, - general: { - # Currently we always send character count as position offset, - # which meanas only utf-32 is supported. - # Adding utf-16 simply for good mesure, as I'm scared some servers will - # give up if they don't support utf-32 only. - positionEncodings: ['utf-32', 'utf-16'] + workspace: { + workspaceFolders: true, + applyEdit: true, + configuration: true, + symbol: { + dynamicRegistration: false + } }, # This is the way clangd expects to be informated about supported encodings: # https://clangd.llvm.org/extensions#utf-8-offsets diff --git a/autoload/lsp/inlayhints.vim b/autoload/lsp/inlayhints.vim index 1bbd331dec38e9b1aa1bcc1a26b6e88441d8d4c5..34daee877e00cb7ed41305b282644b8d739d0002 100644 --- a/autoload/lsp/inlayhints.vim +++ b/autoload/lsp/inlayhints.vim @@ -76,11 +76,11 @@ enddef # Update all the inlay hints. A timer is used to throttle the updates. def LspInlayHintsUpdate(bnr: number) - if !getbufvar(bnr, 'LspInlayHintsNeedsUpdate', true) + if !bnr->getbufvar('LspInlayHintsNeedsUpdate', true) return endif - var timerid = getbufvar(bnr, 'LspInlayHintsTimer', -1) + var timerid = bnr->getbufvar('LspInlayHintsTimer', -1) if timerid != -1 timerid->timer_stop() setbufvar(bnr, 'LspInlayHintsTimer', -1) @@ -113,7 +113,7 @@ enddef # Stop updating the inlay hints. def LspInlayHintsUpdateStop(bnr: number) - var timerid = getbufvar(bnr, 'LspInlayHintsTimer', -1) + var timerid = bnr->getbufvar('LspInlayHintsTimer', -1) if timerid != -1 timerid->timer_stop() setbufvar(bnr, 'LspInlayHintsTimer', -1) diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index b2e6baf40176a6d96e38f7f1708bb6f95e2b6921..930c115efaeeebfd4967b8cc0898c3d9e3d4c6d2 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -337,8 +337,7 @@ return '' enddef # A buffer is saved. Send the "textDocument/didSave" LSP notification -def LspSavedFile() - var bnr: number = expand('')->str2nr() +def LspSavedFile(bnr: number) var lspservers: list> = buf.BufLspServersGet(bnr)->filter( (key, lspsrv) => !lspsrv->empty() && lspsrv.running ) @@ -371,7 +370,7 @@ # file saved notification handler acmds->add({bufnr: bnr, event: 'BufWritePost', group: 'LSPBufferAutocmds', - cmd: 'LspSavedFile()'}) + cmd: $'LspSavedFile({bnr})'}) # Update the diagnostics when insert mode is stopped acmds->add({bufnr: bnr, @@ -385,7 +384,7 @@ lspserver.isDocumentHighlightProvider acmds->add({bufnr: bnr, event: 'CursorMoved', group: 'LSPBufferAutocmds', - cmd: 'call LspDocHighlightClear() | call LspDocHighlight("silent")'}) + cmd: $'call LspDocHighlightClear({bnr}) | call LspDocHighlight({bnr}, "silent")'}) endif # Show diagnostics on the status line @@ -399,6 +398,8 @@ autocmd_add(acmds) enddef +# The LSP server with ID "lspserverId" is ready, initialize the LSP features +# for buffer "bnr". def BufferInit(lspserverId: number, bnr: number): void var lspserver = buf.BufLspServerGetById(bnr, lspserverId) if lspserver->empty() || !lspserver.running @@ -815,28 +816,29 @@ lspserver.showReferences(peek) enddef # highlight all the places where a symbol is referenced -def g:LspDocHighlight(cmdmods: string = '') +def g:LspDocHighlight(bnr: number = bufnr(), cmdmods: string = '') var lspserver: dict = buf.CurbufGetServerChecked('documentHighlight') if lspserver->empty() return endif - lspserver.docHighlight(cmdmods) + lspserver.docHighlight(bnr, cmdmods) enddef # clear the symbol reference highlight -def g:LspDocHighlightClear() +def g:LspDocHighlightClear(bnr: number = bufnr()) var lspserver: dict = buf.CurbufGetServerChecked('documentHighlight') if lspserver->empty() return endif + var propNames = ['LspTextRef', 'LspReadRef', 'LspWriteRef'] if has('patch-9.0.0233') - prop_remove({types: ['LspTextRef', 'LspReadRef', 'LspWriteRef'], all: true}) + prop_remove({types: propNames, bufnr: bnr, all: true}) else - prop_remove({type: 'LspTextRef', all: true}) - prop_remove({type: 'LspReadRef', all: true}) - prop_remove({type: 'LspWriteRef', all: true}) + for propName in propNames + prop_remove({type: propName, bufnr: bnr, all: true}) + endfor endif enddef diff --git a/autoload/lsp/lspserver.vim b/autoload/lsp/lspserver.vim index 4ae40198bd0045fb3dd480c22ad85f342bde307f..66e1124cb72edbb0c5af6754397dd6e3528b6e57 100644 --- a/autoload/lsp/lspserver.vim +++ b/autoload/lsp/lspserver.vim @@ -995,12 +995,15 @@ enddef # Request: "textDocument/documentHighlight" # Param: DocumentHighlightParams -def DocHighlight(lspserver: dict, cmdmods: string): void +def DocHighlight(lspserver: dict, bnr: number, cmdmods: string): void # Check whether LSP server supports getting highlight information if !lspserver.isDocumentHighlightProvider util.ErrMsg('LSP server does not support document highlight') return endif + + # Send the pending buffer changes to the language server + bnr->listener_flush() # interface DocumentHighlightParams # interface TextDocumentPositionParams @@ -1205,6 +1208,9 @@ if !lspserver.isInlayHintProvider && !lspserver.isClangdInlayHintsProvider util.ErrMsg('LSP server does not support inlay hint') return endif + + # Send the pending buffer changes to the language server + bnr->listener_flush() var binfo = bnr->getbufinfo() if binfo->empty() diff --git a/autoload/lsp/options.vim b/autoload/lsp/options.vim index 26a478557fc432ad985b5fa9ebcba67d71ede430..d6822286d16256b3cc0d66dd743d9c25172a0b4f 100644 --- a/autoload/lsp/options.vim +++ b/autoload/lsp/options.vim @@ -78,15 +78,17 @@ # enable snippet completion support snippetSupport: false, # enable SirVer/ultisnips completion support ultisnipsSupport: false, - # enable hrsh7th/vim-vsnip completion support - vsnipSupport: false, - # Use a floating menu to show the code action menu instead of asking for input + # add to autocomplition list current buffer words + useBufferCompletion: false, + # Use a floating menu to show the code action menu instead of asking for + # input usePopupInCodeAction: false, # ShowReferences in a quickfix list instead of a location list` useQuickfixForLocations: false, - # add to autocomplition list current buffer words - useBufferCompletion: false, - # Limit the time autocompletion searches for words in current buffer (in milliseconds) + # enable hrsh7th/vim-vsnip completion support + vsnipSupport: false, + # Limit the time autocompletion searches for words in current buffer (in + # milliseconds) bufferCompletionTimeout: 100, # Enable support for custom completion kinds customCompletionKinds: false, diff --git a/autoload/lsp/signature.vim b/autoload/lsp/signature.vim index 55bb795fceab33049ac8c5355fbf301453662754..66a325db7f400095c0800bc97822e5b20e150441 100644 --- a/autoload/lsp/signature.vim +++ b/autoload/lsp/signature.vim @@ -34,7 +34,7 @@ return endif if !opt.lspOptions.showSignature - # Show signature are disabled + # Show signature support is disabled return endif @@ -59,7 +59,6 @@ return endif if sighelp.signatures->len() <= 0 - util.WarnMsg('No signature help available') CloseSignaturePopup(lspserver) return endif diff --git a/doc/lsp.txt b/doc/lsp.txt index d63ddea6b78c7abce5764c925aea2b76934932c0..7d46ad1b7805bf2fd14e590580969172387dd836 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -861,11 +861,14 @@ *:LspHover* :LspHover Show the documentation for the symbol under the cursor in a popup window. If you want to show the symbol - documentation in the preview window instead of in a - popup set > + documentation in the |preview-window| instead of in a + popup window set > LspOptionsSet({'hoverInPreview': true}) < + You can use the |:pclose| command to close the preview + window. + You can use the |K| key in normal mode to display the documentation for the keyword under the cursor by setting the 'keywordprg' Vim option: > diff --git a/plugin/lsp.vim b/plugin/lsp.vim index 36b7ef4a927b71293b02fee4f71158c9ebe87721..49d667710609d60ddb853e0610e007852c28812b 100644 --- a/plugin/lsp.vim +++ b/plugin/lsp.vim @@ -74,7 +74,7 @@ command! -nargs=0 -bar -count LspGotoDeclaration lsp.GotoDeclaration(v:false, , ) command! -nargs=0 -bar -count LspGotoDefinition lsp.GotoDefinition(v:false, , ) command! -nargs=0 -bar -count LspGotoImpl lsp.GotoImplementation(v:false, , ) command! -nargs=0 -bar -count LspGotoTypeDef lsp.GotoTypedef(v:false, , ) -command! -nargs=0 -bar LspHighlight call LspDocHighlight() +command! -nargs=0 -bar LspHighlight call LspDocHighlight(bufnr(), ) command! -nargs=0 -bar LspHighlightClear call LspDocHighlightClear() command! -nargs=? -bar LspHover lsp.Hover() command! -nargs=1 -bar -complete=customlist,lsp.LspInlayHintsComplete LspInlayHints lsp.InlayHints()