Compare commits

...

33 Commits

Author SHA1 Message Date
David Kleingeld
6f4bfb5875 New plan, call hover_docs on the type where the inlay hint points to
Co-authored-by: Richard Feldman <oss@rtfeldman.com>
2025-09-05 21:57:18 +02:00
David Kleingeld
1a31961dac Extract get docs and show actual hover into function 2025-08-25 17:39:52 +02:00
Richard Feldman
78ca73e0b9 Minimize diff some more
Co-authored-by: David Kleingeld <davidsk@zed.dev>
2025-08-25 11:30:45 -04:00
Richard Feldman
c70178b7ea Go back to using previous_valid_anchor
Co-authored-by: David Kleingeld <davidsk@zed.dev>
2025-08-25 11:10:09 -04:00
Richard Feldman
4df010d33a Remove unnecessary deferred conditional
Co-authored-by: David Kleingeld <davidsk@zed.dev>
2025-08-25 11:07:03 -04:00
Richard Feldman
c44f9dfb17 Remove redundant tag type check
Co-authored-by: David Kleingeld <davidsk@zed.dev>
2025-08-25 11:02:23 -04:00
Richard Feldman
7c5738142a Minimize diff a bit
Co-authored-by: David Kleingeld <davidsk@zed.dev>
2025-08-25 11:00:52 -04:00
Richard Feldman
23c9eb875a Go back to old visible inlay hint mapping
Co-authored-by: David Kleingeld <davidsk@zed.dev>
2025-08-25 11:00:00 -04:00
Richard Feldman
81578c0d9e Restore previous hovered_offset logic
Co-authored-by: David Kleingeld <davidsk@zed.dev>
2025-08-25 10:49:28 -04:00
Richard Feldman
70918609d8 Fix has_pending_selection logic for inlay hovers
Co-authored-by: David Kleingeld <davidsk@zed.dev>
2025-08-25 10:41:34 -04:00
Richard Feldman
835651fc08 Remove conditionals reintroduced by mistake in the merge
Co-authored-by: David Kleingeld <davidsk@zed.dev>
2025-08-25 10:25:33 -04:00
Richard Feldman
267e44e513 Merge remote-tracking branch 'origin/main' into inlay-hint-tooltip 2025-08-25 09:50:07 -04:00
Richard Feldman
7ef2a8211f Merge remote-tracking branch 'origin/main' into inlay-hint-tooltip 2025-07-15 10:53:58 -04:00
Richard Feldman
a509ae241a Revert "wip"
This reverts commit 0bb1a5f98a.
2025-07-11 12:00:43 -04:00
Richard Feldman
0bb1a5f98a wip 2025-07-11 12:00:41 -04:00
Richard Feldman
79f376d752 Clean up inlay hint hover logic 2025-07-11 11:05:23 -04:00
Richard Feldman
fe8b3fe53d Drop debug logging 2025-07-10 22:30:29 -04:00
Richard Feldman
2cd812e54f Delete unused import 2025-07-10 22:23:52 -04:00
Richard Feldman
6adf082e43 Revert "Add a hover when hovering over inlays"
This reverts commit 0d6232b373.
2025-07-10 22:23:39 -04:00
Richard Feldman
e4963e70cc Revert "Attempt to fix hover"
This reverts commit e7c6f228d5.
2025-07-10 22:23:34 -04:00
Richard Feldman
e7c6f228d5 Attempt to fix hover 2025-07-10 22:23:26 -04:00
Richard Feldman
0d6232b373 Add a hover when hovering over inlays 2025-07-10 19:14:36 -04:00
Richard Feldman
ca4df68f31 Remove flashed black circle 2025-07-10 17:54:22 -04:00
Richard Feldman
c96b6a06f0 Don't show loading message 2025-07-10 17:46:13 -04:00
Richard Feldman
b1cd20a435 Remove all debug logging from inlay hint hover implementation 2025-07-10 17:46:08 -04:00
Richard Feldman
509375c83c Remove some debug logging 2025-07-10 17:39:37 -04:00
Richard Feldman
b6bd9c0682 It works 2025-07-10 17:32:12 -04:00
Richard Feldman
8ee82395b8 Kinda make this work 2025-07-10 17:14:30 -04:00
Richard Feldman
a322aa33c7 wip - currently just shows a generic message, not the docs 2025-07-09 16:37:37 -04:00
Richard Feldman
2ff30d20e3 Fix inlay hint hover by not clearing hover when mouse is over inlay
When hovering over an inlay hint, point_for_position.as_valid() returns None
because inlays don't have valid text positions. This was causing hover_at(editor, None)
to be called, which would hide any active hovers.

The fix is simple: don't call hover_at when we're over an inlay position.
The inlay hover is already handled by update_hovered_link, so we don't need
to do anything else.
2025-07-09 13:15:43 -04:00
Richard Feldman
01d7b3345b Fix inlay hint caching 2025-07-09 13:04:11 -04:00
Richard Feldman
17f7312fc0 Extract resolve_hint
Co-authored-by: Cole Miller <cole@zed.dev>
2025-07-07 16:48:33 -04:00
Richard Feldman
a61e478152 Reproduce #33715 in a test 2025-07-02 15:50:02 -04:00

