Add LspAddTreeCallHierarchyIncoming (#1139)

This commit is contained in:
Daisuke Suzuki
2021-06-01 05:41:41 +09:00
committed by GitHub
parent d0f6bd5ae7
commit 541ed984b1
4 changed files with 40 additions and 3 deletions

View File

@@ -109,6 +109,7 @@ Refer to `:h vim-lsp-semantic` for more info.
| Command | Description|
|--|--|
|`:LspAddTreeCallHierarchyIncoming`| Find incoming call hierarchy for the symbol under cursor, but add the result to the current list |
|`:LspCallHierarchyIncoming`| Find incoming call hierarchy for the symbol under cursor |
|`:LspCallHierarchyOutgoing`| Find outgoing call hierarchy for the symbol under cursor |
|`:LspCodeAction`| Gets a list of possible commands that can be applied to a file so it can be fixed (quick fix) |

View File

@@ -345,8 +345,13 @@ function! lsp#ui#vim#code_lens() abort
\ })
endfunction
function! lsp#ui#vim#call_hierarchy_incoming() abort
let l:ctx = { 'method': 'incomingCalls', 'key': 'from' }
function! lsp#ui#vim#add_tree_call_hierarchy_incoming() abort
let l:ctx = { 'add_tree': v:true }
call lsp#ui#vim#call_hierarchy_incoming(l:ctx)
endfunction
function! lsp#ui#vim#call_hierarchy_incoming(ctx) abort
let l:ctx = extend({ 'method': 'incomingCalls', 'key': 'from' }, a:ctx)
call s:prepare_call_hierarchy(l:ctx)
endfunction
@@ -427,10 +432,21 @@ function! s:handle_call_hierarchy(ctx, server, type, data) abort
call lsp#utils#error('No ' . a:type .' found')
else
call lsp#utils#tagstack#_update()
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
endif
endif
endfunction

View File

@@ -53,6 +53,7 @@ CONTENTS *vim-lsp-contents*
|g:lsp_document_code_actions_signs_enabled|
g:lsp_document_code_action_signs_delay
|g:lsp_document_code_actions_signs_delay|
g:lsp_tree_incoming_prefix |g:lsp_tree_incoming_prefix|
g:lsp_format_sync_timeout |g:lsp_format_sync_timeout|
g:lsp_use_event_queue |g:lsp_use_event_queue|
g:lsp_document_highlight_enabled |g:lsp_document_highlight_enabled|
@@ -89,6 +90,7 @@ CONTENTS *vim-lsp-contents*
lsp#get_buffer_first_error_line() |lsp#get_buffer_first_error_line()|
lsp#get_progress() |lsp#get_progress()|
Commands |vim-lsp-commands|
LspAddTreeCallHierarchyIncoming |:LspAddTreeCallHierarchyIncoming|
LspCallHierarchyIncoming |:LspCallHierarchyIncoming|
LspCallHierarchyOutgoing |:LspCallHierarchyOutgoing|
LspCodeAction |:LspCodeAction|
@@ -717,6 +719,16 @@ g:lsp_document_code_action_signs_delay
let g:lsp_document_code_action_signs_delay = 200
let g:lsp_document_code_action_signs_delay = 1000
>
g:lsp_tree_incoming_prefix *g:lsp_tree_incoming_prefix*
Type: |String|
Default: `"<= "`
Specifies the prefix of items added by |LspAddTreeCallHierarchyIncoming|.
Example: >
let g:lsp_tree_incoming_prefix = "← "
let g:lsp_tree_incoming_prefix = "⬅️ "
g:lsp_use_event_queue *g:lsp_use_event_queue*
Type: |Number|
Default: `1` for neovim or vim with patch-8.1.0889
@@ -1397,6 +1409,11 @@ lsp#scroll(count) *lsp#scroll()*
==============================================================================
Commands *vim-lsp-commands*
LspAddTreeCallHierarchyIncoming *:LspAddTreeCallHierarchyIncoming*
Just like |LspCallHierarchyIncoming| , 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.

View File

@@ -41,6 +41,8 @@ let g:lsp_document_code_action_signs_delay = get(g:, 'lsp_document_code_action_s
let g:lsp_document_code_action_signs_hint = get(g:, 'lsp_document_code_action_signs_hint', {})
let g:lsp_document_code_action_signs_priority = get(g:, 'lsp_document_code_action_signs_priority', 10)
let g:lsp_tree_incoming_prefix = get(g:, 'lsp_tree_incoming_prefix', '<= ')
let g:lsp_preview_keep_focus = get(g:, 'lsp_preview_keep_focus', 1)
let g:lsp_use_event_queue = get(g:, 'lsp_use_event_queue', has('nvim') || has('patch-8.1.0889'))
let g:lsp_insert_text_enabled= get(g:, 'lsp_insert_text_enabled', 1)
@@ -76,7 +78,8 @@ if g:lsp_auto_enable
augroup END
endif
command! LspCallHierarchyIncoming call lsp#ui#vim#call_hierarchy_incoming()
command! LspAddTreeCallHierarchyIncoming call lsp#ui#vim#add_tree_call_hierarchy_incoming()
command! LspCallHierarchyIncoming call lsp#ui#vim#call_hierarchy_incoming({})
command! LspCallHierarchyOutgoing call lsp#ui#vim#call_hierarchy_outgoing()
command! -range -nargs=* -complete=customlist,lsp#ui#vim#code_action#complete LspCodeAction call lsp#ui#vim#code_action#do({
\ 'sync': v:false,