Log LSP inlay hint path

This commit is contained in:
Kirill Bulatov 2023-08-26 13:46:55 +03:00
parent e6fb909d89
commit 3fc48fc277
2 changed files with 52 additions and 5 deletions

View file

@ -1252,6 +1252,17 @@ enum InlayHintRefreshReason {
BufferEdited(HashSet<Arc<Language>>), BufferEdited(HashSet<Arc<Language>>),
RefreshRequested, RefreshRequested,
} }
impl InlayHintRefreshReason {
fn description(&self) -> &'static str {
match self {
InlayHintRefreshReason::Toggle(_) => "toggle",
InlayHintRefreshReason::SettingsChange(_) => "settings change",
InlayHintRefreshReason::NewLinesShown => "new lines shown",
InlayHintRefreshReason::BufferEdited(_) => "buffer edited",
InlayHintRefreshReason::RefreshRequested => "refresh requested",
}
}
}
impl Editor { impl Editor {
pub fn single_line( pub fn single_line(
@ -2741,6 +2752,7 @@ impl Editor {
return; return;
} }
let reason_description = reason.description();
let (invalidate_cache, required_languages) = match reason { let (invalidate_cache, required_languages) = match reason {
InlayHintRefreshReason::Toggle(enabled) => { InlayHintRefreshReason::Toggle(enabled) => {
self.inlay_hint_cache.enabled = enabled; self.inlay_hint_cache.enabled = enabled;
@ -2790,6 +2802,7 @@ impl Editor {
to_remove, to_remove,
to_insert, to_insert,
}) = self.inlay_hint_cache.spawn_hint_refresh( }) = self.inlay_hint_cache.spawn_hint_refresh(
reason_description,
self.excerpt_visible_offsets(required_languages.as_ref(), cx), self.excerpt_visible_offsets(required_languages.as_ref(), cx),
invalidate_cache, invalidate_cache,
cx, cx,

View file

@ -13,7 +13,6 @@ use clock::Global;
use futures::future; use futures::future;
use gpui::{ModelContext, ModelHandle, Task, ViewContext}; use gpui::{ModelContext, ModelHandle, Task, ViewContext};
use language::{language_settings::InlayHintKind, Buffer, BufferSnapshot}; use language::{language_settings::InlayHintKind, Buffer, BufferSnapshot};
use log::error;
use parking_lot::RwLock; use parking_lot::RwLock;
use project::{InlayHint, ResolveState}; use project::{InlayHint, ResolveState};
@ -21,7 +20,7 @@ use collections::{hash_map, HashMap, HashSet};
use language::language_settings::InlayHintSettings; use language::language_settings::InlayHintSettings;
use smol::lock::Semaphore; use smol::lock::Semaphore;
use sum_tree::Bias; use sum_tree::Bias;
use text::ToOffset; use text::{ToOffset, ToPoint};
use util::post_inc; use util::post_inc;
pub struct InlayHintCache { pub struct InlayHintCache {
@ -74,6 +73,7 @@ struct ExcerptQuery {
excerpt_id: ExcerptId, excerpt_id: ExcerptId,
cache_version: usize, cache_version: usize,
invalidate: InvalidationStrategy, invalidate: InvalidationStrategy,
reason: &'static str,
} }
impl InvalidationStrategy { impl InvalidationStrategy {
@ -317,6 +317,7 @@ impl InlayHintCache {
pub fn spawn_hint_refresh( pub fn spawn_hint_refresh(
&mut self, &mut self,
reason: &'static str,
excerpts_to_query: HashMap<ExcerptId, (ModelHandle<Buffer>, Global, Range<usize>)>, excerpts_to_query: HashMap<ExcerptId, (ModelHandle<Buffer>, Global, Range<usize>)>,
invalidate: InvalidationStrategy, invalidate: InvalidationStrategy,
cx: &mut ViewContext<Editor>, cx: &mut ViewContext<Editor>,
@ -345,7 +346,14 @@ impl InlayHintCache {
cx.spawn(|editor, mut cx| async move { cx.spawn(|editor, mut cx| async move {
editor editor
.update(&mut cx, |editor, cx| { .update(&mut cx, |editor, cx| {
spawn_new_update_tasks(editor, excerpts_to_query, invalidate, cache_version, cx) spawn_new_update_tasks(
editor,
reason,
excerpts_to_query,
invalidate,
cache_version,
cx,
)
}) })
.ok(); .ok();
}) })
@ -568,6 +576,7 @@ impl InlayHintCache {
fn spawn_new_update_tasks( fn spawn_new_update_tasks(
editor: &mut Editor, editor: &mut Editor,
reason: &'static str,
excerpts_to_query: HashMap<ExcerptId, (ModelHandle<Buffer>, Global, Range<usize>)>, excerpts_to_query: HashMap<ExcerptId, (ModelHandle<Buffer>, Global, Range<usize>)>,
invalidate: InvalidationStrategy, invalidate: InvalidationStrategy,
update_cache_version: usize, update_cache_version: usize,
@ -622,6 +631,7 @@ fn spawn_new_update_tasks(
excerpt_id, excerpt_id,
cache_version: update_cache_version, cache_version: update_cache_version,
invalidate, invalidate,
reason,
}; };
let new_update_task = |query_ranges| { let new_update_task = |query_ranges| {
@ -782,7 +792,7 @@ fn new_update_task(
)); ));
let mut query_range_failed = |range: Range<language::Anchor>, e: anyhow::Error| { let mut query_range_failed = |range: Range<language::Anchor>, e: anyhow::Error| {
error!("inlay hint update task for range {range:?} failed: {e:#}"); log::error!("inlay hint update task for range {range:?} failed: {e:#}");
editor editor
.update(&mut cx, |editor, _| { .update(&mut cx, |editor, _| {
if let Some(task_ranges) = editor if let Some(task_ranges) = editor
@ -844,6 +854,8 @@ async fn fetch_and_update_hints(
None => (Some(lsp_request_limiter.acquire().await), true), None => (Some(lsp_request_limiter.acquire().await), true),
} }
}; };
let fetch_range_to_log =
fetch_range.start.to_point(&buffer_snapshot)..fetch_range.end.to_point(&buffer_snapshot);
let inlay_hints_fetch_task = editor let inlay_hints_fetch_task = editor
.update(&mut cx, |editor, cx| { .update(&mut cx, |editor, cx| {
if got_throttled { if got_throttled {
@ -882,10 +894,25 @@ async fn fetch_and_update_hints(
.ok() .ok()
.flatten(); .flatten();
let new_hints = match inlay_hints_fetch_task { let new_hints = match inlay_hints_fetch_task {
Some(task) => task.await.context("inlay hint fetch task")?, Some(fetch_task) => {
log::debug!(
"Fetching inlay hints for range {fetch_range_to_log:?}, reason: {query_reason}, invalidate: {invalidate}",
query_reason = query.reason,
);
log::trace!(
"Currently visible hints: {visible_hints:?}, cached hints present: {}",
cached_excerpt_hints.is_some(),
);
fetch_task.await.context("inlay hint fetch task")?
}
None => return Ok(()), None => return Ok(()),
}; };
drop(lsp_request_guard); drop(lsp_request_guard);
log::debug!(
"Fetched {} hints for range {fetch_range_to_log:?}",
new_hints.len()
);
log::trace!("Fetched hints: {new_hints:?}");
let background_task_buffer_snapshot = buffer_snapshot.clone(); let background_task_buffer_snapshot = buffer_snapshot.clone();
let backround_fetch_range = fetch_range.clone(); let backround_fetch_range = fetch_range.clone();
@ -904,6 +931,13 @@ async fn fetch_and_update_hints(
}) })
.await; .await;
if let Some(new_update) = new_update { if let Some(new_update) = new_update {
log::info!(
"Applying update for range {fetch_range_to_log:?}: remove from editor: {}, remove from cache: {}, add to cache: {}",
new_update.remove_from_visible.len(),
new_update.remove_from_cache.len(),
new_update.add_to_cache.len()
);
log::trace!("New update: {new_update:?}");
editor editor
.update(&mut cx, |editor, cx| { .update(&mut cx, |editor, cx| {
apply_hint_update( apply_hint_update(