Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DAP Step back support #78

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions assets/icons/debug_step_back.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions crates/debugger_ui/src/debugger_panel_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,18 @@ impl DebugPanelItem {
});
}

pub fn step_back(&mut self, cx: &mut ViewContext<Self>) {
self.update_thread_state_status(ThreadStatus::Running, cx);

let granularity = DebuggerSettings::get_global(cx).stepping_granularity;

self.dap_store.update(cx, |store, cx| {
store
.step_back(&self.client_id, self.thread_id, granularity, cx)
.detach_and_log_err(cx);
});
}

pub fn restart_client(&self, cx: &mut ViewContext<Self>) {
self.dap_store.update(cx, |store, cx| {
store
Expand Down Expand Up @@ -807,6 +819,17 @@ impl Render for DebugPanelItem {
.disabled(thread_status != ThreadStatus::Stopped)
.tooltip(move |cx| Tooltip::text("Step out", cx)),
)
.when(capabilities.supports_step_back.unwrap_or(false), |this| {
this.child(
IconButton::new("debug-step-back", IconName::DebugStepBack)
.icon_size(IconSize::Small)
.on_click(cx.listener(|this, _, cx| {
this.step_back(cx);
}))
.disabled(thread_status != ThreadStatus::Stopped)
.tooltip(move |cx| Tooltip::text("Step back", cx)),
)
})
.child(
IconButton::new("debug-restart", IconName::DebugRestart)
.icon_size(IconSize::Small)
Expand Down
42 changes: 37 additions & 5 deletions crates/project/src/dap_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ use crate::{ProjectEnvironment, ProjectItem as _, ProjectPath};
use anyhow::{anyhow, Context as _, Result};
use async_trait::async_trait;
use collections::HashMap;
use dap::adapters::{DapDelegate, DapStatus, DebugAdapter, DebugAdapterBinary, DebugAdapterName};
use dap::{
adapters::{DapDelegate, DapStatus, DebugAdapter, DebugAdapterBinary, DebugAdapterName},
client::{DebugAdapterClient, DebugAdapterClientId},
messages::{Message, Response},
requests::{
Attach, Completions, ConfigurationDone, Continue, Disconnect, Evaluate, Initialize, Launch,
LoadedSources, Modules, Next, Pause, Request as _, Restart, RunInTerminal, Scopes,
SetBreakpoints, SetExpression, SetVariable, StackTrace, StartDebugging, StepIn, StepOut,
Terminate, TerminateThreads, Variables,
SetBreakpoints, SetExpression, SetVariable, StackTrace, StartDebugging, StepBack, StepIn,
StepOut, Terminate, TerminateThreads, Variables,
},
AttachRequestArguments, Capabilities, CompletionItem, CompletionsArguments,
ConfigurationDoneArguments, ContinueArguments, DisconnectArguments, ErrorResponse,
Expand All @@ -20,8 +20,9 @@ use dap::{
ModulesArguments, NextArguments, PauseArguments, RestartArguments, RunInTerminalResponse,
Scope, ScopesArguments, SetBreakpointsArguments, SetExpressionArguments, SetVariableArguments,
Source, SourceBreakpoint, StackFrame, StackTraceArguments, StartDebuggingRequestArguments,
StartDebuggingRequestArgumentsRequest, StepInArguments, StepOutArguments, SteppingGranularity,
TerminateArguments, TerminateThreadsArguments, Variable, VariablesArguments,
StartDebuggingRequestArgumentsRequest, StepBackArguments, StepInArguments, StepOutArguments,
SteppingGranularity, TerminateArguments, TerminateThreadsArguments, Variable,
VariablesArguments,
};
use dap_adapters::build_adapter;
use fs::Fs;
Expand Down Expand Up @@ -1077,6 +1078,37 @@ impl DapStore {
})
}

pub fn step_back(
&self,
client_id: &DebugAdapterClientId,
thread_id: u64,
granularity: SteppingGranularity,
cx: &mut ModelContext<Self>,
) -> Task<Result<()>> {
let Some(client) = self.client_by_id(client_id) else {
return Task::ready(Err(anyhow!("Could not find client: {:?}", client_id)));
};

let capabilities = self.capabilities_by_id(client_id);

let supports_single_thread_execution_requests = capabilities
.supports_single_thread_execution_requests
.unwrap_or_default();
let supports_stepping_granularity = capabilities
.supports_stepping_granularity
.unwrap_or_default();

cx.background_executor().spawn(async move {
client
.request::<StepBack>(StepBackArguments {
thread_id,
granularity: supports_stepping_granularity.then(|| granularity),
single_thread: supports_single_thread_execution_requests.then(|| true),
})
.await
})
}

pub fn variables(
&self,
client_id: &DebugAdapterClientId,
Expand Down
1 change: 1 addition & 0 deletions crates/ui/src/components/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ pub enum IconName {
DebugStepOver,
DebugStepInto,
DebugStepOut,
DebugStepBack,
DebugRestart,
Debug,
DebugStop,
Expand Down
Loading