Skip to content

Commit da89435

Browse files
bors[bot]Veykril
andauthored
Merge #9764
9764: fix: Don't use the module as the candidate node in fuzzy path flyimport r=Veykril a=Veykril The problem was that the candidate node is whats being used for the scope, so using an inline module will yield the surrounding scope of the module instead of the scope of the module itself. Also seems to fix the problem in this comment #9760 (comment), though I could not recreate that in a test for some reason. Fixes #9760 Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 parents 29506b5 + e138676 commit da89435

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)