From 0b133414ebab5b7fb4ad115d61ebb511a931da9a Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Mon, 21 Feb 2022 07:32:27 -0800 Subject: [PATCH] Handle a null reply from the LSP server properly --- autoload/lsp/handlers.vim | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/autoload/lsp/handlers.vim b/autoload/lsp/handlers.vim index 1af6651..d86156f 100644 --- a/autoload/lsp/handlers.vim +++ b/autoload/lsp/handlers.vim @@ -84,7 +84,7 @@ endif # process the 'initialize' method reply from the LSP server # Result: InitializeResult def ProcessInitializeReply(lspserver: dict, req: dict, reply: dict): void - if reply.result->len() <= 0 + if reply.result->empty() return endif @@ -149,6 +149,9 @@ enddef # process the 'textDocument/signatureHelp' reply from the LSP server # Result: SignatureHelp | null def ProcessSignaturehelpReply(lspserver: dict, req: dict, reply: dict): void + if reply.result->empty() + return + endif signature.SignatureDisplay(lspserver, reply.result) enddef @@ -343,6 +346,12 @@ 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 @@ -524,12 +533,22 @@ enddef # process the 'textDocument/codeAction' reply from the LSP server # Result: (Command | CodeAction)[] | null def ProcessCodeActionReply(lspserver: dict, req: dict, reply: dict) + if reply.result->empty() + # no action can be performed + util.WarnMsg('No code action is available') + return + endif + codeaction.ApplyCodeAction(lspserver, reply.result) enddef # Reply: 'textDocument/selectionRange' # Result: SelectionRange[] | null def ProcessSelectionRangeReply(lspserver: dict, req: dict, reply: dict) + if reply.result->empty() + return + endif + selection.SelectionStart(lspserver, reply.result) enddef @@ -599,7 +618,7 @@ def ProcessWorkspaceSymbolReply(lspserver: dict, req: dict, reply: dic var r: dict> var symName: string - if reply.result->type() != v:t_list + if reply.result->empty() return endif @@ -665,12 +684,20 @@ enddef # process the 'callHierarchy/incomingCalls' reply from the LSP server # Result: CallHierarchyIncomingCall[] | null def ProcessIncomingCalls(lspserver: dict, req: dict, reply: dict) + if reply.result->empty() + return + endif + callhier.IncomingCalls(reply.result) enddef # process the 'callHierarchy/outgoingCalls' reply from the LSP server # Result: CallHierarchyOutgoingCall[] | null def ProcessOutgoingCalls(lspserver: dict, req: dict, reply: dict) + if reply.result->empty() + return + endif + callhier.OutgoingCalls(reply.result) enddef -- 2.48.1