autoload/lsp/callhierarchy.vim | 2 +- autoload/lsp/diag.vim | 4 ++-- autoload/lsp/inlayhints.vim | 7 ++++--- autoload/lsp/lsp.vim | 29 ++++++++++++----------------- autoload/lsp/options.vim | 4 ++-- autoload/lsp/signature.vim | 16 +++++++++++++++- diff --git a/autoload/lsp/callhierarchy.vim b/autoload/lsp/callhierarchy.vim index aa2ed404de020ea604bcfaa50bc1f9872d92d753..aca6a55310a8bcf5e9e0b739233cf2488c8027bb 100644 --- a/autoload/lsp/callhierarchy.vim +++ b/autoload/lsp/callhierarchy.vim @@ -23,7 +23,7 @@ endif if !treeItem->has_key('children') # First time retrieving the children for the item at index "idx" - var lspserver = buf.BufLspServerGet(w:LspBufnr) + var lspserver = buf.BufLspServerGet(w:LspBufnr, 'callHierarchy') if lspserver->empty() || !lspserver.running return endif diff --git a/autoload/lsp/diag.vim b/autoload/lsp/diag.vim index 880e08c8f4a49fa33a29e1e308a6b6f667fbc2c2..6e24a12cc4a48411868a728763b428516971020f 100644 --- a/autoload/lsp/diag.vim +++ b/autoload/lsp/diag.vim @@ -100,9 +100,9 @@ {highlight: 'LspDiagVirtualTextInfo', override: true}) prop_type_add('LspDiagVirtualTextHint', {highlight: 'LspDiagVirtualTextHint', override: true}) - autocmd_add([{group: 'LspOptionsChanged', + autocmd_add([{group: 'LspCmds', event: 'User', - pattern: '*', + pattern: 'LspOptionsChanged', cmd: 'LspDiagsOptionsChanged()'}]) # ALE plugin support diff --git a/autoload/lsp/inlayhints.vim b/autoload/lsp/inlayhints.vim index 45848c3b39290ece34b365a68d667d4853b133cc..726470a30947576edfe1e61406c8f47a5582fad3 100644 --- a/autoload/lsp/inlayhints.vim +++ b/autoload/lsp/inlayhints.vim @@ -16,9 +16,9 @@ ]) prop_type_add('LspInlayHintsType', {highlight: 'LspInlayHintsType'}) prop_type_add('LspInlayHintsParam', {highlight: 'LspInlayHintsParam'}) - autocmd_add([{group: 'LspOptionsChanged', + autocmd_add([{group: 'LspCmds', event: 'User', - pattern: '*', + pattern: 'LspOptionsChanged', cmd: 'LspInlayHintsOptionsChanged()'}]) enddef @@ -175,7 +175,8 @@ if lspservers->empty() continue endif for lspserver in lspservers - if !lspserver.featureEnabled('inlayHint') + if !lspserver.ready + || !lspserver.featureEnabled('inlayHint') || (!lspserver.isInlayHintProvider && !lspserver.isClangdInlayHintsProvider) continue diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index 77544ff1fabd588a7a9c0cccd0665a5142947104..8c4dbe039dae2f254ef1e2e19c4f8a968474b99c 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -322,20 +322,6 @@ lspserver.switchSourceHeader() enddef -# Show the signature using "textDocument/signatureHelp" LSP method -# Invoked from an insert-mode mapping, so return an empty string. -def g:LspShowSignature(): string - var lspserver: dict = buf.CurbufGetServerChecked('signatureHelp') - if lspserver->empty() - return '' - endif - - # first send all the changes in the current buffer to the LSP server - listener_flush() - lspserver.showSignature() - return '' -enddef - # A buffer is saved. Send the "textDocument/didSave" LSP notification def LspSavedFile(bnr: number) var lspservers: list> = buf.BufLspServersGet(bnr)->filter( @@ -409,8 +395,6 @@ AddBufLocalAutocmds(lspserver, bnr) diag.BufferInit(lspserver, bnr) - signature.BufferInit(lspserver) - inlayhints.BufferInit(lspserver, bnr) var allServersReady = true var lspservers: list> = buf.BufLspServersGet(bnr) @@ -423,11 +407,22 @@ endfor if allServersReady for lspsrv in lspservers - # It's only possible to initialize completion when all server capabilities + # It's only possible to initialize the features when the server + # capabilities of all the registered language servers for this file type # are known. var completionServer = buf.BufLspServerGet(bnr, 'completion') if !completionServer->empty() && lspsrv.id == completionServer.id completion.BufferInit(lspsrv, bnr, ftype) + endif + + var signatureServer = buf.BufLspServerGet(bnr, 'signatureHelp') + if !signatureServer->empty() && lspsrv.id == signatureServer.id + signature.BufferInit(lspsrv) + endif + + var inlayHintServer = buf.BufLspServerGet(bnr, 'inlayHint') + if !inlayHintServer->empty() && lspsrv.id == inlayHintServer.id + inlayhints.BufferInit(lspsrv, bnr) endif endfor diff --git a/autoload/lsp/options.vim b/autoload/lsp/options.vim index eae209308f387a14fbe5df58cc6d250c2b7fca24..e79196726df490cfaae6343439f581dab170478f 100644 --- a/autoload/lsp/options.vim +++ b/autoload/lsp/options.vim @@ -156,8 +156,8 @@ lspOptions.completionMatcherValue = COMPLETIONMATCHER_CASE endif # Apply the changed options - if exists('#LspOptionsChanged#User') - :doautocmd LspOptionsChanged User + if exists('LspCmds##User#LspOptionsChanged') + :doautocmd LspCmds User LspOptionsChanged endif enddef diff --git a/autoload/lsp/signature.vim b/autoload/lsp/signature.vim index 4764c784e4a395014ee92e78ac0f17545f19855d..0b229b9a0d62f79bfd81cc04d4580b3f45ed9b85 100644 --- a/autoload/lsp/signature.vim +++ b/autoload/lsp/signature.vim @@ -23,6 +23,20 @@ CloseSignaturePopup(lspserver) enddef +# Show the signature using "textDocument/signatureHelp" LSP method +# Invoked from an insert-mode mapping, so return an empty string. +def g:LspShowSignature(): string + var lspserver: dict = buf.CurbufGetServerChecked('signatureHelp') + if lspserver->empty() + return '' + endif + + # first send all the changes in the current buffer to the LSP server + listener_flush() + lspserver.showSignature() + return '' +enddef + export def InitOnce() hlset([{name: 'LspSigActiveParameter', default: true, linksto: 'LineNr'}]) enddef @@ -43,7 +57,7 @@ endif # map characters that trigger signature help for ch in lspserver.caps.signatureHelpProvider.triggerCharacters - exe $"inoremap {ch} {ch}=LspShowSignature()" + exe $"inoremap {ch} {ch}=g:LspShowSignature()" endfor # close the signature popup when leaving insert mode