diff options
Diffstat (limited to 'crates/completion/src/presentation.rs')
-rw-r--r-- | crates/completion/src/presentation.rs | 70 |
1 files changed, 62 insertions, 8 deletions
diff --git a/crates/completion/src/presentation.rs b/crates/completion/src/presentation.rs index 2a19281cf..0a6f5a1ea 100644 --- a/crates/completion/src/presentation.rs +++ b/crates/completion/src/presentation.rs | |||
@@ -304,9 +304,14 @@ impl Completions { | |||
304 | ) { | 304 | ) { |
305 | let is_deprecated = is_deprecated(variant, ctx.db); | 305 | let is_deprecated = is_deprecated(variant, ctx.db); |
306 | let name = local_name.unwrap_or_else(|| variant.name(ctx.db).to_string()); | 306 | let name = local_name.unwrap_or_else(|| variant.name(ctx.db).to_string()); |
307 | let qualified_name = match &path { | 307 | let (qualified_name, short_qualified_name) = match &path { |
308 | Some(it) => it.to_string(), | 308 | Some(path) => { |
309 | None => name.to_string(), | 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()), | ||
310 | }; | 315 | }; |
311 | let detail_types = variant | 316 | let detail_types = variant |
312 | .fields(ctx.db) | 317 | .fields(ctx.db) |
@@ -335,14 +340,12 @@ impl Completions { | |||
335 | .set_deprecated(is_deprecated) | 340 | .set_deprecated(is_deprecated) |
336 | .detail(detail); | 341 | .detail(detail); |
337 | 342 | ||
338 | if path.is_some() { | ||
339 | res = res.lookup_by(name); | ||
340 | } | ||
341 | |||
342 | if variant_kind == StructKind::Tuple { | 343 | if variant_kind == StructKind::Tuple { |
343 | mark::hit!(inserts_parens_for_tuple_enums); | 344 | mark::hit!(inserts_parens_for_tuple_enums); |
344 | let params = Params::Anonymous(variant.fields(ctx.db).len()); | 345 | 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); | ||
346 | } | 349 | } |
347 | 350 | ||
348 | res.add_to(self); | 351 | res.add_to(self); |
@@ -607,6 +610,57 @@ fn main() { Foo::Fo<|> } | |||
607 | } | 610 | } |
608 | 611 | ||
609 | #[test] | 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 | |||
663 | #[test] | ||
610 | fn sets_deprecated_flag_in_completion_items() { | 664 | fn sets_deprecated_flag_in_completion_items() { |
611 | check( | 665 | check( |
612 | r#" | 666 | r#" |