From 5a08a4a1ef83ea6d960061ea76cb32ff58caa812 Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Tue, 11 Oct 2022 19:11:48 -0700 Subject: [PATCH] Use sync RPC call for showing references --- autoload/lsp/handlers.vim | 13 ------------- autoload/lsp/lspserver.vim | 23 ++++++++++++++--------- autoload/lsp/symbol.vim | 8 +++----- 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/autoload/lsp/handlers.vim b/autoload/lsp/handlers.vim index 27fe1de..b2f0750 100644 --- a/autoload/lsp/handlers.vim +++ b/autoload/lsp/handlers.vim @@ -257,18 +257,6 @@ def ProcessHoverReply(lspserver: dict, req: dict, reply: dict): v endif enddef -# process the 'textDocument/references' reply from the LSP server -# Result: Location[] | null -def ProcessReferencesReply(lspserver: dict, req: dict, reply: dict): 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, req: dict, reply: dict): void @@ -577,7 +565,6 @@ export def ProcessReply(lspserver: dict, req: dict, reply: dict): 'textDocument/signatureHelp': ProcessSignaturehelpReply, 'textDocument/completion': ProcessCompletionReply, 'textDocument/hover': ProcessHoverReply, - 'textDocument/references': ProcessReferencesReply, 'textDocument/documentHighlight': ProcessDocHighlightReply, 'textDocument/documentSymbol': ProcessDocSymbolReply, 'textDocument/codeAction': ProcessCodeActionReply, diff --git a/autoload/lsp/lspserver.vim b/autoload/lsp/lspserver.vim index 2ee3c10..8d9dc8e 100644 --- a/autoload/lsp/lspserver.vim +++ b/autoload/lsp/lspserver.vim @@ -645,18 +645,24 @@ def ShowReferences(lspserver: dict, 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 + 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, isSync: bool, initiali diagsMap: {}, workspaceSymbolPopup: 0, workspaceSymbolQuery: '', - peekSymbol: false, callHierarchyType: '', selection: {} } diff --git a/autoload/lsp/symbol.vim b/autoload/lsp/symbol.vim index 8e46d27..7b36488 100644 --- a/autoload/lsp/symbol.vim +++ b/autoload/lsp/symbol.vim @@ -139,10 +139,9 @@ export def ShowSymbolMenu(lspserver: dict, query: string) enddef # Display or peek symbol references in a location list -export def ShowReferences(lspserver: dict, refs: list>) +export def ShowReferences(lspserver: dict, refs: list>, 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, refs: list>) 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, refs: list>) if !opt.lspOptions.keepFocusInReferences save_winid->win_gotoid() endif - lspserver.peekSymbol = false enddef # Jump to the definition, declaration or implementation of a symbol. -- 2.48.1