Skip to content

Flatten highlights #3447

@matklad

Description

@matklad

The highlight function currently returns a Vec<HighlightedRange>. However, those highlighting ranges can be nested. I believe that for something like #[cfg(feature = "foo")] we produce the range for the whole attribute, and then, separately, a range for a string literal.

It seems like all the clients of syntax highlighting actually want a flat list of highlights. We should refactor highlight so that it produces such flat list. One obvious way to do this is to post-process the current return type, but, given that internally we walk the tree in dfs manner, perhaps we can just not produce nested things in the first place?

The relevant code is here:

https://github.com/rust-analyzer/rust-analyzer/blob/a5da660bd5953c046db5f0bff854c00d830da9c8/crates/ra_ide/src/syntax_highlighting.rs#L34-L38

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-has-instructionsIssue has some instructions and pointers to code to get startedE-medium

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions