rust-lang / rust-lang/rust-analyzer

Add a textmate grammar to better highlight mod path on-hover in vscode

Open
#4,595 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-hover A-vscode C-enhancement S-actionable
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

The problem: add syntax highlight to mod path in on-hover messages.

It would be cool if we added a TextMate grammar that extends markdown fenced code blocks
and adds syntax highlighting for module paths in on-hover messages.

See the sentence in vsocode docs about injection grammars:

Example applications of injection grammars:

  • Adding highlighting for a new language to Markdown fenced code blocks.

So we could enclose the mod path in on-hover message with some custom markdown fenced block like

```rust_mod_path
path::to::the::module
```
```rust
fn signature_of_the_symbol();
```

and assign to the parts of the mod path better textmate scopes so that it is colorized.
E.g., notice how real code mod paths are greenish, while the on-hover message has completely white mod path
Screenshot from 2020-05-24 18-38-54
Of course, we cannot do semantic highlighting in on-hover message (which is a pitty), but we could heuristically assign module token scope to lowercased identifier parts and heuristically struct token scope for PascalCase identifier parts.

I am not sure how we can really hack some semantic highlighting there to further take apart stuct/trait/enum names in there, because textmate uses regular expressions to analyze the input and the only way we can convey this semantic info to it is by adding some anchor symbols for it to determine which kind of token it sees (struct/enum/trait), but this will distort the user experience with foreign characters in mod path.

Maybe we can just hook in our custom on-hover middleware in TypeScript part using the vscode highlighting api directly to preprocess the mod path. This just needs more investigation

cc @matklad @georgewfraser

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the VS Code injection-grammar guidance linked in the issue, then investigate the TypeScript on-hover middleware option described there. Done means module paths in Rust Analyzer hover messages receive useful syntax scopes and highlighting without distorting the displayed text.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, typescript, vscode
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.