Find proper applicable chunks for visible ranges (#42422)

Kirill Bulatov , Smit Barmase , and Lukas Wirth created

Release Notes:

- Fixed inlay hints not being queried for certain long-ranged jumps

Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>
Co-authored-by: Lukas Wirth <lukas@zed.dev>

Change summary

crates/project/src/lsp_store/inlay_hint_cache.rs | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

Detailed changes

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()
     }