Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
chore(xtask): Part 8: Add line breaks before doc comments (#3246)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Sep 22, 2022
1 parent 74147a3 commit 6a430dc
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions crates/rome_service/src/workspace_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
];
Expand Down Expand Up @@ -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"),
];
Expand Down
3 changes: 3 additions & 0 deletions xtask/bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -35,3 +37,4 @@ tikv-jemallocator = "0.5.0"

[features]
dhat-heap = ["dhat", "humansize"]
count = ["countme/print_at_exit"]
33 changes: 18 additions & 15 deletions xtask/codegen/src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}
}
}
Expand Down Expand Up @@ -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<rome_js_syntax::#node_id> for #format_id {
type Context = JsFormatContext;
#[inline(always)]
fn fmt(&self, node: &rome_js_syntax::#node_id, f: &mut JsFormatter) -> FormatResult<()> {
FormatNodeRule::<rome_js_syntax::#node_id>::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<rome_js_syntax::#node_id> for #format_id {
type Context = JsFormatContext;
#[inline(always)]
fn fmt(&self, node: &rome_js_syntax::#node_id, f: &mut JsFormatter) -> FormatResult<()> {
#rule::<rome_js_syntax::#node_id>::fmt(self, node, f)
}
}
}
},
}
};

self.impls.push(quote! {
Expand Down Expand Up @@ -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 )*
};
Expand Down
1 change: 1 addition & 0 deletions xtask/codegen/src/generate_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
];
Expand Down

0 comments on commit 6a430dc

Please sign in to comment.