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,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(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));
@ -7600,9 +7599,7 @@ 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")?

View file

@ -246,34 +246,29 @@ 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)
.as_ref()
.and_then(|path| {
let project = project.read(cx); let project = project.read(cx);
let entry = project.entry_for_path(path, cx)?; let entry = project.entry_for_path(&path, cx)?;
let git_status = project let git_status = project
.project_path_git_status(path, cx) .project_path_git_status(&path, cx)
.map(|status| status.summary()) .map(|status| status.summary())
.unwrap_or_default(); .unwrap_or_default();
Some((entry, git_status)) Some(entry_git_aware_label_color(
git_status,
entry.is_ignored,
selected,
))
}) })
.map(|(entry, git_status)| { .flatten();
entry_git_aware_label_color(git_status, entry.is_ignored, selected)
})
})
.flatten()
};
let colored_icon = icon.color(git_status_color.unwrap_or_default()); 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);
@ -284,16 +279,15 @@ impl TabMatch {
.map(|buffer| buffer.read(cx)); .map(|buffer| buffer.read(cx));
buffer.and_then(|buffer| { buffer.and_then(|buffer| {
buffer buffer
.get_diagnostics(None) .buffer_diagnostics(None)
.unwrap_or_default()
.iter() .iter()
.map(|diag| diag.diagnostic.severity) .map(|diagnostic_entry| diagnostic_entry.diagnostic.severity)
.min() .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)
})
} }
} }