Skip to content

Commit

Permalink
refactor(Formatter): Move Format, Formatter, to rome_formatter (#…
Browse files Browse the repository at this point in the history
…2559)

This PR moves the shared traits `Format`, `Formatter`, `IntoFormatElement`, and the extension traits to `rome_formatter`. 

I introduce two new traits to work around Rust's orphan rule. 

* `AsFormat`: Has a single `format()` method that returns an object that knows how to format `self` (by reference)
* `IntoFormat`: Has a single `into_format()` that returns an object that knows how to format `self` (takes ownership)

An object that isn't able to implement `Format` itself because of Rust's orphan rule can implement `AsFormat`  and `IntoFormat`. 

This PR changes the node formatting by making them implement `AsFormat` and `IntoFormat` instead of implementing `Format`. The formatting is implemented by a `Format*` new-type that has a single static `::format` method. This new type has been necessary to have a way to share the formatting logic between `AsFormat` and `IntoFormat`.
  • Loading branch information
MichaReiser authored May 11, 2022
1 parent ff5a3d5 commit e6409b8
Show file tree
Hide file tree
Showing 427 changed files with 11,672 additions and 5,390 deletions.
6 changes: 5 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions crates/rome_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"

[dependencies]
rome_js_formatter = { path = "../rome_js_formatter" }
rome_formatter = { path = "../rome_formatter" }
rome_js_parser = { path = "../rome_js_parser" }
rome_diagnostics = { path = "../rome_diagnostics" }
rome_core = { path = "../rome_core" }
Expand Down
2 changes: 1 addition & 1 deletion crates/rome_cli/src/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ use rome_diagnostics::{
file::{FileId, Files, SimpleFile},
Diagnostic, DiagnosticHeader, Severity,
};
use rome_formatter::{FormatOptions, IndentStyle};
use rome_fs::{AtomicInterner, FileSystem, PathInterner, RomePath};
use rome_fs::{TraversalContext, TraversalScope};
use rome_js_formatter::{FormatOptions, IndentStyle};
use rome_js_parser::{parse, SourceType};

use crate::{CliSession, Termination};
Expand Down
3 changes: 2 additions & 1 deletion crates/rome_formatter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ edition = "2021"

[dependencies]
rome_rowan = { path = "../rome_rowan" }
tracing = { version = "0.1.31", default-features = false, features = ["std"] }
tracing = { version = "0.1.31", default-features = false, features = ["std"] }
cfg-if = "1.0.0"
3 changes: 1 addition & 2 deletions crates/rome_formatter/src/builders.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::format_element::List;
use crate::{empty_element, FormatElement};
use crate::prelude::*;

#[derive(Default)]
pub struct ConcatBuilder {
Expand Down
73 changes: 0 additions & 73 deletions crates/rome_formatter/src/format_elements.rs

This file was deleted.

Loading

0 comments on commit e6409b8

Please sign in to comment.