mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
refactor(lsp): dont create temporary map in collect_diagnostics_with (#26341)
<summary>Pull request overview</summary> 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
This commit is contained in:
1 parent
04b8957242
commit
ca7104f775
1 file changed
+9
-17
@@ -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<dyn Tool>, &TextDocument) -> DiagnosticResult,
|
||||
{
|
||||
let mut aggregated: FxHashMap<Uri, Vec<Diagnostic>> = 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<Uri> = 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.
|
||||
|
||||
Reference in new issue
Block a user