Use optional server_id for get_diagnostics
This commit is contained in:
parent
5fb79cde9e
commit
d12bd1d6bb
2 changed files with 23 additions and 9 deletions
|
@ -1569,11 +1569,25 @@ impl Buffer {
|
|||
self.send_operation(op, true, cx);
|
||||
}
|
||||
|
||||
pub fn get_diagnostics(&self, server_id: LanguageServerId) -> Option<&DiagnosticSet> {
|
||||
let Ok(idx) = self.diagnostics.binary_search_by_key(&server_id, |v| v.0) else {
|
||||
return None;
|
||||
};
|
||||
Some(&self.diagnostics[idx].1)
|
||||
/// Retrieve the diagnostics entries for the given language server, or all
|
||||
/// diagnostics if `server_id` is `None`.
|
||||
pub fn get_diagnostics(
|
||||
&self,
|
||||
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>) {
|
||||
|
|
|
@ -7588,9 +7588,8 @@ impl LspStore {
|
|||
let snapshot = buffer_handle.read(cx).snapshot();
|
||||
let buffer = buffer_handle.read(cx);
|
||||
let reused_diagnostics = buffer
|
||||
.get_diagnostics(server_id)
|
||||
.into_iter()
|
||||
.flat_map(|diag| {
|
||||
.get_diagnostics(Some(server_id))
|
||||
.map(|diag| {
|
||||
diag.iter()
|
||||
.filter(|v| merge(buffer, &v.diagnostic, cx))
|
||||
.map(|v| {
|
||||
|
@ -7601,8 +7600,9 @@ impl LspStore {
|
|||
diagnostic: v.diagnostic.clone(),
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
.unwrap_or_default();
|
||||
|
||||
self.as_local_mut()
|
||||
.context("cannot merge diagnostics on a remote LspStore")?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue