fix(natu): resolve inherited attributes
This commit was merged in pull request #99.
This commit is contained in:
@@ -51,12 +51,7 @@ fn convert_expr(expr: rnix::ast::Expr) -> ast::Expr {
|
||||
let_in.body().expect("let expressions have bodies"),
|
||||
)),
|
||||
},
|
||||
rnix::ast::Expr::AttrSet(attr_set) => ast::Expr::AttrSet(
|
||||
attr_set
|
||||
.attrpath_values()
|
||||
.filter_map(convert_binding_ast)
|
||||
.collect(),
|
||||
),
|
||||
rnix::ast::Expr::AttrSet(attr_set) => ast::Expr::AttrSet(convert_attr_set(attr_set)),
|
||||
rnix::ast::Expr::Lambda(lambda) => ast::Expr::Lambda {
|
||||
parameters: lambda_parameters(&lambda),
|
||||
body: Box::new(convert_expr(lambda.body().expect("lambdas have bodies"))),
|
||||
@@ -77,10 +72,6 @@ fn convert_binding_ast(binding: rnix::ast::AttrpathValue) -> Option<ast::Binding
|
||||
return None;
|
||||
};
|
||||
|
||||
if attrs.next().is_some() {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(ast::Binding {
|
||||
range: binding.syntax().text_range().into(),
|
||||
key: key.into(),
|
||||
@@ -88,6 +79,40 @@ fn convert_binding_ast(binding: rnix::ast::AttrpathValue) -> Option<ast::Binding
|
||||
})
|
||||
}
|
||||
|
||||
fn convert_attr_set(attr_set: rnix::ast::AttrSet) -> Vec<ast::Binding> {
|
||||
attr_set
|
||||
.entries()
|
||||
.flat_map(|entry| match entry {
|
||||
rnix::ast::Entry::AttrpathValue(binding) => {
|
||||
convert_binding_ast(binding).into_iter().collect()
|
||||
}
|
||||
rnix::ast::Entry::Inherit(inherit) => convert_inherit(inherit),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn convert_inherit(inherit: rnix::ast::Inherit) -> Vec<ast::Binding> {
|
||||
let value = inherit
|
||||
.from()
|
||||
.and_then(|from| from.expr())
|
||||
.map(convert_expr);
|
||||
|
||||
inherit
|
||||
.attrs()
|
||||
.filter_map(|attr| match attr {
|
||||
Attr::Ident(ident) => Some(ident),
|
||||
_ => None,
|
||||
})
|
||||
.map(|key| ast::Binding {
|
||||
range: key.syntax().text_range().into(),
|
||||
value: value
|
||||
.clone()
|
||||
.unwrap_or_else(|| ast::Expr::Ident(key.clone().into())),
|
||||
key: key.into(),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn lambda_parameters(lambda: &rnix::ast::Lambda) -> Vec<ast::Ident> {
|
||||
match lambda.param() {
|
||||
Some(rnix::ast::Param::IdentParam(parameter)) => {
|
||||
|
||||
Reference in New Issue
Block a user