@@ -304,9 +304,14 @@ impl Completions {
304304 ) {
305305 let is_deprecated = is_deprecated ( variant, ctx. db ) ;
306306 let name = local_name. unwrap_or_else ( || variant. name ( ctx. db ) . to_string ( ) ) ;
307- let qualified_name = match & path {
308- Some ( it) => it. to_string ( ) ,
309- None => name. to_string ( ) ,
307+ let ( qualified_name, short_qualified_name) = match & path {
308+ Some ( path) => {
309+ let full = path. to_string ( ) ;
310+ let short =
311+ path. segments [ path. segments . len ( ) . saturating_sub ( 2 ) ..] . iter ( ) . join ( "::" ) ;
312+ ( full, short)
313+ }
314+ None => ( name. to_string ( ) , name. to_string ( ) ) ,
310315 } ;
311316 let detail_types = variant
312317 . fields ( ctx. db )
@@ -335,14 +340,12 @@ impl Completions {
335340 . set_deprecated ( is_deprecated)
336341 . detail ( detail) ;
337342
338- if path. is_some ( ) {
339- res = res. lookup_by ( name) ;
340- }
341-
342343 if variant_kind == StructKind :: Tuple {
343344 mark:: hit!( inserts_parens_for_tuple_enums) ;
344345 let params = Params :: Anonymous ( variant. fields ( ctx. db ) . len ( ) ) ;
345- res = res. add_call_parens ( ctx, qualified_name, params)
346+ res = res. add_call_parens ( ctx, short_qualified_name, params)
347+ } else if path. is_some ( ) {
348+ res = res. lookup_by ( short_qualified_name) ;
346349 }
347350
348351 res. add_to ( self ) ;
@@ -606,6 +609,57 @@ fn main() { Foo::Fo<|> }
606609 ) ;
607610 }
608611
612+ #[ test]
613+ fn lookup_enums_by_two_qualifiers ( ) {
614+ check (
615+ r#"
616+ mod m {
617+ pub enum Spam { Foo, Bar(i32) }
618+ }
619+ fn main() { let _: m::Spam = S<|> }
620+ "# ,
621+ expect ! [ [ r#"
622+ [
623+ CompletionItem {
624+ label: "Spam::Bar(…)",
625+ source_range: 75..76,
626+ delete: 75..76,
627+ insert: "Spam::Bar($0)",
628+ kind: EnumVariant,
629+ lookup: "Spam::Bar",
630+ detail: "(i32)",
631+ trigger_call_info: true,
632+ },
633+ CompletionItem {
634+ label: "m",
635+ source_range: 75..76,
636+ delete: 75..76,
637+ insert: "m",
638+ kind: Module,
639+ },
640+ CompletionItem {
641+ label: "m::Spam::Foo",
642+ source_range: 75..76,
643+ delete: 75..76,
644+ insert: "m::Spam::Foo",
645+ kind: EnumVariant,
646+ lookup: "Spam::Foo",
647+ detail: "()",
648+ },
649+ CompletionItem {
650+ label: "main()",
651+ source_range: 75..76,
652+ delete: 75..76,
653+ insert: "main()$0",
654+ kind: Function,
655+ lookup: "main",
656+ detail: "fn main()",
657+ },
658+ ]
659+ "# ] ] ,
660+ )
661+ }
662+
609663 #[ test]
610664 fn sets_deprecated_flag_in_completion_items ( ) {
611665 check (
0 commit comments