@@ -35,12 +35,17 @@ function! lsp#ui#vim#definition(in_preview, ...) abort
3535 call s: list_location (' definition' , l: ctx )
3636endfunction
3737
38- function ! lsp#ui#vim#references () abort
39- let l: ctx = { ' jump_if_one' : 0 }
38+ function ! lsp#ui#vim#references (ctx ) abort
39+ let l: ctx = extend ( { ' jump_if_one' : 0 }, a: ctx )
4040 let l: request_params = { ' context' : { ' includeDeclaration' : v: false } }
4141 call s: list_location (' references' , l: ctx , l: request_params )
4242endfunction
4343
44+ function ! lsp#ui#vim#add_tree_references () abort
45+ let l: ctx = { ' add_tree' : v: true }
46+ call lsp#ui#vim#references (l: ctx )
47+ endfunction
48+
4449function ! s: list_location (method, ctx, ... ) abort
4550 " typeDefinition => type definition
4651 let l: operation = substitute (a: method , ' \u' , ' \l\0' , ' g' )
@@ -307,10 +312,21 @@ function! s:handle_location(ctx, server, type, data) abort "ctx = {counter, list
307312 echo ' Retrieved ' . a: type
308313 redraw
309314 elseif ! a: ctx [' in_preview' ]
315+ if get (a: ctx , ' add_tree' , v: false )
316+ let l: qf = getqflist ({' idx' : 0 , ' items' : []})
317+ let l: pos = l: qf .idx
318+ let l: parent = l: qf .items
319+ let l: level = count (l: parent [l: pos- 1 ].text, g: lsp_tree_incoming_prefix )
320+ 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 )
321+ endif
310322 call setqflist ([])
311323 call setqflist (a: ctx [' list' ])
312324 echo ' Retrieved ' . a: type
313325 botright copen
326+ if get (a: ctx , ' add_tree' , v: false )
327+ " move the cursor to the newly added item
328+ execute l: pos + 1
329+ endif
314330 else
315331 let l: lines = readfile (l: loc [' filename' ])
316332 if has_key (l: loc ,' viewstart' ) " showing a locationLink
0 commit comments