Better highlight hint ranges
This commit is contained in:
@@ -57,8 +57,6 @@ pub struct InlayHover {
|
|||||||
|
|
||||||
pub fn find_hovered_hint_part(
|
pub fn find_hovered_hint_part(
|
||||||
label_parts: Vec<InlayHintLabelPart>,
|
label_parts: Vec<InlayHintLabelPart>,
|
||||||
padding_left: bool,
|
|
||||||
padding_right: bool,
|
|
||||||
hint_range: Range<InlayOffset>,
|
hint_range: Range<InlayOffset>,
|
||||||
hovered_offset: InlayOffset,
|
hovered_offset: InlayOffset,
|
||||||
) -> Option<(InlayHintLabelPart, Range<InlayOffset>)> {
|
) -> Option<(InlayHintLabelPart, Range<InlayOffset>)> {
|
||||||
@@ -67,19 +65,11 @@ pub fn find_hovered_hint_part(
|
|||||||
let mut part_start = hint_range.start;
|
let mut part_start = hint_range.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 {
|
||||||
let mut part_end = InlayOffset(part_start.0 + part_len);
|
let part_end = InlayOffset(part_start.0 + part_len);
|
||||||
if padding_left {
|
|
||||||
part_start.0 += 1;
|
|
||||||
part_end.0 += 1;
|
|
||||||
}
|
|
||||||
if padding_right {
|
|
||||||
part_start.0 += 1;
|
|
||||||
part_end.0 += 1;
|
|
||||||
}
|
|
||||||
return Some((part, part_start..part_end));
|
return Some((part, part_start..part_end));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -165,11 +165,8 @@ pub fn update_inlay_link_and_hover_points(
|
|||||||
snapshot.display_point_to_inlay_offset(point_for_position.previous_valid, Bias::Left);
|
snapshot.display_point_to_inlay_offset(point_for_position.previous_valid, Bias::Left);
|
||||||
let hint_end_offset =
|
let hint_end_offset =
|
||||||
snapshot.display_point_to_inlay_offset(point_for_position.next_valid, Bias::Right);
|
snapshot.display_point_to_inlay_offset(point_for_position.next_valid, Bias::Right);
|
||||||
let offset_overshoot = point_for_position.column_overshoot_after_line_end as usize;
|
let hovered_offset = if point_for_position.column_overshoot_after_line_end == 0 {
|
||||||
let hovered_offset = if offset_overshoot == 0 {
|
|
||||||
Some(snapshot.display_point_to_inlay_offset(point_for_position.exact_unclipped, Bias::Left))
|
Some(snapshot.display_point_to_inlay_offset(point_for_position.exact_unclipped, Bias::Left))
|
||||||
} else if (hint_end_offset - hint_start_offset).0 >= offset_overshoot {
|
|
||||||
Some(InlayOffset(hint_start_offset.0 + offset_overshoot))
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
@@ -215,17 +212,18 @@ pub fn update_inlay_link_and_hover_points(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ResolveState::Resolved => {
|
ResolveState::Resolved => {
|
||||||
|
let mut actual_hint_start = hint_start_offset;
|
||||||
|
let mut actual_hint_end = hint_end_offset;
|
||||||
|
if cached_hint.padding_left {
|
||||||
|
actual_hint_start.0 += 1;
|
||||||
|
actual_hint_end.0 += 1;
|
||||||
|
}
|
||||||
|
if cached_hint.padding_right {
|
||||||
|
actual_hint_start.0 += 1;
|
||||||
|
actual_hint_end.0 += 1;
|
||||||
|
}
|
||||||
match cached_hint.label {
|
match cached_hint.label {
|
||||||
project::InlayHintLabel::String(_) => {
|
project::InlayHintLabel::String(_) => {
|
||||||
let mut highlight_start = hint_start_offset;
|
|
||||||
let mut highlight_end = hint_end_offset;
|
|
||||||
if cached_hint.padding_left {
|
|
||||||
highlight_start.0 += 1;
|
|
||||||
highlight_end.0 += 1;
|
|
||||||
}
|
|
||||||
if cached_hint.padding_right {
|
|
||||||
highlight_end.0 -= 1;
|
|
||||||
}
|
|
||||||
if let Some(tooltip) = cached_hint.tooltip {
|
if let Some(tooltip) = cached_hint.tooltip {
|
||||||
hover_popover::hover_at_inlay(
|
hover_popover::hover_at_inlay(
|
||||||
editor,
|
editor,
|
||||||
@@ -246,8 +244,8 @@ pub fn update_inlay_link_and_hover_points(
|
|||||||
triggered_from: hovered_offset,
|
triggered_from: hovered_offset,
|
||||||
range: InlayRange {
|
range: InlayRange {
|
||||||
inlay_position: hovered_hint.position,
|
inlay_position: hovered_hint.position,
|
||||||
highlight_start,
|
highlight_start: actual_hint_start,
|
||||||
highlight_end,
|
highlight_end: actual_hint_end,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
cx,
|
cx,
|
||||||
@@ -259,9 +257,7 @@ pub fn update_inlay_link_and_hover_points(
|
|||||||
if let Some((hovered_hint_part, part_range)) =
|
if let Some((hovered_hint_part, part_range)) =
|
||||||
hover_popover::find_hovered_hint_part(
|
hover_popover::find_hovered_hint_part(
|
||||||
label_parts,
|
label_parts,
|
||||||
cached_hint.padding_left,
|
actual_hint_start..actual_hint_end,
|
||||||
cached_hint.padding_right,
|
|
||||||
hint_start_offset..hint_end_offset,
|
|
||||||
hovered_offset,
|
hovered_offset,
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user