From 0811d48a7a5d2ddce4d9dea4a478e78cbef3dfde Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 30 Sep 2025 13:41:49 +0200 Subject: [PATCH] diagnostics: Reduce cloning of `DiagnosticEntry` (#39193) Release Notes: - N/A *or* Added/Fixed/Improved ... --- .../src/diagnostics_command.rs | 4 +- crates/diagnostics/src/buffer_diagnostics.rs | 13 ++- crates/diagnostics/src/diagnostic_renderer.rs | 22 ++--- crates/diagnostics/src/diagnostics.rs | 17 +++- crates/diagnostics/src/items.rs | 14 +-- crates/diagnostics/src/toolbar_controls.rs | 25 +++-- crates/editor/src/editor.rs | 18 ++-- crates/editor/src/hover_popover.rs | 2 +- crates/language/src/buffer.rs | 20 ++-- crates/language/src/diagnostic_set.rs | 96 ++++++++++++++++--- crates/language/src/language.rs | 2 +- crates/multi_buffer/src/multi_buffer.rs | 16 ++-- crates/project/src/project_tests.rs | 15 +-- crates/workspace/src/status_bar.rs | 1 + 14 files changed, 172 insertions(+), 93 deletions(-) diff --git a/crates/assistant_slash_commands/src/diagnostics_command.rs b/crates/assistant_slash_commands/src/diagnostics_command.rs index 77048b1108577689ade4a5e149e54e9784ba0d33..3a9c33061575d385652b685dcca70ee87c6cac35 100644 --- a/crates/assistant_slash_commands/src/diagnostics_command.rs +++ b/crates/assistant_slash_commands/src/diagnostics_command.rs @@ -6,7 +6,7 @@ use assistant_slash_command::{ use fuzzy::{PathMatch, StringMatchCandidate}; use gpui::{App, Entity, Task, WeakEntity}; use language::{ - Anchor, BufferSnapshot, DiagnosticEntry, DiagnosticSeverity, LspAdapterDelegate, + Anchor, BufferSnapshot, DiagnosticEntryRef, DiagnosticSeverity, LspAdapterDelegate, OffsetRangeExt, ToOffset, }; use project::{DiagnosticSummary, PathMatchCandidateSet, Project}; @@ -367,7 +367,7 @@ pub fn collect_buffer_diagnostics( fn collect_diagnostic( output: &mut SlashCommandOutput, - entry: &DiagnosticEntry, + entry: &DiagnosticEntryRef<'_, Anchor>, snapshot: &BufferSnapshot, include_warnings: bool, ) { diff --git a/crates/diagnostics/src/buffer_diagnostics.rs b/crates/diagnostics/src/buffer_diagnostics.rs index 0bdc5c4eb72a35b0a55598e059d28a91ad1cc834..cb3e6eaa7e6b71f8a4105d26444acb795f92559f 100644 --- a/crates/diagnostics/src/buffer_diagnostics.rs +++ b/crates/diagnostics/src/buffer_diagnostics.rs @@ -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>) { - 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>, + diagnostics: &Vec>, snapshot: &BufferSnapshot, ) -> bool { if self.diagnostics.len() != diagnostics.len() { diff --git a/crates/diagnostics/src/diagnostic_renderer.rs b/crates/diagnostics/src/diagnostic_renderer.rs index e22065afa5587e25e35e5c65ffec2e18860b6788..4ce8c03685cd3b15a187fb6f35ff4a9ea2c4c49d 100644 --- a/crates/diagnostics/src/diagnostic_renderer.rs +++ b/crates/diagnostics/src/diagnostic_renderer.rs @@ -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>, + diagnostic_group: Vec>, buffer_id: BufferId, diagnostics_editor: Option>, 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>, + diagnostic_group: Vec>, buffer_id: BufferId, snapshot: EditorSnapshot, editor: WeakEntity, @@ -152,19 +152,15 @@ impl editor::DiagnosticRenderer for DiagnosticRenderer { fn render_hover( &self, - diagnostic_group: Vec>, + diagnostic_group: Vec>, range: Range, buffer_id: BufferId, cx: &mut App, ) -> Option> { 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, 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.; diff --git a/crates/diagnostics/src/diagnostics.rs b/crates/diagnostics/src/diagnostics.rs index ef4d6ec4395189971da710fd5378f65b19199a16..500a5320195a230686488969d6db153f7f043f31 100644 --- a/crates/diagnostics/src/diagnostics.rs +++ b/crates/diagnostics/src/diagnostics.rs @@ -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>, - new: &Vec>, + existing: &[DiagnosticEntry], + 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, }) diff --git a/crates/diagnostics/src/items.rs b/crates/diagnostics/src/items.rs index 11ee4ece96d0c4646714d808037e7a2789bcdf85..afbef4427ffe0c7f5712a94e7c1bc01fbcbf5f54 100644 --- a/crates/diagnostics/src/items.rs +++ b/crates/diagnostics/src/items.rs @@ -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>, workspace: WeakEntity, current_diagnostic: Option, + active_editor: Option>, _observe_active_editor: Option, + 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() diff --git a/crates/diagnostics/src/toolbar_controls.rs b/crates/diagnostics/src/toolbar_controls.rs index ac7bfb0f692d820f6671b0cbb03849bddab58903..b55fa5783dc96965a7d1ce7f52c5e4336b674ed2 100644 --- a/crates/diagnostics/src/toolbar_controls.rs +++ b/crates/diagnostics/src/toolbar_controls.rs @@ -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) + } })), ) } diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index c724459c98a881bb2d32e245585d05286f8f4531..ebea090f80429c80ddead614850648ef1d0867b8 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -122,7 +122,7 @@ use itertools::{Either, Itertools}; use language::{ AutoindentMode, BlockCommentConfig, BracketMatch, BracketPair, Buffer, BufferRow, BufferSnapshot, Capability, CharClassifier, CharKind, CharScopeContext, CodeLabel, CursorShape, - DiagnosticEntry, DiffOptions, EditPredictionsMode, EditPreview, HighlightedText, IndentKind, + DiagnosticEntryRef, DiffOptions, EditPredictionsMode, EditPreview, HighlightedText, IndentKind, IndentSize, Language, OffsetRangeExt, Point, Runnable, RunnableRange, Selection, SelectionGoal, TextObject, TransactionId, TreeSitterOptions, WordsQuery, language_settings::{ @@ -404,7 +404,7 @@ pub fn set_blame_renderer(renderer: impl BlameRenderer + 'static, cx: &mut App) pub trait DiagnosticRenderer { fn render_group( &self, - diagnostic_group: Vec>, + diagnostic_group: Vec>, buffer_id: BufferId, snapshot: EditorSnapshot, editor: WeakEntity, @@ -413,7 +413,7 @@ pub trait DiagnosticRenderer { fn render_hover( &self, - diagnostic_group: Vec>, + diagnostic_group: Vec>, range: Range, buffer_id: BufferId, cx: &mut App, @@ -15970,11 +15970,11 @@ impl Editor { active_group_id = Some(active_group.group_id); } - fn filtered( + fn filtered<'a>( snapshot: EditorSnapshot, severity: GoToDiagnosticSeverityFilter, - diagnostics: impl Iterator>, - ) -> impl Iterator> { + diagnostics: impl Iterator>, + ) -> impl Iterator> { diagnostics .filter(move |entry| severity.matches(entry.diagnostic.severity)) .filter(|entry| entry.range.start != entry.range.end) @@ -15998,7 +15998,7 @@ impl Editor { .filter(|entry| entry.range.start >= selection.start), ); - let mut found: Option> = None; + let mut found: Option> = None; if direction == Direction::Prev { 'outer: for prev_diagnostics in [before.collect::>(), after.collect::>()] { @@ -17521,7 +17521,7 @@ impl Editor { fn activate_diagnostics( &mut self, buffer_id: BufferId, - diagnostic: DiagnosticEntry, + diagnostic: DiagnosticEntryRef<'_, usize>, window: &mut Window, cx: &mut Context, ) { @@ -17710,7 +17710,7 @@ impl Editor { .map(|(line, _)| line) .map(SharedString::new) .unwrap_or_else(|| { - SharedString::from(diagnostic_entry.diagnostic.message) + SharedString::new(&*diagnostic_entry.diagnostic.message) }); let start_anchor = snapshot.anchor_before(diagnostic_entry.range.start); let (Ok(i) | Err(i)) = inline_diagnostics diff --git a/crates/editor/src/hover_popover.rs b/crates/editor/src/hover_popover.rs index bbc01d725d23ef65e8c2660a8635023be9223ed4..07a9f07cc5573fa0f3695e3247697d62f2bace72 100644 --- a/crates/editor/src/hover_popover.rs +++ b/crates/editor/src/hover_popover.rs @@ -371,7 +371,7 @@ fn show_hover( this.update(cx, |_, cx| cx.observe(&markdown, |_, _, cx| cx.notify()))?; let local_diagnostic = DiagnosticEntry { - diagnostic: local_diagnostic.diagnostic, + diagnostic: local_diagnostic.diagnostic.to_owned(), range: snapshot .buffer_snapshot .anchor_before(local_diagnostic.range.start) diff --git a/crates/language/src/buffer.rs b/crates/language/src/buffer.rs index 2a9c9ca4276204a08855dd6f08ee7a0b2fcf0068..ecb7c9d0460b9821270ba909cf6a76b44f6217a5 100644 --- a/crates/language/src/buffer.rs +++ b/crates/language/src/buffer.rs @@ -1,7 +1,7 @@ use crate::{ DebuggerTextObject, LanguageScope, Outline, OutlineConfig, RunnableCapture, RunnableTag, TextObject, TreeSitterOptions, - diagnostic_set::{DiagnosticEntry, DiagnosticGroup}, + diagnostic_set::{DiagnosticEntry, DiagnosticEntryRef, DiagnosticGroup}, language_settings::{LanguageSettings, language_settings}, outline::OutlineItem, syntax_map::{ @@ -4519,7 +4519,7 @@ impl BufferSnapshot { &'a self, search_range: Range, reversed: bool, - ) -> impl 'a + Iterator> + ) -> impl 'a + Iterator> where T: 'a + Clone + ToOffset, O: 'a + FromAnchor, @@ -4552,11 +4552,13 @@ impl BufferSnapshot { })?; iterators[next_ix] .next() - .map(|DiagnosticEntry { range, diagnostic }| DiagnosticEntry { - diagnostic, - range: FromAnchor::from_anchor(&range.start, self) - ..FromAnchor::from_anchor(&range.end, self), - }) + .map( + |DiagnosticEntryRef { range, diagnostic }| DiagnosticEntryRef { + diagnostic, + range: FromAnchor::from_anchor(&range.start, self) + ..FromAnchor::from_anchor(&range.end, self), + }, + ) }) } @@ -4572,7 +4574,7 @@ impl BufferSnapshot { pub fn diagnostic_groups( &self, language_server_id: Option, - ) -> Vec<(LanguageServerId, DiagnosticGroup)> { + ) -> Vec<(LanguageServerId, DiagnosticGroup<'_, Anchor>)> { let mut groups = Vec::new(); if let Some(language_server_id) = language_server_id { @@ -4603,7 +4605,7 @@ impl BufferSnapshot { pub fn diagnostic_group( &self, group_id: usize, - ) -> impl Iterator> + '_ + ) -> impl Iterator> + use<'_, O> where O: FromAnchor + 'static, { diff --git a/crates/language/src/diagnostic_set.rs b/crates/language/src/diagnostic_set.rs index 40e745cf9037f8f1d74b6cff22d3f38aa1b8cc65..fa3263df48ff773b32332980e7341fa8a453ba4f 100644 --- a/crates/language/src/diagnostic_set.rs +++ b/crates/language/src/diagnostic_set.rs @@ -34,19 +34,66 @@ pub struct DiagnosticEntry { pub diagnostic: Diagnostic, } +/// A single diagnostic in a set. Generic over its range type, because +/// the diagnostics are stored internally as [`Anchor`]s, but can be +/// resolved to different coordinates types like [`usize`] byte offsets or +/// [`Point`](gpui::Point)s. +#[derive(Clone, Debug, PartialEq, Eq, Serialize)] +pub struct DiagnosticEntryRef<'a, T> { + /// The range of the buffer where the diagnostic applies. + pub range: Range, + /// The information about the diagnostic. + pub diagnostic: &'a Diagnostic, +} + +impl PartialEq> for DiagnosticEntryRef<'_, T> { + fn eq(&self, other: &DiagnosticEntry) -> bool { + self.range == other.range && *self.diagnostic == other.diagnostic + } +} + +impl PartialEq> for DiagnosticEntry { + fn eq(&self, other: &DiagnosticEntryRef<'_, T>) -> bool { + self.range == other.range && self.diagnostic == *other.diagnostic + } +} + +impl DiagnosticEntryRef<'_, T> { + pub fn to_owned(&self) -> DiagnosticEntry { + DiagnosticEntry { + range: self.range.clone(), + diagnostic: self.diagnostic.clone(), + } + } +} + +impl<'a> DiagnosticEntryRef<'a, Anchor> { + /// Converts the [DiagnosticEntry] to a different buffer coordinate type. + pub fn resolve( + &self, + buffer: &text::BufferSnapshot, + ) -> DiagnosticEntryRef<'a, O> { + DiagnosticEntryRef { + range: O::from_anchor(&self.range.start, buffer) + ..O::from_anchor(&self.range.end, buffer), + diagnostic: &self.diagnostic, + } + } +} + /// A group of related diagnostics, ordered by their start position /// in the buffer. #[derive(Debug, Serialize)] -pub struct DiagnosticGroup { +pub struct DiagnosticGroup<'a, T> { /// The diagnostics. - pub entries: Vec>, + pub entries: Vec>, /// The index into `entries` where the primary diagnostic is stored. pub primary_ix: usize, } -impl DiagnosticGroup { +impl<'a> DiagnosticGroup<'a, Anchor> { /// Converts the entries in this [`DiagnosticGroup`] to a different buffer coordinate type. - pub fn resolve(&self, buffer: &text::BufferSnapshot) -> DiagnosticGroup { + pub fn resolve(&self, buffer: &text::BufferSnapshot) -> DiagnosticGroup<'a, O> { DiagnosticGroup { entries: self .entries @@ -84,6 +131,23 @@ impl DiagnosticEntry { }) } } +impl DiagnosticEntryRef<'_, PointUtf16> { + /// Returns a raw LSP diagnostic used to provide diagnostic context to LSP + /// codeAction request + pub fn to_lsp_diagnostic_stub(&self) -> Result { + let range = range_to_lsp(self.range.clone())?; + + Ok(lsp::Diagnostic { + range, + code: self.diagnostic.code.clone(), + severity: Some(self.diagnostic.severity), + source: self.diagnostic.source.clone(), + message: self.diagnostic.message.clone(), + data: self.diagnostic.data.clone(), + ..Default::default() + }) + } +} impl DiagnosticSet { /// Constructs a [DiagnosticSet] from a sequence of entries, ordered by @@ -138,7 +202,7 @@ impl DiagnosticSet { buffer: &'a text::BufferSnapshot, inclusive: bool, reversed: bool, - ) -> impl 'a + Iterator> + ) -> impl 'a + Iterator> where T: 'a + ToOffset, O: FromAnchor, @@ -179,10 +243,10 @@ impl DiagnosticSet { } /// Adds all of this set's diagnostic groups to the given output vector. - pub fn groups( - &self, + pub fn groups<'a>( + &'a self, language_server_id: LanguageServerId, - output: &mut Vec<(LanguageServerId, DiagnosticGroup)>, + output: &mut Vec<(LanguageServerId, DiagnosticGroup<'a, Anchor>)>, buffer: &text::BufferSnapshot, ) { let mut groups = HashMap::default(); @@ -190,7 +254,10 @@ impl DiagnosticSet { groups .entry(entry.diagnostic.group_id) .or_insert(Vec::new()) - .push(entry.clone()); + .push(DiagnosticEntryRef { + range: entry.range.clone(), + diagnostic: &entry.diagnostic, + }); } let start_ix = output.len(); @@ -224,7 +291,7 @@ impl DiagnosticSet { &'a self, group_id: usize, buffer: &'a text::BufferSnapshot, - ) -> impl 'a + Iterator> { + ) -> impl 'a + Iterator> { self.iter() .filter(move |entry| entry.diagnostic.group_id == group_id) .map(|entry| entry.resolve(buffer)) @@ -247,11 +314,14 @@ impl sum_tree::Item for DiagnosticEntry { impl DiagnosticEntry { /// Converts the [DiagnosticEntry] to a different buffer coordinate type. - pub fn resolve(&self, buffer: &text::BufferSnapshot) -> DiagnosticEntry { - DiagnosticEntry { + pub fn resolve<'a, O: FromAnchor>( + &'a self, + buffer: &text::BufferSnapshot, + ) -> DiagnosticEntryRef<'a, O> { + DiagnosticEntryRef { range: O::from_anchor(&self.range.start, buffer) ..O::from_anchor(&self.range.end, buffer), - diagnostic: self.diagnostic.clone(), + diagnostic: &self.diagnostic, } } } diff --git a/crates/language/src/language.rs b/crates/language/src/language.rs index 1d172576ec454fd20449f28b6fbddeb67be783a2..5ba5ffea9b1620c6b66fba7dfbe20cc8fe00ff1b 100644 --- a/crates/language/src/language.rs +++ b/crates/language/src/language.rs @@ -75,7 +75,7 @@ use util::serde::default_true; pub use buffer::Operation; pub use buffer::*; -pub use diagnostic_set::{DiagnosticEntry, DiagnosticGroup}; +pub use diagnostic_set::{DiagnosticEntry, DiagnosticEntryRef, DiagnosticGroup}; pub use language_registry::{ AvailableLanguage, BinaryStatus, LanguageNotFound, LanguageQueries, LanguageRegistry, QUERY_FILENAME_PREFIXES, diff --git a/crates/multi_buffer/src/multi_buffer.rs b/crates/multi_buffer/src/multi_buffer.rs index 01bf1ee36990981b8de6f771855e916412163cf8..8834dd9f70853ee922d6d2e5f24ce51f6f2ac079 100644 --- a/crates/multi_buffer/src/multi_buffer.rs +++ b/crates/multi_buffer/src/multi_buffer.rs @@ -17,7 +17,7 @@ use gpui::{App, AppContext as _, Context, Entity, EntityId, EventEmitter, Task}; use itertools::Itertools; use language::{ AutoindentMode, Buffer, BufferChunks, BufferRow, BufferSnapshot, Capability, CharClassifier, - CharKind, CharScopeContext, Chunk, CursorShape, DiagnosticEntry, DiskState, File, + CharKind, CharScopeContext, Chunk, CursorShape, DiagnosticEntryRef, DiskState, File, IndentGuideSettings, IndentSize, Language, LanguageScope, OffsetRangeExt, OffsetUtf16, Outline, OutlineItem, Point, PointUtf16, Selection, TextDimension, TextObject, ToOffset as _, ToPoint as _, TransactionId, TreeSitterOptions, Unclipped, @@ -6007,7 +6007,7 @@ impl MultiBufferSnapshot { &self, buffer_id: BufferId, group_id: usize, - ) -> impl Iterator> + '_ { + ) -> impl Iterator> + '_ { self.lift_buffer_metadata(Point::zero()..self.max_point(), move |buffer, range| { if buffer.remote_id() != buffer_id { return None; @@ -6016,16 +6016,16 @@ impl MultiBufferSnapshot { buffer .diagnostics_in_range(range, false) .filter(move |diagnostic| diagnostic.diagnostic.group_id == group_id) - .map(move |DiagnosticEntry { diagnostic, range }| (range, diagnostic)), + .map(move |DiagnosticEntryRef { diagnostic, range }| (range, diagnostic)), ) }) - .map(|(range, diagnostic, _)| DiagnosticEntry { diagnostic, range }) + .map(|(range, diagnostic, _)| DiagnosticEntryRef { diagnostic, range }) } pub fn diagnostics_in_range<'a, T>( &'a self, range: Range, - ) -> impl Iterator> + 'a + ) -> impl Iterator> + 'a where T: 'a + text::ToOffset @@ -6042,13 +6042,13 @@ impl MultiBufferSnapshot { .map(|entry| (entry.range, entry.diagnostic)), ) }) - .map(|(range, diagnostic, _)| DiagnosticEntry { diagnostic, range }) + .map(|(range, diagnostic, _)| DiagnosticEntryRef { diagnostic, range }) } pub fn diagnostics_with_buffer_ids_in_range<'a, T>( &'a self, range: Range, - ) -> impl Iterator)> + 'a + ) -> impl Iterator)> + 'a where T: 'a + text::ToOffset @@ -6065,7 +6065,7 @@ impl MultiBufferSnapshot { .map(|entry| (entry.range, entry.diagnostic)), ) }) - .map(|(range, diagnostic, b)| (b.buffer_id, DiagnosticEntry { diagnostic, range })) + .map(|(range, diagnostic, b)| (b.buffer_id, DiagnosticEntryRef { diagnostic, range })) } pub fn syntax_ancestor( diff --git a/crates/project/src/project_tests.rs b/crates/project/src/project_tests.rs index 4a1f89b619d2fa8644971a7237995f2368125792..226332d739eedd452fccc4e2714924bf7aec76b3 100644 --- a/crates/project/src/project_tests.rs +++ b/crates/project/src/project_tests.rs @@ -20,9 +20,10 @@ use git2::RepositoryInitOptions; use gpui::{App, BackgroundExecutor, SemanticVersion, UpdateGlobal}; use itertools::Itertools; use language::{ - Diagnostic, DiagnosticEntry, DiagnosticSet, DiagnosticSourceKind, DiskState, FakeLspAdapter, - LanguageConfig, LanguageMatcher, LanguageName, LineEnding, ManifestName, ManifestProvider, - ManifestQuery, OffsetRangeExt, Point, ToPoint, ToolchainList, ToolchainLister, + Diagnostic, DiagnosticEntry, DiagnosticEntryRef, DiagnosticSet, DiagnosticSourceKind, + DiskState, FakeLspAdapter, LanguageConfig, LanguageMatcher, LanguageName, LineEnding, + ManifestName, ManifestProvider, ManifestQuery, OffsetRangeExt, Point, ToPoint, ToolchainList, + ToolchainLister, language_settings::{LanguageSettingsContent, language_settings}, tree_sitter_rust, tree_sitter_typescript, }; @@ -1847,9 +1848,9 @@ async fn test_disk_based_diagnostics_progress(cx: &mut gpui::TestAppContext) { .collect::>(); assert_eq!( diagnostics, - &[DiagnosticEntry { + &[DiagnosticEntryRef { range: Point::new(0, 9)..Point::new(0, 10), - diagnostic: Diagnostic { + diagnostic: &Diagnostic { severity: lsp::DiagnosticSeverity::ERROR, message: "undefined variable 'A'".to_string(), group_id: 0, @@ -2024,7 +2025,7 @@ async fn test_restarting_server_with_diagnostics_published(cx: &mut gpui::TestAp buffer .snapshot() .diagnostics_in_range::<_, usize>(0..1, false) - .map(|entry| entry.diagnostic.message) + .map(|entry| entry.diagnostic.message.clone()) .collect::>(), ["the message".to_string()] ); @@ -2050,7 +2051,7 @@ async fn test_restarting_server_with_diagnostics_published(cx: &mut gpui::TestAp buffer .snapshot() .diagnostics_in_range::<_, usize>(0..1, false) - .map(|entry| entry.diagnostic.message) + .map(|entry| entry.diagnostic.message.clone()) .collect::>(), Vec::::new(), ); diff --git a/crates/workspace/src/status_bar.rs b/crates/workspace/src/status_bar.rs index 187e720d9c01fb471d91781435912b6502e2a0a9..9087cbba42b054c1b247bdf3d9402688de4b7add 100644 --- a/crates/workspace/src/status_bar.rs +++ b/crates/workspace/src/status_bar.rs @@ -9,6 +9,7 @@ use ui::{h_flex, prelude::*}; use util::ResultExt; pub trait StatusItemView: Render { + /// Event callback that is triggered when the active pane item changes. fn set_active_pane_item( &mut self, active_pane_item: Option<&dyn crate::ItemHandle>,