From e1de04d60ceff530295f57ae47a65e9c05716bbf Mon Sep 17 00:00:00 2001 From: yue4u Date: Sun, 27 Nov 2022 01:53:45 +0900 Subject: [PATCH] fix: only special casing 3 colon in a row --- crates/ide-completion/src/context.rs | 22 +++------------------- crates/ide-completion/src/tests/special.rs | 8 +------- 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/crates/ide-completion/src/context.rs b/crates/ide-completion/src/context.rs index a0e1153f08b..0e3b677f2d6 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 6cfa72d6539..0e59f4ec541 100644 --- a/crates/ide-completion/src/tests/special.rs +++ b/crates/ide-completion/src/tests/special.rs @@ -967,16 +967,10 @@ 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![""], );