Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Find proper applicable chunks for visible ranges (#42422)
Kirill Bulatov58db38722b57
diff --git a/crates/project/src/lsp_store/inlay_hint_cache.rs b/crates/project/src/lsp_store/inlay_hint_cache.rsindex 51189d8fdae..cca9d66e8c3 100644--- a/crates/project/src/lsp_store/inlay_hint_cache.rs+++ b/crates/project/src/lsp_store/inlay_hint_cache.rs@@ -6,6 +6,7 @@ use gpui::{App, Entity, Task};use language::{Buffer, BufferRow, BufferSnapshot};use lsp::LanguageServerId;use text::OffsetRangeExt;+use util::RangeExt as _;use crate::{InlayHint, InlayId};@@ -123,18 +124,17 @@ impl BufferInlayHints {let row_ranges = ranges.iter().map(|range| range.to_point(&self.snapshot))- .map(|point_range| point_range.start.row..=point_range.end.row)+ // Be lenient and yield multiple chunks if they "touch" the exclusive part of the range.+ // This will result in LSP hints [re-]queried for more ranges, but also more hints already visible when scrolling around.+ .map(|point_range| point_range.start.row..point_range.end.row + 1).collect::<Vec<_>>();self.buffer_chunks.iter()- .filter(move |chunk| -> bool {- // Be lenient and yield multiple chunks if they "touch" the exclusive part of the range.- // This will result in LSP hints [re-]queried for more ranges, but also more hints already visible when scrolling around.+ .filter(move |chunk| {let chunk_range = chunk.start..=chunk.end;- row_ranges.iter().any(|row_range| {- chunk_range.contains(&row_range.start())- || chunk_range.contains(&row_range.end())- })+ row_ranges+ .iter()+ .any(|row_range| chunk_range.overlaps(&row_range))}).copied()}