on master help sign in
editor: support stepIn, stepOut, next and pause commands
commitd93cd2a2611b3305293274f8fb590a01d4b99584 authorDmitry Sharshakov <d3dx12.xx@gmail.com> dateSun 22 Aug 2021, 11:16 (5 years ago) parentdfc70a1
4 files changed+73−6
helix-dap/src/client.rs+3−3 helix-term/src/application.rs+1 helix-term/src/commands.rs+65−3 helix-term/src/keymap.rs+4
helix-dap/src/client.rs+3−3
@@ -30,6 +30,7 @@ pub struct Client {
3030 pub breakpoints: HashMap<PathBuf, Vec<SourceBreakpoint>>,
3131 // TODO: multiple threads support
3232 pub stack_pointer: Option<StackFrame>,
33+ pub stopped_thread: Option<usize>,
3334 pub is_running: bool,
3435}
3536
@@ -52,6 +53,7 @@ impl Client {
5253 //
5354 breakpoints: HashMap::new(),
5455 stack_pointer: None,
56+ stopped_thread: None,
5557 is_running: false,
5658 };
5759
@@ -346,9 +348,7 @@ impl Client {
346348 }
347349
348350 pub async fn pause(&mut self, thread_id: usize) -> Result<()> {
349− let args = requests::PauseArguments {
350− thread_id,
351− };
351+ let args = requests::PauseArguments { thread_id };
352352
353353 self.request::<requests::Pause>(args).await
354354 }
helix-term/src/application.rs+1
@@ -276,6 +276,7 @@ impl Application {
276276 if let Some(main) = main {
277277 let (bt, _) = debugger.stack_trace(main.id).await.unwrap();
278278 debugger.stack_pointer = bt.get(0).cloned();
279+ debugger.stopped_thread = Some(main.id);
279280 }
280281
281282 let scope = match thread_id {
helix-term/src/commands.rs+65−3
@@ -307,6 +307,10 @@ impl Command {
307307 dap_start, "Start debug session",
308308 dap_run, "Begin program execution",
309309 dap_continue, "Continue program execution",
310+ dap_pause, "Pause program execution",
311+ dap_in, "Step in",
312+ dap_out, "Step out",
313+ dap_next, "Step to next",
310314 dap_variable_scopes, "List variable scopes",
311315 dap_terminate, "End debug session",
312316 suspend, "Suspend"
@@ -4394,15 +4398,73 @@ fn dap_continue(cx: &mut Context) {
43944398 .set_status("Debuggee is already running".to_owned());
43954399 return;
43964400 }
4397− // assume 0 to continue all threads for now
4398− // FIXME: spec conformant behavior here
4399− let request = debugger.continue_thread(0);
4401+
4402+ let request = debugger.continue_thread(debugger.stopped_thread.unwrap());
44004403 let _ = block_on(request).unwrap();
44014404 debugger.is_running = true;
44024405 debugger.stack_pointer = None;
44034406 }
44044407}
44054408
4409+fn dap_pause(cx: &mut Context) {
4410+ use helix_lsp::block_on;
4411+
4412+ if let Some(debugger) = &mut cx.editor.debugger {
4413+ if !debugger.is_running {
4414+ cx.editor.set_status("Debuggee is not running".to_owned());
4415+ return;
4416+ }
4417+
4418+ let request = debugger.pause(debugger.stopped_thread.unwrap());
4419+ let _ = block_on(request).unwrap();
4420+ }
4421+}
4422+
4423+fn dap_in(cx: &mut Context) {
4424+ use helix_lsp::block_on;
4425+
4426+ if let Some(debugger) = &mut cx.editor.debugger {
4427+ if debugger.is_running {
4428+ cx.editor
4429+ .set_status("Debuggee is already running".to_owned());
4430+ return;
4431+ }
4432+
4433+ let request = debugger.step_in(debugger.stopped_thread.unwrap());
4434+ let _ = block_on(request).unwrap();
4435+ }
4436+}
4437+
4438+fn dap_out(cx: &mut Context) {
4439+ use helix_lsp::block_on;
4440+
4441+ if let Some(debugger) = &mut cx.editor.debugger {
4442+ if debugger.is_running {
4443+ cx.editor
4444+ .set_status("Debuggee is already running".to_owned());
4445+ return;
4446+ }
4447+
4448+ let request = debugger.step_out(debugger.stopped_thread.unwrap());
4449+ let _ = block_on(request).unwrap();
4450+ }
4451+}
4452+
4453+fn dap_next(cx: &mut Context) {
4454+ use helix_lsp::block_on;
4455+
4456+ if let Some(debugger) = &mut cx.editor.debugger {
4457+ if debugger.is_running {
4458+ cx.editor
4459+ .set_status("Debuggee is already running".to_owned());
4460+ return;
4461+ }
4462+
4463+ let request = debugger.next(debugger.stopped_thread.unwrap());
4464+ let _ = block_on(request).unwrap();
4465+ }
4466+}
4467+
44064468fn dap_variable_scopes(cx: &mut Context) {
44074469 use helix_lsp::block_on;
44084470
helix-term/src/keymap.rs+4
@@ -490,6 +490,10 @@ impl Default for Keymaps {
490490 "b" => dap_toggle_breakpoint,
491491 "r" => dap_run,
492492 "c" => dap_continue,
493+ "h" => dap_pause,
494+ "j" => dap_in,
495+ "k" => dap_out,
496+ "l" => dap_next,
493497 "z" => dap_variable_scopes,
494498 "t" => dap_terminate,
495499 },