diff options
author | Dmitry Sharshakov | 2021-08-22 08:16:11 +0000 |
---|---|---|
committer | Dmitry Sharshakov | 2021-08-22 08:16:11 +0000 |
commit | d93cd2a2611b3305293274f8fb590a01d4b99584 (patch) | |
tree | 968f5649ee3e171b18ff0245207ce059316cc8a7 | |
parent | dfc70a12f337df57e69e3613896663c2f446df8e (diff) |
editor: support stepIn, stepOut, next and pause commands
-rw-r--r-- | helix-dap/src/client.rs | 6 | ||||
-rw-r--r-- | helix-term/src/application.rs | 1 | ||||
-rw-r--r-- | helix-term/src/commands.rs | 68 | ||||
-rw-r--r-- | helix-term/src/keymap.rs | 4 |
4 files changed, 73 insertions, 6 deletions
diff --git a/helix-dap/src/client.rs b/helix-dap/src/client.rs index e2531e11..ebaae83c 100644 --- a/helix-dap/src/client.rs +++ b/helix-dap/src/client.rs @@ -30,6 +30,7 @@ pub struct Client { pub breakpoints: HashMap<PathBuf, Vec<SourceBreakpoint>>, // TODO: multiple threads support pub stack_pointer: Option<StackFrame>, + pub stopped_thread: Option<usize>, pub is_running: bool, } @@ -52,6 +53,7 @@ impl Client { // breakpoints: HashMap::new(), stack_pointer: None, + stopped_thread: None, is_running: false, }; @@ -346,9 +348,7 @@ impl Client { } pub async fn pause(&mut self, thread_id: usize) -> Result<()> { - let args = requests::PauseArguments { - thread_id, - }; + let args = requests::PauseArguments { thread_id }; self.request::<requests::Pause>(args).await } diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 0f0a9ae5..6e3b6e99 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -276,6 +276,7 @@ impl Application { if let Some(main) = main { let (bt, _) = debugger.stack_trace(main.id).await.unwrap(); debugger.stack_pointer = bt.get(0).cloned(); + debugger.stopped_thread = Some(main.id); } let scope = match thread_id { diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 1c0084fc..cc45f79a 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -307,6 +307,10 @@ impl Command { dap_start, "Start debug session", dap_run, "Begin program execution", dap_continue, "Continue program execution", + dap_pause, "Pause program execution", + dap_in, "Step in", + dap_out, "Step out", + dap_next, "Step to next", dap_variable_scopes, "List variable scopes", dap_terminate, "End debug session", suspend, "Suspend" @@ -4394,15 +4398,73 @@ fn dap_continue(cx: &mut Context) { .set_status("Debuggee is already running".to_owned()); return; } - // assume 0 to continue all threads for now - // FIXME: spec conformant behavior here - let request = debugger.continue_thread(0); + + let request = debugger.continue_thread(debugger.stopped_thread.unwrap()); let _ = block_on(request).unwrap(); debugger.is_running = true; debugger.stack_pointer = None; } } +fn dap_pause(cx: &mut Context) { + use helix_lsp::block_on; + + if let Some(debugger) = &mut cx.editor.debugger { + if !debugger.is_running { + cx.editor.set_status("Debuggee is not running".to_owned()); + return; + } + + let request = debugger.pause(debugger.stopped_thread.unwrap()); + let _ = block_on(request).unwrap(); + } +} + +fn dap_in(cx: &mut Context) { + use helix_lsp::block_on; + + if let Some(debugger) = &mut cx.editor.debugger { + if debugger.is_running { + cx.editor + .set_status("Debuggee is already running".to_owned()); + return; + } + + let request = debugger.step_in(debugger.stopped_thread.unwrap()); + let _ = block_on(request).unwrap(); + } +} + +fn dap_out(cx: &mut Context) { + use helix_lsp::block_on; + + if let Some(debugger) = &mut cx.editor.debugger { + if debugger.is_running { + cx.editor + .set_status("Debuggee is already running".to_owned()); + return; + } + + let request = debugger.step_out(debugger.stopped_thread.unwrap()); + let _ = block_on(request).unwrap(); + } +} + +fn dap_next(cx: &mut Context) { + use helix_lsp::block_on; + + if let Some(debugger) = &mut cx.editor.debugger { + if debugger.is_running { + cx.editor + .set_status("Debuggee is already running".to_owned()); + return; + } + + let request = debugger.next(debugger.stopped_thread.unwrap()); + let _ = block_on(request).unwrap(); + } +} + fn dap_variable_scopes(cx: &mut Context) { use helix_lsp::block_on; diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs index 6082521e..541ac233 100644 --- a/helix-term/src/keymap.rs +++ b/helix-term/src/keymap.rs @@ -490,6 +490,10 @@ impl Default for Keymaps { "b" => dap_toggle_breakpoint, "r" => dap_run, "c" => dap_continue, + "h" => dap_pause, + "j" => dap_in, + "k" => dap_out, + "l" => dap_next, "z" => dap_variable_scopes, "t" => dap_terminate, }, |