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

Commit

Permalink
feat(rome_service): introduce a cross-language Workspace abstraction (
Browse files Browse the repository at this point in the history
#2593)

* rename rome_core to rome_service

* feat(rome_service): introduce the workspace abstraction for multi-language support

* PR review

* add module-level documentation
  • Loading branch information
leops committed May 24, 2022
1 parent 67e350d commit a32588d
Show file tree
Hide file tree
Showing 42 changed files with 2,011 additions and 926 deletions.
40 changes: 23 additions & 17 deletions Cargo.lock

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

7 changes: 1 addition & 6 deletions crates/rome_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rome_js_formatter = { path = "../rome_js_formatter" }
rome_formatter = { path = "../rome_formatter" }
rome_js_parser = { path = "../rome_js_parser" }
rome_js_syntax = { path = "../rome_js_syntax" }
rome_diagnostics = { path = "../rome_diagnostics" }
rome_core = { path = "../rome_core" }
rome_service = { path = "../rome_service" }
rome_flags = { path = "../rome_flags" }
rome_fs = { path = "../rome_fs" }
rome_console = { path = "../rome_console" }
rome_analyze = { path = "../rome_analyze" }
rome_rowan = { path = "../rome_rowan" }
pico-args = "0.4.2"
tracing = { version = "0.1.31", default-features = false, features = ["std"] }
tracing-subscriber = "0.3.6"
Expand Down
4 changes: 2 additions & 2 deletions crates/rome_cli/src/commands/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ use super::format::parse_format_options;

/// Handler for the "ci" command of the Rome CLI
pub(crate) fn ci(mut session: CliSession) -> Result<(), Termination> {
let options = parse_format_options(&mut session)?;
traverse(TraversalMode::CI { options }, session)
parse_format_options(&mut session)?;
traverse(TraversalMode::CI, session)
}
28 changes: 16 additions & 12 deletions crates/rome_cli/src/commands/format.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rome_formatter::IndentStyle;
use rome_js_formatter::options::JsFormatOptions;
use rome_service::{settings::WorkspaceSettings, workspace::UpdateSettingsParams};

use crate::{
traversal::{traverse, TraversalMode},
Expand All @@ -8,25 +8,24 @@ use crate::{

/// Handler for the "format" command of the Rome CLI
pub(crate) fn format(mut session: CliSession) -> Result<(), Termination> {
let options = parse_format_options(&mut session)?;
parse_format_options(&mut session)?;

let is_write = session.args.contains("--write");
let ignore_errors = session.args.contains("--skip-errors");

traverse(
TraversalMode::Format {
options,
ignore_errors,
write: is_write,
},
session,
)
}

pub(crate) fn parse_format_options(
session: &mut CliSession,
) -> Result<JsFormatOptions, Termination> {
let mut options = JsFormatOptions::default();
/// Read the formatting options for the command line arguments and inject them
/// into the workspace settings
pub(crate) fn parse_format_options(session: &mut CliSession) -> Result<(), Termination> {
let mut settings = WorkspaceSettings::default();

let size = session
.args
Expand All @@ -46,10 +45,10 @@ pub(crate) fn parse_format_options(

match indent_style {
Some(IndentStyle::Tab) => {
options.indent_style = IndentStyle::Tab;
settings.format.indent_style = Some(IndentStyle::Tab);
}
Some(IndentStyle::Space(default_size)) => {
options.indent_style = IndentStyle::Space(size.unwrap_or(default_size));
settings.format.indent_style = Some(IndentStyle::Space(size.unwrap_or(default_size)));
}
None => {}
}
Expand All @@ -63,7 +62,7 @@ pub(crate) fn parse_format_options(
})?;

if let Some(quote_style) = quote_style {
options.quote_style = quote_style;
settings.languages.javascript.format.quote_style = Some(quote_style);
}

let line_width = session
Expand All @@ -75,8 +74,13 @@ pub(crate) fn parse_format_options(
})?;

if let Some(line_width) = line_width {
options.line_width = line_width;
settings.format.line_width = Some(line_width);
}

Ok(options)
session
.app
.workspace
.update_settings(UpdateSettingsParams { settings })?;

Ok(())
}
2 changes: 1 addition & 1 deletion crates/rome_cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use pico_args::Arguments;
use rome_core::App;
use rome_flags::FeatureFlags;
use rome_service::App;

mod commands;
mod metrics;
Expand Down
5 changes: 5 additions & 0 deletions crates/rome_cli/src/termination.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use rome_service::RomeError;
use std::{
env::current_exe,
ffi::OsString,
Expand Down Expand Up @@ -49,6 +50,10 @@ pub enum Termination {
/// Returned by a traversal command when error diagnostics were emitted
#[error("errors where emitted while running checks")]
CheckError,

/// Wrapper for an underlying `rome_service` error
#[error(transparent)]
WorkspaceError(#[from] RomeError),
}

fn command_name() -> String {
Expand Down
Loading

0 comments on commit a32588d

Please sign in to comment.