]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Add support for peeking the list of references to a symbol
authorYegappan Lakshmanan <yegappan@yahoo.com>
Sun, 16 Jan 2022 07:12:40 +0000 (23:12 -0800)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Sun, 16 Jan 2022 07:12:40 +0000 (23:12 -0800)
autoload/handlers.vim
autoload/lsp.vim
autoload/lspserver.vim
doc/lsp.txt
plugin/lsp.vim

index b13b691fc135df50ed950cf97fde99bf5dd62abd..7065300b42434ebe11a0f28e97d188f8d1869b5e 100644 (file)
@@ -105,14 +105,14 @@ enddef
 def s:processDefDeclReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>): 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<any> = 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<any>, req: dict<any>, reply: dict<any>
     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<any>, req: dict<any>, reply: dict<any>
                        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<any>, req: dict<any>, reply: dict<any>): 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<any>, req: dict<any>, reply: dict<a
                        col: util.GetLineByteFromPos(bnr, loc.range.start) + 1,
                        text: text})
   endfor
-  setloclist(0, [], ' ', {title: 'Symbol Reference', items: qflist})
+
   var save_winid = win_getid()
-  :lopen
+  if lspserver.peekDefDeclRef
+    silent! pedit
+    wincmd P
+  endif
+  setloclist(0, [], ' ', {title: 'Symbol Reference', items: qflist})
+  :belowright vert lopen
+  :30wincmd |
   save_winid->win_gotoid()
+  lspserver.peekDefDeclRef = false
 enddef
 
 # process the 'textDocument/documentHighlight' reply from the LSP server
index bd29f2c99cd35ab31e9e2d7a52319b90f443a474..cdb65941e31687d50bd14d9736fa27da61ba5451 100644 (file)
@@ -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
index 814b9194733a986b36c6684fcb3fdcd05d4b18c6..250cd13541abcfb1cba080904faff8500dee435f 100644 (file)
@@ -424,7 +424,7 @@ def s:gotoDefinition(lspserver: dict<any>, 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<any>, 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<any>, 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<any>, 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<any>): void
+def s:showReferences(lspserver: dict<any>, 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<any>): 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<string>): dict<any>
     diagsMap: {},
     workspaceSymbolPopup: 0,
     workspaceSymbolQuery: '',
-    peekDefDecl: false
+    peekDefDeclRef: false
   }
   # Add the LSP server functions
   lspserver->extend({
index 49fb602ea0f857065002f0ac197b351844c416d6..96bd8c8411a48e7d2172c9524d6d77f6d993c6d8 100644 (file)
@@ -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
index 133415c17838494c744e21e3fc9485809950bf4f..8e85806fdd9309b3a822d432ee0c8f9417ac840a 100644 (file)
@@ -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 <silent> L&sp.Goto.TypeDef :call lsp#gotoTypedef(v:false)<CR>
 
   anoremenu <silent> L&sp.Show\ Signature :call lsp#showSignature()<CR>
-  anoremenu <silent> L&sp.Show\ References :call lsp#showReferences()<CR>
+  anoremenu <silent> L&sp.Show\ References :call lsp#showReferences(v:false)<CR>
   anoremenu <silent> L&sp.Show\ Detail :call lsp#hover()<CR>
   anoremenu <silent> L&sp.Outline :call lsp#outline()<CR>
 
@@ -85,7 +86,7 @@ if has('gui_running')
     anoremenu <silent> PopUp.L&sp.Go\ to\ Declaration
          \ :call lsp#gotoDeclaration(v:false)<CR>
     anoremenu <silent> Popup.L&sp.Find\ All\ References
-         \ :call lsp#showReferences()<CR>
+         \ :call lsp#showReferences(v:false)<CR>
     anoremenu <silent> PopUp.L&sp.Show\ Detail
           \ :call lsp#hover()<CR>
     anoremenu <silent> PopUp.L&sp.Highlight\ Symbol