diff --git a/crates/rome_formatter/src/builders.rs b/crates/rome_formatter/src/builders.rs index 7fef20d8a04..2d262d7a739 100644 --- a/crates/rome_formatter/src/builders.rs +++ b/crates/rome_formatter/src/builders.rs @@ -457,73 +457,6 @@ impl Format for LineSuffixBoundary { } } -/// Marks some content as a comment trivia. -/// -/// This does not directly influence how this content will be printed, but some -/// parts of the formatter may chose to handle this element in a specific way -/// -/// ## Examples -/// -/// ``` -/// use rome_formatter::{format, write, format_args}; -/// use rome_formatter::prelude::*; -/// -/// let elements = format!( -/// SimpleFormatContext::default(), -/// [ -/// group(&format_args![ -/// comment(&format_args![text("// test"), hard_line_break()]), -/// format_with(|f| { -/// write!(f, [ -/// comment(&format_args![text("/* inline */"), hard_line_break()]).memoized(), -/// text("a"), -/// soft_line_break_or_space(), -/// ]) -/// }).memoized(), -/// text("b"), -/// soft_line_break_or_space(), -/// text("c") -/// ]) -/// ] -/// ).unwrap(); -/// -/// assert_eq!( -/// "// test\n/* inline */\na b c", -/// elements.print().as_code() -/// ); -/// ``` -#[inline] -pub fn comment(content: &Content) -> FormatComment -where - Content: Format, -{ - FormatComment { - content: Argument::new(content), - } -} - -#[derive(Copy, Clone)] -pub struct FormatComment<'a, Context> { - content: Argument<'a, Context>, -} - -impl Format for FormatComment<'_, Context> { - fn fmt(&self, f: &mut Formatter) -> FormatResult<()> { - let mut buffer = VecBuffer::new(f.state_mut()); - - buffer.write_fmt(Arguments::from(&self.content))?; - let content = buffer.into_vec(); - - f.write_element(FormatElement::Comment(content.into_boxed_slice())) - } -} - -impl std::fmt::Debug for FormatComment<'_, Context> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_tuple("Comment").field(&"{{content}}").finish() - } -} - /// Marks some content with a label. /// /// This does not directly influence how this content will be printed, but some diff --git a/crates/rome_formatter/src/format_element.rs b/crates/rome_formatter/src/format_element.rs index c2a1b566aff..79c3c57cc0e 100644 --- a/crates/rome_formatter/src/format_element.rs +++ b/crates/rome_formatter/src/format_element.rs @@ -81,12 +81,6 @@ pub enum FormatElement { /// line suffixes, potentially by inserting a hard line break. LineSuffixBoundary, - /// Special semantic element letting the printer and formatter know this is - /// a comment content, and it should only have a limited influence on the - /// formatting (for instance line breaks contained within will not cause - /// the parent group to break if this element is at the start of it). - Comment(Box<[FormatElement]>), - /// A token that tracks tokens/nodes that are printed as verbatim. Verbatim(Verbatim), @@ -193,7 +187,6 @@ impl std::fmt::Debug for FormatElement { fmt.debug_tuple("LineSuffix").field(content).finish() } FormatElement::LineSuffixBoundary => write!(fmt, "LineSuffixBoundary"), - FormatElement::Comment(content) => fmt.debug_tuple("Comment").field(content).finish(), FormatElement::Verbatim(verbatim) => fmt .debug_tuple("Verbatim") .field(&verbatim.content) @@ -675,7 +668,6 @@ impl FormatElement { FormatElement::Group(Group { content, .. }) | FormatElement::ConditionalGroupContent(ConditionalGroupContent { content, .. }) | FormatElement::IndentIfGroupBreaks(IndentIfGroupBreaks { content, .. }) - | FormatElement::Comment(content) | FormatElement::Fill(content) | FormatElement::Verbatim(Verbatim { content, .. }) | FormatElement::Label(Label { content, .. }) @@ -705,13 +697,13 @@ impl FormatElement { /// Utility function to get the "last element" of a [FormatElement], recursing /// into lists and groups to find the last element that's not - /// a line break, or a comment. + /// a line break pub fn last_element(&self) -> Option<&FormatElement> { match self { FormatElement::List(list) => { list.iter().rev().find_map(|element| element.last_element()) } - FormatElement::Line(_) | FormatElement::Comment(_) => None, + FormatElement::Line(_) => None, FormatElement::Group(Group { content, .. }) | FormatElement::Indent(content) => { content.iter().rev().find_map(FormatElement::last_element) @@ -863,9 +855,6 @@ impl Format for FormatElement { FormatElement::LineSuffix(line_suffix) => { write!(f, [text("line_suffix("), line_suffix.as_ref(), text(")")]) } - FormatElement::Comment(content) => { - write!(f, [text("comment("), content.as_ref(), text(")")]) - } FormatElement::Verbatim(verbatim) => { write!(f, [text("verbatim("), verbatim.content.as_ref(), text(")")]) } diff --git a/crates/rome_formatter/src/lib.rs b/crates/rome_formatter/src/lib.rs index 498dff1f674..ff9bf3178ec 100644 --- a/crates/rome_formatter/src/lib.rs +++ b/crates/rome_formatter/src/lib.rs @@ -49,7 +49,7 @@ use crate::printer::{Printer, PrinterOptions}; pub use arguments::{Argument, Arguments}; pub use buffer::{Buffer, BufferExtensions, BufferSnapshot, Inspect, PreambleBuffer, VecBuffer}; pub use builders::{ - block_indent, comment, empty_line, get_lines_before, group, hard_line_break, if_group_breaks, + block_indent, empty_line, get_lines_before, group, hard_line_break, if_group_breaks, if_group_fits_on_line, indent, labelled, line_suffix, soft_block_indent, soft_line_break, soft_line_break_or_space, soft_line_indent_or_space, space, text, BestFitting, };