-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: filter unnecessary completions after colon #13611
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
@@ -812,18 +812,6 @@ pub(crate) fn handle_completion( | |||
let completion_trigger_character = | |||
params.context.and_then(|ctx| ctx.trigger_character).and_then(|s| s.chars().next()); | |||
|
|||
if Some(':') == completion_trigger_character { |
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.
It's possible to keep the filtering here but
- it's not testable (here)
- we need to parse the file when trigger is
Some(':') | None
anyway and I hope this change has similar perf (filtered before context creation) - actually the new behavior has nothing to do with the trigger char
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.
the filtering definitely should not be happening here, so moving the handling into the ide-completion crate seems proper to me 👍
@@ -893,3 +902,89 @@ fn f() { | |||
"#]], | |||
); | |||
} | |||
|
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.
not sure if putting tests here (special.rs) is better than https://github.com/rust-lang/rust-analyzer/blob/45ec315e01dc8dd1146dfeb65f0ef6e5c2efed78/crates/ide-completion/src/tests.rs
I didn't find any expect_test
usage there and not sure if there are any reasons for that
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.
Apologies, I thought I had already reviewed this last week
@@ -812,18 +812,6 @@ pub(crate) fn handle_completion( | |||
let completion_trigger_character = | |||
params.context.and_then(|ctx| ctx.trigger_character).and_then(|s| s.chars().next()); | |||
|
|||
if Some(':') == completion_trigger_character { |
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.
the filtering definitely should not be happening here, so moving the handling into the ide-completion crate seems proper to me 👍
crates/ide-completion/src/context.rs
Outdated
T![:] => { | ||
// return if no prev token before colon | ||
let prev_token = original_token.prev_token()?; | ||
|
||
// only has a single colon | ||
if prev_token.kind() != T![:] { | ||
return None; | ||
} | ||
|
||
if !is_prev_token_valid_path_start_or_segment(&prev_token) { | ||
return None; | ||
} | ||
} |
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 think we can just return None if we find a T![:]
without any additional checks? The previous token can't be another T![:]
as the parser should produce a T![::]
then I think?
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.
Parser will produce two continuous T![:]
if we are inside token streams and that's the case I wanted to support as the video in the description.
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.
However that will produce too much noise if we are accidentally typing like :::
. Every single :
after will trigger the completion again. So I introduced is_prev_token_valid_path_start_or_segment
to solve that. I know it's invalid input but felt this behavior pretty annoying during testing without the check.
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.
Oh I see, ye then we need something like that here. Though I think this is still too restrictive, so maybe let's instead check that we either have a ::
, or exactly two :
tokens in a row (but not three)? I think that's a decent trade off unless I am missing something else. We can't make completions in macros perfect unfortunately. In the future if we know about fragment types for inputs this can be potentially refined.
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.
updated in .b701b14ca5b195fd6e227b913a912a4fcc87efb0 I mean e1de04d
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
I removed the check before
|
@rustbot label -S-waiting-on-author +S-waiting-on-review |
b701b14
to
e1de04d
Compare
@rustbot label -S-waiting-on-author +S-waiting-on-review |
); | ||
check( | ||
r#" | ||
fn foo { crate::::$0 } |
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.
Ah wait, we no longer catch this because the token here is a ::
again right? Let's add that to the check as well as it is simple, I forgot that :) That is, t.kind() == T![:] || t.kind() == T![::]
for the previous token check
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.
done 1ca5cb7
@bors delegate+ |
✌️ @yue4u can now approve this pull request |
@bors r+ |
☀️ Test successful - checks-actions |
close #13597
related: #10173
This PR also happens to fix two extra issues:
after:
tt.mp4
2. completions were triggered even in invalid paths, like
only
:::
and::::
is excluded as discussed in #13611 (comment)