chore(rome_service): remove constraints from settings
MODIFY
crates/rome_cli/src/commands/format.rs
crates/rome_cli/src/commands/format.rs
@@ -87,10 +87,10 @@ pub(crate) fn apply_format_settings_from_cli(
match indent_style {
Some(IndentStyle::Tab) => {
- workspace_settings.format.indent_style = Some(IndentStyle::Tab);
+ workspace_settings.formatter.indent_style = Some(IndentStyle::Tab);
}
Some(IndentStyle::Space(default_size)) => {
- workspace_settings.format.indent_style =
+ workspace_settings.formatter.indent_style =
Some(IndentStyle::Space(size.unwrap_or(default_size)));
}
None => {}
@@ -133,7 +133,7 @@ pub(crate) fn apply_format_settings_from_cli(
})?;
if let Some(line_width) = line_width {
- workspace_settings.format.line_width = Some(line_width);
+ workspace_settings.formatter.line_width = Some(line_width);
}
Ok(())

MODIFY
crates/rome_service/src/configuration/mod.rs
crates/rome_service/src/configuration/mod.rs
@@ -18,7 +18,6 @@ mod formatter;
mod javascript;
pub mod linter;
-pub(crate) use javascript::{deserialize_globals, serialize_globals};
pub use linter::{RuleConfiguration, Rules};
/// The configuration that is contained inside the file `rome.json`

MODIFY
crates/rome_service/src/settings.rs
crates/rome_service/src/settings.rs
@@ -7,26 +7,32 @@ use rome_js_syntax::JsLanguage;
use std::sync::{RwLock, RwLockReadGuard};
/// Global settings for the entire workspace
-#[derive(Debug, Default, serde::Serialize, serde::Deserialize)]
-#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
+#[derive(Debug, Default)]
pub struct WorkspaceSettings {
/// Formatter settings applied to all files in the workspaces
- #[serde(default)]
- pub format: FormatSettings,
+ pub formatter: FormatSettings,
/// Linter settings applied to all files in the workspace
- #[serde(default)]
pub linter: LinterSettings,
/// Language specific settings
- #[serde(default)]
pub languages: LanguagesSettings,
}
impl WorkspaceSettings {
+ /// Retrieves the settings of the formatter
+ pub fn formatter(&self) -> &FormatSettings {
+ &self.formatter
+ }
+
+ /// Retrieves the settings of the linter
+ pub fn linter(&self) -> &LinterSettings {
+ &self.linter
+ }
+
/// The (configuration)[Configuration] is merged into the workspace
pub fn merge_with_configuration(&mut self, configuration: Configuration) {
// formatter part
if let Some(formatter) = configuration.formatter {
- self.format = FormatSettings::from(formatter);
+ self.formatter = FormatSettings::from(formatter);
}
let formatter = configuration
.javascript
@@ -62,8 +68,7 @@ impl WorkspaceSettings {
}
/// Formatter settings for the entire workspace
-#[derive(Debug, serde::Serialize, serde::Deserialize)]
-#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
+#[derive(Debug)]
pub struct FormatSettings {
/// Enabled by default
pub enabled: bool,
@@ -86,8 +91,7 @@ impl Default for FormatSettings {
}
/// Linter settings for the entire workspace
-#[derive(Debug, serde::Serialize, serde::Deserialize)]
-#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
+#[derive(Debug)]
pub struct LinterSettings {
/// Enabled by default
pub enabled: bool,
@@ -106,33 +110,16 @@ impl Default for LinterSettings {
}
/// Static map of language names to language-specific settings
-#[derive(Debug, Default, serde::Serialize, serde::Deserialize)]
-#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
+#[derive(Debug, Default)]
pub struct LanguagesSettings {
- #[serde(default)]
pub javascript: LanguageSettings<JsLanguage>,
}
pub trait Language: rome_rowan::Language {
- #[cfg(not(feature = "schemars"))]
/// Formatter settings type for this language
- type FormatSettings: Default + serde::Serialize + serde::de::DeserializeOwned;
- #[cfg(feature = "schemars")]
- /// Formatter settings type for this language
- type FormatSettings: Default
- + serde::Serialize
- + serde::de::DeserializeOwned
- + schemars::JsonSchema;
-
- #[cfg(not(feature = "schemars"))]
- /// Linter settings type for this language
- type LinterSettings: Default + serde::Serialize + serde::de::DeserializeOwned;
- #[cfg(feature = "schemars")]
- /// Linter settings type for this language
- type LinterSettings: Default
- + serde::Serialize
- + serde::de::DeserializeOwned
- + schemars::JsonSchema;
+ type FormatSettings: Default;
+
+ type LinterSettings: Default;
/// Fully resolved formatter options type for this language
type FormatOptions: rome_formatter::FormatOptions;
@@ -149,30 +136,22 @@ pub trait Language: rome_rowan::Language {
) -> Self::FormatOptions;
}
-#[derive(Debug, Default, serde::Serialize, serde::Deserialize)]
-#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
+#[derive(Debug, Default)]
pub struct LanguageSettings<L: Language> {
/// Formatter settings for this language
- #[serde(default)]
pub format: L::FormatSettings,
/// Linter settings for this language
- #[serde(default)]
pub linter: L::LinterSettings,
/// Globals variables/bindings that can be found in a file
- #[serde(
- default,
- deserialize_with = "crate::configuration::deserialize_globals",
- serialize_with = "crate::configuration::serialize_globals"
- )]
pub globals: Option<IndexSet<String>>,
}
/// Handle object holding a temporary lock on the workspace settings until
/// the deferred language-specific options resolution is called
#[derive(Debug)]
-pub(crate) struct SettingsHandle<'a> {
+pub struct SettingsHandle<'a> {
inner: RwLockReadGuard<'a, WorkspaceSettings>,
}
@@ -197,7 +176,7 @@ impl<'a> SettingsHandle<'a> {
L: Language,
{
L::resolve_format_options(
- &self.inner.format,
+ &self.inner.formatter,
&L::lookup_settings(&self.inner.languages).format,
path,
)

MODIFY
crates/rome_service/src/workspace/server.rs
crates/rome_service/src/workspace/server.rs
@@ -167,9 +167,9 @@ impl Workspace for WorkspaceServer {
let settings = self.settings.read().unwrap();
match params.feature {
FeatureName::Format => {
- capabilities.formatter.format.is_some() && settings.format.enabled
+ capabilities.formatter.format.is_some() && settings.formatter().enabled
}
- FeatureName::Lint => capabilities.analyzer.lint.is_some() && settings.linter.enabled,
+ FeatureName::Lint => capabilities.analyzer.lint.is_some() && settings.linter().enabled,
}
}
@@ -240,7 +240,7 @@ impl Workspace for WorkspaceServer {
let parse = self.get_parse(params.path.clone())?;
let settings = self.settings();
- if !settings.as_ref().format.format_with_errors && parse.has_errors() {
+ if !settings.as_ref().formatter().format_with_errors && parse.has_errors() {
return Err(RomeError::FormatWithErrorsDisabled);
}
@@ -285,7 +285,7 @@ impl Workspace for WorkspaceServer {
let parse = self.get_parse(params.path.clone())?;
let settings = self.settings.read().unwrap();
- let rules = settings.linter.rules.as_ref();
+ let rules = settings.linter().rules.as_ref();
let enabled_rules: Option<Vec<RuleFilter>> = if let Some(rules) = rules {
let enabled: IndexSet<RuleFilter> = rules.as_enabled_rules();
Some(enabled.into_iter().collect())
@@ -316,7 +316,7 @@ impl Workspace for WorkspaceServer {
let parse = self.get_parse(params.path.clone())?;
let settings = self.settings.read().unwrap();
- let rules = settings.linter.rules.as_ref();
+ let rules = settings.linter().rules.as_ref();
Ok(code_actions(&params.path, parse, params.range, rules))
}
@@ -333,7 +333,7 @@ impl Workspace for WorkspaceServer {
let parse = self.get_parse(params.path.clone())?;
let settings = self.settings();
- if !settings.as_ref().format.format_with_errors && parse.has_errors() {
+ if !settings.as_ref().formatter().format_with_errors && parse.has_errors() {
return Err(RomeError::FormatWithErrorsDisabled);
}
@@ -350,7 +350,7 @@ impl Workspace for WorkspaceServer {
let parse = self.get_parse(params.path.clone())?;
let settings = self.settings();
- if !settings.as_ref().format.format_with_errors && parse.has_errors() {
+ if !settings.as_ref().formatter().format_with_errors && parse.has_errors() {
return Err(RomeError::FormatWithErrorsDisabled);
}
@@ -367,7 +367,7 @@ impl Workspace for WorkspaceServer {
let parse = self.get_parse(params.path.clone())?;
let settings = self.settings();
- if !settings.as_ref().format.format_with_errors && parse.has_errors() {
+ if !settings.as_ref().formatter().format_with_errors && parse.has_errors() {
return Err(RomeError::FormatWithErrorsDisabled);
}
@@ -383,7 +383,7 @@ impl Workspace for WorkspaceServer {
let parse = self.get_parse(params.path.clone())?;
let settings = self.settings.read().unwrap();
- let rules = settings.linter.rules.as_ref();
+ let rules = settings.linter().rules.as_ref();
fix_all(FixAllParams {
rome_path: &params.path,
parse,

chore(rome_service): remove constraints from settings (#3157)