Unnamed repository; edit this file 'description' to name the repository.
fix: only special casing 3 colon in a row
yue4u 2022-11-26
parent 7a568f7 · commit e1de04d
-rw-r--r--crates/ide-completion/src/context.rs22
-rw-r--r--crates/ide-completion/src/tests/special.rs8
2 files changed, 4 insertions, 26 deletions
diff --git a/crates/ide-completion/src/context.rs b/crates/ide-completion/src/context.rs
index a0e1153f08..0e3b677f2d 100644
--- a/crates/ide-completion/src/context.rs
+++ b/crates/ide-completion/src/context.rs
@@ -581,7 +581,9 @@ impl<'a> CompletionContext<'a> {
return None;
}
- if !is_prev_token_valid_path_start_or_segment(&prev_token) {
+ // has 3 colon in a row
+ // special casing this as per discussion in https://github.com/rust-lang/rust-analyzer/pull/13611#discussion_r1031845205
+ if prev_token.prev_token().map(|t| t.kind() == T![:]).unwrap_or(false) {
return None;
}
}
@@ -637,24 +639,6 @@ impl<'a> CompletionContext<'a> {
}
}
-fn is_prev_token_valid_path_start_or_segment(token: &SyntaxToken) -> bool {
- if let Some(prev_token) = token.prev_token() {
- // token before coloncolon is invalid
- if !matches!(
- prev_token.kind(),
- // trival
- WHITESPACE | COMMENT
- // PathIdentSegment
- | IDENT | T![super] | T![self] | T![Self] | T![crate]
- // QualifiedPath
- | T![>]
- ) {
- return false;
- }
- }
- true
-}
-
const OP_TRAIT_LANG_NAMES: &[&str] = &[
"add_assign",
"add",
diff --git a/crates/ide-completion/src/tests/special.rs b/crates/ide-completion/src/tests/special.rs
index 6cfa72d653..0e59f4ec54 100644
--- a/crates/ide-completion/src/tests/special.rs
+++ b/crates/ide-completion/src/tests/special.rs
@@ -967,17 +967,11 @@ fn foo { crate:$0 }
}
#[test]
-fn no_completions_in_invalid_path() {
+fn no_completions_in_after_tripple_colon() {
check(
r#"
fn foo { crate:::$0 }
"#,
expect![""],
);
- check(
- r#"
-fn foo { crate::::$0 }
-"#,
- expect![""],
- );
}