feat(xatu): report deprecated toPath calls

This commit is contained in:
2026-09-18 23:57:08 -04:00
parent a6fe84190e
commit f8966fe2a8
9 changed files with 173 additions and 8 deletions

View File

@@ -52,11 +52,22 @@ fn parse_error_range(error: &rnix::ParseError, source_len: usize) -> ast::Source
fn convert_node(node: rnix::SyntaxNode) -> Option<ast::Node> {
match node.kind() {
rnix::SyntaxKind::NODE_APPLY => convert_apply(node),
rnix::SyntaxKind::NODE_INHERIT => convert_inherit(node),
_ => None,
}
}
fn convert_apply(node: rnix::SyntaxNode) -> Option<ast::Node> {
let apply = rnix::ast::Apply::cast(node)?;
let range = apply.syntax().text_range().into();
Some(ast::Node {
range,
data: ast::NodeData::Apply(apply.try_into().ok()?),
})
}
fn convert_inherit(node: rnix::SyntaxNode) -> Option<ast::Node> {
let inherit = rnix::ast::Inherit::cast(node)?;
@@ -75,6 +86,57 @@ impl From<rnix::TextRange> for ast::SourceRange {
}
}
impl TryFrom<rnix::ast::Apply> for ast::Apply {
type Error = ();
fn try_from(apply: rnix::ast::Apply) -> Result<Self, Self::Error> {
Ok(Self {
function: apply.lambda().ok_or(())?.try_into()?,
})
}
}
impl TryFrom<rnix::ast::Expr> for ast::Expr {
type Error = ();
fn try_from(expr: rnix::ast::Expr) -> Result<Self, Self::Error> {
match expr {
rnix::ast::Expr::Ident(ident) => Ok(Self::Ident(ident.try_into()?)),
rnix::ast::Expr::Select(select) => Ok(Self::Select(Box::new(select.try_into()?))),
_ => Err(()),
}
}
}
impl TryFrom<rnix::ast::Ident> for ast::Ident {
type Error = ();
fn try_from(ident: rnix::ast::Ident) -> Result<Self, Self::Error> {
Ok(Self {
name: ident.ident_token().ok_or(())?.text().to_owned(),
})
}
}
impl TryFrom<rnix::ast::Select> for ast::Select {
type Error = ();
fn try_from(select: rnix::ast::Select) -> Result<Self, Self::Error> {
Ok(Self {
receiver: select.expr().ok_or(())?.try_into()?,
attrs: select
.attrpath()
.ok_or(())?
.attrs()
.map(|attr| match attr {
rnix::ast::Attr::Ident(ident) => ident.try_into(),
_ => Err(()),
})
.collect::<Result<Vec<_>, _>>()?,
})
}
}
impl From<rnix::ast::Inherit> for ast::Inherit {
fn from(inherit: rnix::ast::Inherit) -> Self {
Self {