rust-lang / rust-lang/rust-analyzer

Completions in macros should be aware of completing multiple idents

Open
#11,058 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-completion A-macro C-Architecture C-feature E-hard fun S-actionable
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

When typing inside a macro we should consider all downmapped positions of the ident we are currently typing out instead of just the first one, that way we get more completions that might make sense.

Example given the following macro:


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 given position should offer the completion of the foo field as the ident is downmapped to a field position as its second usage, currently we only consider the parameter position though.

This also has the potential to create a lot of duplicate completions which have to be filtered out, as well as making completions in macros potentially very slow if we were to stupidly repeat completions for each downmapped token, so this probably requires some architecture changes if we want to pursue this.

cc https://github.com/rust-analyzer/rust-analyzer/issues/11059

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 macro example in the issue and trace completion handling for downmapped identifier positions. Compare the current first-position behavior with all downmapped uses, including the field position. Done means the example offers the Foo.foo field completion without duplicate results or impractical slowdown.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.