Skip to content

Commit b701b14

Browse files
committed
fix: only special casing 3 colon in a row
1 parent 7a568f7 commit b701b14

File tree

2 files changed

+5
-27
lines changed

2 files changed

+5
-27
lines changed

crates/ide-completion/src/context.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -573,15 +573,17 @@ impl<'a> CompletionContext<'a> {
573573
// this approach works in normal path and inside token tree
574574
match original_token.kind() {
575575
T![:] => {
576-
// return if no prev token before colon
576+
// no prev token before colon
577577
let prev_token = original_token.prev_token()?;
578578

579579
// only has a single colon
580580
if prev_token.kind() != T![:] {
581581
return None;
582582
}
583583

584-
if !is_prev_token_valid_path_start_or_segment(&prev_token) {
584+
// has 3 colon in a row
585+
// special casing this as per discussion in https://github.com/rust-lang/rust-analyzer/pull/13611#discussion_r1031845205
586+
if prev_token.prev_token().map(|t| t.kind() == T![:]).unwrap_or(false) {
585587
return None;
586588
}
587589
}
@@ -637,24 +639,6 @@ impl<'a> CompletionContext<'a> {
637639
}
638640
}
639641

640-
fn is_prev_token_valid_path_start_or_segment(token: &SyntaxToken) -> bool {
641-
if let Some(prev_token) = token.prev_token() {
642-
// token before coloncolon is invalid
643-
if !matches!(
644-
prev_token.kind(),
645-
// trival
646-
WHITESPACE | COMMENT
647-
// PathIdentSegment
648-
| IDENT | T![super] | T![self] | T![Self] | T![crate]
649-
// QualifiedPath
650-
| T![>]
651-
) {
652-
return false;
653-
}
654-
}
655-
true
656-
}
657-
658642
const OP_TRAIT_LANG_NAMES: &[&str] = &[
659643
"add_assign",
660644
"add",

crates/ide-completion/src/tests/special.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -967,16 +967,10 @@ fn foo { crate:$0 }
967967
}
968968

969969
#[test]
970-
fn no_completions_in_invalid_path() {
970+
fn no_completions_in_after_tripple_colon() {
971971
check(
972972
r#"
973973
fn foo { crate:::$0 }
974-
"#,
975-
expect![""],
976-
);
977-
check(
978-
r#"
979-
fn foo { crate::::$0 }
980974
"#,
981975
expect![""],
982976
);

0 commit comments

Comments
 (0)