Mitigate odd offset calculations

This commit is contained in:
Kirill Bulatov 2023-06-22 00:50:49 +03:00
parent 7fddc223cd
commit 1722d61190

View file

@ -53,7 +53,7 @@ struct ExcerptHintsUpdate {
cache_version: usize, cache_version: usize,
remove_from_visible: Vec<InlayId>, remove_from_visible: Vec<InlayId>,
remove_from_cache: HashSet<InlayId>, remove_from_cache: HashSet<InlayId>,
add_to_cache: Vec<(Option<InlayId>, Anchor, InlayHint)>, add_to_cache: Vec<(Anchor, InlayHint)>,
} }
impl InlayHintCache { impl InlayHintCache {
@ -221,29 +221,20 @@ fn new_update_task(
to_insert: Vec::new(), to_insert: Vec::new(),
}; };
for (shown_id, new_hint_position, new_hint) in for (new_hint_position, new_hint) in new_update.add_to_cache {
new_update.add_to_cache let new_inlay_id = InlayId(post_inc(&mut editor.next_inlay_id));
{ if editor
let new_inlay_id = match shown_id { .inlay_hint_cache
Some(id) => id, .snapshot
None => { .allowed_hint_kinds
let new_inlay_id = .contains(&new_hint.kind)
InlayId(post_inc(&mut editor.next_inlay_id)); {
if editor splice.to_insert.push((
.inlay_hint_cache new_hint_position,
.snapshot new_inlay_id,
.allowed_hint_kinds new_hint.clone(),
.contains(&new_hint.kind) ));
{ }
splice.to_insert.push((
new_hint_position,
new_inlay_id,
new_hint.clone(),
));
}
new_inlay_id
}
};
match cached_excerpt_hints.hints.binary_search_by(|probe| { match cached_excerpt_hints.hints.binary_search_by(|probe| {
probe.0.cmp(&new_hint_position, &task_multi_buffer_snapshot) probe.0.cmp(&new_hint_position, &task_multi_buffer_snapshot)
@ -378,7 +369,7 @@ fn new_excerpt_hints_update_result(
new_excerpt_hints: Vec<InlayHint>, new_excerpt_hints: Vec<InlayHint>,
invalidate_cache: bool, invalidate_cache: bool,
) -> Option<ExcerptHintsUpdate> { ) -> Option<ExcerptHintsUpdate> {
let mut add_to_cache: Vec<(Option<InlayId>, Anchor, InlayHint)> = Vec::new(); let mut add_to_cache: Vec<(Anchor, InlayHint)> = Vec::new();
let shown_excerpt_hints = state let shown_excerpt_hints = state
.visible_inlays .visible_inlays
.iter() .iter()
@ -394,12 +385,13 @@ fn new_excerpt_hints_update_result(
let mut excerpt_hints_to_persist = HashSet::default(); let mut excerpt_hints_to_persist = HashSet::default();
for new_hint in new_excerpt_hints { for new_hint in new_excerpt_hints {
// TODO kb this somehow spoils anchors and make them equal for different text anchors.
let new_hint_anchor = state let new_hint_anchor = state
.multi_buffer_snapshot .multi_buffer_snapshot
.anchor_in_excerpt(excerpt_id, new_hint.position); .anchor_in_excerpt(excerpt_id, new_hint.position);
// TODO kb use merge sort or something else better // TODO kb use merge sort or something else better
let should_add_to_cache = match cached_excerpt_hints let should_add_to_cache = match cached_excerpt_hints
.binary_search_by(|probe| new_hint_anchor.cmp(&probe.0, &state.multi_buffer_snapshot)) .binary_search_by(|probe| probe.0.cmp(&new_hint_anchor, &state.multi_buffer_snapshot))
{ {
Ok(ix) => { Ok(ix) => {
let (_, cached_inlay_id, cached_hint) = &cached_excerpt_hints[ix]; let (_, cached_inlay_id, cached_hint) = &cached_excerpt_hints[ix];
@ -441,14 +433,9 @@ fn new_excerpt_hints_update_result(
}; };
if should_add_to_cache { if should_add_to_cache {
let id_to_add = match shown_inlay_id { if shown_inlay_id.is_none() {
Some(&shown_inlay_id) => { add_to_cache.push((new_hint_anchor, new_hint.clone()));
excerpt_hints_to_persist.insert(shown_inlay_id); }
Some(shown_inlay_id)
}
None => None,
};
add_to_cache.push((id_to_add, new_hint_anchor, new_hint.clone()));
} }
} }