Clean up visible inlay hints that got removed from the cache (#7399)

Fixes another flack in the inlay hint cache.
Now that test does not fail after 500 iterations and seems to be stable
at last.

Release Notes:

- N/A
This commit is contained in:
Kirill Bulatov 2024-02-05 22:03:44 +02:00 committed by GitHub
parent 6863b9263e
commit 28a62affe4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -78,7 +78,7 @@ pub(super) enum InvalidationStrategy {
/// "Visible" inlays may not be displayed in the buffer right away, but those are ready to be displayed on further buffer scroll, pane item activations, etc. right away without additional LSP queries or settings changes. /// "Visible" inlays may not be displayed in the buffer right away, but those are ready to be displayed on further buffer scroll, pane item activations, etc. right away without additional LSP queries or settings changes.
/// The data in the cache is never used directly for displaying inlays on the screen, to avoid races with updates from LSP queries and sync overhead. /// The data in the cache is never used directly for displaying inlays on the screen, to avoid races with updates from LSP queries and sync overhead.
/// Splice is picked to help avoid extra hint flickering and "jumps" on the screen. /// Splice is picked to help avoid extra hint flickering and "jumps" on the screen.
#[derive(Debug)] #[derive(Debug, Default)]
pub(super) struct InlaySplice { pub(super) struct InlaySplice {
pub to_remove: Vec<InlayId>, pub to_remove: Vec<InlayId>,
pub to_insert: Vec<Inlay>, pub to_insert: Vec<Inlay>,
@ -87,7 +87,7 @@ pub(super) struct InlaySplice {
#[derive(Debug)] #[derive(Debug)]
struct ExcerptHintsUpdate { struct ExcerptHintsUpdate {
excerpt_id: ExcerptId, excerpt_id: ExcerptId,
remove_from_visible: Vec<InlayId>, remove_from_visible: HashSet<InlayId>,
remove_from_cache: HashSet<InlayId>, remove_from_cache: HashSet<InlayId>,
add_to_cache: Vec<InlayHint>, add_to_cache: Vec<InlayHint>,
} }
@ -1052,7 +1052,7 @@ fn calculate_hint_updates(
} }
} }
let mut remove_from_visible = Vec::new(); let mut remove_from_visible = HashSet::default();
let mut remove_from_cache = HashSet::default(); let mut remove_from_cache = HashSet::default();
if invalidate { if invalidate {
remove_from_visible.extend( remove_from_visible.extend(
@ -1074,6 +1074,7 @@ fn calculate_hint_updates(
}) })
.copied(), .copied(),
); );
remove_from_visible.extend(remove_from_cache.iter().cloned());
} }
} }
@ -1135,10 +1136,8 @@ fn apply_hint_update(
cached_excerpt_hints cached_excerpt_hints
.hints_by_id .hints_by_id
.retain(|hint_id, _| !new_update.remove_from_cache.contains(hint_id)); .retain(|hint_id, _| !new_update.remove_from_cache.contains(hint_id));
let mut splice = InlaySplice { let mut splice = InlaySplice::default();
to_remove: new_update.remove_from_visible, splice.to_remove.extend(new_update.remove_from_visible);
to_insert: Vec::new(),
};
for new_hint in new_update.add_to_cache { for new_hint in new_update.add_to_cache {
let insert_position = match cached_excerpt_hints let insert_position = match cached_excerpt_hints
.ordered_hints .ordered_hints