View File

@@ -15,6 +15,7 @@ use project::{
};
use settings::Settings;
use std::ops::Range;
use text::{self, Point};
use theme::ActiveTheme as _;
use util::{ResultExt, TryFutureExt as _, maybe};
@@ -121,13 +122,25 @@ impl Editor {
cx: &mut Context<Self>,
) {
let hovered_link_modifier = Editor::multi_cursor_modifier(false, &modifiers, cx);
if !hovered_link_modifier || self.has_pending_selection() {
// When you're dragging to select, and you release the drag to create the selection,
// if you happened to end over something hoverable (including an inlay hint), don't
// have the hovered link appear. That would be annoying, because all you're trying
// to do is to create a selection, not hover to see a hovered link.
if self.has_pending_selection() {
self.hide_hovered_link(cx);
return;
}
match point_for_position.as_valid() {
Some(point) => {
// Hide the underline unless you're holding the modifier key on the keyboard
// which will perform a goto definition.
if !hovered_link_modifier {
self.hide_hovered_link(cx);
return;
}
let trigger_point = TriggerPoint::Text(
snapshot
.buffer_snapshot
@@ -319,6 +332,7 @@ 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) {
// Check if we should process this hint for hover
match cached_hint.resolve_state {
ResolveState::CanResolve(_, _) => {
if let Some(buffer_id) = snapshot
@@ -419,31 +433,46 @@ pub fn update_inlay_link_and_hover_points(
);
hover_updated = true;
}
if let Some((language_server_id, location)) =
hovered_hint_part.location
&& secondary_held
&& !editor.has_pending_nonempty_selection()
{
go_to_definition_updated = true;
show_link_definition(
shift_held,
editor,
TriggerPoint::InlayHint(
highlight,
location,
language_server_id,
),
snapshot,
window,
cx,
);
// Now perform the "Go to Definition" flow to get hover documentation
if let Some(project) = editor.project.clone() {
let highlight = highlight.clone();
let hint_value = hovered_hint_part.value.clone();
let location = location.clone();
get_docs_then_show_hover(
editor, window, cx, highlight, hint_value,
location, project,
);
}
if secondary_held
&& !editor.has_pending_nonempty_selection()
{
go_to_definition_updated = true;
show_link_definition(
shift_held,
editor,
TriggerPoint::InlayHint(
highlight,
location,
language_server_id,
),
snapshot,
window,
cx,
);
}
}
}
}
};
}
}
ResolveState::Resolving => {}
}
};
}
}
}
@@ -456,6 +485,92 @@ pub fn update_inlay_link_and_hover_points(
}
}
/// todo dvdsk: This extracts doc comments and shows them, a fine fallback
/// though maybe we should instead alsk the LSP for info on the type?. Lets figure
/// out what normal hoverdocs do.
///
/// issue with Entity<Markdown>. Needs one more (expensive) step before rendering
/// which we need to cache.
///
/// --- PLAN ---
/// - use location to call hover_popover and extract the text
/// - then use claude written 'existing' hover method to see if that works
/// - try use or adapt InfoPopover to get scrollbar/nice rendering (note issue above)
/// - get the unwraps and as_refs out of here
fn get_docs_then_show_hover(
editor: &mut Editor,
window: &mut Window,
cx: &mut Context<'_, Editor>,
highlight: InlayHighlight,
hint_value: String,
location: lsp::Location,
project: Entity<Project>,
) {
let provider = editor.semantics_provider.clone().unwrap();
cx.spawn_in(window, async move |editor, cx| {
async move {
// Convert LSP URL to file path
let file_path = location
.uri
.to_file_path()
.map_err(|_| anyhow::anyhow!("Invalid file URL"))?;
// Open the definition file
let definition_buffer = project
.update(cx, |project, cx| project.open_local_buffer(file_path, cx))?
.await?;
let location = Point::new(location.range.start.line, location.range.start.character);
let buffer_position = definition_buffer
.update(cx, |buffer, _| buffer.snapshot().anchor_after(location))
.unwrap();
// debounce the lsp request
cx.background_executor()
.timer(std::time::Duration::from_millis(50))
.await;
let hover_request =
cx.update(|_, cx| provider.hover(&definition_buffer, buffer_position, cx))?;
let hovers_response = if let Some(hover_request) = hover_request {
hover_request.await.unwrap_or_default()
} else {
Vec::new()
};
let text = hovers_response
.first()
.as_ref()
.unwrap()
.contents
.first()
.as_ref()
.unwrap()
.text
.clone();
editor
.update_in(cx, |editor, window, cx| {
hover_popover::hover_at_inlay(
editor,
InlayHover {
tooltip: HoverBlock {
text,
kind: HoverBlockKind::Markdown,
},
range: highlight,
},
window,
cx,
);
})
.log_err();
anyhow::Ok(())
}
.log_err()
.await
})
.detach();
}
pub fn show_link_definition(
shift_held: bool,
editor: &mut Editor,