Skip to content

Commit b8e75ef

Browse files
authored
Fix making location list from call hierarchy items (#1113)
* fix making location list from call hierarchy items (fix #1112) * use kind and name when detail is not available on handling call hierarchy item
1 parent 2ba31c2 commit b8e75ef

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

autoload/lsp/ui/vim.vim

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,12 @@ function! s:handle_call_hierarchy(ctx, server, type, data) abort
413413

414414
if lsp#client#is_error(a:data['response']) || !has_key(a:data['response'], 'result')
415415
call lsp#utils#error('Failed to retrieve '. a:type . ' for ' . a:server . ': ' . lsp#client#error_message(a:data['response']))
416-
else
416+
elseif a:data['response']['result'] isnot v:null
417417
for l:item in a:data['response']['result']
418-
let a:ctx['list'] = a:ctx['list'] + lsp#utils#location#_lsp_to_vim_list(l:item[a:ctx['key']])
418+
let l:loc = s:hierarchy_item_to_vim(l:item[a:ctx['key']], a:server)
419+
if l:loc isnot v:null
420+
let a:ctx['list'] += [l:loc]
421+
endif
419422
endfor
420423
endif
421424

@@ -431,3 +434,25 @@ function! s:handle_call_hierarchy(ctx, server, type, data) abort
431434
endif
432435
endif
433436
endfunction
437+
438+
function! s:hierarchy_item_to_vim(item, server) abort
439+
let l:uri = a:item['uri']
440+
if !lsp#utils#is_file_uri(l:uri)
441+
return v:null
442+
endif
443+
444+
let l:path = lsp#utils#uri_to_path(l:uri)
445+
let [l:line, l:col] = lsp#utils#position#lsp_to_vim(l:path, a:item['range']['start'])
446+
if has_key(a:item, 'detail')
447+
let l:text = a:item['detail']
448+
else
449+
let l:text = '[' . lsp#ui#vim#utils#_get_symbol_text_from_kind(a:server, a:item['kind']) . '] ' . a:item['name']
450+
endif
451+
452+
return {
453+
\ 'filename': l:path,
454+
\ 'lnum': l:line,
455+
\ 'col': l:col,
456+
\ 'text': l:text,
457+
\ }
458+
endfunction

0 commit comments

Comments
 (0)