Skip to content

Commit 043cd03

Browse files
authored
feat(grit): add formatting of more nodes (#4472)
1 parent 50093fb commit 043cd03

36 files changed

+990
-92
lines changed
Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
use crate::prelude::*;
22
use biome_grit_syntax::GritSequential;
3-
use biome_rowan::AstNode;
3+
44
#[derive(Debug, Clone, Default)]
55
pub(crate) struct FormatGritSequential;
66
impl FormatNodeRule<GritSequential> for FormatGritSequential {
77
fn fmt_fields(&self, node: &GritSequential, f: &mut GritFormatter) -> FormatResult<()> {
88
format_verbatim_node(node.syntax()).fmt(f)
9+
10+
// TODO: investigate the verbatim panic when this code runs
11+
// let GritSequentialFields {
12+
// l_curly_token,
13+
// sequential_token,
14+
// sequential,
15+
// r_curly_token,
16+
// } = node.as_fields();
17+
//
18+
// write!(
19+
// f,
20+
// [
21+
// sequential_token.format(),
22+
// space(),
23+
// l_curly_token.format(),
24+
// sequential.format(),
25+
// r_curly_token.format()
26+
// ]
27+
// )
928
}
1029
}
Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
use crate::prelude::*;
2-
use biome_grit_syntax::GritPatternAnd;
3-
use biome_rowan::AstNode;
2+
use biome_formatter::write;
3+
use biome_grit_syntax::{GritPatternAnd, GritPatternAndFields};
44
#[derive(Debug, Clone, Default)]
55
pub(crate) struct FormatGritPatternAnd;
66
impl FormatNodeRule<GritPatternAnd> for FormatGritPatternAnd {
77
fn fmt_fields(&self, node: &GritPatternAnd, f: &mut GritFormatter) -> FormatResult<()> {
8-
format_verbatim_node(node.syntax()).fmt(f)
8+
let GritPatternAndFields {
9+
patterns,
10+
and_token,
11+
l_curly_token,
12+
r_curly_token,
13+
} = node.as_fields();
14+
15+
write!(
16+
f,
17+
[
18+
and_token.format(),
19+
space(),
20+
l_curly_token.format(),
21+
space(),
22+
patterns.format(),
23+
space(),
24+
r_curly_token.format()
25+
]
26+
)
927
}
1028
}
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
use crate::prelude::*;
2-
use biome_grit_syntax::GritPatternContains;
3-
use biome_rowan::AstNode;
2+
use biome_formatter::write;
3+
use biome_grit_syntax::{GritPatternContains, GritPatternContainsFields};
4+
45
#[derive(Debug, Clone, Default)]
56
pub(crate) struct FormatGritPatternContains;
67
impl FormatNodeRule<GritPatternContains> for FormatGritPatternContains {
78
fn fmt_fields(&self, node: &GritPatternContains, f: &mut GritFormatter) -> FormatResult<()> {
8-
format_verbatim_node(node.syntax()).fmt(f)
9+
let GritPatternContainsFields {
10+
contains,
11+
contains_token,
12+
until_clause,
13+
} = node.as_fields();
14+
15+
write!(f, [contains_token.format(), space(), contains.format()])?;
16+
17+
if let Some(until_clause) = until_clause {
18+
write!(f, [space(), until_clause.format()])?;
19+
}
20+
21+
Ok(())
922
}
1023
}
Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
use crate::prelude::*;
2-
use biome_grit_syntax::GritCurlyPredicateList;
3-
use biome_rowan::AstNode;
2+
use biome_formatter::write;
3+
use biome_grit_syntax::{GritCurlyPredicateList, GritCurlyPredicateListFields};
4+
45
#[derive(Debug, Clone, Default)]
56
pub(crate) struct FormatGritCurlyPredicateList;
67
impl FormatNodeRule<GritCurlyPredicateList> for FormatGritCurlyPredicateList {
78
fn fmt_fields(&self, node: &GritCurlyPredicateList, f: &mut GritFormatter) -> FormatResult<()> {
8-
format_verbatim_node(node.syntax()).fmt(f)
9+
let GritCurlyPredicateListFields {
10+
predicates,
11+
r_curly_token,
12+
l_curly_token,
13+
} = node.as_fields();
14+
15+
write!(
16+
f,
17+
[
18+
l_curly_token.format(),
19+
predicates.format(),
20+
r_curly_token.format()
21+
]
22+
)
923
}
1024
}
Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
use crate::prelude::*;
2-
use biome_grit_syntax::GritPredicateAny;
3-
use biome_rowan::AstNode;
2+
use biome_formatter::write;
3+
use biome_grit_syntax::{GritPredicateAny, GritPredicateAnyFields};
4+
45
#[derive(Debug, Clone, Default)]
56
pub(crate) struct FormatGritPredicateAny;
67
impl FormatNodeRule<GritPredicateAny> for FormatGritPredicateAny {
78
fn fmt_fields(&self, node: &GritPredicateAny, f: &mut GritFormatter) -> FormatResult<()> {
8-
format_verbatim_node(node.syntax()).fmt(f)
9+
let GritPredicateAnyFields {
10+
any_token,
11+
l_curly_token,
12+
predicates,
13+
r_curly_token,
14+
} = node.as_fields();
15+
write!(
16+
f,
17+
[
18+
l_curly_token.format(),
19+
hard_line_break(),
20+
any_token.format(),
21+
hard_line_break(),
22+
soft_block_indent(&predicates.format()),
23+
hard_line_break(),
24+
r_curly_token.format()
25+
]
26+
)
927
}
1028
}
Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
use crate::prelude::*;
2-
use biome_grit_syntax::GritPredicateCall;
3-
use biome_rowan::AstNode;
2+
use biome_formatter::write;
3+
use biome_grit_syntax::{GritPredicateCall, GritPredicateCallFields};
4+
45
#[derive(Debug, Clone, Default)]
56
pub(crate) struct FormatGritPredicateCall;
67
impl FormatNodeRule<GritPredicateCall> for FormatGritPredicateCall {
78
fn fmt_fields(&self, node: &GritPredicateCall, f: &mut GritFormatter) -> FormatResult<()> {
8-
format_verbatim_node(node.syntax()).fmt(f)
9+
let GritPredicateCallFields {
10+
name,
11+
l_paren_token,
12+
named_args,
13+
r_paren_token,
14+
} = node.as_fields();
15+
write!(
16+
f,
17+
[
18+
name.format(),
19+
l_paren_token.format(),
20+
named_args.format(),
21+
r_paren_token.format()
22+
]
23+
)
924
}
1025
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::prelude::*;
2-
use biome_grit_syntax::GritBacktickSnippetLiteral;
3-
use biome_rowan::AstNode;
2+
use biome_formatter::write;
3+
use biome_grit_syntax::{GritBacktickSnippetLiteral, GritBacktickSnippetLiteralFields};
4+
45
#[derive(Debug, Clone, Default)]
56
pub(crate) struct FormatGritBacktickSnippetLiteral;
67
impl FormatNodeRule<GritBacktickSnippetLiteral> for FormatGritBacktickSnippetLiteral {
@@ -9,6 +10,7 @@ impl FormatNodeRule<GritBacktickSnippetLiteral> for FormatGritBacktickSnippetLit
910
node: &GritBacktickSnippetLiteral,
1011
f: &mut GritFormatter,
1112
) -> FormatResult<()> {
12-
format_verbatim_node(node.syntax()).fmt(f)
13+
let GritBacktickSnippetLiteralFields { value_token } = node.as_fields();
14+
write!(f, [value_token.format()])
1315
}
1416
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use crate::prelude::*;
2-
use biome_grit_syntax::GritBooleanLiteral;
3-
use biome_rowan::AstNode;
2+
use biome_formatter::write;
3+
use biome_grit_syntax::{GritBooleanLiteral, GritBooleanLiteralFields};
4+
45
#[derive(Debug, Clone, Default)]
56
pub(crate) struct FormatGritBooleanLiteral;
67
impl FormatNodeRule<GritBooleanLiteral> for FormatGritBooleanLiteral {
78
fn fmt_fields(&self, node: &GritBooleanLiteral, f: &mut GritFormatter) -> FormatResult<()> {
8-
format_verbatim_node(node.syntax()).fmt(f)
9+
let GritBooleanLiteralFields { value } = node.as_fields();
10+
write!(f, [value.format()])
911
}
1012
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use crate::prelude::*;
2-
use biome_grit_syntax::GritCodeSnippet;
3-
use biome_rowan::AstNode;
2+
use biome_formatter::write;
3+
use biome_grit_syntax::{GritCodeSnippet, GritCodeSnippetFields};
4+
45
#[derive(Debug, Clone, Default)]
56
pub(crate) struct FormatGritCodeSnippet;
67
impl FormatNodeRule<GritCodeSnippet> for FormatGritCodeSnippet {
78
fn fmt_fields(&self, node: &GritCodeSnippet, f: &mut GritFormatter) -> FormatResult<()> {
8-
format_verbatim_node(node.syntax()).fmt(f)
9+
let GritCodeSnippetFields { source } = node.as_fields();
10+
write!(f, [source.format()])
911
}
1012
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use crate::prelude::*;
2-
use biome_grit_syntax::GritDoubleLiteral;
3-
use biome_rowan::AstNode;
2+
use biome_formatter::write;
3+
use biome_grit_syntax::{GritDoubleLiteral, GritDoubleLiteralFields};
4+
45
#[derive(Debug, Clone, Default)]
56
pub(crate) struct FormatGritDoubleLiteral;
67
impl FormatNodeRule<GritDoubleLiteral> for FormatGritDoubleLiteral {
78
fn fmt_fields(&self, node: &GritDoubleLiteral, f: &mut GritFormatter) -> FormatResult<()> {
8-
format_verbatim_node(node.syntax()).fmt(f)
9+
let GritDoubleLiteralFields { value_token } = node.as_fields();
10+
write!(f, [value_token.format()])
911
}
1012
}

0 commit comments

Comments
 (0)