Skip to content

Commit

Permalink
Fix making location list from call hierarchy items (#1113)
Browse files Browse the repository at this point in the history
* fix making location list from call hierarchy items (fix #1112)
* use kind and name when detail is not available on handling call hierarchy item
  • Loading branch information
rhysd authored Mar 21, 2021
1 parent 2ba31c2 commit b8e75ef
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions autoload/lsp/ui/vim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,12 @@ function! s:handle_call_hierarchy(ctx, server, type, data) abort

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

Expand All @@ -431,3 +434,25 @@ function! s:handle_call_hierarchy(ctx, server, type, data) abort
endif
endif
endfunction

function! s:hierarchy_item_to_vim(item, server) abort
let l:uri = a:item['uri']
if !lsp#utils#is_file_uri(l:uri)
return v:null
endif

let l:path = lsp#utils#uri_to_path(l:uri)
let [l:line, l:col] = lsp#utils#position#lsp_to_vim(l:path, a:item['range']['start'])
if has_key(a:item, 'detail')
let l:text = a:item['detail']
else
let l:text = '[' . lsp#ui#vim#utils#_get_symbol_text_from_kind(a:server, a:item['kind']) . '] ' . a:item['name']
endif

return {
\ 'filename': l:path,
\ 'lnum': l:line,
\ 'col': l:col,
\ 'text': l:text,
\ }
endfunction

0 comments on commit b8e75ef

Please sign in to comment.