vscode-rust icon indicating copy to clipboard operation
vscode-rust copied to clipboard

Symbol hierarchy

Open Skasselbard opened this issue 7 years ago • 13 comments

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: image

With a hierarchy like in html, the view would be much clearer: image

Skasselbard avatar Aug 18 '17 13:08 Skasselbard

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.

nrc avatar Aug 18 '17 20:08 nrc

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.

Skasselbard avatar Aug 20 '17 08:08 Skasselbard

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?

mikebenfield avatar Oct 03 '17 19:10 mikebenfield

Any update on this? rls-analysis merged the required pull request, and released 0.11.2 28 days ago

LordZane avatar Mar 30 '18 02:03 LordZane

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.

pkoenig10 avatar Mar 30 '18 02:03 pkoenig10

The VSCode team is implementing a native outline panel. The API is being discussed here: https://github.com/Microsoft/vscode/issues/34968

cauebs avatar Jun 07 '18 06:06 cauebs

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.

irrigator avatar Jul 21 '18 04:07 irrigator

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

LordZane avatar Aug 06 '18 16:08 LordZane

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!

charles-lai avatar Feb 05 '19 06:02 charles-lai

Somewhat blocked on https://github.com/rust-lang/rls/issues/1377.

Xanewok avatar Apr 07 '19 11:04 Xanewok

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.

PhilipDaniels avatar Jul 18 '19 08:07 PhilipDaniels

I'm using this plugin (https://github.com/rust-analyzer/rust-analyzer/releases/tag/2020-12-21) and the issue is almost solved.

PeterLinX avatar Dec 25 '20 09:12 PeterLinX

It seems that this issue still exists by now. The plugin mentioned above does indeed support symbol hierarchy.

cmpute avatar Jan 22 '22 21:01 cmpute