Skip to content

Commit cad4cb3

Browse files
author
Jonas Schievink
committed
Make it work with Self { .. }
1 parent e993072 commit cad4cb3

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

crates/ide/src/signature_help.rs

+33-10
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,21 @@ fn signature_help_for_record_lit(
410410
let fields;
411411

412412
let db = sema.db;
413-
match sema.resolve_path(&record.path()?)? {
414-
PathResolution::Def(ModuleDef::Adt(adt)) => match adt {
413+
let path_res = sema.resolve_path(&record.path()?)?;
414+
if let PathResolution::Def(ModuleDef::Variant(variant)) = path_res {
415+
fields = variant.fields(db);
416+
let en = variant.parent_enum(db);
417+
418+
res.doc = en.docs(db).map(|it| it.into());
419+
format_to!(res.signature, "enum {}::{} {{ ", en.name(db), variant.name(db));
420+
} else {
421+
let adt = match path_res {
422+
PathResolution::SelfType(imp) => imp.self_ty(db).as_adt()?,
423+
PathResolution::Def(ModuleDef::Adt(adt)) => adt,
424+
_ => return None,
425+
};
426+
427+
match adt {
415428
hir::Adt::Struct(it) => {
416429
fields = it.fields(db);
417430
res.doc = it.docs(db).map(|it| it.into());
@@ -423,15 +436,7 @@ fn signature_help_for_record_lit(
423436
format_to!(res.signature, "union {} {{ ", it.name(db));
424437
}
425438
_ => return None,
426-
},
427-
PathResolution::Def(ModuleDef::Variant(variant)) => {
428-
fields = variant.fields(db);
429-
let en = variant.parent_enum(db);
430-
431-
res.doc = en.docs(db).map(|it| it.into());
432-
format_to!(res.signature, "enum {}::{} {{ ", en.name(db), variant.name(db));
433439
}
434-
_ => return None,
435440
}
436441

437442
let mut fields =
@@ -1571,4 +1576,22 @@ fn f() {
15711576
"#]],
15721577
);
15731578
}
1579+
1580+
#[test]
1581+
fn record_literal_self() {
1582+
check(
1583+
r#"
1584+
struct S { t: u8 }
1585+
impl S {
1586+
fn new() -> Self {
1587+
Self { $0 }
1588+
}
1589+
}
1590+
"#,
1591+
expect![[r#"
1592+
struct S { t: u8 }
1593+
^^^^^
1594+
"#]],
1595+
);
1596+
}
15741597
}

0 commit comments

Comments
 (0)