From ca7104f775bd372e834845c96218db57b0cb5314 Mon Sep 17 00:00:00 2001 From: Sysix <3897725+Sysix@users.noreply.github.com> Date: Fri, 4 Sep 2026 21:36:42 +0000 Subject: [PATCH] refactor(lsp): dont create temporary map in collect_diagnostics_with (#26341) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pull request overview This PR refactors the language server’s `WorkspaceWorker::collect_diagnostics_with` to avoid building an intermediate map when collecting tool diagnostics, returning the tool’s `DiagnosticResult` directly. This was an old code path when `oxc_language_server` did used both tools (`oxlint` & `oxfmt`) at the same time --- crates/oxc_language_server/src/worker.rs | 26 ++++++++---------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/crates/oxc_language_server/src/worker.rs b/crates/oxc_language_server/src/worker.rs index 92583c4f69..d03c61741a 100644 --- a/crates/oxc_language_server/src/worker.rs +++ b/crates/oxc_language_server/src/worker.rs @@ -1,6 +1,6 @@ use std::{path::Path, sync::Arc}; -use rustc_hash::{FxHashMap, FxHashSet}; +use rustc_hash::FxHashSet; use serde_json::json; use tokio::sync::{Mutex, RwLock}; use tower_lsp_server::{ @@ -123,8 +123,6 @@ impl WorkspaceWorker { where F: Fn(&Box, &TextDocument) -> DiagnosticResult, { - let mut aggregated: FxHashMap> = FxHashMap::default(); - let tool_diagnostics = { let tool_guard = self.tool.read().await; let Some(tool) = tool_guard.as_ref() else { @@ -134,28 +132,22 @@ impl WorkspaceWorker { run(tool, document) }; - match tool_diagnostics { - Ok(diags) => { - for (entry_uri, mut diags) in diags { - aggregated.entry(entry_uri).or_default().append(&mut diags); - } - } + let diagnostics = match tool_diagnostics { + Ok(diags) => diags, Err(err) => { return Err(err); } - } + }; // In push mode, keep track of published diagnostics to clear them on shutdown if self.diagnostic_mode == DiagnosticMode::Push { - let new_published_uris: FxHashSet = aggregated.keys().cloned().collect(); - self.published_diagnostics.lock().await.extend(new_published_uris); + self.published_diagnostics + .lock() + .await + .extend(diagnostics.iter().map(|(uri, _)| uri.clone())); } - let mut result = Vec::with_capacity(aggregated.len()); - for (uri, diags) in aggregated { - result.push((uri, diags)); - } - Ok(result) + Ok(diagnostics) } /// Run different tools to collect diagnostics.