diagnostics: Reduce cloning of DiagnosticEntry (#39193)
Release Notes: - N/A *or* Added/Fixed/Improved ...
This commit is contained in:
@@ -15,7 +15,7 @@ use gpui::{
|
||||
InteractiveElement, IntoElement, ParentElement, Render, SharedString, Styled, Subscription,
|
||||
Task, WeakEntity, Window, actions, div,
|
||||
};
|
||||
use language::{Buffer, DiagnosticEntry, Point};
|
||||
use language::{Buffer, DiagnosticEntry, DiagnosticEntryRef, Point};
|
||||
use project::{
|
||||
DiagnosticSummary, Event, Project, ProjectItem, ProjectPath,
|
||||
project_settings::{DiagnosticSeverity, ProjectSettings},
|
||||
@@ -350,7 +350,7 @@ impl BufferDiagnosticsEditor {
|
||||
grouped
|
||||
.entry(entry.diagnostic.group_id)
|
||||
.or_default()
|
||||
.push(DiagnosticEntry {
|
||||
.push(DiagnosticEntryRef {
|
||||
range: entry.range.to_point(&buffer_snapshot),
|
||||
diagnostic: entry.diagnostic,
|
||||
})
|
||||
@@ -560,13 +560,16 @@ impl BufferDiagnosticsEditor {
|
||||
})
|
||||
}
|
||||
|
||||
fn set_diagnostics(&mut self, diagnostics: &Vec<DiagnosticEntry<Anchor>>) {
|
||||
self.diagnostics = diagnostics.clone();
|
||||
fn set_diagnostics(&mut self, diagnostics: &[DiagnosticEntryRef<'_, Anchor>]) {
|
||||
self.diagnostics = diagnostics
|
||||
.iter()
|
||||
.map(DiagnosticEntryRef::to_owned)
|
||||
.collect();
|
||||
}
|
||||
|
||||
fn diagnostics_are_unchanged(
|
||||
&self,
|
||||
diagnostics: &Vec<DiagnosticEntry<Anchor>>,
|
||||
diagnostics: &Vec<DiagnosticEntryRef<'_, Anchor>>,
|
||||
snapshot: &BufferSnapshot,
|
||||
) -> bool {
|
||||
if self.diagnostics.len() != diagnostics.len() {
|
||||
|
||||
@@ -6,7 +6,7 @@ use editor::{
|
||||
hover_popover::diagnostics_markdown_style,
|
||||
};
|
||||
use gpui::{AppContext, Entity, Focusable, WeakEntity};
|
||||
use language::{BufferId, Diagnostic, DiagnosticEntry};
|
||||
use language::{BufferId, Diagnostic, DiagnosticEntryRef};
|
||||
use lsp::DiagnosticSeverity;
|
||||
use markdown::{Markdown, MarkdownElement};
|
||||
use settings::Settings;
|
||||
@@ -24,7 +24,7 @@ pub struct DiagnosticRenderer;
|
||||
|
||||
impl DiagnosticRenderer {
|
||||
pub fn diagnostic_blocks_for_group(
|
||||
diagnostic_group: Vec<DiagnosticEntry<Point>>,
|
||||
diagnostic_group: Vec<DiagnosticEntryRef<'_, Point>>,
|
||||
buffer_id: BufferId,
|
||||
diagnostics_editor: Option<Arc<dyn DiagnosticsToolbarEditor>>,
|
||||
cx: &mut App,
|
||||
@@ -35,7 +35,7 @@ impl DiagnosticRenderer {
|
||||
else {
|
||||
return Vec::new();
|
||||
};
|
||||
let primary = diagnostic_group[primary_ix].clone();
|
||||
let primary = &diagnostic_group[primary_ix];
|
||||
let group_id = primary.diagnostic.group_id;
|
||||
let mut results = vec![];
|
||||
for entry in diagnostic_group.iter() {
|
||||
@@ -123,7 +123,7 @@ impl DiagnosticRenderer {
|
||||
impl editor::DiagnosticRenderer for DiagnosticRenderer {
|
||||
fn render_group(
|
||||
&self,
|
||||
diagnostic_group: Vec<DiagnosticEntry<Point>>,
|
||||
diagnostic_group: Vec<DiagnosticEntryRef<'_, Point>>,
|
||||
buffer_id: BufferId,
|
||||
snapshot: EditorSnapshot,
|
||||
editor: WeakEntity<Editor>,
|
||||
@@ -152,19 +152,15 @@ impl editor::DiagnosticRenderer for DiagnosticRenderer {
|
||||
|
||||
fn render_hover(
|
||||
&self,
|
||||
diagnostic_group: Vec<DiagnosticEntry<Point>>,
|
||||
diagnostic_group: Vec<DiagnosticEntryRef<'_, Point>>,
|
||||
range: Range<Point>,
|
||||
buffer_id: BufferId,
|
||||
cx: &mut App,
|
||||
) -> Option<Entity<Markdown>> {
|
||||
let blocks = Self::diagnostic_blocks_for_group(diagnostic_group, buffer_id, None, cx);
|
||||
blocks.into_iter().find_map(|block| {
|
||||
if block.initial_range == range {
|
||||
Some(block.markdown)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
blocks
|
||||
.into_iter()
|
||||
.find_map(|block| (block.initial_range == range).then(|| block.markdown))
|
||||
}
|
||||
|
||||
fn open_link(
|
||||
@@ -189,7 +185,7 @@ pub(crate) struct DiagnosticBlock {
|
||||
impl DiagnosticBlock {
|
||||
pub fn render_block(&self, editor: WeakEntity<Editor>, bcx: &BlockContext) -> AnyElement {
|
||||
let cx = &bcx.app;
|
||||
let status_colors = bcx.app.theme().status();
|
||||
let status_colors = cx.theme().status();
|
||||
|
||||
let max_width = bcx.em_width * 120.;
|
||||
|
||||
|
||||
@@ -22,7 +22,8 @@ use gpui::{
|
||||
Subscription, Task, WeakEntity, Window, actions, div,
|
||||
};
|
||||
use language::{
|
||||
Bias, Buffer, BufferRow, BufferSnapshot, DiagnosticEntry, Point, ToTreeSitterPoint,
|
||||
Bias, Buffer, BufferRow, BufferSnapshot, DiagnosticEntry, DiagnosticEntryRef, Point,
|
||||
ToTreeSitterPoint,
|
||||
};
|
||||
use project::{
|
||||
DiagnosticSummary, Project, ProjectPath,
|
||||
@@ -412,8 +413,8 @@ impl ProjectDiagnosticsEditor {
|
||||
|
||||
fn diagnostics_are_unchanged(
|
||||
&self,
|
||||
existing: &Vec<DiagnosticEntry<text::Anchor>>,
|
||||
new: &Vec<DiagnosticEntry<text::Anchor>>,
|
||||
existing: &[DiagnosticEntry<text::Anchor>],
|
||||
new: &[DiagnosticEntryRef<'_, text::Anchor>],
|
||||
snapshot: &BufferSnapshot,
|
||||
) -> bool {
|
||||
if existing.len() != new.len() {
|
||||
@@ -457,7 +458,13 @@ impl ProjectDiagnosticsEditor {
|
||||
}) {
|
||||
return true;
|
||||
}
|
||||
this.diagnostics.insert(buffer_id, diagnostics.clone());
|
||||
this.diagnostics.insert(
|
||||
buffer_id,
|
||||
diagnostics
|
||||
.iter()
|
||||
.map(DiagnosticEntryRef::to_owned)
|
||||
.collect(),
|
||||
);
|
||||
false
|
||||
})?;
|
||||
if unchanged {
|
||||
@@ -469,7 +476,7 @@ impl ProjectDiagnosticsEditor {
|
||||
grouped
|
||||
.entry(entry.diagnostic.group_id)
|
||||
.or_default()
|
||||
.push(DiagnosticEntry {
|
||||
.push(DiagnosticEntryRef {
|
||||
range: entry.range.to_point(&buffer_snapshot),
|
||||
diagnostic: entry.diagnostic,
|
||||
})
|
||||
|
||||
@@ -14,12 +14,14 @@ use workspace::{StatusItemView, ToolbarItemEvent, Workspace, item::ItemHandle};
|
||||
|
||||
use crate::{Deploy, IncludeWarnings, ProjectDiagnosticsEditor};
|
||||
|
||||
/// The status bar item that displays diagnostic counts.
|
||||
pub struct DiagnosticIndicator {
|
||||
summary: project::DiagnosticSummary,
|
||||
active_editor: Option<WeakEntity<Editor>>,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
current_diagnostic: Option<Diagnostic>,
|
||||
active_editor: Option<WeakEntity<Editor>>,
|
||||
_observe_active_editor: Option<Subscription>,
|
||||
|
||||
diagnostics_update: Task<()>,
|
||||
diagnostic_summary_update: Task<()>,
|
||||
}
|
||||
@@ -73,10 +75,9 @@ impl Render for DiagnosticIndicator {
|
||||
cx,
|
||||
)
|
||||
})
|
||||
.on_click(cx.listener(|this, _, window, cx| {
|
||||
this.go_to_next_diagnostic(window, cx);
|
||||
}))
|
||||
.into_any_element(),
|
||||
.on_click(
|
||||
cx.listener(|this, _, window, cx| this.go_to_next_diagnostic(window, cx)),
|
||||
),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
@@ -177,7 +178,8 @@ impl DiagnosticIndicator {
|
||||
.filter(|entry| !entry.range.is_empty())
|
||||
.min_by_key(|entry| (entry.diagnostic.severity, entry.range.len()))
|
||||
.map(|entry| entry.diagnostic);
|
||||
if new_diagnostic != self.current_diagnostic {
|
||||
if new_diagnostic != self.current_diagnostic.as_ref() {
|
||||
let new_diagnostic = new_diagnostic.cloned();
|
||||
self.diagnostics_update =
|
||||
cx.spawn_in(window, async move |diagnostics_indicator, cx| {
|
||||
cx.background_executor()
|
||||
|
||||
@@ -75,12 +75,9 @@ impl Render for ToolbarControls {
|
||||
&ToggleDiagnosticsRefresh,
|
||||
))
|
||||
.on_click(cx.listener(move |toolbar_controls, _, _, cx| {
|
||||
match toolbar_controls.editor() {
|
||||
Some(editor) => {
|
||||
editor.stop_updating(cx);
|
||||
cx.notify();
|
||||
}
|
||||
None => {}
|
||||
if let Some(editor) = toolbar_controls.editor() {
|
||||
editor.stop_updating(cx);
|
||||
cx.notify();
|
||||
}
|
||||
})),
|
||||
)
|
||||
@@ -95,11 +92,10 @@ impl Render for ToolbarControls {
|
||||
&ToggleDiagnosticsRefresh,
|
||||
))
|
||||
.on_click(cx.listener({
|
||||
move |toolbar_controls, _, window, cx| match toolbar_controls
|
||||
.editor()
|
||||
{
|
||||
Some(editor) => editor.refresh_diagnostics(window, cx),
|
||||
None => {}
|
||||
move |toolbar_controls, _, window, cx| {
|
||||
if let Some(editor) = toolbar_controls.editor() {
|
||||
editor.refresh_diagnostics(window, cx)
|
||||
}
|
||||
}
|
||||
})),
|
||||
)
|
||||
@@ -110,9 +106,10 @@ impl Render for ToolbarControls {
|
||||
.icon_color(warning_color)
|
||||
.shape(IconButtonShape::Square)
|
||||
.tooltip(Tooltip::text(warning_tooltip))
|
||||
.on_click(cx.listener(|this, _, window, cx| match &this.editor {
|
||||
Some(editor) => editor.toggle_warnings(window, cx),
|
||||
None => {}
|
||||
.on_click(cx.listener(|this, _, window, cx| {
|
||||
if let Some(editor) = &this.editor {
|
||||
editor.toggle_warnings(window, cx)
|
||||
}
|
||||
})),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user