Rework editors to register and query buffers on scroll (#40388)

Preparation to https://github.com/zed-industries/zed/pull/40183
Moves https://github.com/zed-industries/zed/pull/22958 further: now,
instead of selection, scrolling the buffer into view is enough to get
registered and, later, be queried for its LSP data such as inlay hints,
diagnostics and document colors.

This effectively undoes https://github.com/zed-industries/zed/pull/28855
as now we try to register whatever's visible more aggressively, instead
of implicitly via inlay hints.

Release Notes:

- Reworked editors to register and query buffers on scroll
This commit is contained in:
Kirill Bulatov
2025-10-16 15:13:23 +00:00
committed by GitHub
parent c77cc9b0eb
commit de8dd9bea5
10 changed files with 421 additions and 386 deletions
+29 -7
View File
@@ -2394,6 +2394,8 @@ pub mod tests {
editor.scroll_screen(&ScrollAmount::Page(1.0), window, cx);
})
.unwrap();
// Wait for the first hints request to fire off
cx.executor().advance_clock(Duration::from_millis(100));
cx.executor().run_until_parked();
editor
.update(cx, |editor, window, cx| {
@@ -2752,6 +2754,23 @@ pub mod tests {
})
.unwrap();
cx.executor().run_until_parked();
editor
.update(cx, |editor, _window, cx| {
let expected_hints = vec![
"main hint #0".to_string(),
"main hint #1".to_string(),
"main hint #2".to_string(),
"main hint #3".to_string(),
"main hint #4".to_string(),
"main hint #5".to_string(),
];
assert_eq!(expected_hints, sorted_cached_hint_labels(editor),
"New hints are not shown right after scrolling, we need to wait for the buffer to be registered");
assert_eq!(expected_hints, visible_hint_labels(editor, cx));
})
.unwrap();
cx.executor().advance_clock(Duration::from_millis(100));
cx.executor().run_until_parked();
editor
.update(cx, |editor, _window, cx| {
let expected_hints = vec![
@@ -2766,7 +2785,7 @@ pub mod tests {
"other hint #2".to_string(),
];
assert_eq!(expected_hints, sorted_cached_hint_labels(editor),
"With more scrolls of the multibuffer, more hints should be added into the cache and nothing invalidated without edits");
"After scrolling to the new buffer and waiting for it to be registered, new hints should appear");
assert_eq!(expected_hints, visible_hint_labels(editor, cx));
})
.unwrap();
@@ -2853,15 +2872,18 @@ pub mod tests {
})
.unwrap();
cx.executor().run_until_parked();
// Wait again to trigger the inlay hints fetch on scroll
cx.executor().advance_clock(Duration::from_millis(100));
cx.executor().run_until_parked();
editor
.update(cx, |editor, _window, cx| {
let expected_hints = vec![
"main hint #0".to_string(),
"main hint #1".to_string(),
"main hint #2".to_string(),
"main hint #3".to_string(),
"main hint #4".to_string(),
"main hint #5".to_string(),
"main hint(edited) #0".to_string(),
"main hint(edited) #1".to_string(),
"main hint(edited) #2".to_string(),
"main hint(edited) #3".to_string(),
"main hint(edited) #4".to_string(),
"main hint(edited) #5".to_string(),
"other hint(edited) #0".to_string(),
"other hint(edited) #1".to_string(),
];