From: Yegappan Lakshmanan Date: Sun, 16 Jan 2022 07:12:40 +0000 (-0800) Subject: Add support for peeking the list of references to a symbol X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=4586b17637bc4c43df4f8fc3cfc39bee8eb6d8e7;p=vim-lsp.git Add support for peeking the list of references to a symbol --- diff --git a/autoload/handlers.vim b/autoload/handlers.vim index b13b691..7065300 100644 --- a/autoload/handlers.vim +++ b/autoload/handlers.vim @@ -105,14 +105,14 @@ enddef def s:processDefDeclReply(lspserver: dict, req: dict, reply: dict): void if reply.result->empty() util.WarnMsg("Error: definition is not found") - if !lspserver.peekDefDecl + if !lspserver.peekDefDeclRef # pop the tag stack var tagstack: dict = gettagstack() if tagstack.length > 0 settagstack(winnr(), {curidx: tagstack.length}, 't') endif endif - lspserver.peekDefDecl = false + lspserver.peekDefDeclRef = false return endif @@ -123,7 +123,7 @@ def s:processDefDeclReply(lspserver: dict, req: dict, reply: dict location = reply.result endif var fname = util.LspUriToFile(location.uri) - if lspserver.peekDefDecl + if lspserver.peekDefDeclRef # open the definition/declaration in the preview window and highlight the # matching symbol exe 'pedit ' .. fname @@ -171,7 +171,7 @@ def s:processDefDeclReply(lspserver: dict, req: dict, reply: dict location.range.start.character + 1) endif redraw! - lspserver.peekDefDecl = false + lspserver.peekDefDeclRef = false enddef # process the 'textDocument/signatureHelp' reply from the LSP server @@ -422,6 +422,7 @@ enddef def s:processReferencesReply(lspserver: dict, req: dict, reply: dict): void if reply.result->empty() util.WarnMsg('Error: No references found') + lspserver.peekDefDeclRef = false return endif @@ -444,10 +445,17 @@ def s:processReferencesReply(lspserver: dict, req: dict, reply: dictwin_gotoid() + lspserver.peekDefDeclRef = false enddef # process the 'textDocument/documentHighlight' reply from the LSP server diff --git a/autoload/lsp.vim b/autoload/lsp.vim index bd29f2c..cdb6594 100644 --- a/autoload/lsp.vim +++ b/autoload/lsp.vim @@ -690,7 +690,7 @@ def lsp#hover() enddef # show symbol references -def lsp#showReferences() +def lsp#showReferences(peek: bool) var ftype = &filetype if ftype == '' return @@ -711,7 +711,7 @@ def lsp#showReferences() return endif - lspserver.showReferences() + lspserver.showReferences(peek) enddef # highlight all the places where a symbol is referenced diff --git a/autoload/lspserver.vim b/autoload/lspserver.vim index 814b919..250cd13 100644 --- a/autoload/lspserver.vim +++ b/autoload/lspserver.vim @@ -424,7 +424,7 @@ def s:gotoDefinition(lspserver: dict, peek: bool): void if !peek util.PushCursorToTagStack() endif - lspserver.peekDefDecl = peek + lspserver.peekDefDeclRef = peek var req = lspserver.createRequest('textDocument/definition') # interface DefinitionParams # interface TextDocumentPositionParams @@ -445,7 +445,7 @@ def s:gotoDeclaration(lspserver: dict, peek: bool): void if !peek util.PushCursorToTagStack() endif - lspserver.peekDefDecl = peek + lspserver.peekDefDeclRef = peek var req = lspserver.createRequest('textDocument/declaration') # interface DeclarationParams @@ -468,7 +468,7 @@ def s:gotoTypeDef(lspserver: dict, peek: bool): void if !peek util.PushCursorToTagStack() endif - lspserver.peekDefDecl = peek + lspserver.peekDefDeclRef = peek var req = lspserver.createRequest('textDocument/typeDefinition') # interface TypeDefinitionParams @@ -491,7 +491,7 @@ def s:gotoImplementation(lspserver: dict, peek: bool): void if !peek util.PushCursorToTagStack() endif - lspserver.peekDefDecl = peek + lspserver.peekDefDeclRef = peek var req = lspserver.createRequest('textDocument/implementation') # interface ImplementationParams @@ -554,7 +554,7 @@ enddef # Request: "textDocument/references" # Param: ReferenceParams -def s:showReferences(lspserver: dict): void +def s:showReferences(lspserver: dict, peek: bool): void # Check whether LSP server supports getting reference information if !lspserver.caps->has_key('referencesProvider') || !lspserver.caps.referencesProvider @@ -568,6 +568,7 @@ def s:showReferences(lspserver: dict): void req.params->extend(s:getLspTextDocPosition()) req.params->extend({context: {includeDeclaration: true}}) + lspserver.peekDefDeclRef = peek lspserver.sendMessage(req) enddef @@ -852,7 +853,7 @@ export def NewLspServer(path: string, args: list): dict diagsMap: {}, workspaceSymbolPopup: 0, workspaceSymbolQuery: '', - peekDefDecl: false + peekDefDeclRef: false } # Add the LSP server functions lspserver->extend({ diff --git a/doc/lsp.txt b/doc/lsp.txt index 49fb602..96bd8c8 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -93,6 +93,9 @@ The following commands are provided: :LspDiagCurrent Display the diagnostic message for the current line. :LspShowReferences Display the list of references to the keyword under cursor in a new location list. +:LspPeekReferences Display the list of references to the keyword under + cursor in a location list associated with the preview + window. :LspHighlight Highlight all the matches for the keyword under cursor :LspHighlightClear Clear all the matches highlighted by :LspHighlight :LspOutline Show the list of symbols defined in the current file @@ -314,6 +317,11 @@ diagnostic messages, you can add the following line to your .vimrc file: where the symbol under the cursor is referenced and opens the location window. + *:LspPeekReferences* +:LspPeekReferences Opens the preview window and creates a new location + list with the list of locations where the symbol under + the cursor is referenced and opens the location window. + *:LspHighlight* :LspHighlight Highlights all the matches for the symbol under cursor. The text, read and write references to the diff --git a/plugin/lsp.vim b/plugin/lsp.vim index 133415c..8e85806 100644 --- a/plugin/lsp.vim +++ b/plugin/lsp.vim @@ -34,7 +34,8 @@ command! -nargs=0 -bar LspDiagCurrent call lsp#showCurrentDiag() command! -nargs=0 -bar LspDiagFirst call lsp#jumpToDiag('first') command! -nargs=0 -bar LspDiagNext call lsp#jumpToDiag('next') command! -nargs=0 -bar LspDiagPrev call lsp#jumpToDiag('prev') -command! -nargs=0 -bar LspShowReferences call lsp#showReferences() +command! -nargs=0 -bar LspShowReferences call lsp#showReferences(v:false) +command! -nargs=0 -bar LspPeekReferences call lsp#showReferences(v:true) command! -nargs=0 -bar LspHighlight call lsp#docHighlight() command! -nargs=0 -bar LspHighlightClear call lsp#docHighlightClear() command! -nargs=0 -bar LspOutline call lsp#outline() @@ -59,7 +60,7 @@ if has('gui_running') anoremenu L&sp.Goto.TypeDef :call lsp#gotoTypedef(v:false) anoremenu L&sp.Show\ Signature :call lsp#showSignature() - anoremenu L&sp.Show\ References :call lsp#showReferences() + anoremenu L&sp.Show\ References :call lsp#showReferences(v:false) anoremenu L&sp.Show\ Detail :call lsp#hover() anoremenu L&sp.Outline :call lsp#outline() @@ -85,7 +86,7 @@ if has('gui_running') anoremenu PopUp.L&sp.Go\ to\ Declaration \ :call lsp#gotoDeclaration(v:false) anoremenu Popup.L&sp.Find\ All\ References - \ :call lsp#showReferences() + \ :call lsp#showReferences(v:false) anoremenu PopUp.L&sp.Show\ Detail \ :call lsp#hover() anoremenu PopUp.L&sp.Highlight\ Symbol