From d94ffde29e6985131230e97c3dc5ea3c33b9878f Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Sat, 8 Oct 2022 15:26:47 -0700 Subject: [PATCH] Use sync RPC for SwitchSourceHeader --- autoload/lsp/handlers.vim | 18 ------------------ autoload/lsp/lspserver.vim | 20 ++++++++++++++++---- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/autoload/lsp/handlers.vim b/autoload/lsp/handlers.vim index 79efc0a..f30e14c 100644 --- a/autoload/lsp/handlers.vim +++ b/autoload/lsp/handlers.vim @@ -60,23 +60,6 @@ def ProcessShutdownReply(lspserver: dict, req: dict, reply: dict) return enddef -# process the 'textDocument/switchSourceHeader' reply from the LSP server -# Clangd specific extension -# Result: URI | null -def ProcessSwitchHeaderReply(lspserver: dict, req: dict, reply: dict): void - if reply.result->empty() - return - endif - var fname = util.LspUriToFile(reply.result) - if (&modified && !&hidden) || &buftype != '' - # if the current buffer has unsaved changes and 'hidden' is not set, - # or if the current buffer is a special buffer, then ask to save changes - exe $'confirm edit {fname}' - else - exe $'edit {fname}' - endif -enddef - # process the 'textDocument/signatureHelp' reply from the LSP server # Result: SignatureHelp | null def ProcessSignaturehelpReply(lspserver: dict, req: dict, reply: dict): void @@ -628,7 +611,6 @@ export def ProcessReply(lspserver: dict, req: dict, reply: dict): { 'initialize': ProcessInitializeReply, 'shutdown': ProcessShutdownReply, - 'textDocument/switchSourceHeader': ProcessSwitchHeaderReply, 'textDocument/signatureHelp': ProcessSignaturehelpReply, 'textDocument/completion': ProcessCompletionReply, 'textDocument/hover': ProcessHoverReply, diff --git a/autoload/lsp/lspserver.vim b/autoload/lsp/lspserver.vim index dfa4886..3aeba0f 100644 --- a/autoload/lsp/lspserver.vim +++ b/autoload/lsp/lspserver.vim @@ -538,11 +538,23 @@ enddef # Param: TextDocumentIdentifier # Clangd specific extension def SwitchSourceHeader(lspserver: dict) - var req = lspserver.createRequest('textDocument/switchSourceHeader') - req.params->extend({uri: util.LspFileToUri(@%)}) - lspserver.sendMessage(req) + var param = {} + param.uri = util.LspFileToUri(@%) + var resp = lspserver.rpc('textDocument/switchSourceHeader', param) + if resp->empty() || resp.result->empty() + return + endif - lspserver.waitForResponse(req) + # process the 'textDocument/switchSourceHeader' reply from the LSP server + # Result: URI | null + var fname = util.LspUriToFile(resp.result) + if (&modified && !&hidden) || &buftype != '' + # if the current buffer has unsaved changes and 'hidden' is not set, + # or if the current buffer is a special buffer, then ask to save changes + exe $'confirm edit {fname}' + else + exe $'edit {fname}' + endif enddef # get symbol signature help. -- 2.48.1