This commit is contained in:
Nathan Sobo 2023-11-02 22:56:04 -06:00
parent a731f8fb1e
commit f3b8a9d8c2
26 changed files with 1782 additions and 1665 deletions

View file

@ -170,170 +170,173 @@ pub fn update_inlay_link_and_hover_points(
shift_held: bool,
cx: &mut ViewContext<'_, Editor>,
) {
let hovered_offset = if point_for_position.column_overshoot_after_line_end == 0 {
Some(snapshot.display_point_to_inlay_offset(point_for_position.exact_unclipped, Bias::Left))
} else {
None
};
let mut go_to_definition_updated = false;
let mut hover_updated = false;
if let Some(hovered_offset) = hovered_offset {
let buffer_snapshot = editor.buffer().read(cx).snapshot(cx);
let previous_valid_anchor = buffer_snapshot.anchor_at(
point_for_position.previous_valid.to_point(snapshot),
Bias::Left,
);
let next_valid_anchor = buffer_snapshot.anchor_at(
point_for_position.next_valid.to_point(snapshot),
Bias::Right,
);
if let Some(hovered_hint) = editor
.visible_inlay_hints(cx)
.into_iter()
.skip_while(|hint| {
hint.position
.cmp(&previous_valid_anchor, &buffer_snapshot)
.is_lt()
})
.take_while(|hint| {
hint.position
.cmp(&next_valid_anchor, &buffer_snapshot)
.is_le()
})
.max_by_key(|hint| hint.id)
{
let inlay_hint_cache = editor.inlay_hint_cache();
let excerpt_id = previous_valid_anchor.excerpt_id;
if let Some(cached_hint) = inlay_hint_cache.hint_by_id(excerpt_id, hovered_hint.id) {
match cached_hint.resolve_state {
ResolveState::CanResolve(_, _) => {
if let Some(buffer_id) = previous_valid_anchor.buffer_id {
inlay_hint_cache.spawn_hint_resolve(
buffer_id,
excerpt_id,
hovered_hint.id,
cx,
);
}
}
ResolveState::Resolved => {
let mut extra_shift_left = 0;
let mut extra_shift_right = 0;
if cached_hint.padding_left {
extra_shift_left += 1;
extra_shift_right += 1;
}
if cached_hint.padding_right {
extra_shift_right += 1;
}
match cached_hint.label {
project::InlayHintLabel::String(_) => {
if let Some(tooltip) = cached_hint.tooltip {
hover_popover::hover_at_inlay(
editor,
InlayHover {
excerpt: excerpt_id,
tooltip: match tooltip {
InlayHintTooltip::String(text) => HoverBlock {
text,
kind: HoverBlockKind::PlainText,
},
InlayHintTooltip::MarkupContent(content) => {
HoverBlock {
text: content.value,
kind: content.kind,
}
}
},
range: InlayHighlight {
inlay: hovered_hint.id,
inlay_position: hovered_hint.position,
range: extra_shift_left
..hovered_hint.text.len() + extra_shift_right,
},
},
cx,
);
hover_updated = true;
}
}
project::InlayHintLabel::LabelParts(label_parts) => {
let hint_start =
snapshot.anchor_to_inlay_offset(hovered_hint.position);
if let Some((hovered_hint_part, part_range)) =
hover_popover::find_hovered_hint_part(
label_parts,
hint_start,
hovered_offset,
)
{
let highlight_start =
(part_range.start - hint_start).0 + extra_shift_left;
let highlight_end =
(part_range.end - hint_start).0 + extra_shift_right;
let highlight = InlayHighlight {
inlay: hovered_hint.id,
inlay_position: hovered_hint.position,
range: highlight_start..highlight_end,
};
if let Some(tooltip) = hovered_hint_part.tooltip {
hover_popover::hover_at_inlay(
editor,
InlayHover {
excerpt: excerpt_id,
tooltip: match tooltip {
InlayHintLabelPartTooltip::String(text) => {
HoverBlock {
text,
kind: HoverBlockKind::PlainText,
}
}
InlayHintLabelPartTooltip::MarkupContent(
content,
) => HoverBlock {
text: content.value,
kind: content.kind,
},
},
range: highlight.clone(),
},
cx,
);
hover_updated = true;
}
if let Some((language_server_id, location)) =
hovered_hint_part.location
{
go_to_definition_updated = true;
update_go_to_definition_link(
editor,
Some(GoToDefinitionTrigger::InlayHint(
highlight,
location,
language_server_id,
)),
cmd_held,
shift_held,
cx,
);
}
}
}
};
}
ResolveState::Resolving => {}
}
}
}
}
if !go_to_definition_updated {
update_go_to_definition_link(editor, None, cmd_held, shift_held, cx);
}
if !hover_updated {
hover_popover::hover_at(editor, None, cx);
}
todo!("old implementation below")
}
// ) {
// let hovered_offset = if point_for_position.column_overshoot_after_line_end == 0 {
// Some(snapshot.display_point_to_inlay_offset(point_for_position.exact_unclipped, Bias::Left))
// } else {
// None
// };
// let mut go_to_definition_updated = false;
// let mut hover_updated = false;
// if let Some(hovered_offset) = hovered_offset {
// let buffer_snapshot = editor.buffer().read(cx).snapshot(cx);
// let previous_valid_anchor = buffer_snapshot.anchor_at(
// point_for_position.previous_valid.to_point(snapshot),
// Bias::Left,
// );
// let next_valid_anchor = buffer_snapshot.anchor_at(
// point_for_position.next_valid.to_point(snapshot),
// Bias::Right,
// );
// if let Some(hovered_hint) = editor
// .visible_inlay_hints(cx)
// .into_iter()
// .skip_while(|hint| {
// hint.position
// .cmp(&previous_valid_anchor, &buffer_snapshot)
// .is_lt()
// })
// .take_while(|hint| {
// hint.position
// .cmp(&next_valid_anchor, &buffer_snapshot)
// .is_le()
// })
// .max_by_key(|hint| hint.id)
// {
// let inlay_hint_cache = editor.inlay_hint_cache();
// let excerpt_id = previous_valid_anchor.excerpt_id;
// if let Some(cached_hint) = inlay_hint_cache.hint_by_id(excerpt_id, hovered_hint.id) {
// match cached_hint.resolve_state {
// ResolveState::CanResolve(_, _) => {
// if let Some(buffer_id) = previous_valid_anchor.buffer_id {
// inlay_hint_cache.spawn_hint_resolve(
// buffer_id,
// excerpt_id,
// hovered_hint.id,
// cx,
// );
// }
// }
// ResolveState::Resolved => {
// let mut extra_shift_left = 0;
// let mut extra_shift_right = 0;
// if cached_hint.padding_left {
// extra_shift_left += 1;
// extra_shift_right += 1;
// }
// if cached_hint.padding_right {
// extra_shift_right += 1;
// }
// match cached_hint.label {
// project::InlayHintLabel::String(_) => {
// if let Some(tooltip) = cached_hint.tooltip {
// hover_popover::hover_at_inlay(
// editor,
// InlayHover {
// excerpt: excerpt_id,
// tooltip: match tooltip {
// InlayHintTooltip::String(text) => HoverBlock {
// text,
// kind: HoverBlockKind::PlainText,
// },
// InlayHintTooltip::MarkupContent(content) => {
// HoverBlock {
// text: content.value,
// kind: content.kind,
// }
// }
// },
// range: InlayHighlight {
// inlay: hovered_hint.id,
// inlay_position: hovered_hint.position,
// range: extra_shift_left
// ..hovered_hint.text.len() + extra_shift_right,
// },
// },
// cx,
// );
// hover_updated = true;
// }
// }
// project::InlayHintLabel::LabelParts(label_parts) => {
// let hint_start =
// snapshot.anchor_to_inlay_offset(hovered_hint.position);
// if let Some((hovered_hint_part, part_range)) =
// hover_popover::find_hovered_hint_part(
// label_parts,
// hint_start,
// hovered_offset,
// )
// {
// let highlight_start =
// (part_range.start - hint_start).0 + extra_shift_left;
// let highlight_end =
// (part_range.end - hint_start).0 + extra_shift_right;
// let highlight = InlayHighlight {
// inlay: hovered_hint.id,
// inlay_position: hovered_hint.position,
// range: highlight_start..highlight_end,
// };
// if let Some(tooltip) = hovered_hint_part.tooltip {
// hover_popover::hover_at_inlay(
// editor,
// InlayHover {
// excerpt: excerpt_id,
// tooltip: match tooltip {
// InlayHintLabelPartTooltip::String(text) => {
// HoverBlock {
// text,
// kind: HoverBlockKind::PlainText,
// }
// }
// InlayHintLabelPartTooltip::MarkupContent(
// content,
// ) => HoverBlock {
// text: content.value,
// kind: content.kind,
// },
// },
// range: highlight.clone(),
// },
// cx,
// );
// hover_updated = true;
// }
// if let Some((language_server_id, location)) =
// hovered_hint_part.location
// {
// go_to_definition_updated = true;
// update_go_to_definition_link(
// editor,
// Some(GoToDefinitionTrigger::InlayHint(
// highlight,
// location,
// language_server_id,
// )),
// cmd_held,
// shift_held,
// cx,
// );
// }
// }
// }
// };
// }
// ResolveState::Resolving => {}
// }
// }
// }
// }
// if !go_to_definition_updated {
// update_go_to_definition_link(editor, None, cmd_held, shift_held, cx);
// }
// if !hover_updated {
// hover_popover::hover_at(editor, None, cx);
// }
// }
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum LinkDefinitionKind {
@ -570,34 +573,35 @@ fn go_to_fetched_definition_of_kind(
split: bool,
cx: &mut ViewContext<Editor>,
) {
let cached_definitions = editor.link_go_to_definition_state.definitions.clone();
hide_link_definition(editor, cx);
let cached_definitions_kind = editor.link_go_to_definition_state.kind;
todo!();
// let cached_definitions = editor.link_go_to_definition_state.definitions.clone();
// hide_link_definition(editor, cx);
// let cached_definitions_kind = editor.link_go_to_definition_state.kind;
let is_correct_kind = cached_definitions_kind == Some(kind);
if !cached_definitions.is_empty() && is_correct_kind {
if !editor.focused {
cx.focus_self();
}
// let is_correct_kind = cached_definitions_kind == Some(kind);
// if !cached_definitions.is_empty() && is_correct_kind {
// if !editor.focused {
// cx.focus_self();
// }
editor.navigate_to_definitions(cached_definitions, split, cx);
} else {
editor.select(
SelectPhase::Begin {
position: point.next_valid,
add: false,
click_count: 1,
},
cx,
);
// editor.navigate_to_definitions(cached_definitions, split, cx);
// } else {
// editor.select(
// SelectPhase::Begin {
// position: point.next_valid,
// add: false,
// click_count: 1,
// },
// cx,
// );
if point.as_valid().is_some() {
match kind {
LinkDefinitionKind::Symbol => editor.go_to_definition(&Default::default(), cx),
LinkDefinitionKind::Type => editor.go_to_type_definition(&Default::default(), cx),
}
}
}
// if point.as_valid().is_some() {
// match kind {
// LinkDefinitionKind::Symbol => editor.go_to_definition(&Default::default(), cx),
// LinkDefinitionKind::Type => editor.go_to_type_definition(&Default::default(), cx),
// }
// }
// }
}
// #[cfg(test)]