Hide inlay cache fields

This commit is contained in:
Kirill Bulatov 2023-08-10 14:39:37 +03:00
parent 5ce7ccac32
commit 5d2750e0d4
2 changed files with 41 additions and 24 deletions

View file

@ -7953,7 +7953,8 @@ async fn test_mutual_editor_inlay_hint_cache_update(
); );
let inlay_cache = editor.inlay_hint_cache(); let inlay_cache = editor.inlay_hint_cache();
assert_eq!( assert_eq!(
inlay_cache.version, edits_made, inlay_cache.version(),
edits_made,
"Host editor update the cache version after every cache/view change", "Host editor update the cache version after every cache/view change",
); );
}); });
@ -7976,7 +7977,8 @@ async fn test_mutual_editor_inlay_hint_cache_update(
); );
let inlay_cache = editor.inlay_hint_cache(); let inlay_cache = editor.inlay_hint_cache();
assert_eq!( assert_eq!(
inlay_cache.version, edits_made, inlay_cache.version(),
edits_made,
"Guest editor update the cache version after every cache/view change" "Guest editor update the cache version after every cache/view change"
); );
}); });
@ -7996,7 +7998,7 @@ async fn test_mutual_editor_inlay_hint_cache_update(
"Host should get hints from the 1st edit and 1st LSP query" "Host should get hints from the 1st edit and 1st LSP query"
); );
let inlay_cache = editor.inlay_hint_cache(); let inlay_cache = editor.inlay_hint_cache();
assert_eq!(inlay_cache.version, edits_made); assert_eq!(inlay_cache.version(), edits_made);
}); });
editor_b.update(cx_b, |editor, _| { editor_b.update(cx_b, |editor, _| {
assert_eq!( assert_eq!(
@ -8010,7 +8012,7 @@ async fn test_mutual_editor_inlay_hint_cache_update(
"Guest should get hints the 1st edit and 2nd LSP query" "Guest should get hints the 1st edit and 2nd LSP query"
); );
let inlay_cache = editor.inlay_hint_cache(); let inlay_cache = editor.inlay_hint_cache();
assert_eq!(inlay_cache.version, edits_made); assert_eq!(inlay_cache.version(), edits_made);
}); });
editor_a.update(cx_a, |editor, cx| { editor_a.update(cx_a, |editor, cx| {
@ -8035,7 +8037,7 @@ async fn test_mutual_editor_inlay_hint_cache_update(
4th query was made by guest (but not applied) due to cache invalidation logic" 4th query was made by guest (but not applied) due to cache invalidation logic"
); );
let inlay_cache = editor.inlay_hint_cache(); let inlay_cache = editor.inlay_hint_cache();
assert_eq!(inlay_cache.version, edits_made); assert_eq!(inlay_cache.version(), edits_made);
}); });
editor_b.update(cx_b, |editor, _| { editor_b.update(cx_b, |editor, _| {
assert_eq!( assert_eq!(
@ -8051,7 +8053,7 @@ async fn test_mutual_editor_inlay_hint_cache_update(
"Guest should get hints from 3rd edit, 6th LSP query" "Guest should get hints from 3rd edit, 6th LSP query"
); );
let inlay_cache = editor.inlay_hint_cache(); let inlay_cache = editor.inlay_hint_cache();
assert_eq!(inlay_cache.version, edits_made); assert_eq!(inlay_cache.version(), edits_made);
}); });
fake_language_server fake_language_server
@ -8077,7 +8079,8 @@ async fn test_mutual_editor_inlay_hint_cache_update(
); );
let inlay_cache = editor.inlay_hint_cache(); let inlay_cache = editor.inlay_hint_cache();
assert_eq!( assert_eq!(
inlay_cache.version, edits_made, inlay_cache.version(),
edits_made,
"Host should accepted all edits and bump its cache version every time" "Host should accepted all edits and bump its cache version every time"
); );
}); });
@ -8098,7 +8101,7 @@ async fn test_mutual_editor_inlay_hint_cache_update(
); );
let inlay_cache = editor.inlay_hint_cache(); let inlay_cache = editor.inlay_hint_cache();
assert_eq!( assert_eq!(
inlay_cache.version, inlay_cache.version(),
edits_made, edits_made,
"Guest should accepted all edits and bump its cache version every time" "Guest should accepted all edits and bump its cache version every time"
); );
@ -8264,7 +8267,8 @@ async fn test_inlay_hint_refresh_is_forwarded(
); );
let inlay_cache = editor.inlay_hint_cache(); let inlay_cache = editor.inlay_hint_cache();
assert_eq!( assert_eq!(
inlay_cache.version, 0, inlay_cache.version(),
0,
"Host should not increment its cache version due to no changes", "Host should not increment its cache version due to no changes",
); );
}); });
@ -8279,7 +8283,8 @@ async fn test_inlay_hint_refresh_is_forwarded(
); );
let inlay_cache = editor.inlay_hint_cache(); let inlay_cache = editor.inlay_hint_cache();
assert_eq!( assert_eq!(
inlay_cache.version, edits_made, inlay_cache.version(),
edits_made,
"Guest editor update the cache version after every cache/view change" "Guest editor update the cache version after every cache/view change"
); );
}); });
@ -8296,7 +8301,8 @@ async fn test_inlay_hint_refresh_is_forwarded(
); );
let inlay_cache = editor.inlay_hint_cache(); let inlay_cache = editor.inlay_hint_cache();
assert_eq!( assert_eq!(
inlay_cache.version, 0, inlay_cache.version(),
0,
"Host should not increment its cache version due to no changes", "Host should not increment its cache version due to no changes",
); );
}); });
@ -8311,7 +8317,8 @@ async fn test_inlay_hint_refresh_is_forwarded(
); );
let inlay_cache = editor.inlay_hint_cache(); let inlay_cache = editor.inlay_hint_cache();
assert_eq!( assert_eq!(
inlay_cache.version, edits_made, inlay_cache.version(),
edits_made,
"Guest should accepted all edits and bump its cache version every time" "Guest should accepted all edits and bump its cache version every time"
); );
}); });
@ -8343,13 +8350,10 @@ fn room_participants(room: &ModelHandle<Room>, cx: &mut TestAppContext) -> RoomP
fn extract_hint_labels(editor: &Editor) -> Vec<String> { fn extract_hint_labels(editor: &Editor) -> Vec<String> {
let mut labels = Vec::new(); let mut labels = Vec::new();
for (_, excerpt_hints) in &editor.inlay_hint_cache().hints { for hint in editor.inlay_hint_cache().hints() {
let excerpt_hints = excerpt_hints.read(); match hint.label {
for (_, inlay) in excerpt_hints.hints.iter() { project::InlayHintLabel::String(s) => labels.push(s),
match &inlay.label { _ => unreachable!(),
project::InlayHintLabel::String(s) => labels.push(s.to_string()),
_ => unreachable!(),
}
} }
} }
labels labels

View file

@ -20,10 +20,10 @@ use language::language_settings::InlayHintSettings;
use util::post_inc; use util::post_inc;
pub struct InlayHintCache { pub struct InlayHintCache {
pub hints: HashMap<ExcerptId, Arc<RwLock<CachedExcerptHints>>>, hints: HashMap<ExcerptId, Arc<RwLock<CachedExcerptHints>>>,
pub allowed_hint_kinds: HashSet<Option<InlayHintKind>>, allowed_hint_kinds: HashSet<Option<InlayHintKind>>,
pub version: usize, version: usize,
pub enabled: bool, enabled: bool,
update_tasks: HashMap<ExcerptId, UpdateTask>, update_tasks: HashMap<ExcerptId, UpdateTask>,
} }
@ -32,7 +32,7 @@ pub struct CachedExcerptHints {
version: usize, version: usize,
buffer_version: Global, buffer_version: Global,
buffer_id: u64, buffer_id: u64,
pub hints: Vec<(InlayId, InlayHint)>, hints: Vec<(InlayId, InlayHint)>,
} }
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
@ -368,6 +368,19 @@ impl InlayHintCache {
self.update_tasks.clear(); self.update_tasks.clear();
self.hints.clear(); self.hints.clear();
} }
pub fn hints(&self) -> Vec<InlayHint> {
let mut hints = Vec::new();
for excerpt_hints in self.hints.values() {
let excerpt_hints = excerpt_hints.read();
hints.extend(excerpt_hints.hints.iter().map(|(_, hint)| hint).cloned());
}
hints
}
pub fn version(&self) -> usize {
self.version
}
} }
fn spawn_new_update_tasks( fn spawn_new_update_tasks(