parent
e7c6f228d5
commit
e4963e70cc
3 changed files with 29 additions and 40 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 {
|
||||||
// Don't call hover_at with None when we're over an inlay
|
// When over an inlay or invalid position, clear any existing hover
|
||||||
// The inlay hover is already handled by update_hovered_link
|
hover_at(editor, None, window, cx);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
editor.hide_hovered_link(cx);
|
editor.hide_hovered_link(cx);
|
||||||
|
|
|
@ -303,12 +303,13 @@ 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
|
||||||
let found_inlay = visible_hints.into_iter().find(|inlay| {
|
if let Some(hovered_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;
|
||||||
|
@ -319,9 +320,7 @@ 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;
|
||||||
|
|
||||||
|
@ -387,20 +386,18 @@ 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) => {
|
||||||
// Find which specific part is being hovered
|
// VS Code shows hover for the meaningful part regardless of where you hover
|
||||||
let hint_start =
|
// Find the first part with actual hover information (tooltip or location)
|
||||||
|
let _hint_start =
|
||||||
snapshot.anchor_to_inlay_offset(hovered_inlay.position);
|
snapshot.anchor_to_inlay_offset(hovered_inlay.position);
|
||||||
|
let mut part_offset = 0;
|
||||||
|
|
||||||
if let Some((part, part_range)) = hover_popover::find_hovered_hint_part(
|
for part in label_parts {
|
||||||
label_parts,
|
let part_len = part.value.chars().count();
|
||||||
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
|
||||||
|
@ -436,6 +433,7 @@ 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()
|
||||||
{
|
{
|
||||||
|
@ -460,8 +458,9 @@ 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();
|
||||||
|
@ -674,28 +673,27 @@ 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,12 +193,6 @@ 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>(
|
||||||
|
@ -562,19 +556,16 @@ fn same_info_hover(editor: &Editor, snapshot: &EditorSnapshot, anchor: Anchor) -
|
||||||
.info_popovers
|
.info_popovers
|
||||||
.iter()
|
.iter()
|
||||||
.any(|InfoPopover { symbol_range, .. }| {
|
.any(|InfoPopover { symbol_range, .. }| {
|
||||||
match symbol_range {
|
symbol_range
|
||||||
RangeInEditor::Text(range) => {
|
.as_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)
|
||||||
}
|
})
|
||||||
RangeInEditor::Inlay(_) => {
|
.unwrap_or(false)
|
||||||
// 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