Skip to content

Commit

Permalink
feat(grit): complete formatting of all nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Nov 12, 2024
1 parent 929e86d commit 6d95f3a
Show file tree
Hide file tree
Showing 60 changed files with 969 additions and 414 deletions.
32 changes: 16 additions & 16 deletions crates/biome_grit_factory/src/generated/node_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 35 additions & 35 deletions crates/biome_grit_factory/src/generated/syntax_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 40 additions & 40 deletions crates/biome_grit_formatter/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,46 +442,6 @@ impl IntoFormat<GritFormatContext> for biome_grit_syntax::GritCurlyPattern {
)
}
}
impl FormatRule<biome_grit_syntax::GritCurlyPredicateList>
for crate::grit::predicates::curly_predicate_list::FormatGritCurlyPredicateList
{
type Context = GritFormatContext;
#[inline(always)]
fn fmt(
&self,
node: &biome_grit_syntax::GritCurlyPredicateList,
f: &mut GritFormatter,
) -> FormatResult<()> {
FormatNodeRule::<biome_grit_syntax::GritCurlyPredicateList>::fmt(self, node, f)
}
}
impl AsFormat<GritFormatContext> for biome_grit_syntax::GritCurlyPredicateList {
type Format<'a> = FormatRefWithRule<
'a,
biome_grit_syntax::GritCurlyPredicateList,
crate::grit::predicates::curly_predicate_list::FormatGritCurlyPredicateList,
>;
fn format(&self) -> Self::Format<'_> {
#![allow(clippy::default_constructed_unit_structs)]
FormatRefWithRule::new(
self,
crate::grit::predicates::curly_predicate_list::FormatGritCurlyPredicateList::default(),
)
}
}
impl IntoFormat<GritFormatContext> for biome_grit_syntax::GritCurlyPredicateList {
type Format = FormatOwnedWithRule<
biome_grit_syntax::GritCurlyPredicateList,
crate::grit::predicates::curly_predicate_list::FormatGritCurlyPredicateList,
>;
fn into_format(self) -> Self::Format {
#![allow(clippy::default_constructed_unit_structs)]
FormatOwnedWithRule::new(
self,
crate::grit::predicates::curly_predicate_list::FormatGritCurlyPredicateList::default(),
)
}
}
impl FormatRule<biome_grit_syntax::GritDivOperation>
for crate::grit::patterns::div_operation::FormatGritDivOperation
{
Expand Down Expand Up @@ -2432,6 +2392,46 @@ impl IntoFormat<GritFormatContext> for biome_grit_syntax::GritPredicateCall {
)
}
}
impl FormatRule<biome_grit_syntax::GritPredicateCurly>
for crate::grit::predicates::predicate_curly::FormatGritPredicateCurly
{
type Context = GritFormatContext;
#[inline(always)]
fn fmt(
&self,
node: &biome_grit_syntax::GritPredicateCurly,
f: &mut GritFormatter,
) -> FormatResult<()> {
FormatNodeRule::<biome_grit_syntax::GritPredicateCurly>::fmt(self, node, f)
}
}
impl AsFormat<GritFormatContext> for biome_grit_syntax::GritPredicateCurly {
type Format<'a> = FormatRefWithRule<
'a,
biome_grit_syntax::GritPredicateCurly,
crate::grit::predicates::predicate_curly::FormatGritPredicateCurly,
>;
fn format(&self) -> Self::Format<'_> {
#![allow(clippy::default_constructed_unit_structs)]
FormatRefWithRule::new(
self,
crate::grit::predicates::predicate_curly::FormatGritPredicateCurly::default(),
)
}
}
impl IntoFormat<GritFormatContext> for biome_grit_syntax::GritPredicateCurly {
type Format = FormatOwnedWithRule<
biome_grit_syntax::GritPredicateCurly,
crate::grit::predicates::predicate_curly::FormatGritPredicateCurly,
>;
fn into_format(self) -> Self::Format {
#![allow(clippy::default_constructed_unit_structs)]
FormatOwnedWithRule::new(
self,
crate::grit::predicates::predicate_curly::FormatGritPredicateCurly::default(),
)
}
}
impl FormatRule<biome_grit_syntax::GritPredicateDefinition>
for crate::grit::predicates::predicate_definition::FormatGritPredicateDefinition
{
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_grit_formatter/src/grit/auxiliary/annotation.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::prelude::*;
use biome_formatter::write;
use biome_grit_syntax::GritAnnotation;
use biome_rowan::AstNode;
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritAnnotation;
impl FormatNodeRule<GritAnnotation> for FormatGritAnnotation {
fn fmt_fields(&self, node: &GritAnnotation, f: &mut GritFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
write!(f, [node.value_token().format()])
}
}
43 changes: 23 additions & 20 deletions crates/biome_grit_formatter/src/grit/auxiliary/sequential.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
use crate::prelude::*;
use biome_grit_syntax::GritSequential;
use biome_formatter::{write, FormatOptions};
use biome_grit_syntax::{GritSequential, GritSequentialFields};

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritSequential;
impl FormatNodeRule<GritSequential> for FormatGritSequential {
fn fmt_fields(&self, node: &GritSequential, f: &mut GritFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let GritSequentialFields {
l_curly_token,
sequential_token,
sequential,
r_curly_token,
} = node.as_fields();

// TODO: investigate the verbatim panic when this code runs
// let GritSequentialFields {
// l_curly_token,
// sequential_token,
// sequential,
// r_curly_token,
// } = node.as_fields();
//
// write!(
// f,
// [
// sequential_token.format(),
// space(),
// l_curly_token.format(),
// sequential.format(),
// r_curly_token.format()
// ]
// )
write!(
f,
[sequential_token.format(), space(), l_curly_token.format(),]
)?;

let should_insert_space_around_brackets = f.options().bracket_spacing().value();
write!(
f,
[group(&soft_block_indent_with_maybe_space(
&sequential.format(),
should_insert_space_around_brackets
),)]
)?;

write!(f, [r_curly_token.format()])
}
}
12 changes: 9 additions & 3 deletions crates/biome_grit_formatter/src/grit/auxiliary/within.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
use crate::prelude::*;
use biome_grit_syntax::GritWithin;
use biome_rowan::AstNode;
use biome_formatter::write;
use biome_grit_syntax::{GritWithin, GritWithinFields};

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritWithin;
impl FormatNodeRule<GritWithin> for FormatGritWithin {
fn fmt_fields(&self, node: &GritWithin, f: &mut GritFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let GritWithinFields {
pattern,
within_token,
} = node.as_fields();

write!(f, [within_token.format(), space(), pattern.format()])
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
use crate::prelude::*;
use biome_grit_syntax::GritFunctionDefinition;
use biome_rowan::AstNode;
use biome_formatter::write;
use biome_grit_syntax::{GritFunctionDefinition, GritFunctionDefinitionFields};
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritFunctionDefinition;
impl FormatNodeRule<GritFunctionDefinition> for FormatGritFunctionDefinition {
fn fmt_fields(&self, node: &GritFunctionDefinition, f: &mut GritFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let GritFunctionDefinitionFields {
function_token,
name,
l_paren_token,
args,
r_paren_token,
body,
} = node.as_fields();

write!(
f,
[
function_token.format(),
space(),
name.format(),
l_paren_token.format(),
group(&args.format()),
r_paren_token.format(),
space(),
body.format()
]
)
}
}
Loading

0 comments on commit 6d95f3a

Please sign in to comment.