Skip to content

Commit

Permalink
Add LspAddTreeReferences (#1484)
Browse files Browse the repository at this point in the history
  • Loading branch information
satorunooshie authored Sep 9, 2023
1 parent aa93b2a commit 7233bb2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
20 changes: 18 additions & 2 deletions autoload/lsp/ui/vim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,17 @@ function! lsp#ui#vim#definition(in_preview, ...) abort
call s:list_location('definition', l:ctx)
endfunction

function! lsp#ui#vim#references() abort
let l:ctx = { 'jump_if_one': 0 }
function! lsp#ui#vim#references(ctx) abort
let l:ctx = extend({ 'jump_if_one': 0 }, a:ctx)
let l:request_params = { 'context': { 'includeDeclaration': v:false } }
call s:list_location('references', l:ctx, l:request_params)
endfunction

function! lsp#ui#vim#add_tree_references() abort
let l:ctx = { 'add_tree': v:true }
call lsp#ui#vim#references(l:ctx)
endfunction

function! s:list_location(method, ctx, ...) abort
" typeDefinition => type definition
let l:operation = substitute(a:method, '\u', ' \l\0', 'g')
Expand Down Expand Up @@ -307,10 +312,21 @@ function! s:handle_location(ctx, server, type, data) abort "ctx = {counter, list
echo 'Retrieved ' . a:type
redraw
elseif !a:ctx['in_preview']
if get(a:ctx, 'add_tree', v:false)
let l:qf = getqflist({'idx' : 0, 'items': []})
let l:pos = l:qf.idx
let l:parent = l:qf.items
let l:level = count(l:parent[l:pos-1].text, g:lsp_tree_incoming_prefix)
let a:ctx['list'] = extend(l:parent, map(a:ctx['list'], 'extend(v:val, {"text": repeat("' . g:lsp_tree_incoming_prefix . '", l:level+1) . v:val.text})'), l:pos)
endif
call setqflist([])
call setqflist(a:ctx['list'])
echo 'Retrieved ' . a:type
botright copen
if get(a:ctx, 'add_tree', v:false)
" move the cursor to the newly added item
execute l:pos + 1
endif
else
let l:lines = readfile(l:loc['filename'])
if has_key(l:loc,'viewstart') " showing a locationLink
Expand Down
10 changes: 9 additions & 1 deletion doc/vim-lsp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ CONTENTS *vim-lsp-contents*
lsp#document_hover_preview_winid() |lsp#document_hover_preview_winid()|
Commands |vim-lsp-commands|
LspAddTreeCallHierarchyIncoming |:LspAddTreeCallHierarchyIncoming|
LspAddTreeReferences |:LspAddTreeReferences|
LspCallHierarchyIncoming |:LspCallHierarchyIncoming|
LspCallHierarchyOutgoing |:LspCallHierarchyOutgoing|
LspCodeAction |:LspCodeAction|
Expand Down Expand Up @@ -877,7 +878,9 @@ g:lsp_tree_incoming_prefix *g:lsp_tree_incoming_prefix*
Type: |String|
Default: `"<= "`

Specifies the prefix of items added by |LspAddTreeCallHierarchyIncoming|.
Specifies the prefix of items added by following commands.
* |LspAddTreeCallHierarchyIncoming|
* |LspAddTreeReferences|

Example: >
let g:lsp_tree_incoming_prefix = "← "
Expand Down Expand Up @@ -1680,6 +1683,11 @@ LspAddTreeCallHierarchyIncoming *:LspAddTreeCallHierarchyIncoming*
Just like |LspCallHierarchyIncoming| , but instead of making a new list the
result is appended to the current list.

LspAddTreeReferences *:LspAddTreeReferences*

Just like |LspReferences| , but instead of making a new list the result is
appended to the current list.

LspCallHierarchyIncoming *:LspCallHierarchyIncoming*

Find incoming call hierarchy for the symbol under cursor.
Expand Down
5 changes: 3 additions & 2 deletions plugin/lsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ command! -nargs=* LspNextWarning call lsp#internal#diagnostics#movement#_next_wa
command! -nargs=* LspPreviousWarning call lsp#internal#diagnostics#movement#_previous_warning(<f-args>)
command! -nargs=* LspNextDiagnostic call lsp#internal#diagnostics#movement#_next_diagnostics(<f-args>)
command! -nargs=* LspPreviousDiagnostic call lsp#internal#diagnostics#movement#_previous_diagnostics(<f-args>)
command! LspReferences call lsp#ui#vim#references()
command! LspReferences call lsp#ui#vim#references({})
command! LspAddTreeReferences call lsp#ui#vim#add_tree_references()
command! LspRename call lsp#ui#vim#rename()
command! LspTypeDefinition call lsp#ui#vim#type_definition(0, <q-mods>)
command! LspTypeHierarchy call lsp#internal#type_hierarchy#show()
Expand Down Expand Up @@ -189,7 +190,7 @@ nnoremap <silent> <plug>(lsp-next-diagnostic) :<c-u>call lsp#internal#diagnostic
nnoremap <silent> <plug>(lsp-next-diagnostic-nowrap) :<c-u>call lsp#internal#diagnostics#movement#_next_diagnostics("-wrap=0")<cr>
nnoremap <silent> <plug>(lsp-previous-diagnostic) :<c-u>call lsp#internal#diagnostics#movement#_previous_diagnostics()<cr>
nnoremap <silent> <plug>(lsp-previous-diagnostic-nowrap) :<c-u>call lsp#internal#diagnostics#movement#_previous_diagnostics("-wrap=0")<cr>
nnoremap <silent> <plug>(lsp-references) :<c-u>call lsp#ui#vim#references()<cr>
nnoremap <silent> <plug>(lsp-references) :<c-u>call lsp#ui#vim#references({})<cr>
nnoremap <silent> <plug>(lsp-rename) :<c-u>call lsp#ui#vim#rename()<cr>
nnoremap <silent> <plug>(lsp-type-definition) :<c-u>call lsp#ui#vim#type_definition(0)<cr>
nnoremap <silent> <plug>(lsp-type-hierarchy) :<c-u>call lsp#internal#type_hierarchy#show()<cr>
Expand Down

0 comments on commit 7233bb2

Please sign in to comment.