From f4dbc0023fe89d4053aba50c757aa2ef75a50d31 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Thu, 22 Sep 2022 08:16:42 +0200 Subject: [PATCH] chore(xtask): Part 8: Add line breaks before doc comments (#3246) --- Cargo.lock | 1 + crates/rome_service/src/workspace_types.rs | 2 ++ xtask/bench/Cargo.toml | 3 ++ xtask/codegen/src/formatter.rs | 33 ++++++++++++---------- xtask/codegen/src/generate_bindings.rs | 1 + 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 646237b969a2..a46f6db4aad8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2812,6 +2812,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 3a2674eaff30..ec793f24af37 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 1b3ecca37800..345bfb911de6 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 } @@ -32,3 +34,4 @@ mimalloc = "0.1.29" [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 b044d6e71b3a..ba707c0c1fdb 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 d3b1417ec694..1c9dcd6790d7 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"), ];