on master help sign in
dap: Remap keys, match current thread behavior from dap-mode, switch-thread
commit986828e75c17662da39505c7190220b8c352bc8a authorBlaž Hrastnik <blaz@mxxn.io> dateSun 29 Aug 2021, 23:28 (5 years ago) parent03b2d81
5 files changed+50−23
helix-dap/src/client.rs+2−2 helix-term/src/application.rs+6−13 helix-term/src/commands.rs+1 helix-term/src/commands/dap.rs+32−4 helix-term/src/keymap.rs+9−4
helix-dap/src/client.rs+2−2
@@ -31,7 +31,7 @@ pub struct Client {
3131 pub breakpoints: HashMap<PathBuf, Vec<SourceBreakpoint>>,
3232 // TODO: multiple threads support
3333 pub stack_pointer: Option<StackFrame>,
34− pub stopped_thread: Option<usize>,
34+ pub thread_id: Option<usize>,
3535 pub is_running: bool,
3636}
3737
@@ -77,7 +77,7 @@ impl Client {
7777 //
7878 breakpoints: HashMap::new(),
7979 stack_pointer: None,
80− stopped_thread: None,
80+ thread_id: None,
8181 is_running: false,
8282 };
8383
helix-term/src/application.rs+6−13
@@ -1,4 +1,4 @@
1−use helix_core::{merge_toml_values, syntax, Range, Selection};
1+use helix_core::{merge_toml_values, syntax, Selection};
22use helix_dap::Payload;
33use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap};
44use helix_view::{theme, Editor};
@@ -280,19 +280,13 @@ impl Application {
280280 ..
281281 }) => {
282282 debugger.is_running = false;
283− let main = debugger.threads().await.ok().and_then(|threads| {
284− // Workaround for debugging Go tests. Main thread has * in beginning of its name
285− let mut main = threads.iter().find(|t| t.name.starts_with('*')).cloned();
286− if main.is_none() {
287− main = threads.get(0).cloned();
288− }
289− main
290− });
291283
292− if let Some(main) = main {
293− let (bt, _) = debugger.stack_trace(main.id).await.unwrap();
284+ // whichever thread stops is made "current".
285+ debugger.thread_id = thread_id;
286+
287+ if let Some(thread_id) = thread_id {
288+ let (bt, _) = debugger.stack_trace(thread_id).await.unwrap();
294289 debugger.stack_pointer = bt.get(0).cloned();
295− debugger.stopped_thread = Some(main.id);
296290 }
297291
298292 let scope = match thread_id {
@@ -379,7 +373,6 @@ impl Application {
379373 .set_status("Debugged application started".to_owned());
380374 }
381375 Event::Continued(_) => {
382− debugger.stopped_thread = None;
383376 debugger.stack_pointer = None;
384377 debugger.is_running = true;
385378 }
helix-term/src/commands.rs+1
@@ -316,6 +316,7 @@ impl Command {
316316 dap_next, "Step to next",
317317 dap_variables, "List variables",
318318 dap_terminate, "End debug session",
319+ dap_switch_thread, "Switch current thread",
319320 suspend, "Suspend"
320321 );
321322}
helix-term/src/commands/dap.rs+32−4
@@ -1,4 +1,5 @@
11use super::{Context, Editor};
2+use crate::ui::Picker;
23use helix_dap::Client;
34use helix_lsp::block_on;
45
@@ -221,7 +222,7 @@ pub fn dap_continue(cx: &mut Context) {
221222 return;
222223 }
223224
224− let request = debugger.continue_thread(debugger.stopped_thread.unwrap());
225+ let request = debugger.continue_thread(debugger.thread_id.unwrap());
225226 if let Err(e) = block_on(request) {
226227 cx.editor.set_error(format!("Failed to continue: {:?}", e));
227228 return;
@@ -254,7 +255,7 @@ pub fn dap_step_in(cx: &mut Context) {
254255 return;
255256 }
256257
257− let request = debugger.step_in(debugger.stopped_thread.unwrap());
258+ let request = debugger.step_in(debugger.thread_id.unwrap());
258259 if let Err(e) = block_on(request) {
259260 cx.editor.set_error(format!("Failed to step: {:?}", e));
260261 }
@@ -269,7 +270,7 @@ pub fn dap_step_out(cx: &mut Context) {
269270 return;
270271 }
271272
272− let request = debugger.step_out(debugger.stopped_thread.unwrap());
273+ let request = debugger.step_out(debugger.thread_id.unwrap());
273274 if let Err(e) = block_on(request) {
274275 cx.editor.set_error(format!("Failed to step: {:?}", e));
275276 }
@@ -284,7 +285,7 @@ pub fn dap_next(cx: &mut Context) {
284285 return;
285286 }
286287
287− let request = debugger.next(debugger.stopped_thread.unwrap());
288+ let request = debugger.next(debugger.thread_id.unwrap());
288289 if let Err(e) = block_on(request) {
289290 cx.editor.set_error(format!("Failed to step: {:?}", e));
290291 }
@@ -347,3 +348,30 @@ pub fn dap_terminate(cx: &mut Context) {
347348 cx.editor.debugger = None;
348349 }
349350}
351+
352+pub fn dap_switch_thread(cx: &mut Context) {
353+ if let Some(debugger) = &mut cx.editor.debugger {
354+ let request = debugger.threads();
355+ let threads = match block_on(request) {
356+ Ok(threads) => threads,
357+ Err(e) => {
358+ cx.editor
359+ .set_error(format!("Failed to retrieve threads: {:?}", e));
360+ return;
361+ }
362+ };
363+
364+ let picker = Picker::new(
365+ true,
366+ threads,
367+ |thread| thread.name.clone().into(),
368+ |editor, thread, _action| {
369+ if let Some(debugger) = &mut editor.debugger {
370+ debugger.thread_id = Some(thread.id);
371+ // TODO: probably need to refetch stack frames?
372+ }
373+ },
374+ );
375+ cx.push_layer(Box::new(picker))
376+ }
377+}
helix-term/src/keymap.rs+9−4
@@ -486,16 +486,21 @@ impl Default for Keymaps {
486486 "a" => code_action,
487487 "'" => last_picker,
488488 "d" => { "Debug"
489− "s" => dap_launch,
489+ "l" => dap_launch,
490490 "b" => dap_toggle_breakpoint,
491491 "r" => dap_run,
492492 "c" => dap_continue,
493493 "h" => dap_pause,
494− "j" => dap_step_in,
495− "k" => dap_step_out,
496− "l" => dap_next,
494+ "i" => dap_step_in,
495+ "o" => dap_step_out,
496+ "n" => dap_next,
497497 "v" => dap_variables,
498498 "t" => dap_terminate,
499+ "s" => { "Switch"
500+ "t" => dap_switch_thread,
501+ // f = stack frame
502+ // sl, sb
503+ },
499504 },
500505 "w" => { "Window"
501506 "C-w" | "w" => rotate_view,