autoload/handlers.vim | 4 ---- autoload/lsp.vim | 13 +++++++++++-- autoload/lspserver.vim | 22 ++++++---------------- autoload/util.vim | 11 +++++++++++ diff --git a/autoload/handlers.vim b/autoload/handlers.vim index 923e2f3197441bd935264e50a542a45d34d525d1..86191c30855f583770b8a2577fd497f17adef5f7 100644 --- a/autoload/handlers.vim +++ b/autoload/handlers.vim @@ -859,10 +859,6 @@ # process the 'workspace/symbol' reply from the LSP server # Result: SymbolInformation[] | null def s:processWorkspaceSymbolReply(lspserver: dict, req: dict, reply: dict) - if reply.result->empty() - return - endif - var symbols: list> = [] var symbolType: string var fileName: string diff --git a/autoload/lsp.vim b/autoload/lsp.vim index 62124ca332d124f52bb3a53e76c8b03103171e42..f3a8973e87f44fff48d3c601ab3767e1238be626 100644 --- a/autoload/lsp.vim +++ b/autoload/lsp.vim @@ -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 @@ # Update the popup with the new list of symbol names popupID->popup_settext('') if query != '' lspserver.workspaceQuery(query) + else + []->setwinvar(popupID, 'LspSymbolTable') endif echo 'Symbol: ' .. query endif @@ -1208,8 +1211,14 @@ # popup is canceled return endif - var symTbl: list> = popupID->getwinvar('LspSymbolTable') + var symTbl: list> = 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 = fname->bufnr()->win_findbuf() diff --git a/autoload/lspserver.vim b/autoload/lspserver.vim index 1ae9c2d77bc6c3e9d552aa97ce7c9edeb48cc026..e8942a683f6470e542f599d2b5a6b7e68570b7a8 100644 --- a/autoload/lspserver.vim +++ b/autoload/lspserver.vim @@ -13,7 +13,8 @@ ErrMsg, TraceLog, LspUriToFile, LspBufnrToUri, - LspFileToUri} from './util.vim' + LspFileToUri, + PushCursorToTagStack} from './util.vim' # LSP server standard output handler def s:output_cb(lspserver: dict, chan: channel, msg: string): void @@ -374,17 +375,6 @@ 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('') - }]}, 'a') -enddef - # Request: "textDocument/definition" # Param: DefinitionParams def s:gotoDefinition(lspserver: dict): void @@ -395,7 +385,7 @@ ErrMsg("Error: LSP server does not support jumping to a definition") return endif - s:pushCursorToTagStack() + PushCursorToTagStack() var req = lspserver.createRequest('textDocument/definition') # interface DefinitionParams # interface TextDocumentPositionParams @@ -413,7 +403,7 @@ ErrMsg("Error: LSP server does not support jumping to a declaration") return endif - s:pushCursorToTagStack() + PushCursorToTagStack() var req = lspserver.createRequest('textDocument/declaration') # interface DeclarationParams @@ -433,7 +423,7 @@ ErrMsg("Error: LSP server does not support jumping to a type definition") return endif - s:pushCursorToTagStack() + PushCursorToTagStack() var req = lspserver.createRequest('textDocument/typeDefinition') # interface TypeDefinitionParams @@ -453,7 +443,7 @@ ErrMsg("Error: LSP server does not support jumping to an implementation") return endif - s:pushCursorToTagStack() + PushCursorToTagStack() var req = lspserver.createRequest('textDocument/implementation') # interface ImplementationParams diff --git a/autoload/util.vim b/autoload/util.vim index 4da768e83928d2fcd130337e96c7affc3967a1cd..54c334eae263165c1b3a1e31b51cbe8831a2ad65 100644 --- a/autoload/util.vim +++ b/autoload/util.vim @@ -120,4 +120,15 @@ 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('') + }]}, 't') +enddef + # vim: shiftwidth=2 softtabstop=2