-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
completion relevance consider if types can be unified #8056
completion relevance consider if types can be unified #8056
Conversation
I do have a few questions since I am not very familiar with the type inference code. @flodiebold ?
|
Hmm, CI is failing for a lint I don't see locally. And applying the fix breaks compilation.
|
We use |
I believe I'm running with the latest stable compiler locally. I can re-create the lint by running But I'm still not sure why I'm seeing this lint, given the suggested fix doesn't work. |
Looks like this is the same as a bug reported a couple years ago, although it seems that was fixed 🤷 |
Actually it looks like there is a newer bug report for this, which is still open. I suppose I should add an |
f558e51
to
cb4d024
Compare
cb4d024
to
9436043
Compare
I think adding it for now is fine. We might revamp the HIR type API, but only after the Chalk move.
So, the problem here is that the (Also worth noting that what we'd really want is to check coercion, if the completion is happening at a coercion site...) |
Let’s distinguish between “can unify” and “exact match” in the relevance, so that things like Default::default are less relevant than specific types. |
24e6a9f
to
e80e58c
Compare
@@ -122,7 +122,7 @@ impl fmt::Debug for CompletionItem { | |||
} | |||
} | |||
|
|||
#[derive(Debug, Clone, Copy, Ord, PartialOrd, Eq, PartialEq, Default)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These weren't used, because CompletionRelevance
should only be compared by score. I could re-implement them in terms of score, but that would require updating the Eq
impl which we use in a different way, so it would broaden the scope of this PR a bit.
The reason I removed these at all in this PR is because it didn't make sense to me to derive them on the new enum CompletionRelevanceTypeMatch
.
/// ``` | ||
/// fn foo() { | ||
/// let bar = 0; | ||
/// $0 // `bar` is local |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is unrelated to this PR, but combining these two examples has been discussed as something we'd like to do.
e80e58c
to
80dac6a
Compare
I've updated this to distinguish between these cases, and score an exact match as more relevant than types which can unify. |
80dac6a
to
e6891dc
Compare
e6891dc
to
0e31ae2
Compare
bors r+ |
changelog feature for completion, take into account whether types unify: |
This PR improves completion relevance scoring for generic types, in cases where the types could unify.
Before
After
changelog feature improve completions