@@ -427,9 +427,21 @@ impl Builder {
427427 let insert_text = self . insert_text . unwrap_or_else ( || label. to_string ( ) ) ;
428428
429429 if !self . doc_aliases . is_empty ( ) {
430- let doc_aliases = self . doc_aliases . into_iter ( ) . join ( ", " ) ;
430+ let doc_aliases = self . doc_aliases . iter ( ) . join ( ", " ) ;
431431 label = SmolStr :: from ( format ! ( "{label} (alias {doc_aliases})" ) ) ;
432- lookup = SmolStr :: from ( format ! ( "{lookup} {doc_aliases}" ) ) ;
432+ let lookup_doc_aliases = ( self . doc_aliases . iter ( ) )
433+ // Don't include aliases in `lookup` that aren't valid identifiers as including
434+ // them results in weird completion filtering behavior e.g. `Partial>` matching
435+ // `PartialOrd` because it has an alias of ">".
436+ . filter ( |alias| {
437+ let mut chars = alias. chars ( ) ;
438+ chars. next ( ) . map ( unicode_ident:: is_xid_start) . unwrap_or ( false )
439+ && chars. all ( unicode_ident:: is_xid_continue)
440+ } )
441+ . join ( ", " ) ;
442+ if !lookup_doc_aliases. is_empty ( ) {
443+ lookup = SmolStr :: from ( format ! ( "{lookup} {lookup_doc_aliases}" ) ) ;
444+ }
433445 }
434446 if let [ import_edit] = & * self . imports_to_add {
435447 // snippets can have multiple imports, but normal completions only have up to one
@@ -553,9 +565,12 @@ impl Builder {
553565
554566#[ cfg( test) ]
555567mod tests {
568+ use ide_db:: SymbolKind ;
556569 use itertools:: Itertools ;
557570 use test_utils:: assert_eq_text;
558571
572+ use crate :: { CompletionItem , CompletionItemKind } ;
573+
559574 use super :: {
560575 CompletionRelevance , CompletionRelevancePostfixMatch , CompletionRelevanceTypeMatch ,
561576 } ;
@@ -630,4 +645,19 @@ mod tests {
630645
631646 check_relevance_score_ordered ( expected_relevance_order) ;
632647 }
648+
649+ #[ test]
650+ fn exclude_non_identifier_aliases_from_lookup ( ) {
651+ let mut item = CompletionItem :: new (
652+ CompletionItemKind :: SymbolKind ( SymbolKind :: Trait ) ,
653+ Default :: default ( ) ,
654+ "PartialOrd" ,
655+ ) ;
656+ let aliases = [ ">" , "<" , "<=" , ">=" ] ;
657+ item. doc_aliases ( aliases. iter ( ) . map ( |& alias| alias. into ( ) ) . collect ( ) ) ;
658+ let item = item. build ( & Default :: default ( ) ) ;
659+ for alias in aliases {
660+ assert ! ( !item. lookup( ) . contains( alias) ) ;
661+ }
662+ }
633663}
0 commit comments