From d5b378a8911f927a84b68dedfe5c517eb5b7ea1f Mon Sep 17 00:00:00 2001 From: Julien Tanay Date: Fri, 26 Jan 2024 03:49:25 +0100 Subject: [PATCH] feat(vscode): allow config path configuration (#2172) Fixes #1944 --- crates/oxc_language_server/src/main.rs | 22 +++++++++++++--------- editors/vscode/package.json | 6 ++++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/crates/oxc_language_server/src/main.rs b/crates/oxc_language_server/src/main.rs index ef7370740d443..c6c820c063d05 100644 --- a/crates/oxc_language_server/src/main.rs +++ b/crates/oxc_language_server/src/main.rs @@ -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 { + 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"), ); } } diff --git a/editors/vscode/package.json b/editors/vscode/package.json index 687b3c82d194d..9902e1f353456 100644 --- a/editors/vscode/package.json +++ b/editors/vscode/package.json @@ -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." } } }