Fix the sloppy style

This commit is contained in:
Kirill Bulatov 2025-08-25 22:59:51 +03:00
parent 20169c1a97
commit 5198272ad8
3 changed files with 63 additions and 78 deletions

View file

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

View file

@ -7588,21 +7588,18 @@ 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(Some(server_id)) .buffer_diagnostics(Some(server_id))
.map(|diag| { .iter()
diag.iter() .filter(|v| merge(buffer, &v.diagnostic, cx))
.filter(|v| merge(buffer, &v.diagnostic, cx)) .map(|v| {
.map(|v| { let start = Unclipped(v.range.start.to_point_utf16(&snapshot));
let start = Unclipped(v.range.start.to_point_utf16(&snapshot)); let end = Unclipped(v.range.end.to_point_utf16(&snapshot));
let end = Unclipped(v.range.end.to_point_utf16(&snapshot)); DiagnosticEntry {
DiagnosticEntry { range: start..end,
range: start..end, diagnostic: v.diagnostic.clone(),
diagnostic: v.diagnostic.clone(), }
}
})
.collect::<Vec<_>>()
}) })
.unwrap_or_default(); .collect::<Vec<_>>();
self.as_local_mut() self.as_local_mut()
.context("cannot merge diagnostics on a remote LspStore")? .context("cannot merge diagnostics on a remote LspStore")?

View file

@ -246,54 +246,48 @@ impl TabMatch {
window: &Window, window: &Window,
cx: &App, cx: &App,
) -> Option<DecoratedIcon> { ) -> Option<DecoratedIcon> {
self.item.tab_icon(window, cx).map(|icon| { let icon = self.item.tab_icon(window, cx)?;
let show_diagnostics = ItemSettings::get_global(cx).show_diagnostics; let item_settings = ItemSettings::get_global(cx);
let git_status_color = { let show_diagnostics = item_settings.show_diagnostics;
ItemSettings::get_global(cx) let git_status_color = item_settings
.git_status .git_status
.then(|| { .then(|| {
self.item let path = self.item.project_path(cx)?;
.project_path(cx) let project = project.read(cx);
.as_ref() let entry = project.entry_for_path(&path, cx)?;
.and_then(|path| { let git_status = project
let project = project.read(cx); .project_path_git_status(&path, cx)
let entry = project.entry_for_path(path, cx)?; .map(|status| status.summary())
let git_status = project .unwrap_or_default();
.project_path_git_status(path, cx) Some(entry_git_aware_label_color(
.map(|status| status.summary()) git_status,
.unwrap_or_default(); entry.is_ignored,
Some((entry, git_status)) selected,
}) ))
.map(|(entry, git_status)| { })
entry_git_aware_label_color(git_status, entry.is_ignored, selected) .flatten();
}) let colored_icon = icon.color(git_status_color.unwrap_or_default());
})
.flatten()
};
let colored_icon = icon.color(git_status_color.unwrap_or_default());
let item_diagnostics = { let most_sever_diagostic_level = if show_diagnostics == ShowDiagnostics::Off {
if show_diagnostics == ShowDiagnostics::Off { None
None } else {
} else { let buffer_store = project.read(cx).buffer_store().read(cx);
let buffer_store = project.read(cx).buffer_store().read(cx); let buffer = self
let buffer = self .item
.item .project_path(cx)
.project_path(cx) .and_then(|path| buffer_store.get_by_path(&path))
.and_then(|path| buffer_store.get_by_path(&path)) .map(|buffer| buffer.read(cx));
.map(|buffer| buffer.read(cx)); buffer.and_then(|buffer| {
buffer.and_then(|buffer| { buffer
buffer .buffer_diagnostics(None)
.get_diagnostics(None) .iter()
.unwrap_or_default() .map(|diagnostic_entry| diagnostic_entry.diagnostic.severity)
.iter() .min()
.map(|diag| diag.diagnostic.severity) })
.min() };
})
}
};
let decorations = entry_diagnostic_aware_icon_decoration_and_color(item_diagnostics) let decorations =
entry_diagnostic_aware_icon_decoration_and_color(most_sever_diagostic_level)
.filter(|(d, _)| { .filter(|(d, _)| {
*d != IconDecorationKind::Triangle *d != IconDecorationKind::Triangle
|| show_diagnostics != ShowDiagnostics::Errors || show_diagnostics != ShowDiagnostics::Errors
@ -311,9 +305,7 @@ impl TabMatch {
y: px(-2.), y: px(-2.),
}) })
}); });
Some(DecoratedIcon::new(colored_icon, decorations))
DecoratedIcon::new(colored_icon, decorations)
})
} }
} }