-
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
fix(ide-completion): fix handling of for
in impl T for A
in function body
#18005
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
@lnicola Thanks! The fix per se looks good to me, but I wonder if this is in line with other stuff, such as: rust-analyzer/crates/ide-completion/src/tests/special.rs Lines 1266 to 1299 in 13ac53e
Do we really need all those suggestions? This PR eliminates |
We incorrectly land in a |
Given fn foo() {
struct X;
impl X fo { }
} we get a
(there is a show syntax tree command in vscode to get this view)
so there its a macro call. We should already be handling that case (I get a for completion there), so might be good to check how we handle that in completion analysis |
0d33a77
to
d4fdb5a
Compare
for
in impl T for A
in function body
@Veykril Thanks for your pointers! I think I've found a way to be less disruptive, let's see how the CI goes. Update: Checking fn foo() {
struct X;
impl X { fn bar() { $0 } }
} |
The proper fix will require changes in |
rust-analyzer/crates/ide-completion/src/completions/keyword.rs Lines 7 to 31 in 13ac53e
|
@Veykril I'm aware of this, it's just that the only possible context of this call is: rust-analyzer/crates/ide-completion/src/completions.rs Lines 775 to 777 in 13ac53e
Clearly it's not the same as in a In this case, given how the function is written, I guess Let me see what I can do to improve
|
d4fdb5a
to
e627f38
Compare
If the preceding token to the cursor is an |
I see. I believe it works outside of functions because you special-cased it: rust-analyzer/crates/ide-completion/src/context/analysis.rs Lines 1157 to 1161 in 13ac53e
... maybe I can apply a similar hack to this case. |
Yes thats the special case handling it outside of bodies, would be neat if that can be re-used though its probably a bit more tricky |
e627f38
to
3d13c7f
Compare
@Veykril So by adding the same hack to records in 3d13c7f, I was able to address the original issue. However, I'm still more interested in the |
What exaclty is with |
The
|
Isn't that this case? https://github.com/rust-lang/rust-analyzer/pull/18005/files#diff-9cef2bb04b7b1bc7d74e0d5822c991876dec30dce47004692a99369f18651442R166-R180 |
3d13c7f
to
c74a829
Compare
@Veykril No worries. I believe now I've fixed both of them. |
c74a829
to
0b28126
Compare
Thanks! |
☀️ Test successful - checks-actions |
Closes #17787.