diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rs index ed57e537bd5f46661f6747fb4cd5d09fa4ef32d6..88cdd9ac3668c43b1ebc34ed45f40440d96f27c1 100644 --- a/crates/editor/src/display_map.rs +++ b/crates/editor/src/display_map.rs @@ -761,6 +761,14 @@ impl DisplaySnapshot { let type_id = TypeId::of::(); self.text_highlights.get(&Some(type_id)).cloned() } + + #[cfg(any(test, feature = "test-support"))] + pub fn inlay_highlight_ranges( + &self, + ) -> Option)>> { + let type_id = TypeId::of::(); + self.inlay_highlights.get(&Some(type_id)).cloned() + } } #[derive(Copy, Clone, Default, Eq, Ord, PartialOrd, PartialEq)] diff --git a/crates/editor/src/display_map/inlay_map.rs b/crates/editor/src/display_map/inlay_map.rs index 5efa15a1c2b54704c80ad66cd532537abbf97aff..62ec3f6eef005431625574efecec6401b5c75b08 100644 --- a/crates/editor/src/display_map/inlay_map.rs +++ b/crates/editor/src/display_map/inlay_map.rs @@ -1711,7 +1711,6 @@ mod tests { .filter_map(|i| { let (_, inlay) = &inlays[i]; let inlay_text_len = inlay.text.len(); - // TODO kb gen_range match inlay_text_len { 0 => None, 1 => Some(InlayHighlight { diff --git a/crates/editor/src/hover_popover.rs b/crates/editor/src/hover_popover.rs index 79de3786a7befa7281f53ed1753ea2368361daca..f460b18bce30d23a9aad2da737e57fc7e474747a 100644 --- a/crates/editor/src/hover_popover.rs +++ b/crates/editor/src/hover_popover.rs @@ -796,6 +796,7 @@ mod tests { inlay_hint_cache::tests::{cached_hint_labels, visible_hint_labels}, link_go_to_definition::update_inlay_link_and_hover_points, test::editor_lsp_test_context::EditorLspTestContext, + InlayId, }; use collections::BTreeSet; use gpui::fonts::Weight; @@ -1462,29 +1463,19 @@ mod tests { .advance_clock(Duration::from_millis(HOVER_DELAY_MILLIS + 100)); cx.foreground().run_until_parked(); cx.update_editor(|editor, cx| { - let snapshot = editor.snapshot(cx); let hover_state = &editor.hover_state; assert!(hover_state.diagnostic_popover.is_none() && hover_state.info_popover.is_some()); let popover = hover_state.info_popover.as_ref().unwrap(); let buffer_snapshot = editor.buffer().update(cx, |buffer, cx| buffer.snapshot(cx)); - let entire_inlay_start = snapshot.display_point_to_inlay_offset( - inlay_range.start.to_display_point(&snapshot), - Bias::Left, + assert_eq!( + popover.symbol_range, + RangeInEditor::Inlay(InlayHighlight { + inlay: InlayId::Hint(0), + inlay_position: buffer_snapshot.anchor_at(inlay_range.start, Bias::Right), + range: ": ".len()..": ".len() + new_type_label.len(), + }), + "Popover range should match the new type label part" ); - - let expected_new_type_label_start = InlayOffset(entire_inlay_start.0 + ": ".len()); - // TODO kb - // assert_eq!( - // popover.symbol_range, - // RangeInEditor::Inlay(InlayRange { - // inlay_position: buffer_snapshot.anchor_at(inlay_range.start, Bias::Right), - // highlight_start: expected_new_type_label_start, - // highlight_end: InlayOffset( - // expected_new_type_label_start.0 + new_type_label.len() - // ), - // }), - // "Popover range should match the new type label part" - // ); assert_eq!( popover .rendered_content @@ -1529,27 +1520,20 @@ mod tests { .advance_clock(Duration::from_millis(HOVER_DELAY_MILLIS + 100)); cx.foreground().run_until_parked(); cx.update_editor(|editor, cx| { - let snapshot = editor.snapshot(cx); let hover_state = &editor.hover_state; assert!(hover_state.diagnostic_popover.is_none() && hover_state.info_popover.is_some()); let popover = hover_state.info_popover.as_ref().unwrap(); let buffer_snapshot = editor.buffer().update(cx, |buffer, cx| buffer.snapshot(cx)); - let entire_inlay_start = snapshot.display_point_to_inlay_offset( - inlay_range.start.to_display_point(&snapshot), - Bias::Left, + assert_eq!( + popover.symbol_range, + RangeInEditor::Inlay(InlayHighlight { + inlay: InlayId::Hint(0), + inlay_position: buffer_snapshot.anchor_at(inlay_range.start, Bias::Right), + range: ": ".len() + new_type_label.len() + "<".len() + ..": ".len() + new_type_label.len() + "<".len() + struct_label.len(), + }), + "Popover range should match the struct label part" ); - let expected_struct_label_start = - InlayOffset(entire_inlay_start.0 + ": ".len() + new_type_label.len() + "<".len()); - // TODO kb - // assert_eq!( - // popover.symbol_range, - // RangeInEditor::Inlay(InlayRange { - // inlay_position: buffer_snapshot.anchor_at(inlay_range.start, Bias::Right), - // highlight_start: expected_struct_label_start, - // highlight_end: InlayOffset(expected_struct_label_start.0 + struct_label.len()), - // }), - // "Popover range should match the struct label part" - // ); assert_eq!( popover .rendered_content diff --git a/crates/editor/src/link_go_to_definition.rs b/crates/editor/src/link_go_to_definition.rs index 581bda7e58c78070ebeca40485fe45d3e9ed93bb..3de6fb872e5583f3d51f96c43df6bf47b2c8dc49 100644 --- a/crates/editor/src/link_go_to_definition.rs +++ b/crates/editor/src/link_go_to_definition.rs @@ -1196,22 +1196,17 @@ mod tests { cx.update_editor(|editor, cx| { let snapshot = editor.snapshot(cx); let actual_ranges = snapshot - .text_highlight_ranges::() + .inlay_highlight_ranges::() .map(|ranges| ranges.as_ref().clone().1) .unwrap_or_default(); let buffer_snapshot = editor.buffer().update(cx, |buffer, cx| buffer.snapshot(cx)); - let expected_highlight_start = snapshot.display_point_to_inlay_offset( - inlay_range.start.to_display_point(&snapshot), - Bias::Left, - ); - // TODO kb - // let expected_ranges = vec![InlayRange { - // inlay_position: buffer_snapshot.anchor_at(inlay_range.start, Bias::Right), - // highlight_start: expected_highlight_start, - // highlight_end: InlayOffset(expected_highlight_start.0 + hint_label.len()), - // }]; - // assert_set_eq!(actual_ranges, expected_ranges); + let expected_ranges = vec![InlayHighlight { + inlay: InlayId::Hint(0), + inlay_position: buffer_snapshot.anchor_at(inlay_range.start, Bias::Right), + range: 0..hint_label.len(), + }]; + assert_set_eq!(actual_ranges, expected_ranges); }); // Unpress cmd causes highlight to go away