Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support hierarchical document symbols #316

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

Conversation

greye
Copy link

@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
Owner

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

@greye
Copy link
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
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
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
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
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
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
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
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
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
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
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.

endif
let g:vista.functions =
\ filter(copy(symlist), 'v:val.kind ==? "Method" || v:val.kind ==? "Function"')
Copy link
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