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

feat(dap): implement Restart request #5651

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 17 additions & 0 deletions helix-dap/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub struct Client {
server_tx: UnboundedSender<Payload>,
request_counter: AtomicU64,
connection_type: Option<ConnectionType>,
starting_request_args: Option<Value>,
pub caps: Option<DebuggerCapabilities>,
// thread_id -> frames
pub stack_frames: HashMap<ThreadId, Vec<StackFrame>>,
Expand Down Expand Up @@ -87,6 +88,7 @@ impl Client {
request_counter: AtomicU64::new(0),
caps: None,
connection_type: None,
starting_request_args: None,
stack_frames: HashMap::new(),
thread_states: HashMap::new(),
thread_id: None,
Expand Down Expand Up @@ -158,6 +160,10 @@ impl Client {
)
}

pub fn starting_request_args(&self) -> &Option<Value> {
&self.starting_request_args
}

pub async fn tcp_process(
cmd: &str,
args: Vec<&str>,
Expand Down Expand Up @@ -356,14 +362,25 @@ impl Client {

pub fn launch(&mut self, args: serde_json::Value) -> impl Future<Output = Result<Value>> {
self.connection_type = Some(ConnectionType::Launch);
self.starting_request_args = Some(args.clone());
self.call::<requests::Launch>(args)
}

pub fn attach(&mut self, args: serde_json::Value) -> impl Future<Output = Result<Value>> {
self.connection_type = Some(ConnectionType::Attach);
self.starting_request_args = Some(args.clone());
self.call::<requests::Attach>(args)
}

pub fn restart(&self) -> impl Future<Output = Result<Value>> {
let args = if let Some(args) = &self.starting_request_args {
args.clone()
} else {
Value::Null
};
self.call::<requests::Restart>(args)
}

pub async fn set_breakpoints(
&self,
file: PathBuf,
Expand Down
13 changes: 11 additions & 2 deletions helix-dap/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ pub mod requests {

impl Request for Launch {
type Arguments = Value;
type Result = Value;
type Result = ();
const COMMAND: &'static str = "launch";
}

Expand All @@ -387,7 +387,7 @@ pub mod requests {

impl Request for Attach {
type Arguments = Value;
type Result = Value;
type Result = ();
const COMMAND: &'static str = "attach";
}

Expand All @@ -402,6 +402,15 @@ pub mod requests {
pub suspend_debuggee: Option<bool>,
}

#[derive(Debug)]
pub enum Restart {}

impl Request for Restart {
type Arguments = Value;
type Result = ();
const COMMAND: &'static str = "restart";
}

#[derive(Debug)]
pub enum Disconnect {}

Expand Down
1 change: 1 addition & 0 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ impl MappableCommand {
goto_next_paragraph, "Goto next paragraph",
goto_prev_paragraph, "Goto previous paragraph",
dap_launch, "Launch debug target",
dap_restart, "Restart debugging session",
dap_toggle_breakpoint, "Toggle breakpoint",
dap_continue, "Continue program execution",
dap_pause, "Pause program execution",
Expand Down
30 changes: 30 additions & 0 deletions helix-term/src/commands/dap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,36 @@ pub fn dap_launch(cx: &mut Context) {
))));
}

pub fn dap_restart(cx: &mut Context) {
let debugger = match &cx.editor.debugger {
Some(debugger) => debugger,
None => {
cx.editor.set_error("Debugger is not running");
return;
}
};
if !debugger
.capabilities()
.supports_restart_request
.unwrap_or(false)
{
cx.editor
.set_error("Debugger does not support session restarts");
return;
}
if debugger.starting_request_args().is_none() {
cx.editor
.set_error("No arguments found with which to restart the sessions");
return;
}

dap_callback(
cx.jobs,
debugger.restart(),
|editor, _compositor, _resp: ()| editor.set_status("Debugging session restarted"),
);
}

fn debug_parameter_prompt(
completions: Vec<DebugConfigCompletion>,
config_name: String,
Expand Down
1 change: 1 addition & 0 deletions helix-term/src/keymap/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ pub fn default() -> HashMap<Mode, Keymap> {
"'" => last_picker,
"g" => { "Debug (experimental)" sticky=true
"l" => dap_launch,
"r" => dap_restart,
"b" => dap_toggle_breakpoint,
"c" => dap_continue,
"h" => dap_pause,
Expand Down