diff options
Diffstat (limited to 'crates/ide_completion/src')
-rw-r--r-- | crates/ide_completion/src/completions.rs | 1 | ||||
-rw-r--r-- | crates/ide_completion/src/completions/macro_in_item_position.rs | 48 | ||||
-rw-r--r-- | crates/ide_completion/src/completions/qualified_path.rs | 11 | ||||
-rw-r--r-- | crates/ide_completion/src/completions/unqualified_path.rs | 22 | ||||
-rw-r--r-- | crates/ide_completion/src/context.rs | 6 | ||||
-rw-r--r-- | crates/ide_completion/src/lib.rs | 1 |
6 files changed, 17 insertions, 72 deletions
diff --git a/crates/ide_completion/src/completions.rs b/crates/ide_completion/src/completions.rs index ffdcdc930..7a4d71e91 100644 --- a/crates/ide_completion/src/completions.rs +++ b/crates/ide_completion/src/completions.rs | |||
@@ -6,7 +6,6 @@ pub(crate) mod flyimport; | |||
6 | pub(crate) mod fn_param; | 6 | pub(crate) mod fn_param; |
7 | pub(crate) mod keyword; | 7 | pub(crate) mod keyword; |
8 | pub(crate) mod lifetime; | 8 | pub(crate) mod lifetime; |
9 | pub(crate) mod macro_in_item_position; | ||
10 | pub(crate) mod mod_; | 9 | pub(crate) mod mod_; |
11 | pub(crate) mod pattern; | 10 | pub(crate) mod pattern; |
12 | pub(crate) mod postfix; | 11 | pub(crate) mod postfix; |
diff --git a/crates/ide_completion/src/completions/macro_in_item_position.rs b/crates/ide_completion/src/completions/macro_in_item_position.rs deleted file mode 100644 index 781b96ff1..000000000 --- a/crates/ide_completion/src/completions/macro_in_item_position.rs +++ /dev/null | |||
@@ -1,48 +0,0 @@ | |||
1 | //! Completes macro invocations used in item position. | ||
2 | |||
3 | use crate::{CompletionContext, Completions}; | ||
4 | |||
5 | // Ideally this should be removed and moved into `(un)qualified_path` respectively | ||
6 | pub(crate) fn complete_macro_in_item_position(acc: &mut Completions, ctx: &CompletionContext) { | ||
7 | // Show only macros in top level. | ||
8 | if !ctx.expects_item() { | ||
9 | return; | ||
10 | } | ||
11 | |||
12 | ctx.scope.process_all_names(&mut |name, res| { | ||
13 | if let hir::ScopeDef::MacroDef(mac) = res { | ||
14 | acc.add_macro(ctx, Some(name.clone()), mac); | ||
15 | } | ||
16 | // FIXME: This should be done in qualified_path/unqualified_path instead? | ||
17 | if let hir::ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = res { | ||
18 | acc.add_resolution(ctx, name, &res); | ||
19 | } | ||
20 | }) | ||
21 | } | ||
22 | |||
23 | #[cfg(test)] | ||
24 | mod tests { | ||
25 | use expect_test::{expect, Expect}; | ||
26 | |||
27 | use crate::{test_utils::completion_list, CompletionKind}; | ||
28 | |||
29 | fn check(ra_fixture: &str, expect: Expect) { | ||
30 | let actual = completion_list(ra_fixture, CompletionKind::Reference); | ||
31 | expect.assert_eq(&actual) | ||
32 | } | ||
33 | |||
34 | #[test] | ||
35 | fn completes_macros_as_item() { | ||
36 | check( | ||
37 | r#" | ||
38 | macro_rules! foo { () => {} } | ||
39 | fn foo() {} | ||
40 | |||
41 | $0 | ||
42 | "#, | ||
43 | expect![[r#" | ||
44 | ma foo!(…) macro_rules! foo | ||
45 | "#]], | ||
46 | ) | ||
47 | } | ||
48 | } | ||
diff --git a/crates/ide_completion/src/completions/qualified_path.rs b/crates/ide_completion/src/completions/qualified_path.rs index c072de7b5..d58745fb4 100644 --- a/crates/ide_completion/src/completions/qualified_path.rs +++ b/crates/ide_completion/src/completions/qualified_path.rs | |||
@@ -7,7 +7,7 @@ use syntax::AstNode; | |||
7 | use crate::{CompletionContext, Completions}; | 7 | use crate::{CompletionContext, Completions}; |
8 | 8 | ||
9 | pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionContext) { | 9 | pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionContext) { |
10 | if ctx.is_path_disallowed() || ctx.expects_item() { | 10 | if ctx.is_path_disallowed() { |
11 | return; | 11 | return; |
12 | } | 12 | } |
13 | let path = match ctx.path_qual() { | 13 | let path = match ctx.path_qual() { |
@@ -20,7 +20,8 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon | |||
20 | None => return, | 20 | None => return, |
21 | }; | 21 | }; |
22 | let context_module = ctx.scope.module(); | 22 | let context_module = ctx.scope.module(); |
23 | if ctx.expects_assoc_item() { | 23 | |
24 | if ctx.expects_item() || ctx.expects_assoc_item() { | ||
24 | if let hir::PathResolution::Def(hir::ModuleDef::Module(module)) = resolution { | 25 | if let hir::PathResolution::Def(hir::ModuleDef::Module(module)) = resolution { |
25 | let module_scope = module.scope(ctx.db, context_module); | 26 | let module_scope = module.scope(ctx.db, context_module); |
26 | for (name, def) in module_scope { | 27 | for (name, def) in module_scope { |
@@ -631,17 +632,17 @@ impl MyStruct { | |||
631 | "#, | 632 | "#, |
632 | expect![[r##" | 633 | expect![[r##" |
633 | md bar | 634 | md bar |
634 | ma foo! #[macro_export] macro_rules! foo | 635 | ma foo!(…) #[macro_export] macro_rules! foo |
635 | "##]], | 636 | "##]], |
636 | ); | 637 | ); |
637 | } | 638 | } |
638 | 639 | ||
639 | #[test] | 640 | #[test] |
640 | #[ignore] // FIXME doesn't complete anything atm | ||
641 | fn completes_in_item_list() { | 641 | fn completes_in_item_list() { |
642 | check( | 642 | check( |
643 | r#" | 643 | r#" |
644 | struct MyStruct {} | 644 | struct MyStruct {} |
645 | #[macro_export] | ||
645 | macro_rules! foo {} | 646 | macro_rules! foo {} |
646 | mod bar {} | 647 | mod bar {} |
647 | 648 | ||
@@ -649,7 +650,7 @@ crate::$0 | |||
649 | "#, | 650 | "#, |
650 | expect![[r#" | 651 | expect![[r#" |
651 | md bar | 652 | md bar |
652 | ma foo! macro_rules! foo | 653 | ma foo!(…) #[macro_export] macro_rules! foo |
653 | "#]], | 654 | "#]], |
654 | ) | 655 | ) |
655 | } | 656 | } |
diff --git a/crates/ide_completion/src/completions/unqualified_path.rs b/crates/ide_completion/src/completions/unqualified_path.rs index f321ed52b..8b22933e0 100644 --- a/crates/ide_completion/src/completions/unqualified_path.rs +++ b/crates/ide_completion/src/completions/unqualified_path.rs | |||
@@ -5,26 +5,25 @@ use hir::ScopeDef; | |||
5 | use crate::{CompletionContext, Completions}; | 5 | use crate::{CompletionContext, Completions}; |
6 | 6 | ||
7 | pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionContext) { | 7 | pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionContext) { |
8 | if !ctx.is_trivial_path() { | 8 | if ctx.is_path_disallowed() || !ctx.is_trivial_path() { |
9 | return; | ||
10 | } | ||
11 | if ctx.is_path_disallowed() || ctx.expects_item() { | ||
12 | return; | 9 | return; |
13 | } | 10 | } |
14 | 11 | ||
15 | if ctx.expects_assoc_item() { | 12 | if ctx.expects_item() || ctx.expects_assoc_item() { |
16 | ctx.scope.process_all_names(&mut |name, def| { | 13 | // only show macros in {Assoc}ItemList |
17 | if let ScopeDef::MacroDef(macro_def) = def { | 14 | ctx.scope.process_all_names(&mut |name, res| { |
18 | acc.add_macro(ctx, Some(name.clone()), macro_def); | 15 | if let hir::ScopeDef::MacroDef(mac) = res { |
16 | acc.add_macro(ctx, Some(name.clone()), mac); | ||
19 | } | 17 | } |
20 | if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = def { | 18 | if let hir::ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = res { |
21 | acc.add_resolution(ctx, name, &def); | 19 | acc.add_resolution(ctx, name, &res); |
22 | } | 20 | } |
23 | }); | 21 | }); |
24 | return; | 22 | return; |
25 | } | 23 | } |
26 | 24 | ||
27 | if ctx.expects_use_tree() { | 25 | if ctx.expects_use_tree() { |
26 | // only show modules in a fresh UseTree | ||
28 | cov_mark::hit!(only_completes_modules_in_import); | 27 | cov_mark::hit!(only_completes_modules_in_import); |
29 | ctx.scope.process_all_names(&mut |name, res| { | 28 | ctx.scope.process_all_names(&mut |name, res| { |
30 | if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = res { | 29 | if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = res { |
@@ -693,12 +692,11 @@ impl MyStruct { | |||
693 | "#, | 692 | "#, |
694 | expect![[r#" | 693 | expect![[r#" |
695 | md bar | 694 | md bar |
696 | ma foo! macro_rules! foo | 695 | ma foo!(…) macro_rules! foo |
697 | "#]], | 696 | "#]], |
698 | ) | 697 | ) |
699 | } | 698 | } |
700 | 699 | ||
701 | // FIXME: The completions here currently come from `macro_in_item_position`, but they shouldn't | ||
702 | #[test] | 700 | #[test] |
703 | fn completes_in_item_list() { | 701 | fn completes_in_item_list() { |
704 | check( | 702 | check( |
diff --git a/crates/ide_completion/src/context.rs b/crates/ide_completion/src/context.rs index 58762a3cd..7e4b14926 100644 --- a/crates/ide_completion/src/context.rs +++ b/crates/ide_completion/src/context.rs | |||
@@ -561,10 +561,6 @@ impl<'a> CompletionContext<'a> { | |||
561 | self.name_ref_syntax = | 561 | self.name_ref_syntax = |
562 | find_node_at_offset(original_file, name_ref.syntax().text_range().start()); | 562 | find_node_at_offset(original_file, name_ref.syntax().text_range().start()); |
563 | 563 | ||
564 | if matches!(self.completion_location, Some(ImmediateLocation::ItemList)) { | ||
565 | return; | ||
566 | } | ||
567 | |||
568 | self.use_item_syntax = | 564 | self.use_item_syntax = |
569 | self.sema.token_ancestors_with_macros(self.token.clone()).find_map(ast::Use::cast); | 565 | self.sema.token_ancestors_with_macros(self.token.clone()).find_map(ast::Use::cast); |
570 | 566 | ||
@@ -595,7 +591,7 @@ impl<'a> CompletionContext<'a> { | |||
595 | path_ctx.call_kind = match_ast! { | 591 | path_ctx.call_kind = match_ast! { |
596 | match p { | 592 | match p { |
597 | ast::PathExpr(it) => it.syntax().parent().and_then(ast::CallExpr::cast).map(|_| CallKind::Expr), | 593 | ast::PathExpr(it) => it.syntax().parent().and_then(ast::CallExpr::cast).map(|_| CallKind::Expr), |
598 | ast::MacroCall(_it) => Some(CallKind::Mac), | 594 | ast::MacroCall(it) => it.excl_token().and(Some(CallKind::Mac)), |
599 | ast::TupleStructPat(_it) => Some(CallKind::Pat), | 595 | ast::TupleStructPat(_it) => Some(CallKind::Pat), |
600 | _ => None | 596 | _ => None |
601 | } | 597 | } |
diff --git a/crates/ide_completion/src/lib.rs b/crates/ide_completion/src/lib.rs index 6fb38f50d..18983aa01 100644 --- a/crates/ide_completion/src/lib.rs +++ b/crates/ide_completion/src/lib.rs | |||
@@ -158,7 +158,6 @@ pub fn completions( | |||
158 | completions::record::complete_record(&mut acc, &ctx); | 158 | completions::record::complete_record(&mut acc, &ctx); |
159 | completions::pattern::complete_pattern(&mut acc, &ctx); | 159 | completions::pattern::complete_pattern(&mut acc, &ctx); |
160 | completions::postfix::complete_postfix(&mut acc, &ctx); | 160 | completions::postfix::complete_postfix(&mut acc, &ctx); |
161 | completions::macro_in_item_position::complete_macro_in_item_position(&mut acc, &ctx); | ||
162 | completions::trait_impl::complete_trait_impl(&mut acc, &ctx); | 161 | completions::trait_impl::complete_trait_impl(&mut acc, &ctx); |
163 | completions::mod_::complete_mod(&mut acc, &ctx); | 162 | completions::mod_::complete_mod(&mut acc, &ctx); |
164 | completions::flyimport::import_on_the_fly(&mut acc, &ctx); | 163 | completions::flyimport::import_on_the_fly(&mut acc, &ctx); |