Use optional server_id for get_diagnostics

This commit is contained in:
Alvaro Parker 2025-08-25 15:27:28 -04:00
parent 5fb79cde9e
commit d12bd1d6bb
No known key found for this signature in database
2 changed files with 23 additions and 9 deletions

View file

@ -1569,11 +1569,25 @@ impl Buffer {
self.send_operation(op, true, cx); self.send_operation(op, true, cx);
} }
pub fn get_diagnostics(&self, server_id: LanguageServerId) -> Option<&DiagnosticSet> { /// Retrieve the diagnostics entries for the given language server, or all
let Ok(idx) = self.diagnostics.binary_search_by_key(&server_id, |v| v.0) else { /// diagnostics if `server_id` is `None`.
return None; pub fn get_diagnostics(
}; &self,
Some(&self.diagnostics[idx].1) server_id: Option<LanguageServerId>,
) -> Option<Vec<&DiagnosticEntry<Anchor>>> {
if let Some(server_id) = server_id {
let Ok(idx) = self.diagnostics.binary_search_by_key(&server_id, |v| v.0) else {
return None;
};
Some(self.diagnostics[idx].1.iter().collect::<Vec<_>>())
} else {
let diag = self
.diagnostics
.iter()
.flat_map(|(_, diags)| (*diags).iter())
.collect::<Vec<_>>();
Some(diag)
}
} }
fn request_autoindent(&mut self, cx: &mut Context<Self>) { fn request_autoindent(&mut self, cx: &mut Context<Self>) {

View file

@ -7588,9 +7588,8 @@ impl LspStore {
let snapshot = buffer_handle.read(cx).snapshot(); let snapshot = buffer_handle.read(cx).snapshot();
let buffer = buffer_handle.read(cx); let buffer = buffer_handle.read(cx);
let reused_diagnostics = buffer let reused_diagnostics = buffer
.get_diagnostics(server_id) .get_diagnostics(Some(server_id))
.into_iter() .map(|diag| {
.flat_map(|diag| {
diag.iter() diag.iter()
.filter(|v| merge(buffer, &v.diagnostic, cx)) .filter(|v| merge(buffer, &v.diagnostic, cx))
.map(|v| { .map(|v| {
@ -7601,8 +7600,9 @@ impl LspStore {
diagnostic: v.diagnostic.clone(), diagnostic: v.diagnostic.clone(),
} }
}) })
.collect::<Vec<_>>()
}) })
.collect::<Vec<_>>(); .unwrap_or_default();
self.as_local_mut() self.as_local_mut()
.context("cannot merge diagnostics on a remote LspStore")? .context("cannot merge diagnostics on a remote LspStore")?