Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit d4b79ad

Browse files
committed
Auto merge of rust-lang#12678 - Veykril:flyimport, r=Veykril
fix: Trigger flyimport completions in item lists again Fixes rust-lang/rust-analyzer#12656
2 parents ec78b6b + cd42b20 commit d4b79ad

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

crates/ide-completion/src/completions/flyimport.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ use ide_db::imports::{
55
insert_use::ImportScope,
66
};
77
use itertools::Itertools;
8-
use syntax::{ast, AstNode, SyntaxNode, T};
8+
use syntax::{
9+
ast::{self},
10+
AstNode, SyntaxNode, T,
11+
};
912

1013
use crate::{
1114
context::{
@@ -123,6 +126,7 @@ pub(crate) fn import_on_the_fly_path(
123126
| PathKind::Type { .. }
124127
| PathKind::Attr { .. }
125128
| PathKind::Derive { .. }
129+
| PathKind::Item { .. }
126130
| PathKind::Pat { .. },
127131
qualified,
128132
..
@@ -161,7 +165,7 @@ pub(crate) fn import_on_the_fly_pat(
161165
let potential_import_name = import_name(ctx);
162166
let import_assets = import_assets_for_path(ctx, &potential_import_name, None)?;
163167

164-
import_on_the_fly_pat2(
168+
import_on_the_fly_pat_(
165169
acc,
166170
ctx,
167171
pattern_ctx,
@@ -227,7 +231,7 @@ fn import_on_the_fly(
227231
| PathKind::Pat { .. },
228232
ItemInNs::Macros(mac),
229233
) => mac.is_fn_like(ctx.db),
230-
(PathKind::Item { .. }, _) => true,
234+
(PathKind::Item { .. }, ..) => false,
231235

232236
(PathKind::Expr { .. }, ItemInNs::Types(_) | ItemInNs::Values(_)) => true,
233237

@@ -279,7 +283,7 @@ fn import_on_the_fly(
279283
Some(())
280284
}
281285

282-
fn import_on_the_fly_pat2(
286+
fn import_on_the_fly_pat_(
283287
acc: &mut Completions,
284288
ctx: &CompletionContext,
285289
pattern_ctx: &PatternContext,

crates/ide-completion/src/tests/flyimport.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,3 +1210,23 @@ fn f<T>() where T: Comp$0
12101210
"#]],
12111211
);
12121212
}
1213+
1214+
#[test]
1215+
fn flyimport_source_file() {
1216+
check(
1217+
r#"
1218+
//- /main.rs crate:main deps:dep
1219+
def$0
1220+
//- /lib.rs crate:dep
1221+
#[macro_export]
1222+
macro_rules! define_struct {
1223+
() => {
1224+
pub struct Foo;
1225+
};
1226+
}
1227+
"#,
1228+
expect![[r#"
1229+
ma define_struct!(…) (use dep::define_struct) macro_rules! define_struct
1230+
"#]],
1231+
);
1232+
}

0 commit comments

Comments
 (0)