debugger: Add support for inline value hints (#28656)

This PR uses Tree Sitter to show inline values while a user is in a
debug session.

We went with Tree Sitter over the LSP Inline Values request because the
LSP request isn't widely supported. Tree Sitter is easy for
languages/extensions to add support to. Tree Sitter can compute the
inline values locally, so there's no need to add extra RPC messages for
Collab. Tree Sitter also gives Zed more control over how we want to show
variables.

There's still more work to be done after this PR, namely differentiating
between global/local scoped variables, but it's a great starting point
to start iteratively improving it.

Release Notes:

- N/A

---------

Co-authored-by: Piotr Osiewicz <peterosiewicz@gmail.com>
Co-authored-by: Anthony Eid <hello@anthonyeid.me>
Co-authored-by: Cole Miller <m@cole-miller.net>
Co-authored-by: Anthony <anthony@zed.dev>
Co-authored-by: Kirill <kirill@zed.dev>
This commit is contained in:
Remco Smits 2025-04-24 00:27:27 +02:00 committed by GitHub
parent d095bab8ad
commit 218496744c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
30 changed files with 709 additions and 54 deletions

View file

@ -4,7 +4,7 @@
use anyhow::{Result, anyhow};
use breakpoints_in_file::BreakpointsInFile;
use collections::BTreeMap;
use dap::client::SessionId;
use dap::{StackFrameId, client::SessionId};
use gpui::{App, AppContext, AsyncApp, Context, Entity, EventEmitter, Subscription, Task};
use itertools::Itertools;
use language::{Buffer, BufferSnapshot, proto::serialize_anchor as serialize_text_anchor};
@ -17,6 +17,8 @@ use text::{Point, PointUtf16};
use crate::{Project, ProjectPath, buffer_store::BufferStore, worktree_store::WorktreeStore};
use super::session::ThreadId;
mod breakpoints_in_file {
use language::{BufferEvent, DiskState};
@ -108,10 +110,20 @@ enum BreakpointStoreMode {
Local(LocalBreakpointStore),
Remote(RemoteBreakpointStore),
}
#[derive(Clone)]
pub struct ActiveStackFrame {
pub session_id: SessionId,
pub thread_id: ThreadId,
pub stack_frame_id: StackFrameId,
pub path: Arc<Path>,
pub position: text::Anchor,
}
pub struct BreakpointStore {
breakpoints: BTreeMap<Arc<Path>, BreakpointsInFile>,
downstream_client: Option<(AnyProtoClient, u64)>,
active_stack_frame: Option<(SessionId, Arc<Path>, text::Anchor)>,
active_stack_frame: Option<ActiveStackFrame>,
// E.g ssh
mode: BreakpointStoreMode,
}
@ -493,7 +505,7 @@ impl BreakpointStore {
})
}
pub fn active_position(&self) -> Option<&(SessionId, Arc<Path>, text::Anchor)> {
pub fn active_position(&self) -> Option<&ActiveStackFrame> {
self.active_stack_frame.as_ref()
}
@ -504,7 +516,7 @@ impl BreakpointStore {
) {
if let Some(session_id) = session_id {
self.active_stack_frame
.take_if(|(id, _, _)| *id == session_id);
.take_if(|active_stack_frame| active_stack_frame.session_id == session_id);
} else {
self.active_stack_frame.take();
}
@ -513,11 +525,7 @@ impl BreakpointStore {
cx.notify();
}
pub fn set_active_position(
&mut self,
position: (SessionId, Arc<Path>, text::Anchor),
cx: &mut Context<Self>,
) {
pub fn set_active_position(&mut self, position: ActiveStackFrame, cx: &mut Context<Self>) {
self.active_stack_frame = Some(position);
cx.emit(BreakpointStoreEvent::ActiveDebugLineChanged);
cx.notify();