]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Update the logic used to jump to a symbol location.
authorYegappan Lakshmanan <yegappan@yahoo.com>
Thu, 27 Oct 2022 01:07:21 +0000 (18:07 -0700)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Thu, 27 Oct 2022 01:07:21 +0000 (18:07 -0700)
autoload/lsp/handlers.vim
autoload/lsp/symbol.vim

index 4da87f5f0eca0e4de3ebd42f8aae4e297ac74457..0501384410d463ba6fe8272fd28f64e54735e49f 100644 (file)
@@ -34,7 +34,7 @@ def ProcessInitializeReply(lspserver: dict<any>, req: dict<any>, reply: dict<any
   # 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 <nomodeline> User LspServerReady{lspserver.name}'
   endif
 
@@ -148,13 +148,14 @@ def ProcessCompletionReply(lspserver: dict<any>, req: dict<any>, reply: dict<any
       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 @@ def ProcessResolveReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>):
     # 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<any>, req: dict<any>, reply: dict<any>): 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
index 808b93f605db40623128fff76d9f617d2eadb072..c0ded0ae476f7e0bdd7c5ad9a64060747f03830b 100644 (file)
@@ -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<number> = fname->bufnr()->win_findbuf()
+    var bufnum = fname->bufnr()
+    var winList: list<number> = 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<any>, location: dict<any>, 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