]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Use sync RPC call for showing references
authorYegappan Lakshmanan <yegappan@yahoo.com>
Wed, 12 Oct 2022 02:11:48 +0000 (19:11 -0700)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Wed, 12 Oct 2022 02:11:48 +0000 (19:11 -0700)
autoload/lsp/handlers.vim
autoload/lsp/lspserver.vim
autoload/lsp/symbol.vim

index 27fe1dedd316bb0da67e7068f9283f15a56d4dd1..b2f0750eb3ace382c093c338032c0c523fba60f0 100644 (file)
@@ -257,18 +257,6 @@ def ProcessHoverReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>): v
   endif
 enddef
 
-# process the 'textDocument/references' reply from the LSP server
-# Result: Location[] | null
-def ProcessReferencesReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>): void
-  if reply.result->empty()
-    util.WarnMsg('Error: No references found')
-    lspserver.peekSymbol = false
-    return
-  endif
-
-  symbol.ShowReferences(lspserver, reply.result)
-enddef
-
 # process the 'textDocument/documentHighlight' reply from the LSP server
 # Result: DocumentHighlight[] | null
 def ProcessDocHighlightReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>): void
@@ -577,7 +565,6 @@ export def ProcessReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>):
       'textDocument/signatureHelp': ProcessSignaturehelpReply,
       'textDocument/completion': ProcessCompletionReply,
       'textDocument/hover': ProcessHoverReply,
-      'textDocument/references': ProcessReferencesReply,
       'textDocument/documentHighlight': ProcessDocHighlightReply,
       'textDocument/documentSymbol': ProcessDocSymbolReply,
       'textDocument/codeAction': ProcessCodeActionReply,
index 2ee3c10c4db2edf8300a07943bb028b7eed45310..8d9dc8e61f8b4ba3256768f018a683829ff8f9f0 100644 (file)
@@ -645,18 +645,24 @@ def ShowReferences(lspserver: dict<any>, peek: bool): void
     return
   endif
 
-  var req = lspserver.createRequest('textDocument/references')
   # interface ReferenceParams
   #   interface TextDocumentPositionParams
-  req.params->extend(GetLspTextDocPosition())
-  req.params->extend({context: {includeDeclaration: true}})
+  var param: dict<any>
+  param = GetLspTextDocPosition()
+  param.context = {includeDeclaration: true}
+  var reply = lspserver.rpc('textDocument/references', param)
 
-  lspserver.peekSymbol = peek
-  lspserver.sendMessage(req)
-  if exists('g:LSPTest') && g:LSPTest
-    # When running LSP tests, make this a synchronous call
-    lspserver.waitForResponse(req)
+  # Result: Location[] | null
+  if reply->empty()
+    return
   endif
+
+  if reply.result->empty()
+    util.WarnMsg('Error: No references found')
+    return
+  endif
+
+  symbol.ShowReferences(lspserver, reply.result, peek)
 enddef
 
 # Request: "textDocument/documentHighlight"
@@ -1073,7 +1079,6 @@ export def NewLspServer(path: string, args: list<string>, isSync: bool, initiali
     diagsMap: {},
     workspaceSymbolPopup: 0,
     workspaceSymbolQuery: '',
-    peekSymbol: false,
     callHierarchyType: '',
     selection: {}
   }
index 8e46d27da461acc520408f0fadecbc7d06f279de..7b36488bca80330e74ef147fd5a56f6e00c98a42 100644 (file)
@@ -139,10 +139,9 @@ export def ShowSymbolMenu(lspserver: dict<any>, query: string)
 enddef
 
 # Display or peek symbol references in a location list
-export def ShowReferences(lspserver: dict<any>, refs: list<dict<any>>)
+export def ShowReferences(lspserver: dict<any>, refs: list<dict<any>>, peekSymbol: bool)
   if refs->empty()
     util.WarnMsg('Error: No references found')
-    lspserver.peekSymbol = false
     return
   endif
 
@@ -166,13 +165,13 @@ export def ShowReferences(lspserver: dict<any>, refs: list<dict<any>>)
   endfor
 
   var save_winid = win_getid()
-  if lspserver.peekSymbol
+  if peekSymbol
     silent! pedit
     wincmd P
   endif
   setloclist(0, [], ' ', {title: 'Symbol Reference', items: qflist})
   var mods: string = ''
-  if lspserver.peekSymbol
+  if peekSymbol
     # When peeking the references, open the location list in a vertically
     # split window to the right and make the location list window 30% of the
     # source window width
@@ -182,7 +181,6 @@ export def ShowReferences(lspserver: dict<any>, refs: list<dict<any>>)
   if !opt.lspOptions.keepFocusInReferences
     save_winid->win_gotoid()
   endif
-  lspserver.peekSymbol = false
 enddef
 
 # Jump to the definition, declaration or implementation of a symbol.