rust-lang / rust-lang/rust-analyzer

Record macro fragment captures

Open
#11,183 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-ide A-macro C-Architecture E-unknown
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

In short we should be able to ask a token in a macro-call tokentree in what way it has been captured, that is the fragment type it got captured as as well as asking for all the tokens that are part of the same capture.

This would allow us to potentially offer more IDE features for declarative macro-call inputs, as an example lets look at our match_ast macro
https://github.com/rust-analyzer/rust-analyzer/blob/1ba9a924d7b161c52e605e157ee16d582e4a8684/crates/syntax/src/lib.rs#L186-L196
Using this macro causes the match arm expressions in the input to lose all inlay hints. This is due to the input being just a bunch of unparsed tokens, but the fragment captures give us enough information to tell what tokens make up a valid expression in the input which should allow us to properly add inlay hints to these.

Completions would also benefit from this information https://github.com/rust-analyzer/rust-analyzer/issues/11059

The token map rewrite might be relevant here https://github.com/rust-analyzer/rust-analyzer/issues/9403

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

Start with the match_ast macro example in crates/syntax/src/lib.rs and review the token map rewrite referenced by issue #9403. Trace how macro-call token trees represent captures, then determine how token fragment types and tokens sharing a capture should be exposed. Done means callers can query that capture information for IDE features such as inlay hints and completions.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.