diff options
author | Lukas Wirth <[email protected]> | 2021-06-16 14:08:44 +0100 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2021-06-16 14:08:44 +0100 |
commit | 354ad29493dbb258c11190abd7632af95c538e16 (patch) | |
tree | 09418c3c079d2a849cc99aaeddf5feaab39317f3 /crates/ide_completion/src/completions/unqualified_path.rs | |
parent | 79703efc7fddce3f0080d3d97c200d6a2a2ffaa9 (diff) |
Filter out non-type completions in the respective completions modules instead
Diffstat (limited to 'crates/ide_completion/src/completions/unqualified_path.rs')
-rw-r--r-- | crates/ide_completion/src/completions/unqualified_path.rs | 58 |
1 files changed, 32 insertions, 26 deletions
diff --git a/crates/ide_completion/src/completions/unqualified_path.rs b/crates/ide_completion/src/completions/unqualified_path.rs index f86b2d3f3..b5af1c810 100644 --- a/crates/ide_completion/src/completions/unqualified_path.rs +++ b/crates/ide_completion/src/completions/unqualified_path.rs | |||
@@ -36,12 +36,14 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC | |||
36 | return; | 36 | return; |
37 | } | 37 | } |
38 | 38 | ||
39 | if let Some(hir::Adt::Enum(e)) = | 39 | if !ctx.expects_type() { |
40 | ctx.expected_type.as_ref().and_then(|ty| ty.strip_references().as_adt()) | 40 | if let Some(hir::Adt::Enum(e)) = |
41 | { | 41 | ctx.expected_type.as_ref().and_then(|ty| ty.strip_references().as_adt()) |
42 | super::complete_enum_variants(acc, ctx, e, |acc, ctx, variant, path| { | 42 | { |
43 | acc.add_qualified_enum_variant(ctx, variant, path) | 43 | super::complete_enum_variants(acc, ctx, e, |acc, ctx, variant, path| { |
44 | }); | 44 | acc.add_qualified_enum_variant(ctx, variant, path) |
45 | }); | ||
46 | } | ||
45 | } | 47 | } |
46 | 48 | ||
47 | if let Some(ImmediateLocation::GenericArgList(arg_list)) = &ctx.completion_location { | 49 | if let Some(ImmediateLocation::GenericArgList(arg_list)) = &ctx.completion_location { |
@@ -59,12 +61,25 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC | |||
59 | } | 61 | } |
60 | 62 | ||
61 | ctx.scope.process_all_names(&mut |name, res| { | 63 | ctx.scope.process_all_names(&mut |name, res| { |
62 | if let ScopeDef::GenericParam(hir::GenericParam::LifetimeParam(_)) = res { | 64 | if let ScopeDef::GenericParam(hir::GenericParam::LifetimeParam(_)) | ScopeDef::Label(_) = |
65 | res | ||
66 | { | ||
63 | cov_mark::hit!(skip_lifetime_completion); | 67 | cov_mark::hit!(skip_lifetime_completion); |
64 | return; | 68 | return; |
65 | } | 69 | } |
66 | let add_resolution = match res { | 70 | let add_resolution = match res { |
71 | // Don't suggest attribute macros and derives. | ||
67 | ScopeDef::MacroDef(mac) => mac.is_fn_like(), | 72 | ScopeDef::MacroDef(mac) => mac.is_fn_like(), |
73 | // no values in type places | ||
74 | ScopeDef::ModuleDef(hir::ModuleDef::Function(_)) | ||
75 | | ScopeDef::ModuleDef(hir::ModuleDef::Variant(_)) | ||
76 | | ScopeDef::ModuleDef(hir::ModuleDef::Static(_)) | ||
77 | | ScopeDef::Local(_) => !ctx.expects_type(), | ||
78 | // unless its a constant in a generic arg list position | ||
79 | ScopeDef::ModuleDef(hir::ModuleDef::Const(_)) | ||
80 | | ScopeDef::GenericParam(hir::GenericParam::ConstParam(_)) => { | ||
81 | !ctx.expects_type() || ctx.expects_generic_arg() | ||
82 | } | ||
68 | _ => true, | 83 | _ => true, |
69 | }; | 84 | }; |
70 | if add_resolution { | 85 | if add_resolution { |
@@ -794,36 +809,27 @@ $0 | |||
794 | } | 809 | } |
795 | 810 | ||
796 | #[test] | 811 | #[test] |
797 | fn completes_assoc_types_in_dynimpl_trait() { | 812 | fn completes_types_and_const_in_arg_list() { |
798 | check( | 813 | check( |
799 | r#" | 814 | r#" |
800 | trait Foo { | 815 | enum Bar { |
801 | type Bar; | 816 | Baz |
802 | } | 817 | } |
803 | |||
804 | fn foo(_: impl Foo<B$0>) {} | ||
805 | "#, | ||
806 | expect![[r#" | ||
807 | ta Bar = type Bar; | ||
808 | tt Foo | ||
809 | "#]], | ||
810 | ); | ||
811 | } | ||
812 | |||
813 | #[test] | ||
814 | fn completes_assoc_types_in_trait_bound() { | ||
815 | check( | ||
816 | r#" | ||
817 | trait Foo { | 818 | trait Foo { |
818 | type Bar; | 819 | type Bar; |
819 | } | 820 | } |
820 | 821 | ||
821 | fn foo<T: Foo<B$0>>(_: T) {} | 822 | const CONST: () = (); |
823 | |||
824 | fn foo<T: Foo<$0>, const CONST_PARAM: usize>(_: T) {} | ||
822 | "#, | 825 | "#, |
823 | expect![[r#" | 826 | expect![[r#" |
824 | ta Bar = type Bar; | 827 | ta Bar = type Bar; |
825 | tp T | 828 | tp T |
829 | cp CONST_PARAM | ||
826 | tt Foo | 830 | tt Foo |
831 | en Bar | ||
832 | ct CONST | ||
827 | "#]], | 833 | "#]], |
828 | ); | 834 | ); |
829 | } | 835 | } |