]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
When jumping to the location of a symbol, wait for the response from LSP server
authorYegappan Lakshmanan <yegappan@yahoo.com>
Mon, 17 Jan 2022 20:19:02 +0000 (12:19 -0800)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Mon, 17 Jan 2022 20:19:02 +0000 (12:19 -0800)
autoload/lspserver.vim
test/unit_tests.vim

index d3b2bd529b4b4f895cb4df6539a3c079900a9d1f..c739389ebe7e514408ee83942afa740e12dc3925 100644 (file)
@@ -279,6 +279,18 @@ def s:sendMessage(lspserver: dict<any>, content: dict<any>): void
   ch->ch_sendraw(payload_js)
 enddef
 
+# Wait for a response message from the LSP server for the request "req"
+# Waits for a maximum of 5 seconds
+def s:waitForReponse(lspserver: dict<any>, req: dict<any>)
+  var maxCount: number = 500
+  var key: string = req.id->string()
+
+  while lspserver.requests->has_key(key) && maxCount > 0
+    sleep 10m
+    maxCount -= 1
+  endwhile
+enddef
+
 # Send a LSP "textDocument/didOpen" notification
 # Params: DidOpenTextDocumentParams
 def s:textdocDidOpen(lspserver: dict<any>, bnr: number, ftype: string): void
@@ -415,7 +427,7 @@ enddef
 
 # Request: "textDocument/definition"
 # Param: DefinitionParams
-def s:gotoDefinition(lspserver: dict<any>, peek: bool): void
+def s:gotoDefinition(lspserver: dict<any>, peek: bool)
   # Check whether LSP server supports jumping to a definition
   if !lspserver.caps->has_key('definitionProvider')
                                || !lspserver.caps.definitionProvider
@@ -432,6 +444,8 @@ def s:gotoDefinition(lspserver: dict<any>, peek: bool): void
   #   interface TextDocumentPositionParams
   req.params->extend(s:getLspTextDocPosition())
   lspserver.sendMessage(req)
+
+  s:waitForReponse(lspserver, req)
 enddef
 
 # Request: "textDocument/declaration"
@@ -455,6 +469,8 @@ def s:gotoDeclaration(lspserver: dict<any>, peek: bool): void
   req.params->extend(s:getLspTextDocPosition())
 
   lspserver.sendMessage(req)
+
+  s:waitForReponse(lspserver, req)
 enddef
 
 # Request: "textDocument/typeDefinition"
@@ -478,6 +494,8 @@ def s:gotoTypeDef(lspserver: dict<any>, peek: bool): void
   req.params->extend(s:getLspTextDocPosition())
 
   lspserver.sendMessage(req)
+
+  s:waitForReponse(lspserver, req)
 enddef
 
 # Request: "textDocument/implementation"
@@ -501,6 +519,8 @@ def s:gotoImplementation(lspserver: dict<any>, peek: bool): void
   req.params->extend(s:getLspTextDocPosition())
 
   lspserver.sendMessage(req)
+
+  s:waitForReponse(lspserver, req)
 enddef
 
 # get symbol signature help.
index 8703ae3adf5c00dcd64b07e4411e91c2e2aae1f3..e6527f726cc9f34b489a6ec3888da0340dea5e99 100644 (file)
@@ -423,17 +423,14 @@ def Test_lsp_goto_definition()
   :sleep 1
   cursor(24, 6)
   :LspGotoDeclaration
-  :sleep 1
   assert_equal([6, 19], [line('.'), col('.')])
   exe "normal! \<C-t>"
   assert_equal([24, 6], [line('.'), col('.')])
   :LspGotoDefinition
-  :sleep 1
   assert_equal([9, 12], [line('.'), col('.')])
   exe "normal! \<C-t>"
   assert_equal([24, 6], [line('.'), col('.')])
   :LspGotoImpl
-  :sleep 1
   assert_equal([15, 11], [line('.'), col('.')])
   exe "normal! \<C-t>"
   assert_equal([24, 6], [line('.'), col('.')])