Reuse values from last debug panel inert state if they exist (#27211)

This should allow the team to iterate faster when using the debug panel
to set up a session

Release Notes:

- N/A
This commit is contained in:
Anthony Eid 2025-03-20 14:53:11 -04:00 committed by GitHub
parent ac452799b0
commit a74f2bb18b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 106 additions and 22 deletions

View file

@ -3,8 +3,8 @@ use anyhow::{anyhow, Result};
use collections::HashMap;
use command_palette_hooks::CommandPaletteFilter;
use dap::{
client::SessionId, debugger_settings::DebuggerSettings, ContinuedEvent, LoadedSourceEvent,
ModuleEvent, OutputEvent, StoppedEvent, ThreadEvent,
client::SessionId, debugger_settings::DebuggerSettings, ContinuedEvent, DebugAdapterConfig,
LoadedSourceEvent, ModuleEvent, OutputEvent, StoppedEvent, ThreadEvent,
};
use futures::{channel::mpsc, SinkExt as _};
use gpui::{
@ -21,6 +21,7 @@ use settings::Settings;
use std::{any::TypeId, path::PathBuf};
use terminal_view::terminal_panel::TerminalPanel;
use ui::prelude::*;
use util::ResultExt;
use workspace::{
dock::{DockPosition, Panel, PanelEvent},
pane, Continue, Disconnect, Pane, Pause, Restart, StepBack, StepInto, StepOut, StepOver, Stop,
@ -51,6 +52,7 @@ pub struct DebugPanel {
project: WeakEntity<Project>,
workspace: WeakEntity<Workspace>,
_subscriptions: Vec<Subscription>,
pub(crate) last_inert_config: Option<DebugAdapterConfig>,
}
impl DebugPanel {
@ -63,6 +65,7 @@ impl DebugPanel {
let project = workspace.project().clone();
let dap_store = project.read(cx).dap_store();
let weak_workspace = workspace.weak_handle();
let debug_panel = cx.weak_entity();
let pane = cx.new(|cx| {
let mut pane = Pane::new(
workspace.weak_handle(),
@ -81,6 +84,7 @@ impl DebugPanel {
pane.set_render_tab_bar_buttons(cx, {
let project = project.clone();
let weak_workspace = weak_workspace.clone();
let debug_panel = debug_panel.clone();
move |_, _, cx| {
let project = project.clone();
let weak_workspace = weak_workspace.clone();
@ -91,21 +95,34 @@ impl DebugPanel {
.child(
IconButton::new("new-debug-session", IconName::Plus)
.icon_size(IconSize::Small)
.on_click(cx.listener(move |pane, _, window, cx| {
pane.add_item(
Box::new(DebugSession::inert(
project.clone(),
weak_workspace.clone(),
.on_click({
let debug_panel = debug_panel.clone();
cx.listener(move |pane, _, window, cx| {
let config = debug_panel
.read_with(cx, |this: &DebugPanel, _| {
this.last_inert_config.clone()
})
.log_err()
.flatten();
pane.add_item(
Box::new(DebugSession::inert(
project.clone(),
weak_workspace.clone(),
debug_panel.clone(),
config,
window,
cx,
)),
false,
false,
None,
window,
cx,
)),
false,
false,
None,
window,
cx,
);
})),
);
})
}),
)
.into_any_element(),
),
@ -116,6 +133,8 @@ impl DebugPanel {
Box::new(DebugSession::inert(
project.clone(),
weak_workspace.clone(),
debug_panel.clone(),
None,
window,
cx,
)),
@ -138,6 +157,7 @@ impl DebugPanel {
pane,
size: px(300.),
_subscriptions,
last_inert_config: None,
project: project.downgrade(),
workspace: workspace.weak_handle(),
};
@ -280,8 +300,14 @@ impl DebugPanel {
// We already have an item for this session.
return;
}
let session_item =
DebugSession::running(project, self.workspace.clone(), session, window, cx);
let session_item = DebugSession::running(
project,
self.workspace.clone(),
session,
cx.weak_entity(),
window,
cx,
);
self.pane.update(cx, |pane, cx| {
pane.add_item(Box::new(session_item), true, true, None, window, cx);
@ -504,12 +530,16 @@ impl Panel for DebugPanel {
let Some(project) = self.project.clone().upgrade() else {
return;
};
let config = self.last_inert_config.clone();
let panel = cx.weak_entity();
// todo: We need to revisit it when we start adding stopped items to pane (as that'll cause us to add two items).
self.pane.update(cx, |this, cx| {
this.add_item(
Box::new(DebugSession::inert(
project,
self.workspace.clone(),
panel,
config,
window,
cx,
)),