Skip to content

Commit b29e8ed

Browse files
committed
Remove unnecessary completion::macro_in_item_position
1 parent aa29364 commit b29e8ed

File tree

6 files changed

+17
-72
lines changed

6 files changed

+17
-72
lines changed

crates/ide_completion/src/completions.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ pub(crate) mod flyimport;
66
pub(crate) mod fn_param;
77
pub(crate) mod keyword;
88
pub(crate) mod lifetime;
9-
pub(crate) mod macro_in_item_position;
109
pub(crate) mod mod_;
1110
pub(crate) mod pattern;
1211
pub(crate) mod postfix;

crates/ide_completion/src/completions/macro_in_item_position.rs

Lines changed: 0 additions & 48 deletions
This file was deleted.

crates/ide_completion/src/completions/qualified_path.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use syntax::AstNode;
77
use crate::{CompletionContext, Completions};
88

99
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() {
1111
return;
1212
}
1313
let path = match ctx.path_qual() {
@@ -20,7 +20,8 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
2020
None => return,
2121
};
2222
let context_module = ctx.scope.module();
23-
if ctx.expects_assoc_item() {
23+
24+
if ctx.expects_item() || ctx.expects_assoc_item() {
2425
if let hir::PathResolution::Def(hir::ModuleDef::Module(module)) = resolution {
2526
let module_scope = module.scope(ctx.db, context_module);
2627
for (name, def) in module_scope {
@@ -631,25 +632,25 @@ impl MyStruct {
631632
"#,
632633
expect![[r##"
633634
md bar
634-
ma foo! #[macro_export] macro_rules! foo
635+
ma foo!(…) #[macro_export] macro_rules! foo
635636
"##]],
636637
);
637638
}
638639

639640
#[test]
640-
#[ignore] // FIXME doesn't complete anything atm
641641
fn completes_in_item_list() {
642642
check(
643643
r#"
644644
struct MyStruct {}
645+
#[macro_export]
645646
macro_rules! foo {}
646647
mod bar {}
647648
648649
crate::$0
649650
"#,
650651
expect![[r#"
651652
md bar
652-
ma foo! macro_rules! foo
653+
ma foo!(…) #[macro_export] macro_rules! foo
653654
"#]],
654655
)
655656
}

crates/ide_completion/src/completions/unqualified_path.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,25 @@ use hir::ScopeDef;
55
use crate::{CompletionContext, Completions};
66

77
pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionContext) {
8-
if !ctx.is_trivial_path() {
9-
return;
10-
}
11-
if ctx.is_path_disallowed() || ctx.expects_item() {
8+
if ctx.is_path_disallowed() || !ctx.is_trivial_path() {
129
return;
1310
}
1411

15-
if ctx.expects_assoc_item() {
16-
ctx.scope.process_all_names(&mut |name, def| {
17-
if let ScopeDef::MacroDef(macro_def) = def {
18-
acc.add_macro(ctx, Some(name.clone()), macro_def);
12+
if ctx.expects_item() || ctx.expects_assoc_item() {
13+
// only show macros in {Assoc}ItemList
14+
ctx.scope.process_all_names(&mut |name, res| {
15+
if let hir::ScopeDef::MacroDef(mac) = res {
16+
acc.add_macro(ctx, Some(name.clone()), mac);
1917
}
20-
if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = def {
21-
acc.add_resolution(ctx, name, &def);
18+
if let hir::ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = res {
19+
acc.add_resolution(ctx, name, &res);
2220
}
2321
});
2422
return;
2523
}
2624

2725
if ctx.expects_use_tree() {
26+
// only show modules in a fresh UseTree
2827
cov_mark::hit!(only_completes_modules_in_import);
2928
ctx.scope.process_all_names(&mut |name, res| {
3029
if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = res {
@@ -693,12 +692,11 @@ impl MyStruct {
693692
"#,
694693
expect![[r#"
695694
md bar
696-
ma foo! macro_rules! foo
695+
ma foo!(…) macro_rules! foo
697696
"#]],
698697
)
699698
}
700699

701-
// FIXME: The completions here currently come from `macro_in_item_position`, but they shouldn't
702700
#[test]
703701
fn completes_in_item_list() {
704702
check(

crates/ide_completion/src/context.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -561,10 +561,6 @@ impl<'a> CompletionContext<'a> {
561561
self.name_ref_syntax =
562562
find_node_at_offset(original_file, name_ref.syntax().text_range().start());
563563

564-
if matches!(self.completion_location, Some(ImmediateLocation::ItemList)) {
565-
return;
566-
}
567-
568564
self.use_item_syntax =
569565
self.sema.token_ancestors_with_macros(self.token.clone()).find_map(ast::Use::cast);
570566

@@ -595,7 +591,7 @@ impl<'a> CompletionContext<'a> {
595591
path_ctx.call_kind = match_ast! {
596592
match p {
597593
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)),
599595
ast::TupleStructPat(_it) => Some(CallKind::Pat),
600596
_ => None
601597
}

crates/ide_completion/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ pub fn completions(
158158
completions::record::complete_record(&mut acc, &ctx);
159159
completions::pattern::complete_pattern(&mut acc, &ctx);
160160
completions::postfix::complete_postfix(&mut acc, &ctx);
161-
completions::macro_in_item_position::complete_macro_in_item_position(&mut acc, &ctx);
162161
completions::trait_impl::complete_trait_impl(&mut acc, &ctx);
163162
completions::mod_::complete_mod(&mut acc, &ctx);
164163
completions::flyimport::import_on_the_fly(&mut acc, &ctx);

0 commit comments

Comments
 (0)