Skip to content

Commit e138676

Browse files
committed
Don't use the module as the candidate node in fuzzy path flyimport
1 parent 8e0a7d8 commit e138676

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

crates/ide_completion/src/completions/flyimport.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,12 @@ fn import_assets(ctx: &CompletionContext, fuzzy_name: String) -> Option<ImportAs
186186
)
187187
} else {
188188
let fuzzy_name_length = fuzzy_name.len();
189-
let approximate_node = match current_module.definition_source(ctx.db).value {
190-
hir::ModuleSource::SourceFile(s) => s.syntax().clone(),
191-
hir::ModuleSource::Module(m) => m.syntax().clone(),
192-
hir::ModuleSource::BlockExpr(b) => b.syntax().clone(),
193-
};
194189
let assets_for_path = ImportAssets::for_fuzzy_path(
195190
current_module,
196191
ctx.path_qual().cloned(),
197192
fuzzy_name,
198193
&ctx.sema,
199-
approximate_node,
194+
ctx.token.parent()?,
200195
)?;
201196

202197
if matches!(assets_for_path.import_candidate(), ImportCandidate::Path(_))
@@ -1189,4 +1184,23 @@ impl<T> Private for T {}
11891184
expect![[r#""#]],
11901185
);
11911186
}
1187+
1188+
#[test]
1189+
fn regression_9760() {
1190+
check(
1191+
r#"
1192+
struct Struct;
1193+
fn main() {}
1194+
1195+
mod mud {
1196+
fn func() {
1197+
let struct_instance = Stru$0
1198+
}
1199+
}
1200+
"#,
1201+
expect![[r#"
1202+
st Struct (use crate::Struct)
1203+
"#]],
1204+
);
1205+
}
11921206
}

0 commit comments

Comments
 (0)