From df484168b238ef1e7ec993eae915e2ed4c96a479 Mon Sep 17 00:00:00 2001 From: Sysix <3897725+Sysix@users.noreply.github.com> Date: Fri, 17 Oct 2025 20:18:32 +0000 Subject: [PATCH] perf(language_server): return `Diagnostic` when relinting all files (#14737) When relinting the files, the `PossibleFixContent` is not relevant for the processes. These are: - changing language server configuration - changing oxlint configuration --- crates/oxc_language_server/src/backend.rs | 12 ++--------- .../src/linter/server_linter.rs | 20 ++++++++++--------- crates/oxc_language_server/src/worker.rs | 13 +++++------- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/crates/oxc_language_server/src/backend.rs b/crates/oxc_language_server/src/backend.rs index d911a5020bf1c..13a1c9ad4f155 100644 --- a/crates/oxc_language_server/src/backend.rs +++ b/crates/oxc_language_server/src/backend.rs @@ -335,12 +335,7 @@ impl LanguageServer for Backend { } if let Some(diagnostics) = diagnostics { - for (uri, reports) in &diagnostics.pin() { - new_diagnostics.push(( - uri.clone(), - reports.iter().map(|d| d.diagnostic.clone()).collect(), - )); - } + new_diagnostics.extend(diagnostics); } if let Some(watchers) = watchers @@ -412,10 +407,7 @@ impl LanguageServer for Backend { continue; }; - for (uri, reports) in &diagnostics.pin() { - all_diagnostics - .push((uri.clone(), reports.iter().map(|d| d.diagnostic.clone()).collect())); - } + all_diagnostics.extend(diagnostics); } if !all_diagnostics.is_empty() { diff --git a/crates/oxc_language_server/src/linter/server_linter.rs b/crates/oxc_language_server/src/linter/server_linter.rs index 6bb7e81eae486..92d316b29b78d 100644 --- a/crates/oxc_language_server/src/linter/server_linter.rs +++ b/crates/oxc_language_server/src/linter/server_linter.rs @@ -7,7 +7,7 @@ use log::{debug, warn}; use oxc_linter::{AllowWarnDeny, LintIgnoreMatcher}; use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet}; use tokio::sync::Mutex; -use tower_lsp_server::lsp_types::Uri; +use tower_lsp_server::lsp_types::{Diagnostic, Uri}; use oxc_linter::{ Config, ConfigStore, ConfigStoreBuilder, ExternalPluginStore, LintOptions, Oxlintrc, @@ -283,17 +283,19 @@ impl ServerLinter { .collect() } - pub async fn revalidate_diagnostics( - &self, - uris: Vec, - ) -> ConcurrentHashMap> { - let map = ConcurrentHashMap::default(); + pub async fn revalidate_diagnostics(&self, uris: Vec) -> Vec<(String, Vec)> { + let mut diagnostics = Vec::with_capacity(uris.len()); for uri in uris { - if let Some(diagnostics) = self.run_single(&uri, None, ServerLinterRun::Always).await { - map.pin().insert(uri.to_string(), diagnostics); + if let Some(file_diagnostic) = + self.run_single(&uri, None, ServerLinterRun::Always).await + { + diagnostics.push(( + uri.to_string(), + file_diagnostic.into_iter().map(|d| d.diagnostic).collect(), + )); } } - map + diagnostics } fn is_ignored(&self, uri: &Uri) -> bool { diff --git a/crates/oxc_language_server/src/worker.rs b/crates/oxc_language_server/src/worker.rs index ce4b78a536bf0..4d12e9aaadd34 100644 --- a/crates/oxc_language_server/src/worker.rs +++ b/crates/oxc_language_server/src/worker.rs @@ -11,7 +11,7 @@ use tower_lsp_server::{ }; use crate::{ - ConcurrentHashMap, FORMAT_CONFIG_FILE, + FORMAT_CONFIG_FILE, code_actions::{apply_all_fix_code_action, apply_fix_code_actions, fix_all_text_edit}, formatter::{options::FormatOptions, server_formatter::ServerFormatter}, linter::{ @@ -215,12 +215,9 @@ impl WorkspaceWorker { /// Revalidate diagnostics for the given URIs /// This will re-lint all opened files and return the new diagnostics - async fn revalidate_diagnostics( - &self, - uris: Vec, - ) -> ConcurrentHashMap> { + async fn revalidate_diagnostics(&self, uris: Vec) -> Vec<(String, Vec)> { let Some(server_linter) = &*self.server_linter.read().await else { - return ConcurrentHashMap::default(); + return Vec::new(); }; server_linter.revalidate_diagnostics(uris).await @@ -319,7 +316,7 @@ impl WorkspaceWorker { pub async fn did_change_watched_files( &self, _file_event: &FileEvent, - ) -> Option>> { + ) -> Option)>> { // TODO: the tools should implement a helper function to detect if the changed file is relevant let files = { let server_linter_guard = self.server_linter.read().await; @@ -348,7 +345,7 @@ impl WorkspaceWorker { changed_options: &Options, ) -> ( // Diagnostic reports that need to be revalidated - Option>>, + Option)>>, // File system watcher for lint/fmt config changes // - `None` if no watcher changes are needed // - empty vector if all watchers should be removed