debugger: Add console indicator and resolve debug configs from NewSessionModal (#28489)
The debug console will now show an indicator when it's unopened and there's unread messages. `NewSessionModal` attempts to resolve debug configurations before using the config to start debugging. This allows users to use zed's task variables in the modal prompt. I had to invert tasks_ui dependency on debugger_ui so `NewSessionModal` could get the correct `TaskContexts` by calling tasks_ui functions. A consequence of this workspace has a new event `ShowAttachModal` that I'm not a big fan of. @osiewicz if you have time could you please take a look to see if there's a way around adding the event. I'm open to pair on it too. Release Notes: - N/A
This commit is contained in:
parent
66dd6726df
commit
cf65d9437a
12 changed files with 204 additions and 82 deletions
|
@ -45,6 +45,7 @@ serde_json.workspace = true
|
|||
settings.workspace = true
|
||||
sysinfo.workspace = true
|
||||
task.workspace = true
|
||||
tasks_ui.workspace = true
|
||||
terminal_view.workspace = true
|
||||
theme.workspace = true
|
||||
ui.workspace = true
|
||||
|
|
|
@ -77,8 +77,45 @@ impl DebugPanel {
|
|||
let project = workspace.project().clone();
|
||||
let dap_store = project.read(cx).dap_store();
|
||||
|
||||
let _subscriptions =
|
||||
vec![cx.subscribe_in(&dap_store, window, Self::handle_dap_store_event)];
|
||||
let weak = cx.weak_entity();
|
||||
|
||||
let modal_subscription =
|
||||
cx.observe_new::<tasks_ui::TasksModal>(move |_, window, cx| {
|
||||
let modal_entity = cx.entity();
|
||||
|
||||
weak.update(cx, |_: &mut DebugPanel, cx| {
|
||||
let Some(window) = window else {
|
||||
log::error!("Debug panel couldn't subscribe to tasks modal because there was no window");
|
||||
return;
|
||||
};
|
||||
|
||||
cx.subscribe_in(
|
||||
&modal_entity,
|
||||
window,
|
||||
|panel, _, event: &tasks_ui::ShowAttachModal, window, cx| {
|
||||
panel.workspace.update(cx, |workspace, cx| {
|
||||
let project = workspace.project().clone();
|
||||
workspace.toggle_modal(window, cx, |window, cx| {
|
||||
crate::attach_modal::AttachModal::new(
|
||||
project,
|
||||
event.debug_config.clone(),
|
||||
true,
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
});
|
||||
}).ok();
|
||||
},
|
||||
)
|
||||
.detach();
|
||||
})
|
||||
.ok();
|
||||
});
|
||||
|
||||
let _subscriptions = vec![
|
||||
cx.subscribe_in(&dap_store, window, Self::handle_dap_store_event),
|
||||
modal_subscription,
|
||||
];
|
||||
|
||||
let debug_panel = Self {
|
||||
size: px(300.),
|
||||
|
|
|
@ -156,7 +156,17 @@ pub fn init(cx: &mut App) {
|
|||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
)
|
||||
.register_action(|workspace: &mut Workspace, _: &Start, window, cx| {
|
||||
tasks_ui::toggle_modal(
|
||||
workspace,
|
||||
None,
|
||||
task::TaskModal::DebugModal,
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
.detach();
|
||||
});
|
||||
})
|
||||
})
|
||||
.detach();
|
||||
|
@ -237,7 +247,7 @@ pub fn init(cx: &mut App) {
|
|||
|
||||
state.session().update(cx, |session, cx| {
|
||||
session.evaluate(text, None, stack_id, None, cx);
|
||||
})
|
||||
});
|
||||
});
|
||||
Some(())
|
||||
});
|
||||
|
|
|
@ -102,7 +102,8 @@ impl NewSessionModal {
|
|||
},
|
||||
})
|
||||
}
|
||||
fn start_new_session(&self, cx: &mut Context<Self>) -> Result<()> {
|
||||
|
||||
fn start_new_session(&self, window: &mut Window, cx: &mut Context<Self>) -> Result<()> {
|
||||
let workspace = self.workspace.clone();
|
||||
let config = self
|
||||
.debug_config(cx)
|
||||
|
@ -112,10 +113,41 @@ impl NewSessionModal {
|
|||
panel.past_debug_definition = Some(config.clone());
|
||||
});
|
||||
|
||||
let task_contexts = workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
tasks_ui::task_contexts(workspace, window, cx)
|
||||
})
|
||||
.ok();
|
||||
|
||||
cx.spawn(async move |this, cx| {
|
||||
let task_context = if let Some(task) = task_contexts {
|
||||
task.await
|
||||
.active_worktree_context
|
||||
.map_or(task::TaskContext::default(), |context| context.1)
|
||||
} else {
|
||||
task::TaskContext::default()
|
||||
};
|
||||
let project = workspace.update(cx, |workspace, _| workspace.project().clone())?;
|
||||
let task =
|
||||
project.update(cx, |this, cx| this.start_debug_session(config.into(), cx))?;
|
||||
|
||||
let task = project.update(cx, |this, cx| {
|
||||
if let Some(debug_config) =
|
||||
config
|
||||
.clone()
|
||||
.to_zed_format()
|
||||
.ok()
|
||||
.and_then(|task_template| {
|
||||
task_template
|
||||
.resolve_task("debug_task", &task_context)
|
||||
.and_then(|resolved_task| {
|
||||
resolved_task.resolved_debug_adapter_config()
|
||||
})
|
||||
})
|
||||
{
|
||||
this.start_debug_session(debug_config, cx)
|
||||
} else {
|
||||
this.start_debug_session(config.into(), cx)
|
||||
}
|
||||
})?;
|
||||
let spawn_result = task.await;
|
||||
if spawn_result.is_ok() {
|
||||
this.update(cx, |_, cx| {
|
||||
|
@ -614,8 +646,8 @@ impl Render for NewSessionModal {
|
|||
})
|
||||
.child(
|
||||
Button::new("debugger-spawn", "Start")
|
||||
.on_click(cx.listener(|this, _, _, cx| {
|
||||
this.start_new_session(cx).log_err();
|
||||
.on_click(cx.listener(|this, _, window, cx| {
|
||||
this.start_new_session(window, cx).log_err();
|
||||
}))
|
||||
.disabled(self.debugger.is_none()),
|
||||
),
|
||||
|
|
|
@ -26,8 +26,8 @@ use rpc::proto::ViewId;
|
|||
use settings::Settings;
|
||||
use stack_frame_list::StackFrameList;
|
||||
use ui::{
|
||||
App, Context, ContextMenu, DropdownMenu, InteractiveElement, IntoElement, ParentElement,
|
||||
Render, SharedString, Styled, Window, div, h_flex, v_flex,
|
||||
AnyElement, App, Context, ContextMenu, DropdownMenu, InteractiveElement, IntoElement, Label,
|
||||
LabelCommon as _, ParentElement, Render, SharedString, Styled, Window, div, h_flex, v_flex,
|
||||
};
|
||||
use util::ResultExt;
|
||||
use variable_list::VariableList;
|
||||
|
@ -86,6 +86,7 @@ struct SubView {
|
|||
inner: AnyView,
|
||||
pane_focus_handle: FocusHandle,
|
||||
tab_name: SharedString,
|
||||
show_indicator: Box<dyn Fn(&App) -> bool>,
|
||||
}
|
||||
|
||||
impl SubView {
|
||||
|
@ -93,12 +94,14 @@ impl SubView {
|
|||
pane_focus_handle: FocusHandle,
|
||||
view: AnyView,
|
||||
tab_name: SharedString,
|
||||
show_indicator: Option<Box<dyn Fn(&App) -> bool>>,
|
||||
cx: &mut App,
|
||||
) -> Entity<Self> {
|
||||
cx.new(|_| Self {
|
||||
tab_name,
|
||||
inner: view,
|
||||
pane_focus_handle,
|
||||
show_indicator: show_indicator.unwrap_or(Box::new(|_| false)),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -110,8 +113,27 @@ impl Focusable for SubView {
|
|||
impl EventEmitter<()> for SubView {}
|
||||
impl Item for SubView {
|
||||
type Event = ();
|
||||
fn tab_content_text(&self, _window: &Window, _cx: &App) -> Option<SharedString> {
|
||||
Some(self.tab_name.clone())
|
||||
|
||||
fn tab_content(
|
||||
&self,
|
||||
params: workspace::item::TabContentParams,
|
||||
_: &Window,
|
||||
cx: &App,
|
||||
) -> AnyElement {
|
||||
let label = Label::new(self.tab_name.clone())
|
||||
.color(params.text_color())
|
||||
.into_any_element();
|
||||
|
||||
if !params.selected && self.show_indicator.as_ref()(cx) {
|
||||
return h_flex()
|
||||
.justify_between()
|
||||
.child(ui::Indicator::dot())
|
||||
.gap_2()
|
||||
.child(label)
|
||||
.into_any_element();
|
||||
}
|
||||
|
||||
label
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -315,6 +337,7 @@ impl RunningState {
|
|||
this.focus_handle(cx),
|
||||
stack_frame_list.clone().into(),
|
||||
SharedString::new_static("Frames"),
|
||||
None,
|
||||
cx,
|
||||
)),
|
||||
true,
|
||||
|
@ -329,6 +352,7 @@ impl RunningState {
|
|||
breakpoints.focus_handle(cx),
|
||||
breakpoints.into(),
|
||||
SharedString::new_static("Breakpoints"),
|
||||
None,
|
||||
cx,
|
||||
)),
|
||||
true,
|
||||
|
@ -346,6 +370,7 @@ impl RunningState {
|
|||
variable_list.focus_handle(cx),
|
||||
variable_list.clone().into(),
|
||||
SharedString::new_static("Variables"),
|
||||
None,
|
||||
cx,
|
||||
)),
|
||||
true,
|
||||
|
@ -359,6 +384,7 @@ impl RunningState {
|
|||
this.focus_handle(cx),
|
||||
module_list.clone().into(),
|
||||
SharedString::new_static("Modules"),
|
||||
None,
|
||||
cx,
|
||||
)),
|
||||
false,
|
||||
|
@ -371,11 +397,17 @@ impl RunningState {
|
|||
});
|
||||
let rightmost_pane = new_debugger_pane(workspace.clone(), project.clone(), window, cx);
|
||||
rightmost_pane.update(cx, |this, cx| {
|
||||
let weak_console = console.downgrade();
|
||||
this.add_item(
|
||||
Box::new(SubView::new(
|
||||
this.focus_handle(cx),
|
||||
console.clone().into(),
|
||||
SharedString::new_static("Console"),
|
||||
Some(Box::new(move |cx| {
|
||||
weak_console
|
||||
.read_with(cx, |console, cx| console.show_indicator(cx))
|
||||
.unwrap_or_default()
|
||||
})),
|
||||
cx,
|
||||
)),
|
||||
true,
|
||||
|
|
|
@ -105,6 +105,10 @@ impl Console {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn show_indicator(&self, cx: &App) -> bool {
|
||||
self.session.read(cx).has_new_output(self.last_token)
|
||||
}
|
||||
|
||||
pub fn add_messages<'a>(
|
||||
&mut self,
|
||||
events: impl Iterator<Item = &'a OutputEvent>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue