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>,
|
||||
) {
|
||||
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() {
|
||||
self.hide_hovered_link(cx);
|
||||
return;
|
||||
|
@ -137,15 +153,7 @@ impl Editor {
|
|||
show_link_definition(modifiers.shift, self, trigger_point, snapshot, window, cx);
|
||||
}
|
||||
None => {
|
||||
update_inlay_link_and_hover_points(
|
||||
snapshot,
|
||||
point_for_position,
|
||||
self,
|
||||
hovered_link_modifier,
|
||||
modifiers.shift,
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
// This case is now handled above
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -319,8 +327,17 @@ pub fn update_inlay_link_and_hover_points(
|
|||
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 {
|
||||
// Check if we should process this hint for hover
|
||||
let should_process_hint = match cached_hint.resolve_state {
|
||||
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 {
|
||||
inlay_hint_cache.spawn_hint_resolve(
|
||||
buffer_id,
|
||||
|
@ -330,8 +347,30 @@ pub fn update_inlay_link_and_hover_points(
|
|||
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 => {
|
||||
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_right = 0;
|
||||
if cached_hint.padding_left {
|
||||
|
@ -373,8 +412,7 @@ pub fn update_inlay_link_and_hover_points(
|
|||
}
|
||||
}
|
||||
project::InlayHintLabel::LabelParts(label_parts) => {
|
||||
let hint_start =
|
||||
snapshot.anchor_to_inlay_offset(hovered_hint.position);
|
||||
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,
|
||||
|
@ -419,9 +457,7 @@ pub fn update_inlay_link_and_hover_points(
|
|||
if let Some((language_server_id, location)) =
|
||||
hovered_hint_part.location
|
||||
{
|
||||
if secondary_held
|
||||
&& !editor.has_pending_nonempty_selection()
|
||||
{
|
||||
if secondary_held && !editor.has_pending_nonempty_selection() {
|
||||
go_to_definition_updated = true;
|
||||
show_link_definition(
|
||||
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 gpui::{AppContext as _, AsyncApp, Context, Entity, Task, Window};
|
||||
use language::{Buffer, BufferSnapshot, language_settings::InlayHintKind};
|
||||
use lsp::LanguageServerId;
|
||||
use parking_lot::RwLock;
|
||||
use project::{InlayHint, ResolveState};
|
||||
|
||||
|
@ -622,10 +623,25 @@ impl InlayHintCache {
|
|||
let mut guard = excerpt_hints.write();
|
||||
if let Some(cached_hint) = guard.hints_by_id.get_mut(&id) {
|
||||
if let ResolveState::CanResolve(server_id, _) = &cached_hint.resolve_state {
|
||||
let hint_to_resolve = cached_hint.clone();
|
||||
let server_id = *server_id;
|
||||
let mut cached_hint = cached_hint.clone();
|
||||
cached_hint.resolve_state = ResolveState::Resolving;
|
||||
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| {
|
||||
let resolved_hint_task = editor.update(cx, |editor, cx| {
|
||||
let buffer = editor.buffer().read(cx).buffer(buffer_id)?;
|
||||
|
@ -637,12 +653,9 @@ impl InlayHintCache {
|
|||
)
|
||||
})?;
|
||||
if let Some(resolved_hint_task) = resolved_hint_task {
|
||||
let mut resolved_hint =
|
||||
resolved_hint_task.await.context("hint resolve task")?;
|
||||
editor.read_with(cx, |editor, _| {
|
||||
if let Some(excerpt_hints) =
|
||||
editor.inlay_hint_cache.hints.get(&excerpt_id)
|
||||
{
|
||||
let mut resolved_hint = resolved_hint_task.await.context("hint resolve task")?;
|
||||
editor.update(cx, |editor, cx| {
|
||||
if let Some(excerpt_hints) = editor.inlay_hint_cache.hints.get(&excerpt_id) {
|
||||
let mut guard = excerpt_hints.write();
|
||||
if let Some(cached_hint) = guard.hints_by_id.get_mut(&id) {
|
||||
if cached_hint.resolve_state == ResolveState::Resolving {
|
||||
|
@ -651,15 +664,13 @@ impl InlayHintCache {
|
|||
}
|
||||
}
|
||||
}
|
||||
// Notify to trigger UI update
|
||||
cx.notify();
|
||||
})?;
|
||||
}
|
||||
|
||||
anyhow::Ok(())
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue