]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Wait for the LSP server to become ready before running the tests
authorYegappan Lakshmanan <yegappan@yahoo.com>
Mon, 17 Jan 2022 16:33:42 +0000 (08:33 -0800)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Mon, 17 Jan 2022 16:33:42 +0000 (08:33 -0800)
autoload/handlers.vim
autoload/lsp.vim
autoload/lspserver.vim
test/unit_tests.vim

index 67b78651a1aca05680688f92640cb8d5a85fc8a9..c17de720915ffa4a1133ab4841ce947f987b24c8 100644 (file)
@@ -99,6 +99,7 @@ def s:processInitializeReply(lspserver: dict<any>, req: dict<any>, reply: dict<a
 
   # send a "initialized" notification to server
   lspserver.sendInitializedNotif()
+  lspserver.ready = true
 
   # if the outline window is opened, then request the symbols for the current
   # buffer
index c3a2e86bd0c65120b3fa38065494e74fc64d4ffa..a8308b0e9dfa12ee64e70b57d6c9e04d87f10691 100644 (file)
@@ -488,6 +488,21 @@ def lsp#addServer(serverList: list<dict<any>>)
   endfor
 enddef
 
+# The LSP server is considered ready when the server capabilities are
+# received ('initialize' LSP reply message)
+def lsp#serverReady(): bool
+  var ftype = &filetype
+  if ftype == '' || @% == ''
+    return false
+  endif
+
+  var lspserver: dict<any> = s:lspGetServer(ftype)
+  if lspserver->empty()
+    return false
+  endif
+  return lspserver.ready
+enddef
+
 # set the LSP server trace level for the current buffer
 # Params: SetTraceParams
 def lsp#setTraceServer(traceVal: string)
index 59cb5bcc9fac391a2b5b75cd2a06562d1245f491..d3b2bd529b4b4f895cb4df6539a3c079900a9d1f 100644 (file)
@@ -65,6 +65,7 @@ def s:exit_cb(lspserver: dict<any>, job: job, status: number): void
   util.WarnMsg("LSP server exited with status " .. status)
   lspserver.job = v:none
   lspserver.running = false
+  lspserver.ready = false
   lspserver.requests = {}
 enddef
 
@@ -202,6 +203,7 @@ def s:stopServer(lspserver: dict<any>): number
   lspserver.job->job_stop()
   lspserver.job = v:none
   lspserver.running = false
+  lspserver.ready = false
   lspserver.requests = {}
   return 0
 enddef
@@ -843,6 +845,7 @@ export def NewLspServer(path: string, args: list<string>): dict<any>
     path: path,
     args: args,
     running: false,
+    ready: false,
     job: v:none,
     data: '',
     nextID: 1,
index 15d23244f3448b67c5e3d2d8fdaf7005086da7e0..a8076f705335a4b0b4ea898ab99f9f4d9840e1ef 100644 (file)
@@ -10,7 +10,7 @@ set rtp+=../
 source ../plugin/lsp.vim
 var lspServers = [{
       filetype: ['c', 'cpp'],
-      path: '/usr/bin/clangd-12',
+      path: '/usr/bin/clangd',
       args: ['--background-index', '--clang-tidy']
   }]
 lsp#addServer(lspServers)
@@ -396,7 +396,12 @@ def LspRunTests()
 
   # Edit a dummy C file to start the LSP server
   :edit Xtest.c
-  :sleep 2
+  # Wait for the LSP server to become ready (max 10 seconds)
+  var maxcount = 100
+  while maxcount > 0 && !lsp#serverReady()
+    :sleep 100m
+    maxcount -= 1
+  endwhile
   :%bw!
 
   # Get the list of test functions in this file and call them