Clean up inlay hint hover logic

This commit is contained in:
Richard Feldman 2025-07-11 10:26:06 -04:00
parent fe8b3fe53d
commit 79f376d752
No known key found for this signature in database
3 changed files with 17 additions and 34 deletions

View file

@ -1238,8 +1238,7 @@ impl EditorElement {
hover_at(editor, Some(anchor), window, cx); hover_at(editor, Some(anchor), window, cx);
Self::update_visible_cursor(editor, point, position_map, window, cx); Self::update_visible_cursor(editor, point, position_map, window, cx);
} else { } else {
// Don't call hover_at with None when we're over an inlay hover_at(editor, None, window, cx);
// The inlay hover is already handled by update_hovered_link
} }
} else { } else {
editor.hide_hovered_link(cx); editor.hide_hovered_link(cx);

View file

@ -124,28 +124,13 @@ impl Editor {
) { ) {
let hovered_link_modifier = Editor::multi_cursor_modifier(false, &modifiers, cx); let hovered_link_modifier = Editor::multi_cursor_modifier(false, &modifiers, cx);
// Allow inlay hover points to be updated even without modifier key
if point_for_position.as_valid().is_none() {
// Hovering over inlay - check for hover tooltips
update_inlay_link_and_hover_points(
snapshot,
point_for_position,
self,
hovered_link_modifier,
modifiers.shift,
window,
cx,
);
return;
}
if !hovered_link_modifier || self.has_pending_selection() {
self.hide_hovered_link(cx);
return;
}
match point_for_position.as_valid() { match point_for_position.as_valid() {
Some(point) => { Some(point) => {
if !hovered_link_modifier || self.has_pending_selection() {
self.hide_hovered_link(cx);
return;
}
let trigger_point = TriggerPoint::Text( let trigger_point = TriggerPoint::Text(
snapshot snapshot
.buffer_snapshot .buffer_snapshot
@ -155,8 +140,15 @@ impl Editor {
show_link_definition(modifiers.shift, self, trigger_point, snapshot, window, cx); show_link_definition(modifiers.shift, self, trigger_point, snapshot, window, cx);
} }
None => { None => {
// This case should not be reached anymore as we handle it above update_inlay_link_and_hover_points(
unreachable!("Invalid position should have been handled earlier"); snapshot,
point_for_position,
self,
hovered_link_modifier,
modifiers.shift,
window,
cx,
);
} }
} }
} }
@ -337,17 +329,11 @@ pub fn update_inlay_link_and_hover_points(
window, window,
cx, cx,
); );
// Don't set hover_updated during resolution to prevent empty tooltip
// hover_updated = true;
} }
false // Don't process unresolved hints false // Don't process unresolved hints
} }
ResolveState::Resolved => true, ResolveState::Resolved => true,
ResolveState::Resolving => { ResolveState::Resolving => false,
// Don't set hover_updated during resolution to prevent empty tooltip
// hover_updated = true;
false // Don't process further
}
}; };
if should_process_hint { if should_process_hint {
@ -392,7 +378,6 @@ pub fn update_inlay_link_and_hover_points(
} }
} }
project::InlayHintLabel::LabelParts(label_parts) => { project::InlayHintLabel::LabelParts(label_parts) => {
// VS Code shows hover for the meaningful part regardless of where you hover
// Find the first part with actual hover information (tooltip or location) // Find the first part with actual hover information (tooltip or location)
let _hint_start = let _hint_start =
snapshot.anchor_to_inlay_offset(hovered_inlay.position); snapshot.anchor_to_inlay_offset(hovered_inlay.position);
@ -609,7 +594,6 @@ pub fn update_inlay_link_and_hover_points(
} }
} }
// Found and processed the meaningful part
break; break;
} }

View file

@ -110,7 +110,7 @@ pub fn find_hovered_hint_part(
let mut part_start = hint_start; let mut part_start = hint_start;
for part in label_parts { for part in label_parts {
let part_len = part.value.chars().count(); let part_len = part.value.chars().count();
if hovered_character >= part_len { if hovered_character > part_len {
hovered_character -= part_len; hovered_character -= part_len;
part_start.0 += part_len; part_start.0 += part_len;
} else { } else {