Skip to content

Completions in macros should be aware of completing multiple idents #11058

Open
@Veykril

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 #11059

Metadata

Assignees

No one assigned

    Labels

    A-completionautocompletionA-macromacro expansionC-ArchitectureBig architectural things which we need to figure up-front (or suggestions for rewrites :0) )C-featureCategory: feature requestE-hardS-actionableSomeone could pick this issue up and work on it right nowfunA technically challenging issue with high impact

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions