-
-
Notifications
You must be signed in to change notification settings - Fork 88
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
base: master
Are you sure you want to change the base?
Conversation
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. |
endfunction | ||
|
||
function! s:IsDocumentSymbol(sym) | ||
return has_key(a:sym, 'selectionRange') |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
autoload/vista/parser/lsp.vim
Outdated
\ 'kind': a:symbol.kind, | ||
\ 'level': a:symbol.level | ||
\ }) | ||
function! vista#parser#lsp#FilterDocumentSymbols(symbols) abort |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
autoload/vista/parser/lsp.vim
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be simplified as:
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.
There was a problem hiding this comment.
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"') |
There was a problem hiding this comment.
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
.
Needs support from both LSP client and server.
Falls back to grouping symbols by kind when not supported.
Uses CoC data model and renderer.