rust-lang / rust-lang/rust-analyzer
Injected rustdoc code blocks are not highlighted when used with a proc-macro attribute
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
This is related to #4170 but I'm hoping it might be possible to implement without larger architectural changes? Since many other RA features (including highlighting e.g. for fn parameters) can "look through" macros like this, I wonder if it's possible to add the same functionality to semantic token injection for rustdoc code blocks.
Example pmacro/lib.rs
use proc_macro::TokenStream;
// trivially emit the same tokens without modification
#[proc_macro_attribute]
pub fn noop(_attr: TokenStream, tokens: TokenStream) -> TokenStream {
tokens
}
lib.rs:
use pmacro::noop;
#[noop]
/// ```
/// println!("xyz");
/// ```
pub fn foo() {}
The resulting [EXPANSION].rs looks like
// Recursive expansion of noop macro
// ==================================
#[doc = " ```"]
#[doc = " println!(\"xyz\");"]
#[doc = " ```"]
pub fn foo() {}
In this case, I expect the println! code block to be highlighted with *.injected semantic tokens, but the actual result is that nothing is highlighted as long as the proc macro attribute is present. I also tried moving the #[noop] attribute after the doc comments, but the result is the same either way.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue using the proc-macro example in pmacro/lib.rs and the annotated function in lib.rs. Start by examining semantic token injection for rustdoc code blocks across the generated [EXPANSION].rs output. Done means the println! code block receives *.injected semantic tokens even when the #[noop] proc-macro attribute is present.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100