Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(grit): add more formatting nodes #4515

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 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.

25 changes: 3 additions & 22 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.

5 changes: 3 additions & 2 deletions crates/biome_grit_formatter/src/comments.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::GritFormatContext;

use biome_formatter::comments::CommentKind;
use biome_formatter::{
comments::{is_doc_comment, CommentStyle, Comments, SourceComment},
prelude::*,
Expand All @@ -23,8 +24,8 @@ impl CommentStyle for GritCommentStyle {

fn get_comment_kind(
_comment: &biome_rowan::SyntaxTriviaPieceComments<Self::Language>,
) -> biome_formatter::comments::CommentKind {
todo!()
) -> CommentKind {
CommentKind::Line
}

fn place_comment(
Expand Down
40 changes: 0 additions & 40 deletions crates/biome_grit_formatter/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1644,46 +1644,6 @@ impl IntoFormat<GritFormatContext> for biome_grit_syntax::GritPatternAny {
)
}
}
impl FormatRule<biome_grit_syntax::GritPatternArgList>
for crate::grit::patterns::pattern_arg_list::FormatGritPatternArgList
{
type Context = GritFormatContext;
#[inline(always)]
fn fmt(
&self,
node: &biome_grit_syntax::GritPatternArgList,
f: &mut GritFormatter,
) -> FormatResult<()> {
FormatNodeRule::<biome_grit_syntax::GritPatternArgList>::fmt(self, node, f)
}
}
impl AsFormat<GritFormatContext> for biome_grit_syntax::GritPatternArgList {
type Format<'a> = FormatRefWithRule<
'a,
biome_grit_syntax::GritPatternArgList,
crate::grit::patterns::pattern_arg_list::FormatGritPatternArgList,
>;
fn format(&self) -> Self::Format<'_> {
#![allow(clippy::default_constructed_unit_structs)]
FormatRefWithRule::new(
self,
crate::grit::patterns::pattern_arg_list::FormatGritPatternArgList::default(),
)
}
}
impl IntoFormat<GritFormatContext> for biome_grit_syntax::GritPatternArgList {
type Format = FormatOwnedWithRule<
biome_grit_syntax::GritPatternArgList,
crate::grit::patterns::pattern_arg_list::FormatGritPatternArgList,
>;
fn into_format(self) -> Self::Format {
#![allow(clippy::default_constructed_unit_structs)]
FormatOwnedWithRule::new(
self,
crate::grit::patterns::pattern_arg_list::FormatGritPatternArgList::default(),
)
}
}
impl FormatRule<biome_grit_syntax::GritPatternAs>
for crate::grit::patterns::pattern_as::FormatGritPatternAs
{
Expand Down
20 changes: 17 additions & 3 deletions crates/biome_grit_formatter/src/grit/auxiliary/bubble.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
use crate::prelude::*;
use biome_grit_syntax::GritBubble;
use biome_rowan::AstNode;
use biome_formatter::write;
use biome_grit_syntax::{GritBubble, GritBubbleFields};
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritBubble;
impl FormatNodeRule<GritBubble> for FormatGritBubble {
fn fmt_fields(&self, node: &GritBubble, f: &mut GritFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let GritBubbleFields {
pattern,
bubble_token,
scope,
} = node.as_fields();

write!(
f,
[
bubble_token.format(),
scope.format(),
space(),
pattern.format()
]
)
}
}
19 changes: 16 additions & 3 deletions crates/biome_grit_formatter/src/grit/auxiliary/bubble_scope.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
use crate::prelude::*;
use biome_grit_syntax::GritBubbleScope;
use biome_rowan::AstNode;
use biome_formatter::write;
use biome_grit_syntax::{GritBubbleScope, GritBubbleScopeFields};
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritBubbleScope;
impl FormatNodeRule<GritBubbleScope> for FormatGritBubbleScope {
fn fmt_fields(&self, node: &GritBubbleScope, f: &mut GritFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let GritBubbleScopeFields {
l_paren_token,
variables,
r_paren_token,
} = node.as_fields();

write!(
f,
[
l_paren_token.format(),
variables.format(),
r_paren_token.format()
]
)
}
}
4 changes: 2 additions & 2 deletions crates/biome_grit_formatter/src/grit/auxiliary/dot.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::GritDot;
use biome_rowan::AstNode;
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritDot;
impl FormatNodeRule<GritDot> for FormatGritDot {
fn fmt_fields(&self, node: &GritDot, f: &mut GritFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
write!(f, [node.dot_token().format()])
}
}
4 changes: 2 additions & 2 deletions crates/biome_grit_formatter/src/grit/auxiliary/dotdotdot.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::GritDotdotdot;
use biome_rowan::AstNode;
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritDotdotdot;
impl FormatNodeRule<GritDotdotdot> for FormatGritDotdotdot {
fn fmt_fields(&self, node: &GritDotdotdot, f: &mut GritFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
write!(f, [node.dotdotdot_token().format()])
}
}
11 changes: 8 additions & 3 deletions crates/biome_grit_formatter/src/grit/auxiliary/every.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
use crate::prelude::*;
use biome_grit_syntax::GritEvery;
use biome_rowan::AstNode;
use biome_formatter::write;
use biome_grit_syntax::{GritEvery, GritEveryFields};
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritEvery;
impl FormatNodeRule<GritEvery> for FormatGritEvery {
fn fmt_fields(&self, node: &GritEvery, f: &mut GritFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let GritEveryFields {
pattern,
every_token,
} = node.as_fields();

write!(f, [every_token.format(), space(), pattern.format()])
}
}
22 changes: 19 additions & 3 deletions crates/biome_grit_formatter/src/grit/auxiliary/files.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
use crate::prelude::*;
use biome_grit_syntax::GritFiles;
use biome_rowan::AstNode;
use biome_formatter::write;
use biome_grit_syntax::{GritFiles, GritFilesFields};
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritFiles;
impl FormatNodeRule<GritFiles> for FormatGritFiles {
fn fmt_fields(&self, node: &GritFiles, f: &mut GritFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let GritFilesFields {
multifile_token,
l_curly_token,
files,
r_curly_token,
} = node.as_fields();

write!(
f,
[
multifile_token.format(),
space(),
l_curly_token.format(),
group(&soft_space_or_block_indent(&files.format())),
r_curly_token.format()
]
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::prelude::*;
use biome_grit_syntax::GritLanguageDeclaration;
use biome_rowan::AstNode;
use biome_formatter::write;
use biome_grit_syntax::{GritLanguageDeclaration, GritLanguageDeclarationFields};
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritLanguageDeclaration;
impl FormatNodeRule<GritLanguageDeclaration> for FormatGritLanguageDeclaration {
Expand All @@ -9,6 +9,25 @@ impl FormatNodeRule<GritLanguageDeclaration> for FormatGritLanguageDeclaration {
node: &GritLanguageDeclaration,
f: &mut GritFormatter,
) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let GritLanguageDeclarationFields {
language_token,
name,
flavor,
semicolon_token,
} = node.as_fields();
write!(
f,
[
language_token.format(),
space(),
name.format(),
flavor.format()
]
)?;

match semicolon_token {
None => write!(f, [text(";")]),
Some(semicolon_token) => write!(f, [semicolon_token.format()]),
}
}
}
19 changes: 16 additions & 3 deletions crates/biome_grit_formatter/src/grit/auxiliary/language_flavor.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
use crate::prelude::*;
use biome_grit_syntax::GritLanguageFlavor;
use biome_rowan::AstNode;
use biome_formatter::write;
use biome_grit_syntax::{GritLanguageFlavor, GritLanguageFlavorFields};
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritLanguageFlavor;
impl FormatNodeRule<GritLanguageFlavor> for FormatGritLanguageFlavor {
fn fmt_fields(&self, node: &GritLanguageFlavor, f: &mut GritFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let GritLanguageFlavorFields {
l_paren_token,
flavors,
r_paren_token,
} = node.as_fields();

write!(
f,
[
l_paren_token.format(),
flavors.format(),
r_paren_token.format()
]
)
}
}
Loading
Loading