Attempt to fix hover
This commit is contained in:
parent
0d6232b373
commit
e7c6f228d5
3 changed files with 40 additions and 29 deletions
|
@ -1238,8 +1238,8 @@ 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 {
|
||||||
// When over an inlay or invalid position, clear any existing hover
|
// 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);
|
||||||
|
|
|
@ -303,13 +303,12 @@ pub fn update_inlay_link_and_hover_points(
|
||||||
let hovered_offset = snapshot.display_point_to_inlay_offset(clipped_point, Bias::Left);
|
let hovered_offset = snapshot.display_point_to_inlay_offset(clipped_point, Bias::Left);
|
||||||
|
|
||||||
let mut go_to_definition_updated = false;
|
let mut go_to_definition_updated = false;
|
||||||
let mut hover_updated = false;
|
|
||||||
|
|
||||||
// Get all visible inlay hints
|
// Get all visible inlay hints
|
||||||
let visible_hints = editor.visible_inlay_hints(cx);
|
let visible_hints = editor.visible_inlay_hints(cx);
|
||||||
|
|
||||||
// Find if we're hovering over an inlay hint
|
// Find if we're hovering over an inlay hint
|
||||||
if let Some(hovered_inlay) = visible_hints.into_iter().find(|inlay| {
|
let found_inlay = visible_hints.into_iter().find(|inlay| {
|
||||||
// Only process hint inlays
|
// Only process hint inlays
|
||||||
if !matches!(inlay.id, InlayId::Hint(_)) {
|
if !matches!(inlay.id, InlayId::Hint(_)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -320,7 +319,9 @@ pub fn update_inlay_link_and_hover_points(
|
||||||
let inlay_end = InlayOffset(inlay_start.0 + inlay.text.len());
|
let inlay_end = InlayOffset(inlay_start.0 + inlay.text.len());
|
||||||
|
|
||||||
hovered_offset >= inlay_start && hovered_offset < inlay_end
|
hovered_offset >= inlay_start && hovered_offset < inlay_end
|
||||||
}) {
|
});
|
||||||
|
|
||||||
|
if let Some(hovered_inlay) = found_inlay {
|
||||||
let inlay_hint_cache = editor.inlay_hint_cache();
|
let inlay_hint_cache = editor.inlay_hint_cache();
|
||||||
let excerpt_id = hovered_inlay.position.excerpt_id;
|
let excerpt_id = hovered_inlay.position.excerpt_id;
|
||||||
|
|
||||||
|
@ -386,18 +387,20 @@ pub fn update_inlay_link_and_hover_points(
|
||||||
window,
|
window,
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
hover_updated = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
project::InlayHintLabel::LabelParts(label_parts) => {
|
project::InlayHintLabel::LabelParts(label_parts) => {
|
||||||
// VS Code shows hover for the meaningful part regardless of where you hover
|
// Find which specific part is being hovered
|
||||||
// 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);
|
||||||
let mut part_offset = 0;
|
|
||||||
|
|
||||||
for part in label_parts {
|
if let Some((part, part_range)) = hover_popover::find_hovered_hint_part(
|
||||||
let part_len = part.value.chars().count();
|
label_parts,
|
||||||
|
hint_start,
|
||||||
|
hovered_offset,
|
||||||
|
) {
|
||||||
|
let part_offset = (part_range.start - hint_start).0;
|
||||||
|
let part_len = (part_range.end - part_range.start).0;
|
||||||
|
|
||||||
if part.tooltip.is_some() || part.location.is_some() {
|
if part.tooltip.is_some() || part.location.is_some() {
|
||||||
// Found the meaningful part - show hover for it
|
// Found the meaningful part - show hover for it
|
||||||
|
@ -433,7 +436,6 @@ pub fn update_inlay_link_and_hover_points(
|
||||||
window,
|
window,
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
hover_updated = true;
|
|
||||||
} else if let Some((_language_server_id, location)) =
|
} else if let Some((_language_server_id, location)) =
|
||||||
part.location.clone()
|
part.location.clone()
|
||||||
{
|
{
|
||||||
|
@ -458,9 +460,8 @@ pub fn update_inlay_link_and_hover_points(
|
||||||
window,
|
window,
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
hover_updated = true;
|
|
||||||
|
|
||||||
// Now perform the "Go to Definition" flow to get hover documentation
|
// Now perform the "Go to Definition" flow to get hover documentation
|
||||||
|
// Prepare data needed for the async task
|
||||||
if let Some(project) = editor.project.clone() {
|
if let Some(project) = editor.project.clone() {
|
||||||
let highlight = highlight.clone();
|
let highlight = highlight.clone();
|
||||||
let hint_value = part.value.clone();
|
let hint_value = part.value.clone();
|
||||||
|
@ -673,27 +674,28 @@ pub fn update_inlay_link_and_hover_points(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Found and processed the meaningful part
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
part_offset += part_len;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// No inlay is being hovered, hide any existing inlay hover
|
||||||
|
if editor
|
||||||
|
.hover_state
|
||||||
|
.info_popovers
|
||||||
|
.iter()
|
||||||
|
.any(|popover| matches!(popover.symbol_range, RangeInEditor::Inlay(_)))
|
||||||
|
{
|
||||||
|
hover_popover::hide_hover(editor, cx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !go_to_definition_updated {
|
if !go_to_definition_updated {
|
||||||
editor.hide_hovered_link(cx)
|
editor.hide_hovered_link(cx)
|
||||||
}
|
}
|
||||||
if !hover_updated {
|
|
||||||
hover_popover::hover_at(editor, None, window, cx);
|
|
||||||
editor.clear_background_highlights::<HoverState>(cx);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn show_link_definition(
|
pub fn show_link_definition(
|
||||||
|
|
|
@ -193,6 +193,12 @@ pub fn hover_at_inlay(
|
||||||
};
|
};
|
||||||
|
|
||||||
this.update(cx, |this, cx| {
|
this.update(cx, |this, cx| {
|
||||||
|
// Check if we should still show this hover (haven't moved to different location)
|
||||||
|
if this.hover_state.info_task.is_none() {
|
||||||
|
// Task was cancelled, don't show the hover
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Highlight the inlay using background highlighting
|
// Highlight the inlay using background highlighting
|
||||||
let highlight_range = inlay_hover.range.clone();
|
let highlight_range = inlay_hover.range.clone();
|
||||||
this.highlight_inlays::<HoverState>(
|
this.highlight_inlays::<HoverState>(
|
||||||
|
@ -556,16 +562,19 @@ fn same_info_hover(editor: &Editor, snapshot: &EditorSnapshot, anchor: Anchor) -
|
||||||
.info_popovers
|
.info_popovers
|
||||||
.iter()
|
.iter()
|
||||||
.any(|InfoPopover { symbol_range, .. }| {
|
.any(|InfoPopover { symbol_range, .. }| {
|
||||||
symbol_range
|
match symbol_range {
|
||||||
.as_text_range()
|
RangeInEditor::Text(range) => {
|
||||||
.map(|range| {
|
|
||||||
let hover_range = range.to_offset(&snapshot.buffer_snapshot);
|
let hover_range = range.to_offset(&snapshot.buffer_snapshot);
|
||||||
let offset = anchor.to_offset(&snapshot.buffer_snapshot);
|
let offset = anchor.to_offset(&snapshot.buffer_snapshot);
|
||||||
// LSP returns a hover result for the end index of ranges that should be hovered, so we need to
|
// LSP returns a hover result for the end index of ranges that should be hovered, so we need to
|
||||||
// use an inclusive range here to check if we should dismiss the popover
|
// use an inclusive range here to check if we should dismiss the popover
|
||||||
(hover_range.start..=hover_range.end).contains(&offset)
|
(hover_range.start..=hover_range.end).contains(&offset)
|
||||||
})
|
}
|
||||||
.unwrap_or(false)
|
RangeInEditor::Inlay(_) => {
|
||||||
|
// If we have an inlay hover and we're checking a text position, they're not the same
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue