Skip to content

Support hierarchical document symbols#316

Open
greye wants to merge 14 commits intoliuchengxu:masterfrom
greye:master
Open

Support hierarchical document symbols#316
greye wants to merge 14 commits intoliuchengxu:masterfrom
greye:master

Conversation

@greye
Copy link
Copy Markdown

@greye greye commented Jul 6, 2020

Needs support from both LSP client and server.
Falls back to grouping symbols by kind when not supported.
Uses CoC data model and renderer.

@liuchengxu
Copy link
Copy Markdown
Owner

Is there any language server that I can try this without using coc?

@greye
Copy link
Copy Markdown
Author

greye commented Jul 6, 2020

Is there any language server that I can try this without using coc?

I'm using modified vim-lsc (had to set proper capability) with clangd.
Basically, any compatible client-server pair should work the same provided both have support and capabilities set.

endfunction

function! s:IsDocumentSymbol(sym)
return has_key(a:sym, 'selectionRange')
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? The author of previous patch about this part uses the range.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both range and selectionRange are mandatory in documentSymbol response, the latter is used for consistency with CoC behavior.

" https://microsoft.github.io/language-server-protocol/specification#textDocument_documentSymbol
function! vista#parser#lsp#ExtractSymbol(symbol, container) abort
let symbol = a:symbol
function! vista#parser#lsp#DispatchDocumentSymbols(symbols)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be used only once, therefore it's not worthy to define another function.

\ 'kind': a:symbol.kind,
\ 'level': a:symbol.level
\ })
function! vista#parser#lsp#FilterDocumentSymbols(symbols) abort
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function don't have to be public.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DispatchDocumentSymbols and FilterDocumentSymbols were made public to allow to reuse them in actual CoC handler: the latter contains this exact code.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, where is the actual coc handler?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lsp.vim:133: vista#parser#lsp#CocSymbols

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, not really: CocSymbols is to be replaced, handler is in executive/coc.vim: s:Extract

Comment on lines +68 to +73
for lspsym in a:symbols
let loc = lspsym.location
if s:IsFileUri(loc.uri)
call add(a:outlist, s:LspToLocalSymbol(lspsym, loc.range))
endif
endfor
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be simplified as:

Suggested change
for lspsym in a:symbols
let loc = lspsym.location
if s:IsFileUri(loc.uri)
call add(a:outlist, s:LspToLocalSymbol(lspsym, loc.range))
endif
endfor
let outlist = map(filter(symbols, 's:IsFileUri(v:val["localtion"]["uri"])'), 's:LspToLocalSymbol(v:val, v:val["location"]["range"])')

Then no need to define this function.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change is ok, but I'd rather leave the function in place to highlight complementary nature of ParseSymboInfoList and ParseDocumentSymbolsRec. Actually both of them use the same functional interface for consistency.

call filter(symlist, 'index(g:vista_ignore_kinds, v:val) < 0')
endif
let g:vista.functions =
\ filter(copy(symlist), 'v:val.kind ==? "Method" || v:val.kind ==? "Function"')
Copy link
Copy Markdown
Owner

@liuchengxu liuchengxu Jul 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure which one is better, if you put this filter logic into s:GroupSymbolsByKind(), then you have only one for loop, these two fitler can be saved and don't have to worry about the copy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants