@@ -19,7 +19,7 @@ use syntax::{
19
19
ast:: { self , AttrKind , NameOrNameRef } ,
20
20
AstNode ,
21
21
SyntaxKind :: { self , * } ,
22
- SyntaxToken , TextRange , TextSize ,
22
+ SyntaxToken , TextRange , TextSize , T ,
23
23
} ;
24
24
use text_edit:: Indel ;
25
25
@@ -569,6 +569,28 @@ impl<'a> CompletionContext<'a> {
569
569
// completing on
570
570
let original_token = original_file. syntax ( ) . token_at_offset ( offset) . left_biased ( ) ?;
571
571
572
+ // try to skip completions on path with qinvalid colons
573
+ // this approach works in normal path and inside token tree
574
+ match original_token. kind ( ) {
575
+ T ! [ : ] => {
576
+ // return if no prev token before colon
577
+ let prev_token = original_token. prev_token ( ) ?;
578
+
579
+ // only has a single colon
580
+ if prev_token. kind ( ) != T ! [ : ] {
581
+ return None ;
582
+ }
583
+
584
+ if !is_prev_token_valid_path_start_or_segment ( & prev_token) {
585
+ return None ;
586
+ }
587
+ }
588
+ T ! [ :: ] if !is_prev_token_valid_path_start_or_segment ( & original_token) => {
589
+ return None ;
590
+ }
591
+ _ => { }
592
+ }
593
+
572
594
let AnalysisResult {
573
595
analysis,
574
596
expected : ( expected_type, expected_name) ,
@@ -618,6 +640,24 @@ impl<'a> CompletionContext<'a> {
618
640
}
619
641
}
620
642
643
+ fn is_prev_token_valid_path_start_or_segment ( token : & SyntaxToken ) -> bool {
644
+ if let Some ( prev_token) = token. prev_token ( ) {
645
+ // token before coloncolon is invalid
646
+ if !matches ! (
647
+ prev_token. kind( ) ,
648
+ // trival
649
+ WHITESPACE | COMMENT
650
+ // PathIdentSegment
651
+ | IDENT | T ![ super ] | T ![ self ] | T ![ Self ] | T ![ crate ]
652
+ // QualifiedPath
653
+ | T ![ >]
654
+ ) {
655
+ return false ;
656
+ }
657
+ }
658
+ true
659
+ }
660
+
621
661
const OP_TRAIT_LANG_NAMES : & [ & str ] = & [
622
662
"add_assign" ,
623
663
"add" ,
0 commit comments