Skip to content

Conversation

Veykril
Copy link
Member

@Veykril Veykril commented Feb 12, 2021

This PR moves the filering for enum constructors to the HIR, with this unprefixed variants as well as when the enum has been renamed via use will then still show up properly.
We now walk the ast of the NameRef up until we find a PathExpr(which also handles CallExpr for tuple-type structs and variants already) or a RecordExpr. For enum search we then take the path out of that expression and do a resolution on it to compare it with the definition enum.
With this PR we now support searching for all constructor literals, Unit-, Tuple- and Record-Structs, Unit-, Tuple- and Record-Variants as well as Unions.

There is one shortcoming due to how the search is triggered. Unit Variants constructors can't be searched as we have no position for it to kick off the search(since a comma doesn't have to exist for the last variant).

Closes #2549 though it doesn't implement it as outlined in the issue since the reference kind was removed recently, though I believe the approach taken here is better personally.

For all struct kinds, unions and enums, as well as for record- and
tuple-variants but not for unit-variants, as these have no trailing
character we can anchor the search to. Functionality wise it is
implemented though.
@matklad
Copy link
Contributor

matklad commented Feb 14, 2021

bors r+

I believe the approach taken here is better personally.

I do think that classification (rather than filtering) approach is preferable long term. The ideal client will show the search results grouped by the kind of occurrence:

created: 4 references
  ...
written: 10 references
  ...
read: 92 references
  ...

That'd be waaay more discoverable that "place the cursor on the {". But, as we don't have such an ideal client, the current impl is OK

@bors
Copy link
Contributor

bors bot commented Feb 14, 2021

@bors bors bot merged commit a0322de into rust-lang:master Feb 14, 2021
@Veykril Veykril deleted the lit-search branch February 14, 2021 16:33
@lnicola
Copy link
Member

lnicola commented Feb 15, 2021

ctor-search

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Find usages for struct "constructors"

3 participants