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);
}
/// Retrieve the diagnostics entries for the given language server, or all
/// diagnostics if `server_id` is `None`.
pub fn get_diagnostics(
pub fn buffer_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
for_server: Option<LanguageServerId>,
) -> Vec<&DiagnosticEntry<Anchor>> {
match for_server {
Some(server_id) => match self.diagnostics.binary_search_by_key(&server_id, |v| v.0) {
Ok(idx) => self.diagnostics[idx].1.iter().collect(),
Err(_) => Vec::new(),
},
None => self
.diagnostics
.iter()
.flat_map(|(_, diags)| (*diags).iter())
.collect::<Vec<_>>();
Some(diag)
.flat_map(|(_, diagnostic_set)| diagnostic_set.iter())
.collect(),
}
}

View file

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

View file

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