Skip to content

Commit

Permalink
feat(vscode): allow config path configuration (#2172)
Browse files Browse the repository at this point in the history
Fixes #1944
  • Loading branch information
Djiit committed Jan 26, 2024
1 parent b268cb2 commit d5b378a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
22 changes: 13 additions & 9 deletions crates/oxc_language_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
}
}

Expand All @@ -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)]
Expand Down Expand Up @@ -329,21 +337,17 @@ 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;
*linter = ServerLinter::new_with_linter(
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"),
);
}
}
Expand Down
6 changes: 6 additions & 0 deletions editors/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
}
Expand Down

0 comments on commit d5b378a

Please sign in to comment.