]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
When jumping to a workspace symbol, save current location in the tag stack. When...
authorYegappan Lakshmanan <yegappan@yahoo.com>
Sun, 7 Mar 2021 20:41:31 +0000 (12:41 -0800)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Sun, 7 Mar 2021 20:41:31 +0000 (12:41 -0800)
autoload/handlers.vim
autoload/lsp.vim
autoload/lspserver.vim
autoload/util.vim

index 923e2f3197441bd935264e50a542a45d34d525d1..86191c30855f583770b8a2577fd497f17adef5f7 100644 (file)
@@ -859,10 +859,6 @@ enddef
 # process the 'workspace/symbol' reply from the LSP server
 # Result: SymbolInformation[] | null
 def s:processWorkspaceSymbolReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>)
-  if reply.result->empty()
-    return
-  endif
-
   var symbols: list<dict<any>> = []
   var symbolType: string
   var fileName: string
index 62124ca332d124f52bb3a53e76c8b03103171e42..f3a8973e87f44fff48d3c601ab3767e1238be626 100644 (file)
@@ -7,7 +7,8 @@ import {WarnMsg,
        ErrMsg,
        lsp_server_trace,
        ClearTraceLogs,
-       GetLineByteFromPos} from './util.vim'
+       GetLineByteFromPos,
+       PushCursorToTagStack} from './util.vim'
 import {LspDiagsUpdated} from './buf.vim'
 
 # Needs Vim 8.2.2342 and higher
@@ -1184,6 +1185,8 @@ def s:filterSymbols(lspserver: dict<any>, popupID: number, key: string): bool
     popupID->popup_settext('')
     if query != ''
       lspserver.workspaceQuery(query)
+    else
+      []->setwinvar(popupID, 'LspSymbolTable')
     endif
     echo 'Symbol: ' .. query
   endif
@@ -1208,8 +1211,14 @@ def s:jumpToWorkspaceSymbol(popupID: number, result: number): void
     return
   endif
 
-  var symTbl: list<dict<any>> = popupID->getwinvar('LspSymbolTable')
+  var symTbl: list<dict<any>> = popupID->getwinvar('LspSymbolTable', [])
+  if symTbl->empty()
+    return
+  endif
   try
+    # Save the current location in the tag stack
+    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<number> = fname->bufnr()->win_findbuf()
index 1ae9c2d77bc6c3e9d552aa97ce7c9edeb48cc026..e8942a683f6470e542f599d2b5a6b7e68570b7a8 100644 (file)
@@ -13,7 +13,8 @@ import {WarnMsg,
        TraceLog,
        LspUriToFile,
        LspBufnrToUri,
-       LspFileToUri} from './util.vim'
+       LspFileToUri,
+       PushCursorToTagStack} from './util.vim'
 
 # LSP server standard output handler
 def s:output_cb(lspserver: dict<any>, chan: channel, msg: string): void
@@ -374,17 +375,6 @@ def s:getCompletion(lspserver: dict<any>, triggerKind_arg: number): void
   lspserver.sendMessage(req)
 enddef
 
-# push the current location on to the tag stack
-def s:pushCursorToTagStack()
-  settagstack(winnr(), {items: [
-                        {
-                          bufnr: bufnr(),
-                          from: getpos('.'),
-                          matchnr: 1,
-                          tagname: expand('<cword>')
-                        }]}, 'a')
-enddef
-
 # Request: "textDocument/definition"
 # Param: DefinitionParams
 def s:gotoDefinition(lspserver: dict<any>): void
@@ -395,7 +385,7 @@ def s:gotoDefinition(lspserver: dict<any>): void
     return
   endif
 
-  s:pushCursorToTagStack()
+  PushCursorToTagStack()
   var req = lspserver.createRequest('textDocument/definition')
   # interface DefinitionParams
   #   interface TextDocumentPositionParams
@@ -413,7 +403,7 @@ def s:gotoDeclaration(lspserver: dict<any>): void
     return
   endif
 
-  s:pushCursorToTagStack()
+  PushCursorToTagStack()
   var req = lspserver.createRequest('textDocument/declaration')
 
   # interface DeclarationParams
@@ -433,7 +423,7 @@ def s:gotoTypeDef(lspserver: dict<any>): void
     return
   endif
 
-  s:pushCursorToTagStack()
+  PushCursorToTagStack()
   var req = lspserver.createRequest('textDocument/typeDefinition')
 
   # interface TypeDefinitionParams
@@ -453,7 +443,7 @@ def s:gotoImplementation(lspserver: dict<any>): void
     return
   endif
 
-  s:pushCursorToTagStack()
+  PushCursorToTagStack()
   var req = lspserver.createRequest('textDocument/implementation')
 
   # interface ImplementationParams
index 4da768e83928d2fcd130337e96c7affc3967a1cd..54c334eae263165c1b3a1e31b51cbe8831a2ad65 100644 (file)
@@ -120,4 +120,15 @@ export def GetLineByteFromPos(bnr: number, pos: dict<number>): number
   return col
 enddef
 
+# push the current location on to the tag stack
+export def PushCursorToTagStack()
+  settagstack(winnr(), {items: [
+                        {
+                          bufnr: bufnr(),
+                          from: getpos('.'),
+                          matchnr: 1,
+                          tagname: expand('<cword>')
+                        }]}, 't')
+enddef
+
 # vim: shiftwidth=2 softtabstop=2