From 79f376d75226a1c23ca43576fc758b46b03ebe64 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 11 Jul 2025 10:26:06 -0400 Subject: [PATCH] Clean up inlay hint hover logic --- crates/editor/src/element.rs | 3 +- crates/editor/src/hover_links.rs | 46 ++++++++++-------------------- crates/editor/src/hover_popover.rs | 2 +- 3 files changed, 17 insertions(+), 34 deletions(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index d4cd126f32..a4b2ceb5de 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -1238,8 +1238,7 @@ impl EditorElement { hover_at(editor, Some(anchor), window, cx); Self::update_visible_cursor(editor, point, position_map, window, cx); } else { - // Don't call hover_at with None when we're over an inlay - // The inlay hover is already handled by update_hovered_link + hover_at(editor, None, window, cx); } } else { editor.hide_hovered_link(cx); diff --git a/crates/editor/src/hover_links.rs b/crates/editor/src/hover_links.rs index 68e4c60c10..651a6fefb9 100644 --- a/crates/editor/src/hover_links.rs +++ b/crates/editor/src/hover_links.rs @@ -124,28 +124,13 @@ impl Editor { ) { 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() { Some(point) => { + if !hovered_link_modifier || self.has_pending_selection() { + self.hide_hovered_link(cx); + return; + } + let trigger_point = TriggerPoint::Text( snapshot .buffer_snapshot @@ -155,8 +140,15 @@ impl Editor { show_link_definition(modifiers.shift, self, trigger_point, snapshot, window, cx); } None => { - // This case should not be reached anymore as we handle it above - unreachable!("Invalid position should have been handled earlier"); + update_inlay_link_and_hover_points( + 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, cx, ); - // Don't set hover_updated during resolution to prevent empty tooltip - // hover_updated = true; } false // Don't process unresolved hints } ResolveState::Resolved => true, - ResolveState::Resolving => { - // Don't set hover_updated during resolution to prevent empty tooltip - // hover_updated = true; - false // Don't process further - } + ResolveState::Resolving => false, }; if should_process_hint { @@ -392,7 +378,6 @@ pub fn update_inlay_link_and_hover_points( } } 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) let _hint_start = 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; } diff --git a/crates/editor/src/hover_popover.rs b/crates/editor/src/hover_popover.rs index 39ae7c7bde..cae4789535 100644 --- a/crates/editor/src/hover_popover.rs +++ b/crates/editor/src/hover_popover.rs @@ -110,7 +110,7 @@ pub fn find_hovered_hint_part( let mut part_start = hint_start; for part in label_parts { let part_len = part.value.chars().count(); - if hovered_character >= part_len { + if hovered_character > part_len { hovered_character -= part_len; part_start.0 += part_len; } else {