mirror of
https://github.com/RGBCube/alejandra
synced 2025-07-30 12:07:46 +00:00
refactor: remove unnecessary code
This commit is contained in:
parent
5c3d7ab8b7
commit
9f33b633a8
19 changed files with 133 additions and 173 deletions
|
@ -1,12 +1,5 @@
|
|||
#[derive(Clone)]
|
||||
pub(crate) struct Child {
|
||||
pub element: rnix::SyntaxElement,
|
||||
#[allow(dead_code)]
|
||||
pub pos: crate::position::Position,
|
||||
}
|
||||
|
||||
pub(crate) struct Children {
|
||||
children: Vec<Child>,
|
||||
children: Vec<rnix::SyntaxElement>,
|
||||
current_index: usize,
|
||||
}
|
||||
|
||||
|
@ -20,44 +13,34 @@ impl Children {
|
|||
build_ctx: &crate::builder::BuildCtx,
|
||||
node: &rnix::SyntaxNode,
|
||||
) -> Children {
|
||||
let mut children = Vec::new();
|
||||
let mut children: Vec<rnix::SyntaxElement> = Vec::new();
|
||||
|
||||
let mut pos = build_ctx.pos_old.clone();
|
||||
|
||||
for child in node.children_with_tokens() {
|
||||
match child {
|
||||
rnix::SyntaxElement::Node(node) => {
|
||||
children.push(Child {
|
||||
element: node.clone().into(),
|
||||
pos: pos.clone(),
|
||||
});
|
||||
children.push(node.clone().into());
|
||||
pos.update(&node.text().to_string());
|
||||
}
|
||||
rnix::SyntaxElement::Token(token) => {
|
||||
match token.kind() {
|
||||
rnix::SyntaxKind::TOKEN_COMMENT => {
|
||||
children.push(Child {
|
||||
element: crate::builder::make_isolated_token(
|
||||
children.push(
|
||||
crate::builder::make_isolated_token(
|
||||
rnix::SyntaxKind::TOKEN_COMMENT,
|
||||
&dedent_comment(&pos, token.text()),
|
||||
)
|
||||
.into(),
|
||||
pos: pos.clone(),
|
||||
});
|
||||
);
|
||||
}
|
||||
rnix::SyntaxKind::TOKEN_WHITESPACE => {
|
||||
if crate::utils::count_newlines(token.text()) > 0 {
|
||||
children.push(Child {
|
||||
element: token.clone().into(),
|
||||
pos: pos.clone(),
|
||||
});
|
||||
children.push(token.clone().into());
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
children.push(Child {
|
||||
element: token.clone().into(),
|
||||
pos: pos.clone(),
|
||||
});
|
||||
children.push(token.clone().into());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,7 +52,7 @@ impl Children {
|
|||
Children { children, current_index: 0 }
|
||||
}
|
||||
|
||||
pub fn get(&mut self, index: usize) -> Option<Child> {
|
||||
pub fn get(&mut self, index: usize) -> Option<rnix::SyntaxElement> {
|
||||
if index + 1 > self.children.len() {
|
||||
None
|
||||
} else {
|
||||
|
@ -77,13 +60,13 @@ impl Children {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_next(&mut self) -> Option<Child> {
|
||||
pub fn get_next(&mut self) -> Option<rnix::SyntaxElement> {
|
||||
let child = self.get(self.current_index);
|
||||
self.move_next();
|
||||
child
|
||||
}
|
||||
|
||||
pub fn get_remaining(&mut self) -> Vec<Child> {
|
||||
pub fn get_remaining(&mut self) -> Vec<rnix::SyntaxElement> {
|
||||
let remaining = &self.children[self.current_index..self.children.len()];
|
||||
self.current_index = self.children.len();
|
||||
remaining.to_vec()
|
||||
|
@ -93,11 +76,11 @@ impl Children {
|
|||
self.current_index < self.children.len()
|
||||
}
|
||||
|
||||
pub fn peek_next(&mut self) -> Option<Child> {
|
||||
pub fn peek_next(&mut self) -> Option<rnix::SyntaxElement> {
|
||||
self.get(self.current_index)
|
||||
}
|
||||
|
||||
pub fn peek_prev(&mut self) -> Option<Child> {
|
||||
pub fn peek_prev(&mut self) -> Option<rnix::SyntaxElement> {
|
||||
self.get(self.current_index - 1)
|
||||
}
|
||||
|
||||
|
@ -110,38 +93,32 @@ impl Children {
|
|||
}
|
||||
|
||||
pub fn has_comments(&self) -> bool {
|
||||
self.children.iter().any(|child| {
|
||||
child.element.kind() == rnix::SyntaxKind::TOKEN_COMMENT
|
||||
})
|
||||
self.children
|
||||
.iter()
|
||||
.any(|child| child.kind() == rnix::SyntaxKind::TOKEN_COMMENT)
|
||||
}
|
||||
|
||||
pub fn has_newlines(&self) -> bool {
|
||||
self.children.iter().any(|child| {
|
||||
child.element.kind() == rnix::SyntaxKind::TOKEN_WHITESPACE
|
||||
child.kind() == rnix::SyntaxKind::TOKEN_WHITESPACE
|
||||
&& crate::utils::has_newlines(
|
||||
child.element.as_token().as_ref().unwrap().text(),
|
||||
child.as_token().as_ref().unwrap().text(),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn drain_trivia<F: FnMut(Trivia)>(&mut self, mut callback: F) {
|
||||
while let Some(child) = self.peek_next() {
|
||||
match child.element.kind() {
|
||||
match child.kind() {
|
||||
rnix::SyntaxKind::TOKEN_COMMENT => {
|
||||
callback(Trivia::Comment(
|
||||
child.element.into_token().unwrap().text().to_string(),
|
||||
child.into_token().unwrap().text().to_string(),
|
||||
));
|
||||
self.move_next();
|
||||
}
|
||||
rnix::SyntaxKind::TOKEN_WHITESPACE => {
|
||||
callback(Trivia::Whitespace(
|
||||
child
|
||||
.element
|
||||
.as_token()
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.text()
|
||||
.to_string(),
|
||||
child.as_token().as_ref().unwrap().text().to_string(),
|
||||
));
|
||||
self.move_next();
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ pub(crate) fn parse(
|
|||
});
|
||||
|
||||
// expr
|
||||
if_else.if_expr = Some(children.get_next().unwrap().element);
|
||||
if_else.if_expr = Some(children.get_next().unwrap());
|
||||
|
||||
// /**/
|
||||
children.drain_trivia(|element| match element {
|
||||
|
@ -54,7 +54,7 @@ pub(crate) fn parse(
|
|||
});
|
||||
|
||||
// expr
|
||||
if_else.then_expr = Some(children.get_next().unwrap().element);
|
||||
if_else.then_expr = Some(children.get_next().unwrap());
|
||||
|
||||
// /**/
|
||||
children.drain_trivia(|element| match element {
|
||||
|
@ -76,7 +76,7 @@ pub(crate) fn parse(
|
|||
});
|
||||
|
||||
// expr
|
||||
if_else.else_expr = Some(children.get_next().unwrap().element);
|
||||
if_else.else_expr = Some(children.get_next().unwrap());
|
||||
|
||||
if_else
|
||||
}
|
||||
|
|
|
@ -27,8 +27,8 @@ pub(crate) fn parse(
|
|||
|
||||
// x @
|
||||
let child = children.peek_next().unwrap();
|
||||
if let rnix::SyntaxKind::NODE_PAT_BIND = child.element.kind() {
|
||||
pattern.initial_at = Some(child.element);
|
||||
if let rnix::SyntaxKind::NODE_PAT_BIND = child.kind() {
|
||||
pattern.initial_at = Some(child);
|
||||
children.move_next();
|
||||
}
|
||||
|
||||
|
@ -50,9 +50,9 @@ pub(crate) fn parse(
|
|||
// Before an item we can have: comma, comments, whitespace
|
||||
loop {
|
||||
let child = children.peek_next().unwrap();
|
||||
// eprintln!("before item {:?}", child.element.kind());
|
||||
// eprintln!("before item {:?}", child.kind());
|
||||
|
||||
match child.element.kind() {
|
||||
match child.kind() {
|
||||
rnix::SyntaxKind::NODE_PAT_ENTRY
|
||||
| rnix::SyntaxKind::TOKEN_CURLY_B_CLOSE
|
||||
| rnix::SyntaxKind::TOKEN_ELLIPSIS => {
|
||||
|
@ -62,8 +62,7 @@ pub(crate) fn parse(
|
|||
children.move_next();
|
||||
}
|
||||
rnix::SyntaxKind::TOKEN_COMMENT => {
|
||||
let content =
|
||||
child.element.into_token().unwrap().to_string();
|
||||
let content = child.into_token().unwrap().to_string();
|
||||
|
||||
argument.comments_before.push_back(content);
|
||||
children.move_next();
|
||||
|
@ -77,8 +76,8 @@ pub(crate) fn parse(
|
|||
|
||||
// item
|
||||
let child = children.peek_next().unwrap();
|
||||
// eprintln!("item {:?}", child.element.kind());
|
||||
match child.element.kind() {
|
||||
// eprintln!("item {:?}", child.kind());
|
||||
match child.kind() {
|
||||
rnix::SyntaxKind::TOKEN_CURLY_B_CLOSE => {
|
||||
pattern.comments_before_curly_b_close =
|
||||
argument.comments_before;
|
||||
|
@ -86,7 +85,7 @@ pub(crate) fn parse(
|
|||
}
|
||||
rnix::SyntaxKind::TOKEN_ELLIPSIS
|
||||
| rnix::SyntaxKind::NODE_PAT_ENTRY => {
|
||||
argument.item = Some(child.element);
|
||||
argument.item = Some(child);
|
||||
children.move_next();
|
||||
}
|
||||
_ => {}
|
||||
|
@ -95,9 +94,9 @@ pub(crate) fn parse(
|
|||
// After an item we can have: comma, comments, whitespace
|
||||
loop {
|
||||
let child = children.peek_next().unwrap();
|
||||
// eprintln!("after item {:?}", child.element.kind());
|
||||
// eprintln!("after item {:?}", child.kind());
|
||||
|
||||
match child.element.kind() {
|
||||
match child.kind() {
|
||||
rnix::SyntaxKind::NODE_PAT_ENTRY
|
||||
| rnix::SyntaxKind::TOKEN_ELLIPSIS
|
||||
| rnix::SyntaxKind::TOKEN_CURLY_B_CLOSE => {
|
||||
|
@ -107,16 +106,14 @@ pub(crate) fn parse(
|
|||
children.move_next();
|
||||
}
|
||||
rnix::SyntaxKind::TOKEN_COMMENT => {
|
||||
let content =
|
||||
child.element.into_token().unwrap().to_string();
|
||||
let content = child.into_token().unwrap().to_string();
|
||||
|
||||
children.move_next();
|
||||
argument.comment_after = Some(content);
|
||||
break;
|
||||
}
|
||||
rnix::SyntaxKind::TOKEN_WHITESPACE => {
|
||||
let content =
|
||||
child.element.into_token().unwrap().to_string();
|
||||
let content = child.into_token().unwrap().to_string();
|
||||
|
||||
children.move_next();
|
||||
if crate::utils::count_newlines(&content) > 0 {
|
||||
|
@ -143,8 +140,8 @@ pub(crate) fn parse(
|
|||
|
||||
// @ x
|
||||
if let Some(child) = children.peek_next() {
|
||||
if let rnix::SyntaxKind::NODE_PAT_BIND = child.element.kind() {
|
||||
pattern.end_at = Some(child.element);
|
||||
if let rnix::SyntaxKind::NODE_PAT_BIND = child.kind() {
|
||||
pattern.end_at = Some(child);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,9 +14,9 @@ pub(crate) fn rule(
|
|||
let child = children.get_next().unwrap();
|
||||
|
||||
if vertical {
|
||||
steps.push_back(crate::builder::Step::FormatWider(child.element));
|
||||
steps.push_back(crate::builder::Step::FormatWider(child));
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
}
|
||||
|
||||
// /**/
|
||||
|
@ -35,24 +35,24 @@ pub(crate) fn rule(
|
|||
let child = children.get_next().unwrap();
|
||||
if vertical {
|
||||
if let rnix::SyntaxKind::TOKEN_COMMENT
|
||||
| rnix::SyntaxKind::TOKEN_WHITESPACE = child_prev.element.kind()
|
||||
| rnix::SyntaxKind::TOKEN_WHITESPACE = child_prev.kind()
|
||||
{
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
} else if let rnix::SyntaxKind::NODE_ATTR_SET
|
||||
| rnix::SyntaxKind::NODE_LIST
|
||||
| rnix::SyntaxKind::NODE_PAREN
|
||||
| rnix::SyntaxKind::NODE_STRING = child.element.kind()
|
||||
| rnix::SyntaxKind::NODE_STRING = child.kind()
|
||||
{
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
};
|
||||
steps.push_back(crate::builder::Step::FormatWider(child.element));
|
||||
steps.push_back(crate::builder::Step::FormatWider(child));
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
}
|
||||
|
||||
steps
|
||||
|
|
|
@ -12,7 +12,7 @@ pub(crate) fn rule(
|
|||
|
||||
// with
|
||||
let child = children.get_next().unwrap();
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
|
||||
// /**/
|
||||
let mut comment = false;
|
||||
|
@ -36,14 +36,14 @@ pub(crate) fn rule(
|
|||
// expr
|
||||
let child = children.get_next().unwrap();
|
||||
if vertical {
|
||||
steps.push_back(crate::builder::Step::FormatWider(child.element));
|
||||
steps.push_back(crate::builder::Step::FormatWider(child));
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
}
|
||||
|
||||
// ;
|
||||
let child = children.get_next().unwrap();
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
|
||||
// /**/
|
||||
let mut comment: bool = false;
|
||||
|
@ -62,16 +62,16 @@ pub(crate) fn rule(
|
|||
if vertical {
|
||||
if {
|
||||
matches!(
|
||||
child.element.kind(),
|
||||
child.kind(),
|
||||
rnix::SyntaxKind::NODE_ASSERT | rnix::SyntaxKind::NODE_WITH
|
||||
)
|
||||
} {
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
steps.push_back(crate::builder::Step::FormatWider(child.element));
|
||||
steps.push_back(crate::builder::Step::FormatWider(child));
|
||||
} else if comment
|
||||
|| !matches!(
|
||||
child.element.kind(),
|
||||
child.kind(),
|
||||
rnix::SyntaxKind::NODE_ATTR_SET
|
||||
| rnix::SyntaxKind::NODE_IDENT
|
||||
| rnix::SyntaxKind::NODE_PAREN
|
||||
|
@ -84,15 +84,15 @@ pub(crate) fn rule(
|
|||
steps.push_back(crate::builder::Step::Indent);
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
steps.push_back(crate::builder::Step::FormatWider(child.element));
|
||||
steps.push_back(crate::builder::Step::FormatWider(child));
|
||||
steps.push_back(crate::builder::Step::Dedent);
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
steps.push_back(crate::builder::Step::FormatWider(child.element));
|
||||
steps.push_back(crate::builder::Step::FormatWider(child));
|
||||
}
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
}
|
||||
|
||||
steps
|
||||
|
|
|
@ -32,13 +32,13 @@ pub(crate) fn rule(
|
|||
|
||||
// rec
|
||||
let child = children.peek_next().unwrap();
|
||||
if let rnix::SyntaxKind::TOKEN_REC = child.element.kind() {
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
if let rnix::SyntaxKind::TOKEN_REC = child.kind() {
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
children.move_next();
|
||||
|
||||
if let rnix::SyntaxKind::TOKEN_COMMENT
|
||||
| rnix::SyntaxKind::TOKEN_WHITESPACE =
|
||||
children.peek_next().unwrap().element.kind()
|
||||
children.peek_next().unwrap().kind()
|
||||
{
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
|
@ -59,7 +59,7 @@ pub(crate) fn rule(
|
|||
|
||||
// {
|
||||
let child = children.get_next().unwrap();
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
if vertical {
|
||||
steps.push_back(crate::builder::Step::Indent);
|
||||
}
|
||||
|
@ -93,8 +93,7 @@ pub(crate) fn rule(
|
|||
});
|
||||
|
||||
if let Some(child) = children.peek_next() {
|
||||
if let rnix::SyntaxKind::TOKEN_CURLY_B_CLOSE = child.element.kind()
|
||||
{
|
||||
if let rnix::SyntaxKind::TOKEN_CURLY_B_CLOSE = child.kind() {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -103,14 +102,12 @@ pub(crate) fn rule(
|
|||
if vertical {
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
steps.push_back(crate::builder::Step::FormatWider(
|
||||
child.element,
|
||||
));
|
||||
steps.push_back(crate::builder::Step::FormatWider(child));
|
||||
} else {
|
||||
if item_index > 1 {
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
}
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
}
|
||||
children.move_next();
|
||||
inline_next_comment = true;
|
||||
|
@ -124,7 +121,7 @@ pub(crate) fn rule(
|
|||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
}
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
|
||||
steps
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ pub(crate) fn rule_with_configuration(
|
|||
// expr
|
||||
let child = children.get_next().unwrap();
|
||||
if vertical {
|
||||
let kind = child.element.kind();
|
||||
let kind = child.kind();
|
||||
|
||||
if (parent_kind == "bin_op_and_or_default"
|
||||
&& matches!(
|
||||
|
@ -32,14 +32,14 @@ pub(crate) fn rule_with_configuration(
|
|||
|| (parent_kind == "select"
|
||||
&& matches!(kind, rnix::SyntaxKind::NODE_SELECT))
|
||||
{
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::FormatWider(child.element));
|
||||
steps.push_back(crate::builder::Step::FormatWider(child));
|
||||
}
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
}
|
||||
|
||||
// /**/
|
||||
|
@ -57,7 +57,7 @@ pub(crate) fn rule_with_configuration(
|
|||
if !vertical && parent_kind == "bin_op_and_or_default" {
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
}
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
|
||||
// /**/
|
||||
let mut comment = false;
|
||||
|
@ -81,9 +81,9 @@ pub(crate) fn rule_with_configuration(
|
|||
// expr
|
||||
let child = children.get_next().unwrap();
|
||||
if vertical {
|
||||
steps.push_back(crate::builder::Step::FormatWider(child.element));
|
||||
steps.push_back(crate::builder::Step::FormatWider(child));
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
}
|
||||
|
||||
steps
|
||||
|
|
|
@ -12,7 +12,7 @@ pub(crate) fn rule(
|
|||
|
||||
// ${
|
||||
let child = children.get_next().unwrap();
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
if vertical {
|
||||
steps.push_back(crate::builder::Step::Indent);
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
|
@ -32,9 +32,9 @@ pub(crate) fn rule(
|
|||
// expr
|
||||
let child = children.get_next().unwrap();
|
||||
if vertical {
|
||||
steps.push_back(crate::builder::Step::FormatWider(child.element));
|
||||
steps.push_back(crate::builder::Step::FormatWider(child));
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
}
|
||||
|
||||
// /**/
|
||||
|
@ -54,7 +54,7 @@ pub(crate) fn rule(
|
|||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
}
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
|
||||
steps
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ pub(crate) fn rule(
|
|||
|
||||
// inherit
|
||||
let child = children.get_next().unwrap();
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
if vertical {
|
||||
steps.push_back(crate::builder::Step::Indent);
|
||||
}
|
||||
|
@ -33,16 +33,13 @@ pub(crate) fn rule(
|
|||
if vertical {
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
steps.push_back(crate::builder::Step::FormatWider(
|
||||
child.element,
|
||||
));
|
||||
steps.push_back(crate::builder::Step::FormatWider(child));
|
||||
} else {
|
||||
if let rnix::SyntaxKind::TOKEN_SEMICOLON = child.element.kind()
|
||||
{
|
||||
if let rnix::SyntaxKind::TOKEN_SEMICOLON = child.kind() {
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
}
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
|
|
|
@ -13,9 +13,9 @@ pub(crate) fn rule(
|
|||
// a
|
||||
let child = children.get_next().unwrap();
|
||||
if vertical {
|
||||
steps.push_back(crate::builder::Step::FormatWider(child.element));
|
||||
steps.push_back(crate::builder::Step::FormatWider(child));
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
}
|
||||
|
||||
// /**/
|
||||
|
@ -67,7 +67,7 @@ pub(crate) fn rule(
|
|||
|
||||
// =
|
||||
let mut dedent = false;
|
||||
steps.push_back(crate::builder::Step::Format(child_equal.element));
|
||||
steps.push_back(crate::builder::Step::Format(child_equal));
|
||||
|
||||
if vertical {
|
||||
if !comments_before.is_empty() || !comments_after.is_empty() {
|
||||
|
@ -76,7 +76,7 @@ pub(crate) fn rule(
|
|||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
} else if matches!(
|
||||
child_expr.element.kind(),
|
||||
child_expr.kind(),
|
||||
rnix::SyntaxKind::NODE_ASSERT
|
||||
| rnix::SyntaxKind::NODE_ATTR_SET
|
||||
| rnix::SyntaxKind::NODE_PAREN
|
||||
|
@ -86,7 +86,7 @@ pub(crate) fn rule(
|
|||
| rnix::SyntaxKind::NODE_STRING
|
||||
| rnix::SyntaxKind::NODE_WITH
|
||||
) || (matches!(
|
||||
child_expr.element.kind(),
|
||||
child_expr.kind(),
|
||||
rnix::SyntaxKind::NODE_APPLY
|
||||
) && !newlines)
|
||||
{
|
||||
|
@ -110,13 +110,13 @@ pub(crate) fn rule(
|
|||
|
||||
// expr
|
||||
if vertical {
|
||||
steps.push_back(crate::builder::Step::FormatWider(child_expr.element));
|
||||
steps.push_back(crate::builder::Step::FormatWider(child_expr));
|
||||
if !comments_after.is_empty() {
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
}
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::Format(child_expr.element));
|
||||
steps.push_back(crate::builder::Step::Format(child_expr));
|
||||
}
|
||||
|
||||
// /**/
|
||||
|
@ -128,7 +128,7 @@ pub(crate) fn rule(
|
|||
|
||||
// ;
|
||||
let child = children.get_next().unwrap();
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
if dedent {
|
||||
steps.push_back(crate::builder::Step::Dedent);
|
||||
}
|
||||
|
|
|
@ -13,14 +13,14 @@ pub(crate) fn rule(
|
|||
// a
|
||||
let child = children.get_next().unwrap();
|
||||
if vertical {
|
||||
steps.push_back(crate::builder::Step::FormatWider(child.element));
|
||||
steps.push_back(crate::builder::Step::FormatWider(child));
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
}
|
||||
|
||||
if let rnix::SyntaxKind::TOKEN_COMMENT
|
||||
| rnix::SyntaxKind::TOKEN_WHITESPACE =
|
||||
children.peek_next().unwrap().element.kind()
|
||||
children.peek_next().unwrap().kind()
|
||||
{
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
|
@ -38,7 +38,7 @@ pub(crate) fn rule(
|
|||
|
||||
// :
|
||||
let child = children.get_next().unwrap();
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
|
||||
// /**/
|
||||
let mut comment = false;
|
||||
|
@ -57,7 +57,7 @@ pub(crate) fn rule(
|
|||
if vertical {
|
||||
if comment
|
||||
|| !matches!(
|
||||
child.element.kind(),
|
||||
child.kind(),
|
||||
rnix::SyntaxKind::NODE_ATTR_SET
|
||||
| rnix::SyntaxKind::NODE_PAREN
|
||||
| rnix::SyntaxKind::NODE_LAMBDA
|
||||
|
@ -68,7 +68,7 @@ pub(crate) fn rule(
|
|||
)
|
||||
{
|
||||
let should_indent = !matches!(
|
||||
child.element.kind(),
|
||||
child.kind(),
|
||||
rnix::SyntaxKind::NODE_ATTR_SET
|
||||
| rnix::SyntaxKind::NODE_PAREN
|
||||
| rnix::SyntaxKind::NODE_LAMBDA
|
||||
|
@ -83,17 +83,17 @@ pub(crate) fn rule(
|
|||
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
steps.push_back(crate::builder::Step::FormatWider(child.element));
|
||||
steps.push_back(crate::builder::Step::FormatWider(child));
|
||||
if should_indent {
|
||||
steps.push_back(crate::builder::Step::Dedent);
|
||||
}
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
steps.push_back(crate::builder::Step::FormatWider(child.element));
|
||||
steps.push_back(crate::builder::Step::FormatWider(child));
|
||||
}
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
}
|
||||
|
||||
steps
|
||||
|
|
|
@ -25,7 +25,7 @@ pub(crate) fn rule(
|
|||
|
||||
// let
|
||||
let child = children.get_next().unwrap();
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
if vertical {
|
||||
steps.push_back(crate::builder::Step::Indent);
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ pub(crate) fn rule(
|
|||
});
|
||||
|
||||
if let Some(child) = children.peek_next() {
|
||||
if let rnix::SyntaxKind::TOKEN_IN = child.element.kind() {
|
||||
if let rnix::SyntaxKind::TOKEN_IN = child.kind() {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -67,12 +67,10 @@ pub(crate) fn rule(
|
|||
if vertical {
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
steps.push_back(crate::builder::Step::FormatWider(
|
||||
child.element,
|
||||
));
|
||||
steps.push_back(crate::builder::Step::FormatWider(child));
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
}
|
||||
|
||||
children.move_next();
|
||||
|
@ -105,11 +103,11 @@ pub(crate) fn rule(
|
|||
|
||||
// in
|
||||
let mut dedent = false;
|
||||
steps.push_back(crate::builder::Step::Format(child_in.element));
|
||||
steps.push_back(crate::builder::Step::Format(child_in));
|
||||
if vertical {
|
||||
if child_comments.is_empty()
|
||||
&& matches!(
|
||||
child_expr.element.kind(),
|
||||
child_expr.kind(),
|
||||
rnix::SyntaxKind::NODE_ATTR_SET
|
||||
| rnix::SyntaxKind::NODE_LET_IN
|
||||
| rnix::SyntaxKind::NODE_LIST
|
||||
|
@ -135,13 +133,13 @@ pub(crate) fn rule(
|
|||
|
||||
// expr
|
||||
if vertical {
|
||||
steps.push_back(crate::builder::Step::FormatWider(child_expr.element));
|
||||
steps.push_back(crate::builder::Step::FormatWider(child_expr));
|
||||
if dedent {
|
||||
steps.push_back(crate::builder::Step::Dedent);
|
||||
}
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
steps.push_back(crate::builder::Step::Format(child_expr.element));
|
||||
steps.push_back(crate::builder::Step::Format(child_expr));
|
||||
}
|
||||
|
||||
steps
|
||||
|
|
|
@ -20,7 +20,7 @@ pub(crate) fn rule(
|
|||
|
||||
// [
|
||||
let child = children.get_next().unwrap();
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
if vertical {
|
||||
steps.push_back(crate::builder::Step::Indent);
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ pub(crate) fn rule(
|
|||
});
|
||||
|
||||
if let Some(child) = children.peek_next() {
|
||||
let child_kind = child.element.kind();
|
||||
let child_kind = child.kind();
|
||||
|
||||
if let rnix::SyntaxKind::TOKEN_SQUARE_B_CLOSE = child_kind {
|
||||
break;
|
||||
|
@ -71,14 +71,12 @@ pub(crate) fn rule(
|
|||
if vertical {
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
steps.push_back(crate::builder::Step::FormatWider(
|
||||
child.element,
|
||||
));
|
||||
steps.push_back(crate::builder::Step::FormatWider(child));
|
||||
} else {
|
||||
if item_index > 1 {
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
}
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
}
|
||||
|
||||
children.move_next();
|
||||
|
@ -93,7 +91,7 @@ pub(crate) fn rule(
|
|||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
}
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
|
||||
steps
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ pub(crate) fn rule(
|
|||
|
||||
// (
|
||||
let child = children.get_next().unwrap();
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
if vertical && has_comments_or_newlines {
|
||||
steps.push_back(crate::builder::Step::Indent);
|
||||
}
|
||||
|
@ -35,9 +35,9 @@ pub(crate) fn rule(
|
|||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
}
|
||||
steps.push_back(crate::builder::Step::FormatWider(child.element));
|
||||
steps.push_back(crate::builder::Step::FormatWider(child));
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
}
|
||||
|
||||
// /**/
|
||||
|
@ -57,7 +57,7 @@ pub(crate) fn rule(
|
|||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
}
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
|
||||
steps
|
||||
}
|
||||
|
|
|
@ -12,9 +12,9 @@ pub(crate) fn rule(
|
|||
|
||||
let child = children.get_next().unwrap();
|
||||
if vertical {
|
||||
steps.push_back(crate::builder::Step::FormatWider(child.element));
|
||||
steps.push_back(crate::builder::Step::FormatWider(child));
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
}
|
||||
|
||||
// /**/
|
||||
|
@ -38,9 +38,9 @@ pub(crate) fn rule(
|
|||
|
||||
let child = children.get_next().unwrap();
|
||||
if vertical {
|
||||
steps.push_back(crate::builder::Step::FormatWider(child.element));
|
||||
steps.push_back(crate::builder::Step::FormatWider(child));
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
}
|
||||
children.move_prev();
|
||||
|
||||
|
|
|
@ -13,9 +13,9 @@ pub(crate) fn rule(
|
|||
// expr
|
||||
let child = children.get_next().unwrap();
|
||||
if vertical {
|
||||
steps.push_back(crate::builder::Step::FormatWider(child.element));
|
||||
steps.push_back(crate::builder::Step::FormatWider(child));
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
}
|
||||
|
||||
if children.has_next() {
|
||||
|
@ -40,7 +40,7 @@ pub(crate) fn rule(
|
|||
|
||||
// operator
|
||||
let child = children.get_next().unwrap();
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
|
||||
// /**/
|
||||
let mut comment = false;
|
||||
|
@ -62,7 +62,7 @@ pub(crate) fn rule(
|
|||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
} else if matches!(
|
||||
child.element.kind(),
|
||||
child.kind(),
|
||||
rnix::SyntaxKind::NODE_ATTR_SET
|
||||
| rnix::SyntaxKind::NODE_IDENT
|
||||
| rnix::SyntaxKind::NODE_PAREN
|
||||
|
@ -73,7 +73,7 @@ pub(crate) fn rule(
|
|||
| rnix::SyntaxKind::NODE_STRING,
|
||||
) || crate::builder::fits_in_single_line(
|
||||
build_ctx,
|
||||
child.element.clone(),
|
||||
child.clone(),
|
||||
) {
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
} else {
|
||||
|
@ -84,9 +84,9 @@ pub(crate) fn rule(
|
|||
}
|
||||
|
||||
if vertical {
|
||||
steps.push_back(crate::builder::Step::FormatWider(child.element));
|
||||
steps.push_back(crate::builder::Step::FormatWider(child));
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
}
|
||||
if dedent {
|
||||
steps.push_back(crate::builder::Step::Dedent);
|
||||
|
|
|
@ -22,12 +22,10 @@ pub(crate) fn rule(
|
|||
|
||||
if let Some(child) = children.get_next() {
|
||||
if vertical {
|
||||
steps.push_back(crate::builder::Step::FormatWider(
|
||||
child.element,
|
||||
));
|
||||
steps.push_back(crate::builder::Step::FormatWider(child));
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,25 +13,23 @@ pub(crate) fn rule(
|
|||
let mut children = crate::children::Children::new(build_ctx, node);
|
||||
|
||||
let child = children.get_next().unwrap();
|
||||
let child_token = child.element.clone().into_token().unwrap();
|
||||
let child_token = child.clone().into_token().unwrap();
|
||||
let text = child_token.text();
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
|
||||
if text == "\"" {
|
||||
while let Some(child) = children.get_next() {
|
||||
if build_ctx.vertical {
|
||||
steps.push_back(crate::builder::Step::FormatWider(
|
||||
child.element,
|
||||
));
|
||||
steps.push_back(crate::builder::Step::FormatWider(child));
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let elements: Vec<rnix::SyntaxElement> = children
|
||||
.get_remaining()
|
||||
.iter()
|
||||
.map(|child| child.element.clone())
|
||||
.map(|child| child.clone())
|
||||
.collect();
|
||||
|
||||
let mut interpolations = elements
|
||||
|
|
|
@ -12,7 +12,7 @@ pub(crate) fn rule(
|
|||
|
||||
// ${
|
||||
let child = children.get_next().unwrap();
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
if vertical {
|
||||
steps.push_back(crate::builder::Step::Indent);
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
|
@ -32,9 +32,9 @@ pub(crate) fn rule(
|
|||
// expr
|
||||
let child = children.get_next().unwrap();
|
||||
if vertical {
|
||||
steps.push_back(crate::builder::Step::FormatWider(child.element));
|
||||
steps.push_back(crate::builder::Step::FormatWider(child));
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
}
|
||||
|
||||
// /**/
|
||||
|
@ -54,7 +54,7 @@ pub(crate) fn rule(
|
|||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
}
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
steps.push_back(crate::builder::Step::Format(child));
|
||||
|
||||
steps
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue