Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide_completion/src/completions/record.rs')
-rw-r--r--crates/ide_completion/src/completions/record.rs36
1 files changed, 35 insertions, 1 deletions
diff --git a/crates/ide_completion/src/completions/record.rs b/crates/ide_completion/src/completions/record.rs
index f0c81f66bc..d50f889ee4 100644
--- a/crates/ide_completion/src/completions/record.rs
+++ b/crates/ide_completion/src/completions/record.rs
@@ -59,7 +59,12 @@ pub(crate) fn complete_record_literal(
}
if let hir::Adt::Struct(strukt) = ctx.expected_type.as_ref()?.as_adt()? {
- acc.add_struct_literal(ctx, strukt, None);
+ let module =
+ if let Some(module) = ctx.scope.module() { module } else { strukt.module(ctx.db) };
+
+ let path = module.find_use_path(ctx.db, hir::ModuleDef::from(strukt));
+
+ acc.add_struct_literal(ctx, strukt, path, None);
}
Some(())
@@ -95,6 +100,35 @@ fn baz() {
}
#[test]
+ fn literal_struct_completion_from_sub_modules() {
+ check_edit(
+ "Struct {…}",
+ r#"
+mod submod {
+ pub struct Struct {
+ pub a: u64,
+ }
+}
+
+fn f() -> submod::Struct {
+ Stru$0
+}
+ "#,
+ r#"
+mod submod {
+ pub struct Struct {
+ pub a: u64,
+ }
+}
+
+fn f() -> submod::Struct {
+ submod::Struct { a: ${1:()} }$0
+}
+ "#,
+ )
+ }
+
+ #[test]
fn literal_struct_complexion_module() {
check_edit(
"FooDesc {…}",