From 680f2514756f4be5ebd9857bec4736ae3ad2d0e6 Mon Sep 17 00:00:00 2001 From: ea1thoobeloa9aer Date: Mon, 16 Jan 2023 15:41:09 +0100 Subject: [PATCH 1/9] feat(rome_cli): Add a new option --config to set the path to rome.json --- crates/rome_cli/src/commands/help.rs | 3 + crates/rome_cli/src/commands/rage.rs | 2 +- crates/rome_cli/src/configuration.rs | 15 +++- crates/rome_cli/tests/commands/format.rs | 90 +++++++++++++++++++ .../custom_config_file_path.snap | 35 ++++++++ .../invalid_config_file_path.snap | 23 +++++ crates/rome_lsp/src/session.rs | 2 +- crates/rome_service/src/configuration/mod.rs | 31 +++---- website/src/pages/cli.mdx | 6 ++ 9 files changed, 187 insertions(+), 20 deletions(-) create mode 100644 crates/rome_cli/tests/snapshots/main_commands_format/custom_config_file_path.snap create mode 100644 crates/rome_cli/tests/snapshots/main_commands_format/invalid_config_file_path.snap diff --git a/crates/rome_cli/src/commands/help.rs b/crates/rome_cli/src/commands/help.rs index 3ae3b3f1be8..463133191f5 100644 --- a/crates/rome_cli/src/commands/help.rs +++ b/crates/rome_cli/src/commands/help.rs @@ -37,6 +37,7 @@ const CHECK: Markup = markup! { ""--apply"" Apply safe fixes ""--apply-unsafe"" Apply safe and unsafe fixes ""--max-diagnostics"" Cap the amount of diagnostics displayed (default: 20) + ""--config"" Set the filesystem path to the directory of the rome.json configuration file ""--verbose"" Print additional verbose advices on diagnostics " }; @@ -65,6 +66,7 @@ const CI: Markup = markup! { ""--formatter-enabled"" Allow to enable or disable the formatter check. (default: true) ""--linter-enabled"" Allow to enable or disable the linter check. (default: true) ""--max-diagnostics"" Cap the amount of diagnostics displayed (default: 50) + ""--config"" Set the filesystem path to the directory of the rome.json configuration file ""--verbose"" Print additional verbose advices on diagnostics" {FORMAT_OPTIONS} }; @@ -81,6 +83,7 @@ const FORMAT: Markup = markup! { ""--write"" Edit the files in place (beware!) instead of printing the diff to the console ""--skip-errors"" Skip over files containing syntax errors instead of emitting an error diagnostic. ""--max-diagnostics"" Cap the amount of diagnostics displayed (default: 50) + ""--config"" Set the filesystem path to the directory of the rome.json configuration file ""--verbose"" Print additional verbose advices on diagnostics" {FORMAT_OPTIONS} """--stdin-file-path "" 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 diff --git a/crates/rome_cli/src/commands/rage.rs b/crates/rome_cli/src/commands/rage.rs index 57bbf870881..23a15082941 100644 --- a/crates/rome_cli/src/commands/rage.rs +++ b/crates/rome_cli/src/commands/rage.rs @@ -163,7 +163,7 @@ impl Display for RageConfiguration<'_, '_> { fn fmt(&self, fmt: &mut Formatter) -> io::Result<()> { Section("Rome Configuration").fmt(fmt)?; - match load_config(self.0, None) { + match load_config(self.0, None, false) { Ok(None) => KeyValuePair("Status", markup!("unset")).fmt(fmt)?, Ok(Some(configuration)) => { markup! ( diff --git a/crates/rome_cli/src/configuration.rs b/crates/rome_cli/src/configuration.rs index 3c9c6c06578..5c50e7f22f4 100644 --- a/crates/rome_cli/src/configuration.rs +++ b/crates/rome_cli/src/configuration.rs @@ -1,3 +1,5 @@ +use std::path::PathBuf; + use rome_service::{load_config, Configuration}; use crate::{CliDiagnostic, CliSession}; @@ -5,7 +7,14 @@ use crate::{CliDiagnostic, CliSession}; /// Load the configuration for this session of the CLI, merging the content of /// the `rome.json` file if it exists on disk with common command line options pub(crate) fn load_configuration(session: &mut CliSession) -> Result { - let mut configuration = load_config(&session.app.fs, None)?.unwrap_or_default(); + let config_path: Option = session + .args + .opt_value_from_str("--config") + .map_err(|source| CliDiagnostic::parse_error("--config", source))?; + + let is_config_path = config_path.is_some(); + + let mut config = load_config(&session.app.fs, config_path, is_config_path)?.unwrap_or_default(); let files_max_size = session .args @@ -13,9 +22,9 @@ pub(crate) fn load_configuration(session: &mut CliSession) -> Result +``` + + diff --git a/crates/rome_cli/tests/snapshots/main_commands_format/invalid_config_file_path.snap b/crates/rome_cli/tests/snapshots/main_commands_format/invalid_config_file_path.snap new file mode 100644 index 00000000000..7b483ff15e9 --- /dev/null +++ b/crates/rome_cli/tests/snapshots/main_commands_format/invalid_config_file_path.snap @@ -0,0 +1,23 @@ +--- +source: crates/rome_cli/tests/snap_test.rs +assertion_line: 335 +expression: content +--- +## `file.js` + +```js +content +``` + +# Termination Message + +```block +/test/rome.json internalError/fs ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Rome couldn't read the following file, maybe for permissions reasons or it doesn't exists: /test/rome.json + + + +``` + + diff --git a/crates/rome_lsp/src/session.rs b/crates/rome_lsp/src/session.rs index 548cf2d9b86..35b6ecf8e0a 100644 --- a/crates/rome_lsp/src/session.rs +++ b/crates/rome_lsp/src/session.rs @@ -366,7 +366,7 @@ impl Session { pub(crate) async fn load_workspace_settings(&self) { let base_path = self.base_path(); - let status = match load_config(&self.fs, base_path) { + let status = match load_config(&self.fs, base_path, false) { Ok(Some(configuration)) => { info!("Loaded workspace settings: {configuration:#?}"); diff --git a/crates/rome_service/src/configuration/mod.rs b/crates/rome_service/src/configuration/mod.rs index 713ad9666aa..8c9a2a2ca49 100644 --- a/crates/rome_service/src/configuration/mod.rs +++ b/crates/rome_service/src/configuration/mod.rs @@ -128,50 +128,51 @@ impl FilesConfiguration { pub fn load_config( file_system: &DynRef, base_path: Option, + show_error: bool, ) -> Result, WorkspaceError> { let config_name = file_system.config_name(); - let configuration_path = if let Some(base_path) = base_path { + let config_path = if let Some(ref base_path) = base_path { base_path.join(config_name) } else { PathBuf::from(config_name) }; info!( - "Attempting to load the configuration file at path {:?}", - configuration_path + "Attempting to read the configuration file from {:?}", + config_path ); let options = OpenOptions::default().read(true); - let file = file_system.open_with_options(&configuration_path, options); + let file = file_system.open_with_options(&config_path, options); match file { Ok(mut file) => { let mut buffer = String::new(); file.read_to_string(&mut buffer).map_err(|_| { - WorkspaceError::cant_read_file(format!("{}", configuration_path.display())) + WorkspaceError::cant_read_file(format!("{}", config_path.display())) })?; - let configuration: Configuration = serde_json::from_str(&buffer).map_err(|err| { + let config: Configuration = serde_json::from_str(&buffer).map_err(|err| { WorkspaceError::Configuration(ConfigurationDiagnostic::new_deserialization_error( err.to_string(), from_serde_error_to_range(&err, &buffer), )) })?; - Ok(Some(configuration)) + Ok(Some(config)) } Err(err) => { - // We throw an error only when the error is found. - // In case we don't fine the file, we swallow the error and we continue; not having - // a file should not be a cause of error (for now) - if err.kind() != ErrorKind::NotFound { + // We skip the error when the configuration file is not found + // and the base path is not explicitly set; not having a configuration + // file is not a cause of error + if show_error || err.kind() != ErrorKind::NotFound { return Err(WorkspaceError::cant_read_file(format!( "{}", - configuration_path.display() + config_path.display() ))); } error!( - "Could not find the file configuration at {:?}", - configuration_path.display() + "Could not read the configuration file from {:?}, reason:\n {}", + config_path.display(), + err ); - error!("Reason: {:?}", err); Ok(None) } } diff --git a/website/src/pages/cli.mdx b/website/src/pages/cli.mdx index 80a176a8998..ce4fb703b4c 100644 --- a/website/src/pages/cli.mdx +++ b/website/src/pages/cli.mdx @@ -59,6 +59,12 @@ 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 +### `--config` + +Set the filesystem path to the directory of the rome.json configuration file. +This is optional. Rome will try to read a rome.json configuration file from the +current working directory by default. + ### `--use-server` Connect to a running instance of the Rome daemon server From 7548b5791171d0cae29dbd7129051ee9fc8cf2ed Mon Sep 17 00:00:00 2001 From: ea1thoobeloa9aer Date: Sun, 12 Feb 2023 20:15:06 +0100 Subject: [PATCH 2/9] rename option config -> config-path --- crates/rome_cli/src/commands/help.rs | 6 +++--- crates/rome_cli/src/configuration.rs | 4 ++-- crates/rome_cli/tests/commands/format.rs | 4 ++-- website/src/pages/cli.mdx | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/rome_cli/src/commands/help.rs b/crates/rome_cli/src/commands/help.rs index 463133191f5..219f6b745ec 100644 --- a/crates/rome_cli/src/commands/help.rs +++ b/crates/rome_cli/src/commands/help.rs @@ -37,7 +37,7 @@ const CHECK: Markup = markup! { ""--apply"" Apply safe fixes ""--apply-unsafe"" Apply safe and unsafe fixes ""--max-diagnostics"" Cap the amount of diagnostics displayed (default: 20) - ""--config"" Set the filesystem path to the directory of the rome.json configuration file + ""--config-path"" Set the filesystem path to the directory of the rome.json configuration file ""--verbose"" Print additional verbose advices on diagnostics " }; @@ -66,7 +66,7 @@ const CI: Markup = markup! { ""--formatter-enabled"" Allow to enable or disable the formatter check. (default: true) ""--linter-enabled"" Allow to enable or disable the linter check. (default: true) ""--max-diagnostics"" Cap the amount of diagnostics displayed (default: 50) - ""--config"" Set the filesystem path to the directory of the rome.json configuration file + ""--config-path"" Set the filesystem path to the directory of the rome.json configuration file ""--verbose"" Print additional verbose advices on diagnostics" {FORMAT_OPTIONS} }; @@ -83,7 +83,7 @@ const FORMAT: Markup = markup! { ""--write"" Edit the files in place (beware!) instead of printing the diff to the console ""--skip-errors"" Skip over files containing syntax errors instead of emitting an error diagnostic. ""--max-diagnostics"" Cap the amount of diagnostics displayed (default: 50) - ""--config"" Set the filesystem path to the directory of the rome.json configuration file + ""--config-path"" Set the filesystem path to the directory of the rome.json configuration file ""--verbose"" Print additional verbose advices on diagnostics" {FORMAT_OPTIONS} """--stdin-file-path "" 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 diff --git a/crates/rome_cli/src/configuration.rs b/crates/rome_cli/src/configuration.rs index 5c50e7f22f4..52f2cbc76b3 100644 --- a/crates/rome_cli/src/configuration.rs +++ b/crates/rome_cli/src/configuration.rs @@ -9,8 +9,8 @@ use crate::{CliDiagnostic, CliSession}; pub(crate) fn load_configuration(session: &mut CliSession) -> Result { let config_path: Option = session .args - .opt_value_from_str("--config") - .map_err(|source| CliDiagnostic::parse_error("--config", source))?; + .opt_value_from_str("--config-path") + .map_err(|source| CliDiagnostic::parse_error("--config-path", source))?; let is_config_path = config_path.is_some(); diff --git a/crates/rome_cli/tests/commands/format.rs b/crates/rome_cli/tests/commands/format.rs index b4d3916da6a..bed33cb90d8 100644 --- a/crates/rome_cli/tests/commands/format.rs +++ b/crates/rome_cli/tests/commands/format.rs @@ -264,7 +264,7 @@ fn custom_config_file_path() { &mut console, Arguments::from_vec(vec![ OsString::from("format"), - OsString::from("--config"), + OsString::from("--config-path"), OsString::from(config_path), OsString::from("--write"), file_path.as_os_str().into(), @@ -308,7 +308,7 @@ fn invalid_config_file_path() { &mut console, Arguments::from_vec(vec![ OsString::from("format"), - OsString::from("--config"), + OsString::from("--config-path"), OsString::from(config_path), OsString::from("--write"), file_path.as_os_str().into(), diff --git a/website/src/pages/cli.mdx b/website/src/pages/cli.mdx index ce4fb703b4c..e3f60c23475 100644 --- a/website/src/pages/cli.mdx +++ b/website/src/pages/cli.mdx @@ -59,7 +59,7 @@ 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 -### `--config` +### `--config-path` Set the filesystem path to the directory of the rome.json configuration file. This is optional. Rome will try to read a rome.json configuration file from the From 188d5887fcd35d12d24160c08f16afad0fbb98ae Mon Sep 17 00:00:00 2001 From: ea1thoobeloa9aer Date: Sun, 12 Feb 2023 20:32:21 +0100 Subject: [PATCH 3/9] indentation --- crates/rome_cli/src/commands/help.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/rome_cli/src/commands/help.rs b/crates/rome_cli/src/commands/help.rs index 219f6b745ec..b4d30d650c0 100644 --- a/crates/rome_cli/src/commands/help.rs +++ b/crates/rome_cli/src/commands/help.rs @@ -37,7 +37,7 @@ const CHECK: Markup = markup! { ""--apply"" Apply safe fixes ""--apply-unsafe"" Apply safe and unsafe fixes ""--max-diagnostics"" Cap the amount of diagnostics displayed (default: 20) - ""--config-path"" Set the filesystem path to the directory of the rome.json configuration file + ""--config-path"" Set the filesystem path to the directory of the rome.json configuration file ""--verbose"" Print additional verbose advices on diagnostics " }; @@ -66,7 +66,7 @@ const CI: Markup = markup! { ""--formatter-enabled"" Allow to enable or disable the formatter check. (default: true) ""--linter-enabled"" Allow to enable or disable the linter check. (default: true) ""--max-diagnostics"" Cap the amount of diagnostics displayed (default: 50) - ""--config-path"" Set the filesystem path to the directory of the rome.json configuration file + ""--config-path"" Set the filesystem path to the directory of the rome.json configuration file ""--verbose"" Print additional verbose advices on diagnostics" {FORMAT_OPTIONS} }; @@ -83,7 +83,7 @@ const FORMAT: Markup = markup! { ""--write"" Edit the files in place (beware!) instead of printing the diff to the console ""--skip-errors"" Skip over files containing syntax errors instead of emitting an error diagnostic. ""--max-diagnostics"" Cap the amount of diagnostics displayed (default: 50) - ""--config-path"" Set the filesystem path to the directory of the rome.json configuration file + ""--config-path"" Set the filesystem path to the directory of the rome.json configuration file ""--verbose"" Print additional verbose advices on diagnostics" {FORMAT_OPTIONS} """--stdin-file-path "" 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 From 2ca77be7a46d536538167fbc51669cca2725d1b6 Mon Sep 17 00:00:00 2001 From: ea1thoobeloa9aer Date: Sun, 12 Feb 2023 22:45:59 +0100 Subject: [PATCH 4/9] remove the website documentation for the config-path option --- website/src/pages/cli.mdx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/website/src/pages/cli.mdx b/website/src/pages/cli.mdx index e3f60c23475..80a176a8998 100644 --- a/website/src/pages/cli.mdx +++ b/website/src/pages/cli.mdx @@ -59,12 +59,6 @@ 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 -### `--config-path` - -Set the filesystem path to the directory of the rome.json configuration file. -This is optional. Rome will try to read a rome.json configuration file from the -current working directory by default. - ### `--use-server` Connect to a running instance of the Rome daemon server From 2f268526d1f2b7aa1b4a7bdf154507447a5cd176 Mon Sep 17 00:00:00 2001 From: ea1thoobeloa9aer Date: Sun, 12 Feb 2023 22:50:25 +0100 Subject: [PATCH 5/9] rename config_path -> configuration_path --- crates/rome_service/src/configuration/mod.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/rome_service/src/configuration/mod.rs b/crates/rome_service/src/configuration/mod.rs index 6d3239e6596..642cff52d73 100644 --- a/crates/rome_service/src/configuration/mod.rs +++ b/crates/rome_service/src/configuration/mod.rs @@ -126,26 +126,26 @@ pub fn load_config( show_error: bool, ) -> LoadConfig { let config_name = file_system.config_name(); - let config_path = if let Some(ref base_path) = base_path { + let configuration_path = if let Some(ref base_path) = base_path { base_path.join(config_name) } else { PathBuf::from(config_name) }; info!( "Attempting to read the configuration file from {:?}", - config_path + configuration_path ); let options = OpenOptions::default().read(true); - let file = file_system.open_with_options(&config_path, options); + let file = file_system.open_with_options(&configuration_path, options); match file { Ok(mut file) => { let mut buffer = String::new(); file.read_to_string(&mut buffer).map_err(|_| { - WorkspaceError::cant_read_file(format!("{}", config_path.display())) + WorkspaceError::cant_read_file(format!("{}", configuration_path.display())) })?; let deserialized = deserialize_from_json::(&buffer) - .with_file_path(&config_path.display().to_string()); + .with_file_path(&configuration_path.display().to_string()); Ok(Some(deserialized)) } Err(err) => { @@ -155,12 +155,12 @@ pub fn load_config( if show_error || err.kind() != ErrorKind::NotFound { return Err(WorkspaceError::cant_read_file(format!( "{}", - config_path.display() + configuration_path.display() ))); } error!( "Could not read the configuration file from {:?}, reason:\n {}", - config_path.display(), + configuration_path.display(), err ); Ok(None) From 21c4537b128509c0b2d6b29a7ed567c7381fca20 Mon Sep 17 00:00:00 2001 From: ea1thoobeloa9aer Date: Mon, 13 Feb 2023 18:47:00 +0100 Subject: [PATCH 6/9] refactor the base path option --- crates/rome_cli/src/commands/rage.rs | 4 +-- crates/rome_cli/src/configuration.rs | 11 ++++-- crates/rome_lsp/src/session.rs | 9 +++-- crates/rome_service/src/configuration/mod.rs | 37 +++++++++++++------- crates/rome_service/src/lib.rs | 3 +- 5 files changed, 42 insertions(+), 22 deletions(-) diff --git a/crates/rome_cli/src/commands/rage.rs b/crates/rome_cli/src/commands/rage.rs index c6bb70270f3..f26c299c5c9 100644 --- a/crates/rome_cli/src/commands/rage.rs +++ b/crates/rome_cli/src/commands/rage.rs @@ -4,7 +4,7 @@ use rome_diagnostics::termcolor::{ColorChoice, WriteColor}; use rome_diagnostics::{termcolor, PrintDescription}; use rome_fs::FileSystem; use rome_service::workspace::{client, RageEntry, RageParams}; -use rome_service::{load_config, DynRef, Workspace}; +use rome_service::{load_config, BasePath, DynRef, Workspace}; use std::{env, io, ops::Deref}; use tokio::runtime::Runtime; @@ -163,7 +163,7 @@ impl Display for RageConfiguration<'_, '_> { fn fmt(&self, fmt: &mut Formatter) -> io::Result<()> { Section("Rome Configuration").fmt(fmt)?; - match load_config(self.0, None, false) { + match load_config(self.0, BasePath::default()) { Ok(None) => KeyValuePair("Status", markup!("unset")).fmt(fmt)?, Ok(Some(deserialized)) => { let (configuration, diagnostics) = deserialized.consume(); diff --git a/crates/rome_cli/src/configuration.rs b/crates/rome_cli/src/configuration.rs index 1d94016a23e..a1162040138 100644 --- a/crates/rome_cli/src/configuration.rs +++ b/crates/rome_cli/src/configuration.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; use crate::{CliDiagnostic, CliSession}; use rome_deserialize::Deserialized; -use rome_service::{load_config, Configuration}; +use rome_service::{load_config, BasePath, Configuration}; /// Load the configuration for this session of the CLI, merging the content of /// the `rome.json` file if it exists on disk with common command line options @@ -14,7 +14,12 @@ pub(crate) fn load_configuration( .opt_value_from_str("--config-path") .map_err(|source| CliDiagnostic::parse_error("--config-path", source))?; - let is_config_path = config_path.is_some(); + let base_path = match config_path { + None => BasePath::default(), + Some(path) => BasePath::FromUser(path), + }; - Ok(load_config(&session.app.fs, config_path, is_config_path)?.unwrap_or_default()) + let config = load_config(&session.app.fs, base_path)?; + + Ok(config.unwrap_or_default()) } diff --git a/crates/rome_lsp/src/session.rs b/crates/rome_lsp/src/session.rs index 0bfa3354c55..7adbb6e00ad 100644 --- a/crates/rome_lsp/src/session.rs +++ b/crates/rome_lsp/src/session.rs @@ -10,7 +10,7 @@ use rome_console::markup; use rome_fs::{FileSystem, OsFileSystem, RomePath}; use rome_service::workspace::{FeatureName, PullDiagnosticsParams, SupportsFeatureParams}; use rome_service::workspace::{RageEntry, RageParams, RageResult, UpdateSettingsParams}; -use rome_service::{load_config, Workspace}; +use rome_service::{load_config, BasePath, Workspace}; use rome_service::{DynRef, WorkspaceError}; use serde_json::Value; use std::collections::HashMap; @@ -364,9 +364,12 @@ impl Session { /// the root URI and update the workspace settings accordingly #[tracing::instrument(level = "debug", skip(self))] pub(crate) async fn load_workspace_settings(&self) { - let base_path = self.base_path(); + let base_path = match self.base_path() { + None => BasePath::default(), + Some(path) => BasePath::Lsp(path), + }; - let status = match load_config(&self.fs, base_path, false) { + let status = match load_config(&self.fs, base_path) { Ok(Some(deserialized)) => { let (configuration, diagnostics) = deserialized.consume(); if diagnostics.is_empty() { diff --git a/crates/rome_service/src/configuration/mod.rs b/crates/rome_service/src/configuration/mod.rs index 642cff52d73..0eeeb9c31f4 100644 --- a/crates/rome_service/src/configuration/mod.rs +++ b/crates/rome_service/src/configuration/mod.rs @@ -117,19 +117,27 @@ impl FilesConfiguration { type LoadConfig = Result>, WorkspaceError>; -/// This function is responsible to load the rome configuration. +#[derive(Default, PartialEq, Eq)] +pub enum BasePath { + /// The default mode, not having a configuration file is not an error. + #[default] + None, + /// The base path provided by the LSP, not having a configuration file is not an error. + Lsp(PathBuf), + /// The base path provided by the user, not having a configuration file is an error. + /// Throws any kind of I/O errors. + FromUser(PathBuf), +} + +/// Load the configuration from the file system. /// -/// The `file_system` will read the configuration file. A base path can be passed -pub fn load_config( - file_system: &DynRef, - base_path: Option, - show_error: bool, -) -> LoadConfig { +/// The configuration file will be read from the `file_system`. +/// An optional base path can be appended to the configuration file path. +pub fn load_config(file_system: &DynRef, base_path: BasePath) -> LoadConfig { let config_name = file_system.config_name(); - let configuration_path = if let Some(ref base_path) = base_path { - base_path.join(config_name) - } else { - PathBuf::from(config_name) + let configuration_path = match base_path { + BasePath::Lsp(ref path) | BasePath::FromUser(ref path) => path.join(config_name), + _ => PathBuf::from(config_name), }; info!( "Attempting to read the configuration file from {:?}", @@ -151,8 +159,11 @@ pub fn load_config( Err(err) => { // We skip the error when the configuration file is not found // and the base path is not explicitly set; not having a configuration - // file is not a cause of error - if show_error || err.kind() != ErrorKind::NotFound { + // file is only a cause of error when the `load_data` is set to `FromUser`. + if match base_path { + BasePath::FromUser(_) => false, + _ => err.kind() != ErrorKind::NotFound, + } { return Err(WorkspaceError::cant_read_file(format!( "{}", configuration_path.display() diff --git a/crates/rome_service/src/lib.rs b/crates/rome_service/src/lib.rs index b3805e7fd9d..f448b02d094 100644 --- a/crates/rome_service/src/lib.rs +++ b/crates/rome_service/src/lib.rs @@ -14,7 +14,8 @@ mod diagnostics; pub mod workspace_types; pub use crate::configuration::{ - create_config, load_config, Configuration, ConfigurationDiagnostic, RuleConfiguration, Rules, + create_config, load_config, BasePath, Configuration, ConfigurationDiagnostic, + RuleConfiguration, Rules, }; pub use crate::matcher::{MatchOptions, Matcher, Pattern}; From 83ace244133802e9a8f9b700b7f5c59a5a8aae6d Mon Sep 17 00:00:00 2001 From: ea1thoobeloa9aer Date: Mon, 13 Feb 2023 18:55:43 +0100 Subject: [PATCH 7/9] debug artifacts --- crates/rome_service/src/configuration/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/rome_service/src/configuration/mod.rs b/crates/rome_service/src/configuration/mod.rs index 0eeeb9c31f4..4a21493e259 100644 --- a/crates/rome_service/src/configuration/mod.rs +++ b/crates/rome_service/src/configuration/mod.rs @@ -117,7 +117,7 @@ impl FilesConfiguration { type LoadConfig = Result>, WorkspaceError>; -#[derive(Default, PartialEq, Eq)] +#[derive(Default, PartialEq)] pub enum BasePath { /// The default mode, not having a configuration file is not an error. #[default] @@ -161,7 +161,7 @@ pub fn load_config(file_system: &DynRef, base_path: BasePath) -> // and the base path is not explicitly set; not having a configuration // file is only a cause of error when the `load_data` is set to `FromUser`. if match base_path { - BasePath::FromUser(_) => false, + BasePath::FromUser(_) => true, _ => err.kind() != ErrorKind::NotFound, } { return Err(WorkspaceError::cant_read_file(format!( From 6845d0974fb67fb839417bd969e73bdec2be92e3 Mon Sep 17 00:00:00 2001 From: ea1thoobeloa9aer Date: Mon, 13 Feb 2023 18:57:24 +0100 Subject: [PATCH 8/9] update comment --- crates/rome_service/src/configuration/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/rome_service/src/configuration/mod.rs b/crates/rome_service/src/configuration/mod.rs index 4a21493e259..5c7e3fd4136 100644 --- a/crates/rome_service/src/configuration/mod.rs +++ b/crates/rome_service/src/configuration/mod.rs @@ -157,9 +157,9 @@ pub fn load_config(file_system: &DynRef, base_path: BasePath) -> Ok(Some(deserialized)) } Err(err) => { - // We skip the error when the configuration file is not found - // and the base path is not explicitly set; not having a configuration - // file is only a cause of error when the `load_data` is set to `FromUser`. + // We skip the error when the configuration file is not found. + // Not having a configuration file is only an error when the `base_path` is + // set to `BasePath::FromUser`. if match base_path { BasePath::FromUser(_) => true, _ => err.kind() != ErrorKind::NotFound, From 970ab42ffb42d612e8a88534a1c0d8edcf0a77e3 Mon Sep 17 00:00:00 2001 From: ea1thoobeloa9aer Date: Mon, 13 Feb 2023 19:00:41 +0100 Subject: [PATCH 9/9] formatting --- crates/rome_service/src/configuration/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/rome_service/src/configuration/mod.rs b/crates/rome_service/src/configuration/mod.rs index 5c7e3fd4136..25758451688 100644 --- a/crates/rome_service/src/configuration/mod.rs +++ b/crates/rome_service/src/configuration/mod.rs @@ -157,7 +157,7 @@ pub fn load_config(file_system: &DynRef, base_path: BasePath) -> Ok(Some(deserialized)) } Err(err) => { - // We skip the error when the configuration file is not found. + // We skip the error when the configuration file is not found. // Not having a configuration file is only an error when the `base_path` is // set to `BasePath::FromUser`. if match base_path {