rust-lang / rust-lang/rust-analyzer
Completions in macros should consider the fragment type they are part of
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
macro_rules! tuple_to_record_closure {
($ident:ident { $( $field:ident ),+ $(,)? }) => {
|($( $field ),+)| $ident { $( $field ),+ }
};
}
struct Foo { foo: () }
fn main() {
tuple_to_record_closure! {
Foo {
f$0
}
}
}
Typing at the cursor position gives us various completions, one of which is the Foo { foo }: Foo pattern completion as the identifier is used in a pattern position in the expansion. This completion is wrong though, as applying it will lead to syntax errors. In this case we need to consider that the identifier we are completing is being captures as an $ident fragment, as such only stupid identifier completions should be allowed. OTOH if it was a $pat fragment capture, this completion would be fine.
We currently lack the ability of figuring out what kind of fragment type a token got captured by, so that needs to be done first. https://github.com/rust-analyzer/rust-analyzer/issues/11183
cc https://github.com/rust-analyzer/rust-analyzer/issues/11058
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
Start with the reproducer in the issue and read issue #11183, which tracks determining the fragment type captured by a macro token. Trace how completion handles the identifier inside the macro expansion. Done means an $ident capture offers only identifier completions, while a $pat capture can offer pattern completions without producing syntax errors.
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
- 45/100