Correctly pass inlay hints

This commit is contained in:
Kirill Bulatov 2023-06-07 23:39:58 +03:00
parent b5233b3ad5
commit d506522eef
4 changed files with 22 additions and 37 deletions

View file

@ -100,13 +100,9 @@ impl DisplayMap {
let edits = self.buffer_subscription.consume().into_inner(); let edits = self.buffer_subscription.consume().into_inner();
let (fold_snapshot, edits) = self.fold_map.read(buffer_snapshot, edits); let (fold_snapshot, edits) = self.fold_map.read(buffer_snapshot, edits);
let (suggestion_snapshot, edits) = self.suggestion_map.sync(fold_snapshot.clone(), edits); let (suggestion_snapshot, edits) = self.suggestion_map.sync(fold_snapshot.clone(), edits);
let (inlay_snapshot, edits) = self let (inlay_snapshot, edits) = self.inlay_map.sync(suggestion_snapshot.clone(), edits);
.inlay_map
.sync(suggestion_snapshot.clone(), edits);
let tab_size = Self::tab_size(&self.buffer, cx); let tab_size = Self::tab_size(&self.buffer, cx);
let (tab_snapshot, edits) = let (tab_snapshot, edits) = self.tab_map.sync(inlay_snapshot.clone(), edits, tab_size);
self.tab_map
.sync(inlay_snapshot.clone(), edits, tab_size);
let (wrap_snapshot, edits) = self let (wrap_snapshot, edits) = self
.wrap_map .wrap_map
.update(cx, |map, cx| map.sync(tab_snapshot.clone(), edits, cx)); .update(cx, |map, cx| map.sync(tab_snapshot.clone(), edits, cx));
@ -293,24 +289,24 @@ impl DisplayMap {
new_hints: &[project::InlayHint], new_hints: &[project::InlayHint],
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) { ) {
dbg!("---", new_hints.len());
let multi_buffer = self.buffer.read(cx); let multi_buffer = self.buffer.read(cx);
let zz = dbg!(multi_buffer // TODO kb carry both remote and local ids of the buffer?
// now, `.buffer` requires remote id, hence this map.
let buffers_to_local_id = multi_buffer
.all_buffers() .all_buffers()
.into_iter() .into_iter()
.map(|buffer_handle| buffer_handle.id()) .map(|buffer_handle| (buffer_handle.id(), buffer_handle))
.collect::<HashSet<_>>()); .collect::<HashMap<_, _>>();
self.inlay_map.set_inlay_hints( self.inlay_map.set_inlay_hints(
new_hints new_hints
.into_iter() .into_iter()
.filter_map(|hint| { .filter_map(|hint| {
// TODO kb this is all wrong, need to manage both(?) or at least the remote buffer id when needed. let snapshot = buffers_to_local_id
// Here though, `.buffer(` requires remote buffer id, so use the workaround above. .get(&hint.buffer_id)?
dbg!(zz.contains(&(hint.buffer_id as usize))); .read(cx)
let buffer = dbg!(multi_buffer.buffer(dbg!(hint.buffer_id)))?.read(cx); .snapshot();
let snapshot = buffer.snapshot();
Some(InlayHintToRender { Some(InlayHintToRender {
position: inlay_map::InlayPoint(text::ToPoint::to_point( position: inlay_map::InlayPoint(text::ToPoint::to_point(
&hint.position, &hint.position,
@ -419,9 +415,7 @@ impl DisplaySnapshot {
fn point_to_display_point(&self, point: Point, bias: Bias) -> DisplayPoint { fn point_to_display_point(&self, point: Point, bias: Bias) -> DisplayPoint {
let fold_point = self.fold_snapshot.to_fold_point(point, bias); let fold_point = self.fold_snapshot.to_fold_point(point, bias);
let suggestion_point = self.suggestion_snapshot.to_suggestion_point(fold_point); let suggestion_point = self.suggestion_snapshot.to_suggestion_point(fold_point);
let inlay_point = self let inlay_point = self.inlay_snapshot.to_inlay_point(suggestion_point);
.inlay_snapshot
.to_inlay_point(suggestion_point);
let tab_point = self.tab_snapshot.to_tab_point(inlay_point); let tab_point = self.tab_snapshot.to_tab_point(inlay_point);
let wrap_point = self.wrap_snapshot.tab_point_to_wrap_point(tab_point); let wrap_point = self.wrap_snapshot.tab_point_to_wrap_point(tab_point);
let block_point = self.block_snapshot.to_block_point(wrap_point); let block_point = self.block_snapshot.to_block_point(wrap_point);
@ -432,13 +426,8 @@ impl DisplaySnapshot {
let block_point = point.0; let block_point = point.0;
let wrap_point = self.block_snapshot.to_wrap_point(block_point); let wrap_point = self.block_snapshot.to_wrap_point(block_point);
let tab_point = self.wrap_snapshot.to_tab_point(wrap_point); let tab_point = self.wrap_snapshot.to_tab_point(wrap_point);
let inlay_point = self let inlay_point = self.tab_snapshot.to_inlay_point(tab_point, bias).0;
.tab_snapshot let suggestion_point = self.inlay_snapshot.to_suggestion_point(inlay_point, bias);
.to_inlay_point(tab_point, bias)
.0;
let suggestion_point = self
.inlay_snapshot
.to_suggestion_point(inlay_point, bias);
let fold_point = self.suggestion_snapshot.to_fold_point(suggestion_point); let fold_point = self.suggestion_snapshot.to_fold_point(suggestion_point);
fold_point.to_buffer_point(&self.fold_snapshot) fold_point.to_buffer_point(&self.fold_snapshot)
} }
@ -853,9 +842,7 @@ impl DisplayPoint {
let wrap_point = map.block_snapshot.to_wrap_point(self.0); let wrap_point = map.block_snapshot.to_wrap_point(self.0);
let tab_point = map.wrap_snapshot.to_tab_point(wrap_point); let tab_point = map.wrap_snapshot.to_tab_point(wrap_point);
let inlay_point = map.tab_snapshot.to_inlay_point(tab_point, bias).0; let inlay_point = map.tab_snapshot.to_inlay_point(tab_point, bias).0;
let suggestion_point = map let suggestion_point = map.inlay_snapshot.to_suggestion_point(inlay_point, bias);
.inlay_snapshot
.to_suggestion_point(inlay_point, bias);
let fold_point = map.suggestion_snapshot.to_fold_point(suggestion_point); let fold_point = map.suggestion_snapshot.to_fold_point(suggestion_point);
fold_point.to_buffer_offset(&map.fold_snapshot) fold_point.to_buffer_offset(&map.fold_snapshot)
} }

View file

@ -29,12 +29,12 @@ pub struct InlayHintId(usize);
pub struct InlayMap { pub struct InlayMap {
snapshot: Mutex<InlaySnapshot>, snapshot: Mutex<InlaySnapshot>,
next_hint_id: AtomicUsize, next_hint_id: AtomicUsize,
hints: HashMap<InlayHintId, InlayHintToRender>, inlay_hints: HashMap<InlayHintId, InlayHintToRender>,
} }
#[derive(Clone)] #[derive(Clone)]
pub struct InlaySnapshot { pub struct InlaySnapshot {
// TODO kb merge these two together // TODO kb merge these two together?
pub suggestion_snapshot: SuggestionSnapshot, pub suggestion_snapshot: SuggestionSnapshot,
transforms: SumTree<Transform>, transforms: SumTree<Transform>,
pub version: usize, pub version: usize,
@ -141,7 +141,7 @@ impl InlayMap {
Self { Self {
snapshot: Mutex::new(snapshot.clone()), snapshot: Mutex::new(snapshot.clone()),
next_hint_id: AtomicUsize::new(0), next_hint_id: AtomicUsize::new(0),
hints: HashMap::default(), inlay_hints: HashMap::default(),
}, },
snapshot, snapshot,
) )
@ -160,7 +160,6 @@ impl InlayMap {
let mut inlay_edits = Vec::new(); let mut inlay_edits = Vec::new();
dbg!(&suggestion_edits);
for suggestion_edit in suggestion_edits { for suggestion_edit in suggestion_edits {
let old = suggestion_edit.old; let old = suggestion_edit.old;
let new = suggestion_edit.new; let new = suggestion_edit.new;
@ -190,9 +189,8 @@ impl InlayMap {
} }
pub fn set_inlay_hints(&mut self, new_hints: Vec<InlayHintToRender>) { pub fn set_inlay_hints(&mut self, new_hints: Vec<InlayHintToRender>) {
dbg!(new_hints.len());
// TODO kb reuse ids for hints that did not change and similar things // TODO kb reuse ids for hints that did not change and similar things
self.hints = new_hints self.inlay_hints = new_hints
.into_iter() .into_iter()
.map(|hint| { .map(|hint| {
( (

View file

@ -1834,7 +1834,7 @@ impl LspCommand for InlayHints {
.unwrap_or_default() .unwrap_or_default()
.into_iter() .into_iter()
.map(|lsp_hint| InlayHint { .map(|lsp_hint| InlayHint {
buffer_id: buffer.id() as u64, buffer_id: buffer.id(),
position: origin_buffer.anchor_after( position: origin_buffer.anchor_after(
origin_buffer origin_buffer
.clip_point_utf16(point_from_lsp(lsp_hint.position), Bias::Left), .clip_point_utf16(point_from_lsp(lsp_hint.position), Bias::Left),
@ -2007,7 +2007,7 @@ impl LspCommand for InlayHints {
let mut hints = Vec::new(); let mut hints = Vec::new();
for message_hint in message.hints { for message_hint in message.hints {
let hint = InlayHint { let hint = InlayHint {
buffer_id: buffer.id() as u64, buffer_id: buffer.id(),
position: message_hint position: message_hint
.position .position
.and_then(language::proto::deserialize_anchor) .and_then(language::proto::deserialize_anchor)

View file

@ -329,7 +329,7 @@ pub struct Location {
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct InlayHint { pub struct InlayHint {
pub buffer_id: u64, pub buffer_id: usize,
pub position: Anchor, pub position: Anchor,
pub label: InlayHintLabel, pub label: InlayHintLabel,
pub kind: Option<String>, pub kind: Option<String>,