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

Commit

Permalink
Start with documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Sep 19, 2022
1 parent 8ae9e1f commit 0c9e16a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 106 deletions.
4 changes: 4 additions & 0 deletions crates/rome_formatter/src/format_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub enum FormatElement {
/// Line breaks inside of a best fitting don't propagate to parent groups.
BestFitting(BestFitting),

/// A signal that marks the start/end of some content to which some special formatting is applied.
Signal(Signal),
}

Expand Down Expand Up @@ -249,17 +250,20 @@ impl Deref for Text {
}

impl FormatElement {
/// Returns `true` if self is a [FormatElement::Signal]
pub const fn is_signal(&self) -> bool {
matches!(self, FormatElement::Signal(_))
}

/// Returns `true` if self is a [FormatElement::Signal] and `Signal::is_start` is `true`.
pub const fn is_start_signal(&self) -> bool {
match self {
FormatElement::Signal(signal) => signal.is_start(),
_ => false,
}
}

/// Returns `true` if self is a [FormatElement::Signal] and `Signal::is_end` is `true`.
pub const fn is_end_signal(&self) -> bool {
match self {
FormatElement::Signal(signal) => signal.is_end(),
Expand Down
33 changes: 9 additions & 24 deletions crates/rome_formatter/src/format_element/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ use std::any::type_name;
use std::any::TypeId;
use std::num::NonZeroU8;

/// Signal marking the start and end of some content to which some special formatting should be applied.
///
/// Signals always come in pairs of a start and an end signal and the styling defined by this signal
/// will be applied to all elements in between the start/end signals.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum Signal {
/// Indents the content one level deeper, see [crate::indent] for documentation and examples.
Expand Down Expand Up @@ -68,6 +72,7 @@ pub enum Signal {
}

impl Signal {
/// Returns `true` if `self` is any start signal.
pub const fn is_start(&self) -> bool {
match self {
Signal::StartIndent
Expand All @@ -85,6 +90,7 @@ impl Signal {
}
}

/// Returns `true` if `self` is any end signal.
pub const fn is_end(&self) -> bool {
!self.is_start()
}
Expand All @@ -106,12 +112,11 @@ impl Signal {
StartLabelled(_) | EndLabelled => SignalKind::Labelled,
}
}

pub fn eq_kind(&self, other: Signal) -> bool {
self.kind() == other.kind()
}
}

/// The kind of a signal.
///
/// Each start end signal pair has its own signal kind.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum SignalKind {
Expand All @@ -128,26 +133,6 @@ pub enum SignalKind {
Labelled,
}

impl SignalKind {
pub const fn end_signal(&self) -> Signal {
use Signal::*;

match self {
SignalKind::Indent => EndIndent,
SignalKind::Align => EndAlign,
SignalKind::Dedent => EndDedent,
SignalKind::Group => EndGroup,
SignalKind::ConditionalContent => EndConditionalContent,
SignalKind::IndentIfGroupBreaks => EndIndentIfGroupBreaks,
SignalKind::Fill => EndFill,
SignalKind::Entry => EndEntry,
SignalKind::LineSuffix => EndLineSuffix,
SignalKind::Verbatim => EndVerbatim,
SignalKind::Labelled => EndLabelled,
}
}
}

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum DedentMode {
/// Reduces the indent by a level (if the current indent is > 0)
Expand Down
80 changes: 0 additions & 80 deletions crates/rome_formatter/src/intersperse.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/rome_formatter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ pub mod format_element;
mod format_extensions;
pub mod formatter;
pub mod group_id;
pub mod intersperse;
pub mod macros;
pub mod prelude;
#[cfg(debug_assertions)]
Expand Down
5 changes: 4 additions & 1 deletion crates/rome_formatter/src/printer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ use crate::printer::queue::{
use rome_rowan::{TextLen, TextSize};
use std::num::NonZeroU8;

// FIXME: Best Fitting assertions
// `fits_on_line` args
// Filters (naming, implementation and such)

/// Prints the format elements into a string
#[derive(Debug, Default)]
pub struct Printer<'a> {
Expand Down Expand Up @@ -809,7 +813,6 @@ where

/// Tests if it's possible to print the content of the queue up to the first hard line break
/// or the end of the document on a single line without exceeding the line width.
#[must_use = "Only determines if content fits on a single line but doesn't print it"]
fn all_fit<'a, 'print, F>(
mut filter: F,
fits_state: &mut FitsState,
Expand Down

0 comments on commit 0c9e16a

Please sign in to comment.