refactor(xatu): remove unused AST nodes

This commit is contained in:
2026-09-19 20:32:55 -04:00
parent 9b90e9ad3f
commit 3b6184b122
4 changed files with 4 additions and 89 deletions

View File

@@ -28,15 +28,7 @@ impl std::fmt::Display for SourceRange {
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum NodeData {
Apply(Apply),
Assignment(Assignment),
LetIn(LetIn),
Inherit(Inherit),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Apply {
pub function: Expr,
}
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -62,16 +54,6 @@ pub struct Select {
pub attrs: Vec<Ident>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LetIn {
pub binding_count: usize,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Inherit {
pub attr_count: usize,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Token {
pub range: SourceRange,

View File

@@ -1,4 +1,3 @@
use rnix::ast::HasEntry;
use rowan::ast::AstNode;
use crate::{FileId, ast};
@@ -37,35 +36,11 @@ fn convert_syntax(syntax: rnix::SyntaxNode) -> (Vec<ast::Node>, Vec<ast::Token>)
fn convert_node(node: rnix::SyntaxNode) -> Option<ast::Node> {
match node.kind() {
rnix::SyntaxKind::NODE_APPLY => convert_apply(node),
rnix::SyntaxKind::NODE_ATTRPATH_VALUE => convert_assignment(node),
rnix::SyntaxKind::NODE_LET_IN => convert_let_in(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();
let data = apply.try_into().ok()?;
Some(ast::Node {
range,
data: ast::NodeData::Apply(data),
})
}
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()?,
})
}
}
fn convert_assignment(node: rnix::SyntaxNode) -> Option<ast::Node> {
let assignment = rnix::ast::AttrpathValue::cast(node)?;
let range = assignment.syntax().text_range().into();
@@ -140,44 +115,6 @@ impl TryFrom<rnix::ast::Select> for ast::Select {
}
}
fn convert_let_in(node: rnix::SyntaxNode) -> Option<ast::Node> {
let let_in = rnix::ast::LetIn::cast(node)?;
Some(ast::Node {
range: let_in.syntax().text_range().into(),
data: ast::NodeData::LetIn(let_in.into()),
})
}
impl From<rnix::ast::LetIn> for ast::LetIn {
fn from(let_in: rnix::ast::LetIn) -> Self {
Self {
binding_count: let_in.attrpath_values().count()
+ let_in
.inherits()
.map(|inherit| inherit.attrs().count())
.sum::<usize>(),
}
}
}
fn convert_inherit(node: rnix::SyntaxNode) -> Option<ast::Node> {
let inherit = rnix::ast::Inherit::cast(node)?;
Some(ast::Node {
range: inherit.syntax().text_range().into(),
data: ast::NodeData::Inherit(inherit.into()),
})
}
impl From<rnix::ast::Inherit> for ast::Inherit {
fn from(inherit: rnix::ast::Inherit) -> Self {
Self {
attr_count: inherit.attrs().count(),
}
}
}
fn convert_token(token: rnix::SyntaxToken) -> Option<ast::Token> {
match token.kind() {
rnix::SyntaxKind::TOKEN_URI => Some(ast::Token {

View File

@@ -8,10 +8,8 @@ impl NodeRule for ManualInherit {
const ID: &'static str = "manual_inherit";
fn select(data: &ast::NodeData) -> Option<&Self::Node> {
match data {
ast::NodeData::Assignment(assignment) => Some(assignment),
_ => None,
}
let ast::NodeData::Assignment(assignment) = data;
Some(assignment)
}
fn check(assignment: &Self::Node) -> Option<&'static str> {

View File

@@ -8,10 +8,8 @@ impl NodeRule for ManualInheritFrom {
const ID: &'static str = "manual_inherit_from";
fn select(data: &ast::NodeData) -> Option<&Self::Node> {
match data {
ast::NodeData::Assignment(assignment) => Some(assignment),
_ => None,
}
let ast::NodeData::Assignment(assignment) = data;
Some(assignment)
}
fn check(assignment: &Self::Node) -> Option<&'static str> {