feat(vscode): allow config path configuration (#2172)

Fixes #1944
This commit is contained in:
Julien Tanay 2024-01-26 03:49:25 +01:00 committed by GitHub
parent b268cb2545
commit d5b378a891
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 9 deletions

View file

@ -47,11 +47,12 @@ enum Run {
struct Options {
run: Run,
enable: bool,
config_path: String,
}
impl Default for Options {
fn default() -> Self {
Self { enable: true, run: Run::default() }
Self { enable: true, run: Run::default(), config_path: ".eslintrc".into() }
}
}
@ -66,6 +67,13 @@ impl Options {
SyntheticRunLevel::Disable
}
}
fn get_config_path(&self) -> Option<PathBuf> {
if self.config_path.is_empty() {
None
} else {
Some(PathBuf::from(&self.config_path))
}
}
}
#[derive(Debug, PartialEq, PartialOrd, Clone, Copy)]
@ -329,13 +337,9 @@ impl Backend {
return;
};
let mut config_path = None;
let rc_config = root_path.join(".eslintrc");
if rc_config.exists() {
config_path = Some(rc_config);
}
let rc_json_config = root_path.join(".eslintrc.json");
if rc_json_config.exists() {
config_path = Some(rc_json_config);
let config = root_path.join(self.options.lock().await.get_config_path().unwrap());
if config.exists() {
config_path = Some(config);
}
if let Some(config_path) = config_path {
let mut linter = self.server_linter.write().await;
@ -343,7 +347,7 @@ impl Backend {
Linter::from_options(
LintOptions::default().with_fix(true).with_config_path(Some(config_path)),
)
.expect("should initialized linter with new options"),
.expect("should have initialized linter with new options"),
);
}
}

View file

@ -93,6 +93,12 @@
],
"default": "off",
"description": "Traces the communication between VS Code and the language server."
},
"oxc_language_server.configPath": {
"type": "string",
"scope": "window",
"default": ".eslintrc",
"description": "Path to ESlint configuration."
}
}
}