Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Exclude more ignored/worktree-less/project-less buffers from inlay hint requests
Kirill Bulatoveee63835fb8b
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 2558aec1213..ab5d7e00af6 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -3423,7 +3423,7 @@ impl Editor {to_insert,}) = self.inlay_hint_cache.spawn_hint_refresh(reason_description,- self.excerpt_visible_offsets(required_languages.as_ref(), cx),+ self.excerpts_for_inlay_hints_query(required_languages.as_ref(), cx),invalidate_cache,cx,) {@@ -3442,11 +3442,15 @@ impl Editor {.collect()}- pub fn excerpt_visible_offsets(+ pub fn excerpts_for_inlay_hints_query(&self,restrict_to_languages: Option<&HashSet<Arc<Language>>>,cx: &mut ViewContext<'_, '_, Editor>,) -> HashMap<ExcerptId, (ModelHandle<Buffer>, Global, Range<usize>)> {+ let Some(project) = self.project.as_ref() else {+ return HashMap::default();+ };+ let project = project.read(cx);let multi_buffer = self.buffer().read(cx);let multi_buffer_snapshot = multi_buffer.snapshot(cx);let multi_buffer_visible_start = self@@ -3466,6 +3470,14 @@ impl Editor {.filter(|(_, excerpt_visible_range, _)| !excerpt_visible_range.is_empty()).filter_map(|(buffer_handle, excerpt_visible_range, excerpt_id)| {let buffer = buffer_handle.read(cx);+ let buffer_file = project::worktree::File::from_dyn(buffer.file())?;+ let buffer_worktree = project.worktree_for_id(buffer_file.worktree_id(cx), cx)?;+ let worktree_entry = buffer_worktree+ .read(cx)+ .entry_for_id(buffer_file.project_entry_id(cx)?)?;+ if worktree_entry.is_ignored {+ return None;+ }let language = buffer.language()?;if let Some(restrict_to_languages) = restrict_to_languages {if !restrict_to_languages.contains(language) {diff --git a/crates/editor/src/inlay_hint_cache.rs b/crates/editor/src/inlay_hint_cache.rsindex 6b2712e7bf9..47d8a4cf1fb 100644--- a/crates/editor/src/inlay_hint_cache.rs+++ b/crates/editor/src/inlay_hint_cache.rs@@ -861,7 +861,7 @@ async fn fetch_and_update_hints(let inlay_hints_fetch_task = editor.update(&mut cx, |editor, cx| {if got_throttled {- let query_not_around_visible_range = match editor.excerpt_visible_offsets(None, cx).remove(&query.excerpt_id) {+ let query_not_around_visible_range = match editor.excerpts_for_inlay_hints_query(None, cx).remove(&query.excerpt_id) {Some((_, _, current_visible_range)) => {let visible_offset_length = current_visible_range.len();let double_visible_range = current_visible_range@@ -2237,7 +2237,9 @@ pub mod tests {editor: &ViewHandle<Editor>,cx: &mut gpui::TestAppContext,) -> Range<Point> {- let ranges = editor.update(cx, |editor, cx| editor.excerpt_visible_offsets(None, cx));+ let ranges = editor.update(cx, |editor, cx| {+ editor.excerpts_for_inlay_hints_query(None, cx)+ });assert_eq!(ranges.len(),1,diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rsindex fa7bfd77cc0..79375165985 100644--- a/crates/editor2/src/editor.rs+++ b/crates/editor2/src/editor.rs@@ -3444,7 +3444,7 @@ impl Editor {to_insert,}) = self.inlay_hint_cache.spawn_hint_refresh(reason_description,- self.excerpt_visible_offsets(required_languages.as_ref(), cx),+ self.excerpts_for_inlay_hints_query(required_languages.as_ref(), cx),invalidate_cache,cx,) {@@ -3463,11 +3463,15 @@ impl Editor {.collect()}- pub fn excerpt_visible_offsets(+ pub fn excerpts_for_inlay_hints_query(&self,restrict_to_languages: Option<&HashSet<Arc<Language>>>,cx: &mut ViewContext<Editor>,) -> HashMap<ExcerptId, (Model<Buffer>, clock::Global, Range<usize>)> {+ let Some(project) = self.project.as_ref() else {+ return HashMap::default();+ };+ let project = project.read(cx);let multi_buffer = self.buffer().read(cx);let multi_buffer_snapshot = multi_buffer.snapshot(cx);let multi_buffer_visible_start = self@@ -3487,6 +3491,15 @@ impl Editor {.filter(|(_, excerpt_visible_range, _)| !excerpt_visible_range.is_empty()).filter_map(|(buffer_handle, excerpt_visible_range, excerpt_id)| {let buffer = buffer_handle.read(cx);+ let buffer_file = project::worktree::File::from_dyn(buffer.file())?;+ let buffer_worktree = project.worktree_for_id(buffer_file.worktree_id(cx), cx)?;+ let worktree_entry = buffer_worktree+ .read(cx)+ .entry_for_id(buffer_file.project_entry_id(cx)?)?;+ if worktree_entry.is_ignored {+ return None;+ }+let language = buffer.language()?;if let Some(restrict_to_languages) = restrict_to_languages {if !restrict_to_languages.contains(language) {diff --git a/crates/editor2/src/inlay_hint_cache.rs b/crates/editor2/src/inlay_hint_cache.rsindex eba49ccbf74..1610c4826e7 100644--- a/crates/editor2/src/inlay_hint_cache.rs+++ b/crates/editor2/src/inlay_hint_cache.rs@@ -861,7 +861,7 @@ async fn fetch_and_update_hints(let inlay_hints_fetch_task = editor.update(&mut cx, |editor, cx| {if got_throttled {- let query_not_around_visible_range = match editor.excerpt_visible_offsets(None, cx).remove(&query.excerpt_id) {+ let query_not_around_visible_range = match editor.excerpts_for_inlay_hints_query(None, cx).remove(&query.excerpt_id) {Some((_, _, current_visible_range)) => {let visible_offset_length = current_visible_range.len();let double_visible_range = current_visible_range@@ -2201,7 +2201,9 @@ pub mod tests {cx: &mut gpui::TestAppContext,) -> Range<Point> {let ranges = editor- .update(cx, |editor, cx| editor.excerpt_visible_offsets(None, cx))+ .update(cx, |editor, cx| {+ editor.excerpts_for_inlay_hints_query(None, cx)+ }).unwrap();assert_eq!(ranges.len(),