diff --git a/Cargo.lock b/Cargo.lock index 54127814bd9..4d2bbe49ee5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2840,6 +2840,7 @@ name = "xtask_bench" version = "0.0.0" dependencies = [ "ansi_rgb", + "countme", "criterion", "dhat", "humansize", diff --git a/crates/rome_service/src/workspace_types.rs b/crates/rome_service/src/workspace_types.rs index 3a2674eaff3..ec793f24af3 100644 --- a/crates/rome_service/src/workspace_types.rs +++ b/crates/rome_service/src/workspace_types.rs @@ -65,6 +65,7 @@ fn instance_type<'a>( if let Some(description) = description { let comment = format!("/**\n\t* {} \n\t */", description); let trivia = vec![ + (TriviaPieceKind::Newline, "\n"), (TriviaPieceKind::MultiLineComment, comment.as_str()), (TriviaPieceKind::Newline, "\n"), ]; @@ -337,6 +338,7 @@ pub fn generate_type<'a>( if let Some(description) = description { let comment = format!("/**\n\t* {} \n\t */", description); let trivia = vec![ + (TriviaPieceKind::Newline, "\n"), (TriviaPieceKind::MultiLineComment, comment.as_str()), (TriviaPieceKind::Newline, "\n"), ]; diff --git a/xtask/bench/Cargo.toml b/xtask/bench/Cargo.toml index ebe77d3f59a..6ad24dc2001 100644 --- a/xtask/bench/Cargo.toml +++ b/xtask/bench/Cargo.toml @@ -23,6 +23,8 @@ url = "2.2.2" itertools = "0.10.3" ansi_rgb = "0.2.0" +countme = "3.0.1" + # dhat-on dhat = { version = "0.3.0", optional = true } humansize = {version = "1.1.1", optional = true } @@ -35,3 +37,4 @@ tikv-jemallocator = "0.5.0" [features] dhat-heap = ["dhat", "humansize"] +count = ["countme/print_at_exit"] diff --git a/xtask/codegen/src/formatter.rs b/xtask/codegen/src/formatter.rs index b044d6e71b3..ba707c0c1fd 100644 --- a/xtask/codegen/src/formatter.rs +++ b/xtask/codegen/src/formatter.rs @@ -357,18 +357,13 @@ pub fn generate_formatter() { } NodeKind::Unknown => { quote! { - use crate::prelude::*; - use crate::{FormatNodeFields}; - use rome_rowan::AstNode; + use crate::FormatUnknownNodeRule; use rome_js_syntax::#node_id; #[derive(Debug, Clone, Default)] pub struct #format_id; - impl FormatNodeRule<#node_id> for #format_id { - fn fmt_fields(&self, node: &#node_id, f: &mut JsFormatter) -> FormatResult<()> { - format_unknown_node(node.syntax()).fmt(f) - } + impl FormatUnknownNodeRule<#node_id> for #format_id { } } } @@ -437,15 +432,23 @@ impl BoilerplateImpls { fn push(&mut self, kind: &NodeKind, node_id: &Ident, format_id: &TokenStream) { let format_rule_impl = match kind { NodeKind::List { .. } | NodeKind::Union { .. } => quote!(), - _ => quote! { - impl FormatRule for #format_id { - type Context = JsFormatContext; - #[inline(always)] - fn fmt(&self, node: &rome_js_syntax::#node_id, f: &mut JsFormatter) -> FormatResult<()> { - FormatNodeRule::::fmt(self, node, f) + kind => { + let rule = if matches!(kind, NodeKind::Unknown) { + Ident::new("FormatUnknownNodeRule", Span::call_site()) + } else { + Ident::new("FormatNodeRule", Span::call_site()) + }; + + quote! { + impl FormatRule for #format_id { + type Context = JsFormatContext; + #[inline(always)] + fn fmt(&self, node: &rome_js_syntax::#node_id, f: &mut JsFormatter) -> FormatResult<()> { + #rule::::fmt(self, node, f) + } } } - }, + } }; self.impls.push(quote! { @@ -474,7 +477,7 @@ impl BoilerplateImpls { let tokens = quote! { use rome_formatter::{FormatRefWithRule, FormatOwnedWithRule, FormatRule, FormatResult}; - use crate::{AsFormat, IntoFormat, FormatNodeRule, JsFormatter, JsFormatContext}; + use crate::{AsFormat, IntoFormat, FormatNodeRule, FormatUnknownNodeRule, JsFormatter, JsFormatContext}; #( #impls )* }; diff --git a/xtask/codegen/src/generate_bindings.rs b/xtask/codegen/src/generate_bindings.rs index d3b1417ec69..1c9dcd6790d 100644 --- a/xtask/codegen/src/generate_bindings.rs +++ b/xtask/codegen/src/generate_bindings.rs @@ -194,6 +194,7 @@ pub(crate) fn generate_workspace_bindings(mode: Mode) -> Result<()> { if let Some(description) = description { let comment = format!("/**\n\t* {} \n\t */\n", description); let trivia = vec![ + (TriviaPieceKind::Newline, "\n"), (TriviaPieceKind::MultiLineComment, comment.as_str()), (TriviaPieceKind::Newline, "\n"), ];