]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Initialize completion when all server capabilities are known
authorAndreas Louv <andreas@louv.dk>
Fri, 14 Apr 2023 14:58:06 +0000 (16:58 +0200)
committerAndreas Louv <andreas@louv.dk>
Fri, 14 Apr 2023 15:25:37 +0000 (17:25 +0200)
It's only possible to initialize completion when all server capabilities
are known, as this is the time it's known which server will end up being
used for completion.

autoload/lsp/lsp.vim

index f69ac7e736d93620e3521466bc2a63c8aead5f58..303e30ce51074be9e7f209413150404ac2fea6dc 100644 (file)
@@ -432,20 +432,29 @@ def BufferInit(lspserverId: number, bnr: number): void
 
   setbufvar(bnr, '&balloonexpr', 'g:LspDiagExpr()')
 
-  completion.BufferInit(lspserver, bnr, ftype)
   signature.BufferInit(lspserver)
   inlayhints.BufferInit(lspserver, bnr)
 
-  if exists('#User#LspAttached')
-    var allServersReady = true
-    var lspservers: list<dict<any>> = buf.BufLspServersGet(bnr)
+  var allServersReady = true
+  var lspservers: list<dict<any>> = buf.BufLspServersGet(bnr)
+  for lspsrv in lspservers
+    if !lspsrv.ready
+      allServersReady = false
+      break
+    endif
+  endfor
+
+  if allServersReady
     for lspsrv in lspservers
-      if !lspsrv.ready
-        allServersReady = false
+      # It's only possible to initialize completion when all server capabilities
+      # are known.
+      var completionServer = buf.BufLspServerGet(bnr, 'completion')
+      if !completionServer->empty() && lspsrv.id == completionServer.id
+        completion.BufferInit(lspsrv, bnr, ftype)
       endif
     endfor
 
-    if allServersReady
+    if exists('#User#LspAttached')
       doautocmd <nomodeline> User LspAttached
     endif
   endif