Skip to content

Commit

Permalink
Print both symbol name and detail in loc_list
Browse files Browse the repository at this point in the history
This patch fixes the displayed loc_list items when
g:lsp_document_symbol_detail is set to v:true. Before, only the 'detail'
field was used, and the symbol name was not printed, whereas the
children of the hierarchy didn't have the symbol details printed at all
  • Loading branch information
kmARC committed Oct 17, 2023
1 parent c58edb9 commit a55c8f3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions autoload/lsp/ui/vim/utils.vim
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ function! s:symbols_to_loc_list_children(server, path, list, symbols, depth) abo
for l:symbol in a:symbols
let [l:line, l:col] = lsp#utils#position#lsp_to_vim(a:path, l:symbol['range']['start'])

if g:lsp_document_symbol_detail && !has_key(l:symbol, 'detail')
let l:symbol['detail'] = ''
endif
call add(a:list, {
\ 'filename': a:path,
\ 'lnum': l:line,
\ 'col': l:col,
\ 'text': lsp#ui#vim#utils#_get_symbol_text_from_kind(a:server, l:symbol['kind']) . ' : ' . printf('%' . a:depth. 's', ' ') . l:symbol['name'],
\ 'text': lsp#ui#vim#utils#_get_symbol_text_from_kind(a:server, l:symbol['kind']) . ' : ' . printf('%' . a:depth. 's', ' ') . (g:lsp_document_symbol_detail ? l:symbol['name'] . " " . l:symbol['detail'] : l:symbol['name']),

Check failure on line 50 in autoload/lsp/ui/vim/utils.vim

View workflow job for this annotation

GitHub Actions / runner / vint

[vint] reported by reviewdog 🐶 Prefer single quoted strings (see Google VimScript Style Guide (Strings)) Raw Output: autoload/lsp/ui/vim/utils.vim:50:191: Prefer single quoted strings (see Google VimScript Style Guide (Strings))
\ })
if has_key(l:symbol, 'children') && !empty(l:symbol['children'])
call s:symbols_to_loc_list_children(a:server, a:path, a:list, l:symbol['children'], a:depth + 1)
Expand All @@ -63,6 +66,9 @@ function! lsp#ui#vim#utils#symbols_to_loc_list(server, result) abort

if !empty(l:locations) " some servers also return null so check to make sure it isn't empty
for l:symbol in a:result['response']['result']
if g:lsp_document_symbol_detail && !has_key(l:symbol, 'detail')
let l:symbol['detail'] = ''
endif
if has_key(l:symbol, 'location')
let l:location = l:symbol['location']
if lsp#utils#is_file_uri(l:location['uri'])
Expand All @@ -72,7 +78,7 @@ function! lsp#ui#vim#utils#symbols_to_loc_list(server, result) abort
\ 'filename': l:path,
\ 'lnum': l:line,
\ 'col': l:col,
\ 'text': lsp#ui#vim#utils#_get_symbol_text_from_kind(a:server, l:symbol['kind']) . ' : ' . (g:lsp_document_symbol_detail ? l:symbol['detail'] : l:symbol['name']),
\ 'text': lsp#ui#vim#utils#_get_symbol_text_from_kind(a:server, l:symbol['kind']) . ' : ' . (g:lsp_document_symbol_detail ? l:symbol['name'] . " " . l:symbol['detail'] : l:symbol['name']),

Check failure on line 81 in autoload/lsp/ui/vim/utils.vim

View workflow job for this annotation

GitHub Actions / runner / vint

[vint] reported by reviewdog 🐶 Prefer single quoted strings (see Google VimScript Style Guide (Strings)) Raw Output: autoload/lsp/ui/vim/utils.vim:81:168: Prefer single quoted strings (see Google VimScript Style Guide (Strings))
\ })
endif
else
Expand All @@ -84,7 +90,7 @@ function! lsp#ui#vim#utils#symbols_to_loc_list(server, result) abort
\ 'filename': l:path,
\ 'lnum': l:line,
\ 'col': l:col,
\ 'text': lsp#ui#vim#utils#_get_symbol_text_from_kind(a:server, l:symbol['kind']) . ' : ' . (g:lsp_document_symbol_detail ? l:symbol['detail'] : l:symbol['name']),
\ 'text': lsp#ui#vim#utils#_get_symbol_text_from_kind(a:server, l:symbol['kind']) . ' : ' . (g:lsp_document_symbol_detail ? l:symbol['name'] . " " . l:symbol['detail'] : l:symbol['name']),

Check failure on line 93 in autoload/lsp/ui/vim/utils.vim

View workflow job for this annotation

GitHub Actions / runner / vint

[vint] reported by reviewdog 🐶 Prefer single quoted strings (see Google VimScript Style Guide (Strings)) Raw Output: autoload/lsp/ui/vim/utils.vim:93:168: Prefer single quoted strings (see Google VimScript Style Guide (Strings))
\ })
if has_key(l:symbol, 'children') && !empty(l:symbol['children'])
call s:symbols_to_loc_list_children(a:server, l:path, l:list, l:symbol['children'], 1)
Expand Down

0 comments on commit a55c8f3

Please sign in to comment.