debugger: Improve appearance of session list for JavaScript debugging (#34322)

This PR updates the debugger panel's session list to be more useful in
some cases that are commonly hit when using the JavaScript adapter. We
make two adjustments, which only apply to JavaScript sessions:

- For a child session that's the only child of a root session, we
collapse it with its parent. This imitates what VS Code does in the
"call stack" view for JavaScript sessions.
- When a session has exactly one thread, we label the session with that
thread's name, instead of the session label provided by the DAP. VS Code
also makes this adjustment, which surfaces more useful information when
working with browser sessions.

Closes #33072 

Release Notes:

- debugger: Improved the appearance of JavaScript sessions in the debug
panel's session list.

---------

Co-authored-by: Julia <julia@zed.dev>
Co-authored-by: Remco Smits <djsmits12@gmail.com>
This commit is contained in:
Cole Miller 2025-07-12 11:56:05 -04:00 committed by GitHub
parent 13ddd5e4cb
commit a8cc927303
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 392 additions and 236 deletions

View file

@ -6,6 +6,7 @@ use super::{
};
use crate::{
InlayHint, InlayHintLabel, ProjectEnvironment, ResolveState,
debugger::session::SessionQuirks,
project_settings::ProjectSettings,
terminals::{SshCommand, wrap_for_ssh},
worktree_store::WorktreeStore,
@ -385,10 +386,11 @@ impl DapStore {
pub fn new_session(
&mut self,
label: SharedString,
label: Option<SharedString>,
adapter: DebugAdapterName,
task_context: TaskContext,
parent_session: Option<Entity<Session>>,
quirks: SessionQuirks,
cx: &mut Context<Self>,
) -> Entity<Session> {
let session_id = SessionId(util::post_inc(&mut self.next_session_id));
@ -406,6 +408,7 @@ impl DapStore {
label,
adapter,
task_context,
quirks,
cx,
);

View file

@ -151,6 +151,12 @@ pub struct RunningMode {
messages_tx: UnboundedSender<Message>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub struct SessionQuirks {
pub compact: bool,
pub prefer_thread_name: bool,
}
fn client_source(abs_path: &Path) -> dap::Source {
dap::Source {
name: abs_path
@ -656,7 +662,7 @@ pub struct OutputToken(pub usize);
pub struct Session {
pub mode: Mode,
id: SessionId,
label: SharedString,
label: Option<SharedString>,
adapter: DebugAdapterName,
pub(super) capabilities: Capabilities,
child_session_ids: HashSet<SessionId>,
@ -679,6 +685,7 @@ pub struct Session {
background_tasks: Vec<Task<()>>,
restart_task: Option<Task<()>>,
task_context: TaskContext,
quirks: SessionQuirks,
}
trait CacheableCommand: Any + Send + Sync {
@ -792,9 +799,10 @@ impl Session {
breakpoint_store: Entity<BreakpointStore>,
session_id: SessionId,
parent_session: Option<Entity<Session>>,
label: SharedString,
label: Option<SharedString>,
adapter: DebugAdapterName,
task_context: TaskContext,
quirks: SessionQuirks,
cx: &mut App,
) -> Entity<Self> {
cx.new::<Self>(|cx| {
@ -848,6 +856,7 @@ impl Session {
label,
adapter,
task_context,
quirks,
};
this
@ -1022,7 +1031,7 @@ impl Session {
self.adapter.clone()
}
pub fn label(&self) -> SharedString {
pub fn label(&self) -> Option<SharedString> {
self.label.clone()
}
@ -2481,4 +2490,8 @@ impl Session {
pub fn thread_state(&self, thread_id: ThreadId) -> Option<ThreadStatus> {
self.thread_states.thread_state(thread_id)
}
pub fn quirks(&self) -> SessionQuirks {
self.quirks
}
}