vscode-rust
vscode-rust copied to clipboard
Symbol hierarchy
It would be nice if the discovered symbols would have a hierarchy so that tools like Code Outline can arrange them better for a better overview.
Currently all symbols of a rust file are displayed in the first level:
With a hierarchy like in html, the view would be much clearer:
Looks like we need to set the containerName
field of the SymbolInformation
we return for symbols. We have this info from the compiler, but we need to feed it through the RLS.
Also, this is a bit tricky for Rust (c.f., HTML or even Java, etc) because the syntactic nesting is not aligned with semantic nesting. E.g., if you have bar
defined in impl Foo
, should that be bested under Foo
? (It is semantically, but not syntactically). And if in impl Foo for Bar
, under Foo
or Bar
? This is more complicated because for the obvious syntactic nesting, we don't have symbols for the impls.
Well from a user perspective, what I value so much on the code outline in other IDE's, is the summery they provide and the quick navigation to points of interest. In object oriented languages they usually list global variables, classes and its members (class variables, defined types like enums and functions). In this case the outline lists all symbols defined in the file. You can see in my screenshot that e.g. the self symbol is listed several times, even though I pretty much don't care for any of them... But this is nothing you can influence.
From my perspective a useful hierarchy would mask such "uninteresting" symbols in a lower level and of course put the most interesting ones at a higher level.
The most valuable symbols for rust that are coming to my mind are types, (outer) functions and global variables, which seem to me are syntactically defined on a pretty outer level.
You are right that the the semantic information could be beneficial for the nesting. But at least for this use case I think it would be bearable to ignore it. Firstly because I would assume that a lot of files would contain a limited amount (probably often just one) of impl
's (especially if you consider trait implementations for a type as a part of its "default" impl
) and secondly they don't provide much navigation nor overview information.
I am not that deep into all of rusts possibilities, so it could be that I am missing some important things. But I hope it helps as feedback.
Is it possible to create a symbol for each impl
block as reported to VS Code, and then let each function and whatnot in the impl
be nested under that symbol? To my mind, the purpose of the outline is to navigate through the file, so why not let the hierarchy reflect the way they are in fact organized in the file?
Any update on this? rls-analysis merged the required pull request, and released 0.11.2 28 days ago
And it was added to rls in https://github.com/rust-lang-nursery/rls/pull/790.
It works correctly for me in Atom now using the latest nightly toolchain. I'm assuming it also works in VS Code.
The VSCode team is implementing a native outline panel. The API is being discussed here: https://github.com/Microsoft/vscode/issues/34968
I'm using the latest nightly toolchain and rls-vscode on macOS, and I find the outline view still displays function parameters and the hierarchy seems wrong.
I have the same 2 issues as above, function parameters are in the outline view for some reason (idk if that's intended), and there is no proper tree view, its just "{ }" as the root, and than everything else as a child of it
I have installed the newest version of rls and vscode. The vscode's native outline view still display rust symbols in flat mode. It's annoying and I can not find more hints on internet.
Is this issue resolved? Or just my settings are not correctly configured? I'm using rls 1.31.6 (c9d25b6 2019-01-20) with vscode 1.32.0.
Any help would be appreciated!
Somewhat blocked on https://github.com/rust-lang/rls/issues/1377.
Just wanted to add my voice to this issue. The current implementation makes the outline view pretty much useless for Rust code, unfortunately. Something (anything) that helps would be appreciated, such as @Skasselbard 's suggestions of just showing the higher level symbols. It doesn't have to be a Rolls-Royce solution in the first iteration.
I'm using this plugin (https://github.com/rust-analyzer/rust-analyzer/releases/tag/2020-12-21) and the issue is almost solved.
It seems that this issue still exists by now. The plugin mentioned above does indeed support symbol hierarchy.