From: Yegappan Lakshmanan Date: Sun, 20 Nov 2022 17:31:13 +0000 (-0800) Subject: When jumping to a LSP location, retrieve the file name from the location itself X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=b9a6dae099132643968178f50c51da09abcaf256;p=vim-lsp.git When jumping to a LSP location, retrieve the file name from the location itself --- diff --git a/autoload/lsp/symbol.vim b/autoload/lsp/symbol.vim index 17db794..41d0b4d 100644 --- a/autoload/lsp/symbol.vim +++ b/autoload/lsp/symbol.vim @@ -267,9 +267,10 @@ export def ShowReferences(lspserver: dict, refs: list>, peekSymbo endif enddef -# Display the symbol in file 'fname' at 'location' in a popup window. -def PeekSymbolLocation(lspserver: dict, fname: string, - location: dict) +# Display the file specified by LSP 'location' in a popup window and highlight +# the range in 'location'. +def PeekSymbolLocation(lspserver: dict, location: dict) + var fname = util.LspUriToFile(location.uri) var bnum = fname->bufadd() if bnum == 0 # Failed to create or find a buffer @@ -314,13 +315,12 @@ enddef # symbol. export def GotoSymbol(lspserver: dict, location: dict, peekSymbol: bool, cmdmods: string) - var fname = util.LspUriToFile(location.uri) if peekSymbol - PeekSymbolLocation(lspserver, fname, location) + PeekSymbolLocation(lspserver, location) else # Save the current cursor location in the tag stack. util.PushCursorToTagStack() - util.JumpToLspLocation(fname, location, cmdmods) + util.JumpToLspLocation(location, cmdmods) endif enddef diff --git a/autoload/lsp/typehierarchy.vim b/autoload/lsp/typehierarchy.vim index ee5d72e..faedaae 100644 --- a/autoload/lsp/typehierarchy.vim +++ b/autoload/lsp/typehierarchy.vim @@ -129,11 +129,9 @@ def TypeHierPopupCallback(lspserver: dict, typeUriMap: list>, return endif - var item = typeUriMap[selIdx - 1] - var fname = util.LspUriToFile(item.uri) # Save the current cursor location in the tag stack. util.PushCursorToTagStack() - util.JumpToLspLocation(fname, item, '') + util.JumpToLspLocation(typeUriMap[selIdx - 1], '') enddef # Show the super or sub type hierarchy items 'types' as a tree in a popup window diff --git a/autoload/lsp/util.vim b/autoload/lsp/util.vim index 1af97b9..a3d72db 100644 --- a/autoload/lsp/util.vim +++ b/autoload/lsp/util.vim @@ -150,10 +150,12 @@ export def PushCursorToTagStack() }]}, 't') enddef -# Jump to the LSP 'location' in file 'fname'. The user specified -# window command modifiers (e.g. topleft) are in 'cmdmods'. -export def JumpToLspLocation(fname: string, location: dict, - cmdmods: string) +# Jump to the LSP 'location'. The 'location' contains the file name, line +# number and character number. The user specified window command modifiers +# (e.g. topleft) are in 'cmdmods'. +export def JumpToLspLocation(location: dict, cmdmods: string) + var fname = LspUriToFile(location.uri) + # jump to the file and line containing the symbol if cmdmods == '' var bnr: number = fname->bufnr() diff --git a/doc/lsp.txt b/doc/lsp.txt index c567836..635f485 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -545,9 +545,16 @@ To get a particular option value you can use the following: > *:LspSuperTypeHierarchy* :LspSuperTypeHierarchy Show the super type hierarchy for the symbol under the cursor in a popup window. The file containing the - type is shown in another popup window. You can jump - to the location where a type is defined by browsing the - popup menu and selecting an entry. + type is shown in another popup window. As the current + entry in the type hierarchy popup menu changes, the + file popup window is updated to show the location + where the type is defined. You can jump to the + location where a type is defined by selecting the + entry in the popup menu. + + Note that the type hierarchy support is based on the + protocol supported by clangd. This is different from + the one specified in the 3.17 of the LSP standard. *:LspSubTypeHierarchy* :LspSubTypeHierarchy Show the sub type hierarchy for the symbol under the