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

Commit

Permalink
feat: VCS support (#4375)
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico authored Apr 17, 2023
1 parent 309d186 commit b4bd55c
Show file tree
Hide file tree
Showing 69 changed files with 1,586 additions and 187 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Profile-*.json
# Ignore third-party files
**/node_modules
**/dist
**/build
npm/cli-*
.pnpm-debug.log

Expand Down
2 changes: 2 additions & 0 deletions 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 @@ -41,6 +41,7 @@ rome_json_formatter = { path = "../rome_json_formatter" }
rome_json_syntax = { path = "../rome_json_syntax" }
rome_migrate = { path = "../rome_migrate" }
rome_rowan = { path = "../rome_rowan" }
indexmap = { workspace = true }

[target.'cfg(unix)'.dependencies]
libc = "0.2.127"
Expand Down
13 changes: 11 additions & 2 deletions crates/rome_cli/src/commands/check.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
use crate::configuration::load_configuration;
use crate::parse_arguments::{apply_files_settings_from_cli, apply_format_settings_from_cli};
use crate::parse_arguments::{
apply_files_settings_from_cli, apply_format_settings_from_cli, apply_vcs_settings_from_cli,
};
use crate::vcs::store_path_to_ignore_from_vcs;
use crate::{execute_mode, CliDiagnostic, CliSession, Execution, TraversalMode};
use rome_console::{markup, ConsoleExt};
use rome_diagnostics::{DiagnosticExt, PrintDiagnostic, Severity};
use rome_service::workspace::{FixFileMode, UpdateSettingsParams};

/// Handler for the "check" command of the Rome CLI
pub(crate) fn check(mut session: CliSession) -> Result<(), CliDiagnostic> {
let (mut configuration, diagnostics, _) = load_configuration(&mut session)?.consume();
let (mut configuration, diagnostics, configuration_path) =
load_configuration(&mut session)?.consume();
if !diagnostics.is_empty() {
let console = &mut session.app.console;
console.log(markup!{
Expand All @@ -22,6 +26,11 @@ pub(crate) fn check(mut session: CliSession) -> Result<(), CliDiagnostic> {
}
apply_files_settings_from_cli(&mut session, &mut configuration)?;
apply_format_settings_from_cli(&mut session, &mut configuration)?;
apply_vcs_settings_from_cli(&mut session, &mut configuration)?;

// check if support of git ignore files is enabled
let vcs_base_path = configuration_path.or(session.app.fs.working_directory());
store_path_to_ignore_from_vcs(&mut session, &mut configuration, vcs_base_path)?;

session
.app
Expand Down
14 changes: 12 additions & 2 deletions crates/rome_cli/src/commands/ci.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::parse_arguments::{apply_files_settings_from_cli, apply_format_settings_from_cli};
use crate::parse_arguments::{
apply_files_settings_from_cli, apply_format_settings_from_cli, apply_vcs_settings_from_cli,
};
use crate::vcs::store_path_to_ignore_from_vcs;
use crate::{
configuration::load_configuration, execute_mode, CliDiagnostic, CliSession, Execution,
TraversalMode,
Expand All @@ -11,7 +14,8 @@ use rome_service::workspace::UpdateSettingsParams;

/// Handler for the "ci" command of the Rome CLI
pub(crate) fn ci(mut session: CliSession) -> Result<(), CliDiagnostic> {
let (mut configuration, diagnostics, _) = load_configuration(&mut session)?.consume();
let (mut configuration, diagnostics, configuration_path) =
load_configuration(&mut session)?.consume();

if !diagnostics.is_empty() {
let console = &mut session.app.console;
Expand Down Expand Up @@ -77,6 +81,12 @@ pub(crate) fn ci(mut session: CliSession) -> Result<(), CliDiagnostic> {
apply_format_settings_from_cli(&mut session, &mut configuration)?;
}

apply_vcs_settings_from_cli(&mut session, &mut configuration)?;

// check if support of git ignore files is enabled
let vcs_base_path = configuration_path.or(session.app.fs.working_directory());
store_path_to_ignore_from_vcs(&mut session, &mut configuration, vcs_base_path)?;

session
.app
.workspace
Expand Down
12 changes: 10 additions & 2 deletions crates/rome_cli/src/commands/format.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::configuration::load_configuration;
use crate::execute::ReportMode;
use crate::parse_arguments::{apply_files_settings_from_cli, apply_format_settings_from_cli};
use crate::parse_arguments::{
apply_files_settings_from_cli, apply_format_settings_from_cli, apply_vcs_settings_from_cli,
};
use crate::vcs::store_path_to_ignore_from_vcs;
use crate::{execute_mode, CliDiagnostic, CliSession, Execution, TraversalMode};
use rome_console::{markup, ConsoleExt};
use rome_diagnostics::{DiagnosticExt, PrintDiagnostic, Severity};
Expand All @@ -9,7 +12,8 @@ use std::path::PathBuf;

/// Handler for the "format" command of the Rome CLI
pub(crate) fn format(mut session: CliSession) -> Result<(), CliDiagnostic> {
let (mut configuration, diagnostics, _) = load_configuration(&mut session)?.consume();
let (mut configuration, diagnostics, configuration_path) =
load_configuration(&mut session)?.consume();
if !diagnostics.is_empty() {
let console = &mut session.app.console;
console.log(markup!{
Expand All @@ -25,7 +29,11 @@ pub(crate) fn format(mut session: CliSession) -> Result<(), CliDiagnostic> {

apply_files_settings_from_cli(&mut session, &mut configuration)?;
apply_format_settings_from_cli(&mut session, &mut configuration)?;
apply_vcs_settings_from_cli(&mut session, &mut configuration)?;

// check if support of git ignore files is enabled
let vcs_base_path = configuration_path.or(session.app.fs.working_directory());
store_path_to_ignore_from_vcs(&mut session, &mut configuration, vcs_base_path)?;
session
.app
.workspace
Expand Down
28 changes: 20 additions & 8 deletions crates/rome_cli/src/commands/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const MAIN: Markup = markup! {
"<Dim>"--colors=<off|force>"</Dim>" Set the formatting mode for markup: \"off\" prints everything as plain text, \"force\" forces the formatting of markup using ANSI even if the console output is determined to be incompatible
"<Dim>"--use-server"</Dim>" Connect to a running instance of the Rome daemon server
"<Dim>"--version"</Dim>" Show the Rome version information and quit
"<Dim>"--files-max-size"</Dim>" The maximum allowed size for source code files in bytes (default: 1MB)
"
"<Dim>"--files-max-size"</Dim>" The maximum allowed size for source code files in bytes (default: 1MB)"
{VCS_OPTIONS}
};

const CHECK: Markup = markup! {
Expand All @@ -46,6 +46,7 @@ const CHECK: Markup = markup! {
"<Dim>"--config-path"</Dim>" Set the filesystem path to the directory of the rome.json configuration file
"<Dim>"--verbose"</Dim>" Print additional verbose advices on diagnostics
"
{VCS_OPTIONS}
};

const FORMAT_OPTIONS: Markup = markup! {
Expand All @@ -60,6 +61,16 @@ const FORMAT_OPTIONS: Markup = markup! {
"
};

const VCS_OPTIONS: Markup = markup! {
"
"<Dim>"--vcs-enabled <true|false>"</Dim>" Whether Rome should integrate itself with the VCS client
"<Dim>"--vcs-client-kind <git>"</Dim>" The name of the client
"<Dim>"--vcs-use-ignore-file <true|false>"</Dim>" Whether Rome should ignore the paths inside the ignore file
"<Dim>"--vcs-root <string>"</Dim>" Where Rome should look for VCS files. If a rome.json is present, Rome will append this root to the path of where
rome.json is.
"
};

const CI: Markup = markup! {
"Rome CI: Run the linter and formatter check on a set of files
Expand All @@ -74,13 +85,14 @@ const CI: Markup = markup! {
rome ci ./src ./internal ./scripts
"<Emphasis>"OPTIONS:"</Emphasis>"
"<Dim>"--formatter-enabled"</Dim>" Allow to enable or disable the formatter check. (default: true)
"<Dim>"--linter-enabled"</Dim>" Allow to enable or disable the linter check. (default: true)
"<Dim>"--organize-imports-enabled"</Dim>" Allow to enable or disable the organize imports. (default: true)
"<Dim>"--formatter-enabled <true|false>"</Dim>" Allow to enable or disable the formatter check. (default: true)
"<Dim>"--linter-enabled <true|false>"</Dim>" Allow to enable or disable the linter check. (default: true)
"<Dim>"--organize-imports-enabled <true|false>"</Dim>" Allow to enable or disable the organize imports. (default: true)
"<Dim>"--max-diagnostics"</Dim>" Cap the amount of diagnostics displayed (default: 50)
"<Dim>"--config-path"</Dim>" Set the filesystem path to the directory of the rome.json configuration file
"<Dim>"--verbose"</Dim>" Print additional verbose advices on diagnostics"
{FORMAT_OPTIONS}
{VCS_OPTIONS}
};

const FORMAT: Markup = markup! {
Expand All @@ -101,10 +113,10 @@ const FORMAT: Markup = markup! {
"<Dim>"--skip-errors"</Dim>" Skip over files containing syntax errors instead of emitting an error diagnostic.
"<Dim>"--max-diagnostics"</Dim>" Cap the amount of diagnostics displayed (default: 50)
"<Dim>"--config-path"</Dim>" Set the filesystem path to the directory of the rome.json configuration file
"<Dim>"--verbose"</Dim>" Print additional verbose advices on diagnostics"
"<Dim>"--verbose"</Dim>" Print additional verbose advices on diagnostics
"<Dim>"--stdin-file-path <string>"</Dim>" A file name with its extension to pass when reading from standard in, e.g. echo 'let a;' | rome format --stdin-file-path file.js"
{FORMAT_OPTIONS}
""<Dim>"--stdin-file-path <string>"</Dim>" A file name with its extension to pass when reading from standard in, e.g. echo 'let a;' | rome format --stdin-file-path file.js
"
{VCS_OPTIONS}
};

const INIT: Markup = markup! {
Expand Down
3 changes: 2 additions & 1 deletion crates/rome_cli/src/commands/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ use crate::{CliDiagnostic, CliSession};
/// Handler for the "check" command of the Rome CLI
pub(crate) fn migrate(mut session: CliSession) -> Result<(), CliDiagnostic> {
let (_, _, path) = load_configuration(&mut session)?.consume();
let config_name = session.app.fs.config_name();
if let Some(path) = path {
execute_mode(
Execution::new(TraversalMode::Migrate {
write: session.args.contains("--dry-run"),
configuration_path: path,
configuration_path: path.join(config_name),
}),
session,
)
Expand Down
1 change: 1 addition & 0 deletions crates/rome_cli/src/commands/rage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ impl Display for RageConfiguration<'_, '_> {
{KeyValuePair("Formatter disabled", markup!({DebugDisplay(configuration.is_formatter_disabled())}))}
{KeyValuePair("Linter disabled", markup!({DebugDisplay(configuration.is_linter_disabled())}))}
{KeyValuePair("Organize imports disabled", markup!({DebugDisplay(configuration.is_organize_imports_disabled())}))}
{KeyValuePair("VCS disabled", markup!({DebugDisplay(configuration.is_vcs_disabled())}))}
).fmt(fmt)?
}
Err(err) => markup! (
Expand Down
36 changes: 36 additions & 0 deletions crates/rome_cli/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ pub enum CliDiagnostic {
NoFilesWereProcessed(NoFilesWereProcessed),
/// Errors thrown when running the `rome migrate` command
MigrateError(MigrationDiagnostic),
/// When the VCS folder couldn't be found
NoVcsFolderFound(NoVcsFolderFound),
}

#[derive(Debug, Diagnostic)]
Expand Down Expand Up @@ -273,6 +275,31 @@ pub struct MigrationDiagnostic {
pub reason: String,
}

#[derive(Debug, Diagnostic)]
#[diagnostic(
category = "internalError/fs",
severity = Error,
message(
description = "Rome couldn't find the VCS folder at the following path: {path}",
message("Rome couldn't find the VCS folder at the following path: "<Emphasis>{self.path}</Emphasis>),
)
)]
pub struct NoVcsFolderFound {
#[location(resource)]
pub path: String,

#[source]
pub source: Option<Error>,
}

#[derive(Debug, Diagnostic)]
#[diagnostic(
category = "internalError/fs",
severity = Warning,
message = "Rome couldn't determine a directory for the VCS integration. VCS integration will be disabled."
)]
pub struct DisabledVcs {}

/// Advices for the [CliDiagnostic]
#[derive(Debug, Default)]
struct CliAdvice {
Expand Down Expand Up @@ -438,6 +465,7 @@ impl Diagnostic for CliDiagnostic {
CliDiagnostic::NoFilesWereProcessed(diagnostic) => diagnostic.category(),
CliDiagnostic::FileCheckApply(diagnostic) => diagnostic.category(),
CliDiagnostic::MigrateError(diagnostic) => diagnostic.category(),
CliDiagnostic::NoVcsFolderFound(diagnostic) => diagnostic.category(),
}
}

Expand All @@ -459,6 +487,7 @@ impl Diagnostic for CliDiagnostic {
CliDiagnostic::NoFilesWereProcessed(diagnostic) => diagnostic.tags(),
CliDiagnostic::FileCheckApply(diagnostic) => diagnostic.tags(),
CliDiagnostic::MigrateError(diagnostic) => diagnostic.tags(),
CliDiagnostic::NoVcsFolderFound(diagnostic) => diagnostic.tags(),
}
}

Expand All @@ -480,6 +509,7 @@ impl Diagnostic for CliDiagnostic {
CliDiagnostic::NoFilesWereProcessed(diagnostic) => diagnostic.severity(),
CliDiagnostic::FileCheckApply(diagnostic) => diagnostic.severity(),
CliDiagnostic::MigrateError(diagnostic) => diagnostic.severity(),
CliDiagnostic::NoVcsFolderFound(diagnostic) => diagnostic.severity(),
}
}

Expand All @@ -501,6 +531,7 @@ impl Diagnostic for CliDiagnostic {
CliDiagnostic::NoFilesWereProcessed(diagnostic) => diagnostic.location(),
CliDiagnostic::FileCheckApply(diagnostic) => diagnostic.location(),
CliDiagnostic::MigrateError(diagnostic) => diagnostic.location(),
CliDiagnostic::NoVcsFolderFound(diagnostic) => diagnostic.location(),
}
}

Expand All @@ -522,6 +553,7 @@ impl Diagnostic for CliDiagnostic {
CliDiagnostic::NoFilesWereProcessed(diagnostic) => diagnostic.message(fmt),
CliDiagnostic::FileCheckApply(diagnostic) => diagnostic.message(fmt),
CliDiagnostic::MigrateError(diagnostic) => diagnostic.message(fmt),
CliDiagnostic::NoVcsFolderFound(diagnostic) => diagnostic.message(fmt),
}
}

Expand All @@ -543,6 +575,7 @@ impl Diagnostic for CliDiagnostic {
CliDiagnostic::NoFilesWereProcessed(diagnostic) => diagnostic.description(fmt),
CliDiagnostic::FileCheckApply(diagnostic) => diagnostic.description(fmt),
CliDiagnostic::MigrateError(diagnostic) => diagnostic.description(fmt),
CliDiagnostic::NoVcsFolderFound(diagnostic) => diagnostic.description(fmt),
}
}

Expand All @@ -564,6 +597,7 @@ impl Diagnostic for CliDiagnostic {
CliDiagnostic::NoFilesWereProcessed(diagnostic) => diagnostic.advices(visitor),
CliDiagnostic::FileCheckApply(diagnostic) => diagnostic.advices(visitor),
CliDiagnostic::MigrateError(diagnostic) => diagnostic.advices(visitor),
CliDiagnostic::NoVcsFolderFound(diagnostic) => diagnostic.advices(visitor),
}
}

Expand All @@ -589,6 +623,7 @@ impl Diagnostic for CliDiagnostic {
CliDiagnostic::NoFilesWereProcessed(diagnostic) => diagnostic.verbose_advices(visitor),
CliDiagnostic::FileCheckApply(diagnostic) => diagnostic.verbose_advices(visitor),
CliDiagnostic::MigrateError(diagnostic) => diagnostic.verbose_advices(visitor),
CliDiagnostic::NoVcsFolderFound(diagnostic) => diagnostic.verbose_advices(visitor),
}
}

Expand All @@ -610,6 +645,7 @@ impl Diagnostic for CliDiagnostic {
CliDiagnostic::NoFilesWereProcessed(diagnostic) => diagnostic.source(),
CliDiagnostic::FileCheckApply(diagnostic) => diagnostic.source(),
CliDiagnostic::MigrateError(diagnostic) => diagnostic.source(),
CliDiagnostic::NoVcsFolderFound(diagnostic) => diagnostic.source(),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/rome_cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ mod panic;
mod parse_arguments;
mod reports;
mod service;
mod vcs;

pub use diagnostics::CliDiagnostic;
pub(crate) use execute::{execute_mode, Execution, TraversalMode};
Expand Down
44 changes: 44 additions & 0 deletions crates/rome_cli/src/parse_arguments.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{CliDiagnostic, CliSession};
use rome_formatter::IndentStyle;
use rome_service::configuration::vcs::{VcsClientKind, VcsConfiguration};
use rome_service::configuration::{
FormatterConfiguration, JavascriptConfiguration, JavascriptFormatter, PlainIndentStyle,
};
Expand Down Expand Up @@ -107,3 +108,46 @@ pub(crate) fn apply_files_settings_from_cli(

Ok(())
}

pub(crate) fn apply_vcs_settings_from_cli(
session: &mut CliSession,
configuration: &mut Configuration,
) -> Result<(), CliDiagnostic> {
let vcs = configuration
.vcs
.get_or_insert_with(VcsConfiguration::default);

let enabled = session
.args
.opt_value_from_str("--vcs-enabled")
.map_err(|source| CliDiagnostic::parse_error("--vcs-enabled", source))?;
let client_kind = session
.args
.opt_value_from_str("--vcs-client-kind")
.map_err(|source| CliDiagnostic::parse_error("--vcs-client-kind", source))?;

let use_ignore_file = session
.args
.opt_value_from_str("--vcs-use-ignore-file")
.map_err(|source| CliDiagnostic::parse_error("--vcs-use-ignore-file", source))?;
let root = session
.args
.opt_value_from_str("--vcs-root")
.map_err(|source| CliDiagnostic::parse_error("--vcs-root", source))?;

if let Some(enabled) = enabled {
vcs.enabled = enabled;
}

match client_kind {
None => {}
Some(VcsClientKind::Git) => {
vcs.client_kind = Some(VcsClientKind::Git);
}
}

vcs.use_ignore_file = use_ignore_file;
vcs.root = root;

Ok(())
}
Loading

0 comments on commit b4bd55c

Please sign in to comment.