-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Don't show chaining hints for record literals and unit structs #3797
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
Conversation
d5fc772 to
86b0283
Compare
86b0283 to
5ad7fc3
Compare
|
Fixes #3796 actually* |
|
I wonder if there are other expression types we might want to exclude. I think it's fine to leave tuples in. |
|
Unit structs maybe and the unit type itself? Basically i think the most general heuristic is "whether the text already contains the type name" |
|
Good point about those. I'm not sure how to filter them, though, as they show up as a |
|
Hard to say, looks like we can use the if let Some(ra_hir::Adt::Struct(st)) = sema.type_of_expr(expr).as_adt() {
if matches!(st.variant_data(), ra_hir_def::VariantData::Unit) {
}
} |
|
Actually, I think the first approach should mostly be using the |
|
r? @SomeoneToIgnore :) |
|
|
|
Will have a look in an hour. |
5ad7fc3 to
7bd1096
Compare
crates/ra_ide/src/inlay_hints.rs
Outdated
| return None; | ||
| } | ||
| if let Some(Adt::Struct(st)) = ty.as_adt() { | ||
| if st.fields(sema.db).is_empty() { |
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.
I'm still not a fan of the extra allocations.
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.
You cannot avoid them completely with the current approach to the API, where we avoid excessive reference and lifetimes usage, so I think it's a compromise we have to live with for now.
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.
Why not making this a getter like kind -> Union | Record | Tuple. But, here is what I've thought. This will be a false-positive when the expression is not the struct literal, but e.g. some function call that returns a unit or empty-tuple struct. Maybe we lack ra_hir::Expr representation for such cases where we want to determine the kind of expression?
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.
Good point, added a check for PathExpr.
SomeoneToIgnore
left a comment
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.
LGTM when the "compilation error" in the test is fixed
7bd1096 to
10dd3c9
Compare
By the way the PR looks now, it does exaclty this, having the main logic check in Personally, I'm more concerned about the "do not display chain hint" logic spread over 3 places in the file, but that may be addressed later by some other PR. |
10dd3c9 to
70960df
Compare
|
r? @matklad 😄 |
|
bors r+ |
Build succeeded |
Fixes #3796
r? @Veetaha