autoload/lsp/handlers.vim | 11 ++++++----- autoload/lsp/symbol.vim | 75 +++++++++++++++++++++++------------------------------ diff --git a/autoload/lsp/handlers.vim b/autoload/lsp/handlers.vim index 4da87f5f0eca0e4de3ebd42f8aae4e297ac74457..0501384410d463ba6fe8272fd28f64e54735e49f 100644 --- a/autoload/lsp/handlers.vim +++ b/autoload/lsp/handlers.vim @@ -34,7 +34,7 @@ # send a "initialized" notification to server lspserver.sendInitializedNotif() lspserver.ready = true - if exists('#User#LspServerReady' .. lspserver.name) + if exists($'#User#LspServerReady{lspserver.name}') exe $'doautocmd User LspServerReady{lspserver.name}' endif @@ -148,13 +148,14 @@ # no matches return endif - if mode() != 'i' && mode() != 'R' && mode() != 'Rv' + var m = mode() + if m != 'i' && m != 'R' && m != 'Rv' # If not in insert or replace mode, then don't start the completion return endif if completeItems->len() == 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 @@ if reply.result->has_key('detail') # 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 @@ wincmd P 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 808b93f605db40623128fff76d9f617d2eadb072..c0ded0ae476f7e0bdd7c5ad9a64060747f03830b 100644 --- a/autoload/lsp/symbol.vim +++ b/autoload/lsp/symbol.vim @@ -90,7 +90,8 @@ util.PushCursorToTagStack() # 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 @@ else 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 @@ matchaddpos('Search', [pos], 10, 101) 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