From: Yegappan Lakshmanan Date: Tue, 12 Jan 2021 03:30:15 +0000 (-0800) Subject: Use mapnew() instead of map() and check for null LSP reply result X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=7411d0b675b2fc69c533238088e37729cbd8f40c;p=vim-lsp.git Use mapnew() instead of map() and check for null LSP reply result --- diff --git a/autoload/handlers.vim b/autoload/handlers.vim index 8132c88..53f265e 100644 --- a/autoload/handlers.vim +++ b/autoload/handlers.vim @@ -72,6 +72,10 @@ enddef # process the 'textDocument/signatureHelp' reply from the LSP server # Result: SignatureHelp | null def s:processSignaturehelpReply(lspserver: dict, req: dict, reply: dict): void + if reply.result->empty() + return + endif + var result: dict = reply.result if result.signatures->len() <= 0 WarnMsg('No signature help available') @@ -135,6 +139,9 @@ enddef # process the 'textDocument/completion' reply from the LSP server # Result: CompletionItem[] | CompletionList | null def s:processCompletionReply(lspserver: dict, req: dict, reply: dict): void + if reply.result->empty() + return + endif var items: list> if type(reply.result) == v:t_list @@ -178,7 +185,7 @@ enddef # process the 'textDocument/hover' reply from the LSP server # Result: Hover | null def s:processHoverReply(lspserver: dict, req: dict, reply: dict): void - if type(reply.result) == v:t_none + if reply.result->empty() return endif @@ -226,7 +233,7 @@ enddef # process the 'textDocument/references' reply from the LSP server # Result: Location[] | null def s:processReferencesReply(lspserver: dict, req: dict, reply: dict): void - if type(reply.result) == v:t_none || reply.result->empty() + if reply.result->empty() WarnMsg('Error: No references found') return endif @@ -749,10 +756,12 @@ def s:processFoldingRangeReply(lspserver: dict, req: dict, reply: dict for foldRange in reply.result end_lnum = foldRange.endLine + 1 if end_lnum < foldRange.startLine + 2 - end_lnum = foldRange.startLine + 2 + end_lnum = foldRange.startLine + 2 endif exe ':' .. (foldRange.startLine + 2) .. ',' .. end_lnum .. 'fold' - :foldopen! + # Open all the folds, otherwise the subsequently created folds are not + # correct. + :silent! foldopen! endfor if &foldcolumn == 0 @@ -830,7 +839,7 @@ def s:processWorkspaceSymbolReply(lspserver: dict, req: dict, reply: d endfor symbols->setwinvar(lspserver.workspaceSymbolPopup, 'LspSymbolTable') lspserver.workspaceSymbolPopup->popup_settext( - symbols->copy()->map('v:val.name')) + symbols->copy()->mapnew('v:val.name')) enddef # Process various reply messages from the LSP server diff --git a/autoload/lsp.vim b/autoload/lsp.vim index d765204..8408ed5 100644 --- a/autoload/lsp.vim +++ b/autoload/lsp.vim @@ -450,7 +450,7 @@ enddef # sort the diaganostics messages for a buffer by line number def s:getSortedDiagLines(lspserver: dict, bnr: number): list var lnums: list = - lspserver.diagsMap[bnr]->keys()->map((_, v) => str2nr(v)) + lspserver.diagsMap[bnr]->keys()->mapnew((_, v) => str2nr(v)) return lnums->sort((a, b) => a - b) enddef