Skip to content

Commit 7f16b42

Browse files
bors[bot]Veykril
andauthored
Merge #9170
9170: internal: Remove unnecessary `completion::macro_in_item_position` module r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 parents 2f376f7 + b29e8ed commit 7f16b42

File tree

7 files changed

+32
-90
lines changed

7 files changed

+32
-90
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: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,13 @@ pub(crate) struct CompletionContext<'a> {
6767
pub(super) krate: Option<hir::Crate>,
6868
pub(super) expected_name: Option<NameOrNameRef>,
6969
pub(super) expected_type: Option<Type>,
70-
pub(super) name_ref_syntax: Option<ast::NameRef>,
71-
72-
pub(super) use_item_syntax: Option<ast::Use>,
7370

7471
/// The parent function of the cursor position if it exists.
7572
pub(super) function_def: Option<ast::Fn>,
7673
/// The parent impl of the cursor position if it exists.
7774
pub(super) impl_def: Option<ast::Impl>,
75+
pub(super) name_ref_syntax: Option<ast::NameRef>,
76+
pub(super) use_item_syntax: Option<ast::Use>,
7877

7978
// potentially set if we are completing a lifetime
8079
pub(super) lifetime_syntax: Option<ast::Lifetime>,
@@ -89,13 +88,12 @@ pub(crate) struct CompletionContext<'a> {
8988
pub(super) completion_location: Option<ImmediateLocation>,
9089
pub(super) prev_sibling: Option<ImmediatePrevSibling>,
9190
pub(super) attribute_under_caret: Option<ast::Attr>,
91+
pub(super) previous_token: Option<SyntaxToken>,
9292

9393
pub(super) path_context: Option<PathCompletionContext>,
94-
/// FIXME: `ActiveParameter` is string-based, which is very very wrong
9594
pub(super) active_parameter: Option<ActiveParameter>,
9695
pub(super) locals: Vec<(String, Local)>,
9796

98-
pub(super) previous_token: Option<SyntaxToken>,
9997
pub(super) in_loop_body: bool,
10098
pub(super) incomplete_let: bool,
10199

@@ -143,28 +141,28 @@ impl<'a> CompletionContext<'a> {
143141
original_token,
144142
token,
145143
krate,
146-
lifetime_allowed: false,
147144
expected_name: None,
148145
expected_type: None,
146+
function_def: None,
147+
impl_def: None,
149148
name_ref_syntax: None,
149+
use_item_syntax: None,
150150
lifetime_syntax: None,
151151
lifetime_param_syntax: None,
152-
function_def: None,
153-
use_item_syntax: None,
154-
impl_def: None,
155-
active_parameter: ActiveParameter::at(db, position),
152+
lifetime_allowed: false,
156153
is_label_ref: false,
157-
is_param: false,
158154
is_pat_or_const: None,
159-
path_context: None,
160-
previous_token: None,
161-
in_loop_body: false,
155+
is_param: false,
162156
completion_location: None,
163157
prev_sibling: None,
164-
no_completion_required: false,
165-
incomplete_let: false,
166158
attribute_under_caret: None,
159+
previous_token: None,
160+
path_context: None,
161+
active_parameter: ActiveParameter::at(db, position),
167162
locals,
163+
in_loop_body: false,
164+
incomplete_let: false,
165+
no_completion_required: false,
168166
};
169167

170168
let mut original_file = original_file.syntax().clone();
@@ -563,10 +561,6 @@ impl<'a> CompletionContext<'a> {
563561
self.name_ref_syntax =
564562
find_node_at_offset(original_file, name_ref.syntax().text_range().start());
565563

566-
if matches!(self.completion_location, Some(ImmediateLocation::ItemList)) {
567-
return;
568-
}
569-
570564
self.use_item_syntax =
571565
self.sema.token_ancestors_with_macros(self.token.clone()).find_map(ast::Use::cast);
572566

@@ -597,7 +591,7 @@ impl<'a> CompletionContext<'a> {
597591
path_ctx.call_kind = match_ast! {
598592
match p {
599593
ast::PathExpr(it) => it.syntax().parent().and_then(ast::CallExpr::cast).map(|_| CallKind::Expr),
600-
ast::MacroCall(_it) => Some(CallKind::Mac),
594+
ast::MacroCall(it) => it.excl_token().and(Some(CallKind::Mac)),
601595
ast::TupleStructPat(_it) => Some(CallKind::Pat),
602596
_ => None
603597
}

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);

crates/ide_db/src/call_info.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,8 @@ impl FnCallNode {
223223
ast::Expr::PathExpr(path_expr) => path_expr.path()?.segment()?.name_ref()?,
224224
_ => return None,
225225
}),
226-
227226
FnCallNode::MethodCallExpr(call_expr) => {
228-
call_expr.syntax().children().filter_map(ast::NameRef::cast).next()
227+
call_expr.syntax().children().find_map(ast::NameRef::cast)
229228
}
230229
}
231230
}

0 commit comments

Comments
 (0)