Also export flake output under outputs

This commit is contained in:
oxalica 2023-04-22 06:23:12 +08:00
parent 3283d0901b
commit ae9fa0c3a2
2 changed files with 23 additions and 11 deletions

View file

@ -100,8 +100,14 @@ pub fn flake(inputs: &[(&str, Ty)]) -> Ty {
.iter()
// Don't duplicate.
.filter(|(name, _)| *name != "self")
.map(|(name, ty)| {
let ty = merge_attrset(ty, &GENERIC_FLAKE);
.map(|(name, output_ty)| {
let ty = merge_attrset(output_ty, &GENERIC_FLAKE);
let ty = merge_attrset(
&ty,
&ty!({
"outputs": (#output_ty.clone()),
}),
);
(*name, ty, AttrSource::Unknown)
})
.chain(Some(("self", ty!({}), AttrSource::Unknown))),

View file

@ -281,7 +281,8 @@ fn input_flake_ty() {
{
inputs.nixpkgs = "...";
outputs = { self, nixpkgs }: {
export = nixpkgs.hello;
export1 = nixpkgs.outputs.hello;
export2 = nixpkgs.hello;
};
}
"#;
@ -309,12 +310,17 @@ fn input_flake_ty() {
},
)]),
}));
let name = db
.module(file)
.names()
.find(|(_, n)| n.text == "export")
.expect("Name not found")
.0;
let ty = db.infer(file).ty_for_name(name).debug().to_string();
expect.assert_eq(&ty);
let ty_for_name = |name: &str| {
let name = db
.module(file)
.names()
.find(|(_, n)| n.text == name)
.expect("Name not found")
.0;
db.infer(file).ty_for_name(name).debug().to_string()
};
let ty1 = ty_for_name("export1");
let ty2 = ty_for_name("export2");
assert_eq!(ty1, ty2);
expect.assert_eq(&ty1);
}