rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.23k stars 1.6k forks source link

[feature request] more ide features (hover, goto definition, completion/fly-imports, etc...) in documentation code snippets. #12400

Open jhgg opened 2 years ago

jhgg commented 2 years ago

rust-analyzer already provides highlighting in these code snippets in documentation:

image

I think that it would be really awesome if we could also provide some IDE features in these snippets, namely hover, inlay hints, goto defintion and autocomplete/flyimports, rename, and maybe even diagnostics (perhaps diagnostics/inlay hints should only be active while your cursor is within the doc snippet to not be annoying outside of editing the snippet). It would make writing documentation examples much much easier and delightful too.

NotWearingPants commented 2 years ago

rust-analyzer already provides highlighting in these code snippets in documentation

My VSCode fails to do full syntax-highlighting in doc tests: image (rust-analyzer version: https://github.com/rust-lang/rust-analyzer/commit/7e95c14ea730c6b06f5760c8c92e69b9a6def828 2022-05-17 stable)

What editor are you using?

jhgg commented 2 years ago

What editor are you using?

vscode however I have many semantic token colors set - since this isn't syntax as recognized by vscode (since it's in a comment) - the only thing that can color these are semantic tokens. If you hover over the code that isn't being colored and use "inspect token and scopes" you should see the semantic tokens. You can then assign them a color in your editor config.

NotWearingPants commented 2 years ago

If you hover over the code that isn't being colored and use "inspect token and scopes" you should see the semantic tokens

I am aware of the feature and have checked it already, it's not a color problem, the parser is wrong (whether it's a TextMate grammar or semantic). As you can see vec.len() has the wrong type since it appears inside a function/macro call, while vec.push() is fine image image

jhgg commented 2 years ago

If you hover over the code that isn't being colored and use "inspect token and scopes" you should see the semantic tokens

I am aware of the feature and have checked it already, it's not a color problem, the parser is wrong (whether it's a TextMate grammar or semantic). As you can see vec.len() has the wrong type since it appears inside a function/macro call, while vec.push() is fine

Sorry, not really sure what you're asking then. If you want to know how I got colors in there it is via semantic token customization. The colors in my above example are also incorrect in the same fashion, no doubt because we probably are not descending into the macro to provide correct highlighting for tokens contained within.

alice-i-cecile commented 2 years ago

This appears to be a duplicate of #4170. The write-up here is great though!