From 91f4f54ec155e4071a76b7287850cda6e747700e Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Wed, 26 Oct 2022 18:07:21 -0700 Subject: [PATCH] Update the logic used to jump to a symbol location. --- autoload/lsp/handlers.vim | 11 +++--- autoload/lsp/symbol.vim | 75 +++++++++++++++++---------------------- 2 files changed, 39 insertions(+), 47 deletions(-) diff --git a/autoload/lsp/handlers.vim b/autoload/lsp/handlers.vim index 4da87f5..0501384 100644 --- a/autoload/lsp/handlers.vim +++ b/autoload/lsp/handlers.vim @@ -34,7 +34,7 @@ def ProcessInitializeReply(lspserver: dict, req: dict, reply: dict User LspServerReady{lspserver.name}' endif @@ -148,13 +148,14 @@ def ProcessCompletionReply(lspserver: dict, req: dict, reply: dictlen() == 1 - && matchstr(getline('.'), completeItems[0].word .. '\>') != '' + && getline('.')->matchstr(completeItems[0].word .. '\>') != '' # only one complete match. No need to show the completion popup return endif @@ -215,7 +216,7 @@ def ProcessResolveReply(lspserver: dict, req: dict, reply: dict): # Solve a issue where if a server send the detail field with "\n", # on the completion popup, everything will be joined with "^@" # (example: typescript-language-server) - infoText->extend(split(reply.result.detail, "\n")) + infoText->extend(reply.result.detail->split("\n")) endif if reply.result->has_key('documentation') @@ -323,7 +324,7 @@ def ProcessHoverReply(lspserver: dict, req: dict, reply: dict): v setlocal buftype=nofile setlocal bufhidden=delete exe $'setlocal ft={hoverKind}' - deletebufline(bufnr(), 1, '$') + bufnr()->deletebufline(1, '$') append(0, hoverText) cursor(1, 1) wincmd p diff --git a/autoload/lsp/symbol.vim b/autoload/lsp/symbol.vim index 808b93f..c0ded0a 100644 --- a/autoload/lsp/symbol.vim +++ b/autoload/lsp/symbol.vim @@ -90,7 +90,8 @@ def JumpToWorkspaceSymbol(popupID: number, result: number): void # if the selected file is already present in a window, then jump to it var fname: string = symTbl[result - 1].file - var winList: list = fname->bufnr()->win_findbuf() + var bufnum = fname->bufnr() + var winList: list = bufnum->win_findbuf() if winList->len() == 0 # Not present in any window if &modified || &buftype != '' @@ -101,19 +102,13 @@ def JumpToWorkspaceSymbol(popupID: number, result: number): void exe $'confirm edit {symTbl[result - 1].file}' endif else - var wid = fname->bufwinid() - if wid != -1 - # if had one in cur tab - # and cur win is same buf - if bufwinid(bufnr()) == wid - # do nothing - else - # or pick up one in cur tab - wid->win_gotoid() - endif - else - # or pick up one in one tab - winList[0]->win_gotoid() + if bufnr() != bufnum + var winID = fname->bufwinid() + if winID == -1 + # not present in the current tab page + winID = winList[0] + endif + winID->win_gotoid() endif endif # Set the previous cursor location mark. Instead of using setpos(), m' is @@ -302,35 +297,31 @@ export def GotoSymbol(lspserver: dict, location: dict, peekSymbol: boo win_gotoid(cur_wid) else # jump to the file and line containing the symbol - var wid = fname->bufwinid() - if wid != -1 - # `wid` maybe just is one of windows in cur tab which had same buf - # jump to `wid` only if cur one is not same buf or maybe a bit mess - # which should always try to re-use cur one firstly (if it is same) - # otherwise cursor perhaps dumbly jumpped to `wid` though same buf - if bufwinid(bufnr()) != wid - wid->win_gotoid() - endif - else - var bnr: number = fname->bufnr() - if bnr != -1 - # Reuse an existing buffer. If the current buffer has unsaved changes - # and 'hidden' is not set or if the current buffer is a special - # buffer, then open the buffer in a new window. - if (&modified && !&hidden) || &buftype != '' - exe $'sbuffer {bnr}' - else - exe $'buf {bnr}' - endif + var bnr: number = fname->bufnr() + if bnr != bufnr() + var wid = fname->bufwinid() + if wid != -1 + wid->win_gotoid() else - 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 open the file - # in a new window - exe $'split {fname}' - else - exe $'edit {fname}' - endif + if bnr != -1 + # Reuse an existing buffer. If the current buffer has unsaved changes + # and 'hidden' is not set or if the current buffer is a special + # buffer, then open the buffer in a new window. + if (&modified && !&hidden) || &buftype != '' + exe $'sbuffer {bnr}' + else + exe $'buf {bnr}' + endif + else + 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 open the file + # in a new window + exe $'split {fname}' + else + exe $'edit {fname}' + endif + endif endif endif # Set the previous cursor location mark. Instead of using setpos(), m' is -- 2.48.1