Only invalidate when doing first, visible range query

This commit is contained in:
Kirill Bulatov 2023-08-25 15:09:06 +03:00
parent a63e1571dc
commit c10c3e2b54

View file

@ -679,7 +679,7 @@ fn new_update_task(
cx: &mut ViewContext<'_, '_, Editor>, cx: &mut ViewContext<'_, '_, Editor>,
) -> Task<()> { ) -> Task<()> {
cx.spawn(|editor, cx| async move { cx.spawn(|editor, cx| async move {
let fetch_and_update_hints = |range| { let fetch_and_update_hints = |invalidate, range| {
fetch_and_update_hints( fetch_and_update_hints(
editor.clone(), editor.clone(),
multi_buffer_snapshot.clone(), multi_buffer_snapshot.clone(),
@ -687,17 +687,16 @@ fn new_update_task(
Arc::clone(&visible_hints), Arc::clone(&visible_hints),
cached_excerpt_hints.as_ref().map(Arc::clone), cached_excerpt_hints.as_ref().map(Arc::clone),
query, query,
invalidate,
range, range,
cx.clone(), cx.clone(),
) )
}; };
let visible_range_update_results = future::join_all( let visible_range_update_results =
query_ranges future::join_all(query_ranges.visible.into_iter().map(|visible_range| {
.visible fetch_and_update_hints(query.invalidate.should_invalidate(), visible_range)
.into_iter() }))
.map(|visible_range| fetch_and_update_hints(visible_range)), .await;
)
.await;
for result in visible_range_update_results { for result in visible_range_update_results {
if let Err(e) = result { if let Err(e) = result {
error!("visible range inlay hint update task failed: {e:#}"); error!("visible range inlay hint update task failed: {e:#}");
@ -715,7 +714,7 @@ fn new_update_task(
.before_visible .before_visible
.into_iter() .into_iter()
.chain(query_ranges.after_visible.into_iter()) .chain(query_ranges.after_visible.into_iter())
.map(|invisible_range| fetch_and_update_hints(invisible_range)), .map(|invisible_range| fetch_and_update_hints(false, invisible_range)),
) )
.await; .await;
for result in invisible_range_update_results { for result in invisible_range_update_results {
@ -733,6 +732,7 @@ async fn fetch_and_update_hints(
visible_hints: Arc<Vec<Inlay>>, visible_hints: Arc<Vec<Inlay>>,
cached_excerpt_hints: Option<Arc<RwLock<CachedExcerptHints>>>, cached_excerpt_hints: Option<Arc<RwLock<CachedExcerptHints>>>,
query: ExcerptQuery, query: ExcerptQuery,
invalidate: bool,
fetch_range: Range<language::Anchor>, fetch_range: Range<language::Anchor>,
mut cx: gpui::AsyncAppContext, mut cx: gpui::AsyncAppContext,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
@ -761,7 +761,8 @@ async fn fetch_and_update_hints(
.background() .background()
.spawn(async move { .spawn(async move {
calculate_hint_updates( calculate_hint_updates(
query, query.excerpt_id,
invalidate,
backround_fetch_range, backround_fetch_range,
new_hints, new_hints,
&background_task_buffer_snapshot, &background_task_buffer_snapshot,
@ -788,7 +789,8 @@ async fn fetch_and_update_hints(
} }
fn calculate_hint_updates( fn calculate_hint_updates(
query: ExcerptQuery, excerpt_id: ExcerptId,
invalidate: bool,
fetch_range: Range<language::Anchor>, fetch_range: Range<language::Anchor>,
new_excerpt_hints: Vec<InlayHint>, new_excerpt_hints: Vec<InlayHint>,
buffer_snapshot: &BufferSnapshot, buffer_snapshot: &BufferSnapshot,
@ -836,11 +838,11 @@ fn calculate_hint_updates(
let mut remove_from_visible = Vec::new(); let mut remove_from_visible = Vec::new();
let mut remove_from_cache = HashSet::default(); let mut remove_from_cache = HashSet::default();
if query.invalidate.should_invalidate() { if invalidate {
remove_from_visible.extend( remove_from_visible.extend(
visible_hints visible_hints
.iter() .iter()
.filter(|hint| hint.position.excerpt_id == query.excerpt_id) .filter(|hint| hint.position.excerpt_id == excerpt_id)
.map(|inlay_hint| inlay_hint.id) .map(|inlay_hint| inlay_hint.id)
.filter(|hint_id| !excerpt_hints_to_persist.contains_key(hint_id)), .filter(|hint_id| !excerpt_hints_to_persist.contains_key(hint_id)),
); );
@ -863,7 +865,7 @@ fn calculate_hint_updates(
None None
} else { } else {
Some(ExcerptHintsUpdate { Some(ExcerptHintsUpdate {
excerpt_id: query.excerpt_id, excerpt_id,
remove_from_visible, remove_from_visible,
remove_from_cache, remove_from_cache,
add_to_cache, add_to_cache,