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
feat: Implement completion for the callable fields. #15879
Conversation
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.
Some nits and notes, but overall LGTM.
I've now added the tests for both the cases you mentioned and made the refactors as well. |
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.
Just one last nit that I missed in the first review, and otherwise LGTM.
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.
There is one interesting case that we should also have a test for which is foo.bar::<>
, I think this should result in a DotAccessKind::Method { has_parens: false }
(the only case where its false I believe as otherwise missing parens will result in a field access node).
☔ The latest upstream changes (presumably #15825) made this pull request unmergeable. Please resolve the merge conflicts. |
For the |
I should complete to |
variable name change for clearer usage indication
Before it was inserting whenever function field is found but it should happend only in the case of function call.
Sorry I was busy with some thing and couldn't find time to fix the tests. I have fixed the tests now. I'll create a follow up PR for the |
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.
Sorry for all the review rounds and thanks for sticking with it, this should be the last :)
|acc, field, ty| acc.add_tuple_field(ctx, None, field, &ty), | ||
is_field_access, | ||
); | ||
|
||
if let DotAccessKind::Method { .. } = dot_access.kind { | ||
cov_mark::hit!(test_no_struct_field_completion_for_method_call); |
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 cov mark makes little sense to be tested like this now (since the else
branch is gone, which was what this mark wanted to assert is not being called)
"#, | ||
r#" | ||
struct S { va_field: u32, fn_field: fn() } | ||
fn foo() { (S { va_field: 0, fn_field: || {} }).fn_field() } |
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 is why I wanted the check_edit
test :^) The output here is wrong, this should be
fn foo() { (S { va_field: 0, fn_field: || {} }).fn_field() } | |
fn foo() { (S { va_field: 0, fn_field: || {} }.fn_field)() } |
This is how you call fields in rust (to disambiguate from method calls)
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.
Sorry for all the review rounds and thanks for sticking with it, this should be the last :)
No worries, this is just lesson for me to put good a PR next time.
I keep getting confused where to put the end parenthesis. I somehow finally decided this was correct thing, my bad.
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.
No worries, this is just lesson for me to put good a PR next time.
All good, the r-a code base takes time to get accustomed to, and the ide-completion crate is a part where I put more review rounds in in terms of quality than ide-assists for example, so I am a bit more thorough here
I keep getting confused where to put the end parenthesis. I somehow finally decided this was correct thing, my bad.
Understandable, it is a rarely used quirk of the language.
crates/ide-completion/src/render.rs
Outdated
if let Some(receiver) = ctx.completion.sema.original_ast_node(receiver.clone()) { | ||
let range = receiver.syntax().text_range(); | ||
builder.insert(range.start(), "(".to_string()); | ||
builder.insert(range.end(), ")".to_string()); |
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.
To fix the wrong edit we should probably just check the parent of the (original ast node) receiver here, if its a field add the closing parenthesis after the field etc.
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.
Yeah, I should do something like this, right? I suppose storing the range is kinda useless now.
builder.insert(receiver.syntax().text_range().start(), "(".to_string());
builder.insert(ctx.source_range().end(), ")".to_string());
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.
Ye that should work I think
Thanks! |
☀️ Test successful - checks-actions |
fix: make callable fields not complete in method access no parens case Follow up PR for #15879 Fixes the callable field completion appearing in the method access with no parens case.
Fixes #14656
PR is opened with basic changes. It could be improved by having a new
SymbolKind
for the callable fields and implementing a separate render function similar to therender_method
for the newSymbolKind
.It could also be done without any changes to the
SymbolKind
of course, have the new function called based on the type of field.I prefer the former method.
Please give any thoughts or changes you think is appropriate for this method. I could start working on that in this same PR.