Skip to content

Commit

Permalink
feat(language_server)!: add capability diagnosticProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
Sysix committed Nov 24, 2024
1 parent 6f5a737 commit e6e6e5c
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions crates/oxc_language_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,17 @@ enum Run {
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
struct Options {
run: Run,
enable: bool,
config_path: String,
}

impl Default for Options {
fn default() -> Self {
Self { enable: true, run: Run::default(), config_path: ".eslintrc".into() }
Self { enable: true, config_path: ".eslintrc".into() }
}
}

impl Options {
fn get_lint_level(&self) -> SyntheticRunLevel {
if self.enable {
match self.run {
Run::OnSave => SyntheticRunLevel::OnSave,
Run::OnType => SyntheticRunLevel::OnType,
}
} else {
SyntheticRunLevel::Disable
}
}

fn get_config_path(&self) -> Option<PathBuf> {
if self.config_path.is_empty() {
None
Expand All @@ -80,13 +68,6 @@ impl Options {
}
}

#[derive(Debug, PartialEq, PartialOrd, Clone, Copy)]
enum SyntheticRunLevel {
Disable,
OnSave,
OnType,
}

#[tower_lsp::async_trait]
impl LanguageServer for Backend {
async fn initialize(&self, params: InitializeParams) -> Result<InitializeResult> {
Expand Down Expand Up @@ -162,8 +143,8 @@ impl LanguageServer for Backend {
options
};

debug!("{:?}", &changed_options.get_lint_level());
if changed_options.get_lint_level() == SyntheticRunLevel::Disable {
debug!("{:?}", &changed_options.enable);
if !changed_options.enable {
// clear all exists diagnostics when linter is disabled
let opened_files = self.document_content_cache.iter().map(|k| k.key().to_string());
let cleared_diagnostics = opened_files
Expand Down Expand Up @@ -404,7 +385,7 @@ impl Backend {
return None;
};

let result = self.server_linter.read().await.run_single(&uri, content);
let result = self.server_linter.read().await.run_single(uri, content);

if result.is_some() {
self.diagnostics_report_map.insert(uri.to_string(), result.clone().unwrap());
Expand Down

0 comments on commit e6e6e5c

Please sign in to comment.