Rework inlay hint cache tests (#23156)

Closes https://github.com/zed-industries/zed/issues/7928

* uncomments and fixes all inlay hint cache tests
* fixes a bug, where invalidated range did not store the new queried
ranges in the cache: this resulted in extra requests in editor that do
not fit into the screen
* comments a peculiarity with the `RefreshInlayHints` event: all editors
react to that when a new language server is inserted, even though
certain editors are not related to the new language server
* fixes handling of inlay hints for the same position: now the same
order is kept, as in the language server's response
(https://github.com/zed-industries/zed/issues/7928)
* queries for hints when on excerpt(s) expansion

Release Notes:

- Fixed inlay hints handling for the same position
This commit is contained in:
Kirill Bulatov 2025-01-15 20:13:15 +02:00 committed by GitHub
parent 135e58f1e2
commit 22f5fd53ca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 816 additions and 846 deletions

View file

@ -1637,12 +1637,6 @@ async fn test_mutual_editor_inlay_hint_cache_update(
extract_hint_labels(editor),
"Host should get its first hints when opens an editor"
);
let inlay_cache = editor.inlay_hint_cache();
assert_eq!(
inlay_cache.version(),
1,
"Host editor update the cache version after every cache/view change",
);
});
let (workspace_b, cx_b) = client_b.build_workspace(&project_b, cx_b);
let editor_b = workspace_b
@ -1661,12 +1655,6 @@ async fn test_mutual_editor_inlay_hint_cache_update(
extract_hint_labels(editor),
"Client should get its first hints when opens an editor"
);
let inlay_cache = editor.inlay_hint_cache();
assert_eq!(
inlay_cache.version(),
1,
"Guest editor update the cache version after every cache/view change"
);
});
let after_client_edit = edits_made.fetch_add(1, atomic::Ordering::Release) + 1;
@ -1682,16 +1670,12 @@ async fn test_mutual_editor_inlay_hint_cache_update(
vec![after_client_edit.to_string()],
extract_hint_labels(editor),
);
let inlay_cache = editor.inlay_hint_cache();
assert_eq!(inlay_cache.version(), 2);
});
editor_b.update(cx_b, |editor, _| {
assert_eq!(
vec![after_client_edit.to_string()],
extract_hint_labels(editor),
);
let inlay_cache = editor.inlay_hint_cache();
assert_eq!(inlay_cache.version(), 2);
});
let after_host_edit = edits_made.fetch_add(1, atomic::Ordering::Release) + 1;
@ -1707,16 +1691,12 @@ async fn test_mutual_editor_inlay_hint_cache_update(
vec![after_host_edit.to_string()],
extract_hint_labels(editor),
);
let inlay_cache = editor.inlay_hint_cache();
assert_eq!(inlay_cache.version(), 3);
});
editor_b.update(cx_b, |editor, _| {
assert_eq!(
vec![after_host_edit.to_string()],
extract_hint_labels(editor),
);
let inlay_cache = editor.inlay_hint_cache();
assert_eq!(inlay_cache.version(), 3);
});
let after_special_edit_for_refresh = edits_made.fetch_add(1, atomic::Ordering::Release) + 1;
@ -1732,12 +1712,6 @@ async fn test_mutual_editor_inlay_hint_cache_update(
extract_hint_labels(editor),
"Host should react to /refresh LSP request"
);
let inlay_cache = editor.inlay_hint_cache();
assert_eq!(
inlay_cache.version(),
4,
"Host should accepted all edits and bump its cache version every time"
);
});
editor_b.update(cx_b, |editor, _| {
assert_eq!(
@ -1745,12 +1719,6 @@ async fn test_mutual_editor_inlay_hint_cache_update(
extract_hint_labels(editor),
"Guest should get a /refresh LSP request propagated by host"
);
let inlay_cache = editor.inlay_hint_cache();
assert_eq!(
inlay_cache.version(),
4,
"Guest should accepted all edits and bump its cache version every time"
);
});
}
@ -1906,12 +1874,6 @@ async fn test_inlay_hint_refresh_is_forwarded(
extract_hint_labels(editor).is_empty(),
"Host should get no hints due to them turned off"
);
let inlay_cache = editor.inlay_hint_cache();
assert_eq!(
inlay_cache.version(),
0,
"Turned off hints should not generate version updates"
);
});
executor.run_until_parked();
@ -1921,12 +1883,6 @@ async fn test_inlay_hint_refresh_is_forwarded(
extract_hint_labels(editor),
"Client should get its first hints when opens an editor"
);
let inlay_cache = editor.inlay_hint_cache();
assert_eq!(
inlay_cache.version(),
1,
"Should update cache version after first hints"
);
});
other_hints.fetch_or(true, atomic::Ordering::Release);
@ -1938,13 +1894,7 @@ async fn test_inlay_hint_refresh_is_forwarded(
editor_a.update(cx_a, |editor, _| {
assert!(
extract_hint_labels(editor).is_empty(),
"Host should get nop hints due to them turned off, even after the /refresh"
);
let inlay_cache = editor.inlay_hint_cache();
assert_eq!(
inlay_cache.version(),
0,
"Turned off hints should not generate version updates, again"
"Host should get no hints due to them turned off, even after the /refresh"
);
});
@ -1955,12 +1905,6 @@ async fn test_inlay_hint_refresh_is_forwarded(
extract_hint_labels(editor),
"Guest should get a /refresh LSP request propagated by host despite host hints are off"
);
let inlay_cache = editor.inlay_hint_cache();
assert_eq!(
inlay_cache.version(),
2,
"Guest should accepted all edits and bump its cache version every time"
);
});
}