Extract resolve_hint
Co-authored-by: Cole Miller <cole@zed.dev>
This commit is contained in:
parent
a61e478152
commit
17f7312fc0
2 changed files with 182 additions and 137 deletions
|
@ -121,6 +121,22 @@ impl Editor {
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) {
|
) {
|
||||||
let hovered_link_modifier = Editor::multi_cursor_modifier(false, &modifiers, cx);
|
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() {
|
if !hovered_link_modifier || self.has_pending_selection() {
|
||||||
self.hide_hovered_link(cx);
|
self.hide_hovered_link(cx);
|
||||||
return;
|
return;
|
||||||
|
@ -137,15 +153,7 @@ impl Editor {
|
||||||
show_link_definition(modifiers.shift, self, trigger_point, snapshot, window, cx);
|
show_link_definition(modifiers.shift, self, trigger_point, snapshot, window, cx);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
update_inlay_link_and_hover_points(
|
// This case is now handled above
|
||||||
snapshot,
|
|
||||||
point_for_position,
|
|
||||||
self,
|
|
||||||
hovered_link_modifier,
|
|
||||||
modifiers.shift,
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -319,8 +327,17 @@ pub fn update_inlay_link_and_hover_points(
|
||||||
let inlay_hint_cache = editor.inlay_hint_cache();
|
let inlay_hint_cache = editor.inlay_hint_cache();
|
||||||
let excerpt_id = previous_valid_anchor.excerpt_id;
|
let excerpt_id = previous_valid_anchor.excerpt_id;
|
||||||
if let Some(cached_hint) = inlay_hint_cache.hint_by_id(excerpt_id, hovered_hint.id) {
|
if let Some(cached_hint) = inlay_hint_cache.hint_by_id(excerpt_id, hovered_hint.id) {
|
||||||
match cached_hint.resolve_state {
|
// Check if we should process this hint for hover
|
||||||
|
let should_process_hint = match cached_hint.resolve_state {
|
||||||
ResolveState::CanResolve(_, _) => {
|
ResolveState::CanResolve(_, _) => {
|
||||||
|
// Check if the hint already has the data we need (tooltip in label parts)
|
||||||
|
if let project::InlayHintLabel::LabelParts(label_parts) = &cached_hint.label
|
||||||
|
{
|
||||||
|
let has_tooltip_parts =
|
||||||
|
label_parts.iter().any(|part| part.tooltip.is_some());
|
||||||
|
if has_tooltip_parts {
|
||||||
|
true // Process the hint
|
||||||
|
} else {
|
||||||
if let Some(buffer_id) = previous_valid_anchor.buffer_id {
|
if let Some(buffer_id) = previous_valid_anchor.buffer_id {
|
||||||
inlay_hint_cache.spawn_hint_resolve(
|
inlay_hint_cache.spawn_hint_resolve(
|
||||||
buffer_id,
|
buffer_id,
|
||||||
|
@ -330,8 +347,30 @@ pub fn update_inlay_link_and_hover_points(
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
false // Don't process further
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if let Some(buffer_id) = previous_valid_anchor.buffer_id {
|
||||||
|
inlay_hint_cache.spawn_hint_resolve(
|
||||||
|
buffer_id,
|
||||||
|
excerpt_id,
|
||||||
|
hovered_hint.id,
|
||||||
|
window,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
false // Don't process further
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ResolveState::Resolved => {
|
ResolveState::Resolved => {
|
||||||
|
true // Process the hint
|
||||||
|
}
|
||||||
|
ResolveState::Resolving => {
|
||||||
|
false // Don't process yet
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if should_process_hint {
|
||||||
let mut extra_shift_left = 0;
|
let mut extra_shift_left = 0;
|
||||||
let mut extra_shift_right = 0;
|
let mut extra_shift_right = 0;
|
||||||
if cached_hint.padding_left {
|
if cached_hint.padding_left {
|
||||||
|
@ -373,8 +412,7 @@ pub fn update_inlay_link_and_hover_points(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
project::InlayHintLabel::LabelParts(label_parts) => {
|
project::InlayHintLabel::LabelParts(label_parts) => {
|
||||||
let hint_start =
|
let hint_start = snapshot.anchor_to_inlay_offset(hovered_hint.position);
|
||||||
snapshot.anchor_to_inlay_offset(hovered_hint.position);
|
|
||||||
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,
|
||||||
|
@ -419,9 +457,7 @@ pub fn update_inlay_link_and_hover_points(
|
||||||
if let Some((language_server_id, location)) =
|
if let Some((language_server_id, location)) =
|
||||||
hovered_hint_part.location
|
hovered_hint_part.location
|
||||||
{
|
{
|
||||||
if secondary_held
|
if secondary_held && !editor.has_pending_nonempty_selection() {
|
||||||
&& !editor.has_pending_nonempty_selection()
|
|
||||||
{
|
|
||||||
go_to_definition_updated = true;
|
go_to_definition_updated = true;
|
||||||
show_link_definition(
|
show_link_definition(
|
||||||
shift_held,
|
shift_held,
|
||||||
|
@ -441,8 +477,6 @@ pub fn update_inlay_link_and_hover_points(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
ResolveState::Resolving => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ use clock::Global;
|
||||||
use futures::future;
|
use futures::future;
|
||||||
use gpui::{AppContext as _, AsyncApp, Context, Entity, Task, Window};
|
use gpui::{AppContext as _, AsyncApp, Context, Entity, Task, Window};
|
||||||
use language::{Buffer, BufferSnapshot, language_settings::InlayHintKind};
|
use language::{Buffer, BufferSnapshot, language_settings::InlayHintKind};
|
||||||
|
use lsp::LanguageServerId;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use project::{InlayHint, ResolveState};
|
use project::{InlayHint, ResolveState};
|
||||||
|
|
||||||
|
@ -622,10 +623,25 @@ impl InlayHintCache {
|
||||||
let mut guard = excerpt_hints.write();
|
let mut guard = excerpt_hints.write();
|
||||||
if let Some(cached_hint) = guard.hints_by_id.get_mut(&id) {
|
if let Some(cached_hint) = guard.hints_by_id.get_mut(&id) {
|
||||||
if let ResolveState::CanResolve(server_id, _) = &cached_hint.resolve_state {
|
if let ResolveState::CanResolve(server_id, _) = &cached_hint.resolve_state {
|
||||||
let hint_to_resolve = cached_hint.clone();
|
|
||||||
let server_id = *server_id;
|
let server_id = *server_id;
|
||||||
|
let mut cached_hint = cached_hint.clone();
|
||||||
cached_hint.resolve_state = ResolveState::Resolving;
|
cached_hint.resolve_state = ResolveState::Resolving;
|
||||||
drop(guard);
|
drop(guard);
|
||||||
|
self.resolve_hint(server_id, buffer_id, cached_hint, window, cx)
|
||||||
|
.detach_and_log_err(cx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn resolve_hint(
|
||||||
|
&self,
|
||||||
|
server_id: LanguageServerId,
|
||||||
|
buffer_id: BufferId,
|
||||||
|
hint_to_resolve: InlayHint,
|
||||||
|
window: &mut Window,
|
||||||
|
cx: &mut Context<Editor>,
|
||||||
|
) -> Task<anyhow::Result<()>> {
|
||||||
cx.spawn_in(window, async move |editor, cx| {
|
cx.spawn_in(window, async move |editor, cx| {
|
||||||
let resolved_hint_task = editor.update(cx, |editor, cx| {
|
let resolved_hint_task = editor.update(cx, |editor, cx| {
|
||||||
let buffer = editor.buffer().read(cx).buffer(buffer_id)?;
|
let buffer = editor.buffer().read(cx).buffer(buffer_id)?;
|
||||||
|
@ -637,12 +653,9 @@ impl InlayHintCache {
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
if let Some(resolved_hint_task) = resolved_hint_task {
|
if let Some(resolved_hint_task) = resolved_hint_task {
|
||||||
let mut resolved_hint =
|
let mut resolved_hint = resolved_hint_task.await.context("hint resolve task")?;
|
||||||
resolved_hint_task.await.context("hint resolve task")?;
|
editor.update(cx, |editor, cx| {
|
||||||
editor.read_with(cx, |editor, _| {
|
if let Some(excerpt_hints) = editor.inlay_hint_cache.hints.get(&excerpt_id) {
|
||||||
if let Some(excerpt_hints) =
|
|
||||||
editor.inlay_hint_cache.hints.get(&excerpt_id)
|
|
||||||
{
|
|
||||||
let mut guard = excerpt_hints.write();
|
let mut guard = excerpt_hints.write();
|
||||||
if let Some(cached_hint) = guard.hints_by_id.get_mut(&id) {
|
if let Some(cached_hint) = guard.hints_by_id.get_mut(&id) {
|
||||||
if cached_hint.resolve_state == ResolveState::Resolving {
|
if cached_hint.resolve_state == ResolveState::Resolving {
|
||||||
|
@ -651,15 +664,13 @@ impl InlayHintCache {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Notify to trigger UI update
|
||||||
|
cx.notify();
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
|
|
||||||
anyhow::Ok(())
|
anyhow::Ok(())
|
||||||
})
|
})
|
||||||
.detach_and_log_err(cx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue