Skip to content

Commit

Permalink
Merge branch 'debugger' into dap-proto-request
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony-Eid committed Jan 13, 2025
2 parents 3a508d0 + 2736b2f commit c3249ab
Show file tree
Hide file tree
Showing 17 changed files with 1,170 additions and 926 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ runtimelib = { version = "0.25.0", default-features = false, features = [
"async-dispatcher-runtime",
] }
rustc-demangle = "0.1.23"
rust-embed = { version = "8.4", features = ["include-exclude"] }
rust-embed = { version = "8.5", features = ["include-exclude"] }
rustc-hash = "2.1.0"
rustls = "0.21.12"
rustls-native-certs = "0.8.0"
Expand Down
8 changes: 8 additions & 0 deletions assets/keymaps/default-macos.json
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,14 @@
"space": "project_panel::Open"
}
},
{
"context": "VariableList",
"use_key_equivalents": true,
"bindings": {
"left": "variable_list::CollapseSelectedEntry",
"right": "variable_list::ExpandSelectedEntry"
}
},
{
"context": "CollabPanel && not_editing",
"use_key_equivalents": true,
Expand Down
3 changes: 2 additions & 1 deletion crates/debugger_ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ gpui.workspace = true
language.workspace = true
menu.workspace = true
picker.workspace = true
pretty_assertions.workspace = true
project.workspace = true
rpc.workspace = true
serde.workspace = true
Expand All @@ -52,6 +53,6 @@ editor = { workspace = true, features = ["test-support"] }
env_logger.workspace = true
gpui = { workspace = true, features = ["test-support"] }
project = { workspace = true, features = ["test-support"] }
util = { workspace = true, features = ["test-support"] }
unindent.workspace = true
util = { workspace = true, features = ["test-support"] }
workspace = { workspace = true, features = ["test-support"] }
57 changes: 7 additions & 50 deletions crates/debugger_ui/src/debugger_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use dap::{
};
use gpui::{
actions, Action, AppContext, AsyncWindowContext, EventEmitter, FocusHandle, FocusableView,
FontWeight, Model, Subscription, Task, View, ViewContext, WeakView,
Model, Subscription, Task, View, ViewContext, WeakView,
};
use project::{
dap_store::{DapStore, DapStoreEvent},
Expand Down Expand Up @@ -117,7 +117,6 @@ pub struct DebugPanel {
focus_handle: FocusHandle,
dap_store: Model<DapStore>,
workspace: WeakView<Workspace>,
show_did_not_stop_warning: bool,
_subscriptions: Vec<Subscription>,
message_queue: HashMap<DebugAdapterClientId, VecDeque<OutputEvent>>,
thread_states: BTreeMap<(DebugAdapterClientId, u64), Model<ThreadState>>,
Expand Down Expand Up @@ -209,7 +208,6 @@ impl DebugPanel {
size: px(300.),
_subscriptions,
focus_handle: cx.focus_handle(),
show_did_not_stop_warning: false,
thread_states: Default::default(),
message_queue: Default::default(),
workspace: workspace.weak_handle(),
Expand Down Expand Up @@ -810,8 +808,11 @@ impl DebugPanel {

if let Some(thread_state) = self.thread_states.get(&(*client_id, thread_id)) {
if !thread_state.read(cx).stopped && event.reason == ThreadEventReason::Exited {
self.show_did_not_stop_warning = true;
cx.notify();
const MESSAGE: &'static str = "Debug session exited without hitting breakpoints\n\nTry adding a breakpoint, or define the correct path mapping for your debugger.";

self.dap_store.update(cx, |_, cx| {
cx.emit(DapStoreEvent::Notification(MESSAGE.into()));
});
};
}

Expand All @@ -823,6 +824,7 @@ impl DebugPanel {
}

cx.emit(DebugPanelEvent::Thread((*client_id, event.clone())));
cx.notify();
}

fn handle_exited_event(
Expand Down Expand Up @@ -1034,48 +1036,6 @@ impl DebugPanel {

cx.emit(DebugPanelEvent::CapabilitiesChanged(*client_id));
}

fn render_did_not_stop_warning(&self, cx: &mut ViewContext<Self>) -> impl IntoElement {
const TITLE: &'static str = "Debug session exited without hitting any breakpoints";
const DESCRIPTION: &'static str =
"Try adding a breakpoint, or define the correct path mapping for your debugger.";

div()
.absolute()
.right_3()
.bottom_12()
.max_w_96()
.py_2()
.px_3()
.elevation_2(cx)
.occlude()
.child(
v_flex()
.gap_0p5()
.child(
h_flex()
.gap_1p5()
.items_center()
.child(Icon::new(IconName::Warning).color(Color::Conflict))
.child(Label::new(TITLE).weight(FontWeight::MEDIUM)),
)
.child(
Label::new(DESCRIPTION)
.size(LabelSize::Small)
.color(Color::Muted),
)
.child(
h_flex().justify_end().mt_1().child(
Button::new("dismiss", "Dismiss")
.color(Color::Muted)
.on_click(cx.listener(|this, _, cx| {
this.show_did_not_stop_warning = false;
cx.notify();
})),
),
),
)
}
}

impl EventEmitter<PanelEvent> for DebugPanel {}
Expand Down Expand Up @@ -1146,9 +1106,6 @@ impl Render for DebugPanel {
.key_context("DebugPanel")
.track_focus(&self.focus_handle)
.size_full()
.when(self.show_did_not_stop_warning, |this| {
this.child(self.render_did_not_stop_warning(cx))
})
.map(|this| {
if self.pane.read(cx).items_len() == 0 {
this.child(
Expand Down
78 changes: 38 additions & 40 deletions crates/debugger_ui/src/debugger_panel_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,16 @@ impl DebugPanelItem {
return;
}

// The default value of an event category is console
// so we assume that is the output type if it doesn't exist
let output_category = event
.category
.as_ref()
.unwrap_or(&OutputEventCategory::Console);

// skip telemetry output as it pollutes the users output view
if output_category == &OutputEventCategory::Telemetry {
return;
}

match output_category {
OutputEventCategory::Console => {
self.console.update(cx, |console, cx| {
Expand Down Expand Up @@ -528,8 +531,8 @@ impl DebugPanelItem {
}

#[cfg(any(test, feature = "test-support"))]
pub fn thread_status(&self, cx: &ViewContext<Self>) -> ThreadStatus {
self.thread_state.read(cx).status
pub fn thread_state(&self) -> &Model<ThreadState> {
&self.thread_state
}

pub fn capabilities(&self, cx: &mut ViewContext<Self>) -> Capabilities {
Expand Down Expand Up @@ -613,16 +616,15 @@ impl DebugPanelItem {
store.continue_thread(&self.client_id, self.thread_id, cx)
});

let task = cx.spawn(|weak, mut cx| async move {
if let Err(_) = task.await {
weak.update(&mut cx, |this, cx| {
this.update_thread_state_status(ThreadStatus::Stopped, cx);
cx.spawn(|this, mut cx| async move {
if task.await.log_err().is_none() {
this.update(&mut cx, |debug_panel_item, cx| {
debug_panel_item.update_thread_state_status(ThreadStatus::Stopped, cx);
})
.log_err();
}
});

cx.background_executor().spawn(task).detach();
})
.detach();
}

pub fn step_over(&mut self, cx: &mut ViewContext<Self>) {
Expand All @@ -633,16 +635,15 @@ impl DebugPanelItem {
store.step_over(&self.client_id, self.thread_id, granularity, cx)
});

let task = cx.spawn(|weak, mut cx| async move {
if let Err(_) = task.await {
weak.update(&mut cx, |this, cx| {
this.update_thread_state_status(ThreadStatus::Stopped, cx);
cx.spawn(|this, mut cx| async move {
if task.await.log_err().is_none() {
this.update(&mut cx, |debug_panel_item, cx| {
debug_panel_item.update_thread_state_status(ThreadStatus::Stopped, cx);
})
.log_err();
}
});

cx.background_executor().spawn(task).detach();
})
.detach();
}

pub fn step_in(&mut self, cx: &mut ViewContext<Self>) {
Expand All @@ -653,16 +654,15 @@ impl DebugPanelItem {
store.step_in(&self.client_id, self.thread_id, granularity, cx)
});

let task = cx.spawn(|weak, mut cx| async move {
if let Err(_) = task.await {
weak.update(&mut cx, |this, cx| {
this.update_thread_state_status(ThreadStatus::Stopped, cx);
cx.spawn(|this, mut cx| async move {
if task.await.log_err().is_none() {
this.update(&mut cx, |debug_panel_item, cx| {
debug_panel_item.update_thread_state_status(ThreadStatus::Stopped, cx);
})
.log_err();
}
});

cx.background_executor().spawn(task).detach();
})
.detach();
}

pub fn step_out(&mut self, cx: &mut ViewContext<Self>) {
Expand All @@ -673,16 +673,15 @@ impl DebugPanelItem {
store.step_out(&self.client_id, self.thread_id, granularity, cx)
});

let task = cx.spawn(|weak, mut cx| async move {
if let Err(_) = task.await {
weak.update(&mut cx, |this, cx| {
this.update_thread_state_status(ThreadStatus::Stopped, cx);
cx.spawn(|this, mut cx| async move {
if task.await.log_err().is_none() {
this.update(&mut cx, |debug_panel_item, cx| {
debug_panel_item.update_thread_state_status(ThreadStatus::Stopped, cx);
})
.log_err();
}
});

cx.background_executor().spawn(task).detach();
})
.detach();
}

pub fn step_back(&mut self, cx: &mut ViewContext<Self>) {
Expand All @@ -693,16 +692,15 @@ impl DebugPanelItem {
store.step_back(&self.client_id, self.thread_id, granularity, cx)
});

let task = cx.spawn(|weak, mut cx| async move {
if let Err(_) = task.await {
weak.update(&mut cx, |this, cx| {
this.update_thread_state_status(ThreadStatus::Stopped, cx);
cx.spawn(|this, mut cx| async move {
if task.await.log_err().is_none() {
this.update(&mut cx, |debug_panel_item, cx| {
debug_panel_item.update_thread_state_status(ThreadStatus::Stopped, cx);
})
.log_err();
}
});

cx.background_executor().spawn(task).detach();
})
.detach();
}

pub fn restart_client(&self, cx: &mut ViewContext<Self>) {
Expand Down Expand Up @@ -864,7 +862,7 @@ impl Render for DebugPanelItem {

h_flex()
.key_context("DebugPanelItem")
.track_focus(&self.focus_handle)
.track_focus(&self.focus_handle(cx))
.size_full()
.items_start()
.child(
Expand Down
18 changes: 16 additions & 2 deletions crates/debugger_ui/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use gpui::{Model, TestAppContext, WindowHandle};
use gpui::{Model, TestAppContext, View, WindowHandle};
use project::Project;
use settings::SettingsStore;
use terminal_view::terminal_panel::TerminalPanel;
use workspace::Workspace;

use crate::debugger_panel::DebugPanel;
use crate::{debugger_panel::DebugPanel, debugger_panel_item::DebugPanelItem};

mod attach_modal;
mod console;
Expand Down Expand Up @@ -57,3 +57,17 @@ pub async fn init_test_workspace(
.unwrap();
window
}

pub fn active_debug_panel_item(
workspace: WindowHandle<Workspace>,
cx: &mut TestAppContext,
) -> View<DebugPanelItem> {
workspace
.update(cx, |workspace, cx| {
let debug_panel = workspace.panel::<DebugPanel>(cx).unwrap();
debug_panel
.update(cx, |this, cx| this.active_debug_panel_item(cx))
.unwrap()
})
.unwrap()
}
Loading

0 comments on commit c3249ab

Please sign in to comment.