diff options
author | Dmitry Sharshakov | 2021-09-04 19:57:58 +0000 |
---|---|---|
committer | Dmitry Sharshakov | 2021-09-04 19:57:58 +0000 |
commit | 1befbd076c0d182d7b6d9a6198054551d5ba34da (patch) | |
tree | 83bb72291e171061fa9c77b93196789dc6261e0d /helix-term/src/commands | |
parent | e36fc57fff8b7e13a8a7eec9eb5b188efc44371d (diff) |
Add command for editing breakpoint condition
Diffstat (limited to 'helix-term/src/commands')
-rw-r--r-- | helix-term/src/commands/dap.rs | 73 |
1 files changed, 72 insertions, 1 deletions
diff --git a/helix-term/src/commands/dap.rs b/helix-term/src/commands/dap.rs index 3e2a1887..ffb1aa9f 100644 --- a/helix-term/src/commands/dap.rs +++ b/helix-term/src/commands/dap.rs @@ -1,5 +1,8 @@ use super::{align_view, Align, Context, Editor}; -use crate::ui::{FilePicker, Picker}; +use crate::{ + commands, + ui::{FilePicker, Picker, Prompt, PromptEvent}, +}; use helix_core::Selection; use helix_dap::{self as dap, Client}; use helix_lsp::block_on; @@ -474,6 +477,74 @@ pub fn dap_terminate(cx: &mut Context) { cx.editor.debugger = None; } +pub fn dap_edit_condition(cx: &mut Context) { + if let Some((pos, mut bp)) = commands::cmd::get_breakpoint_at_current_line(cx.editor) { + let condition = bp.condition.clone(); + let prompt = Prompt::new( + "condition: ".into(), + None, + |_input: &str| Vec::new(), + move |cx: &mut crate::compositor::Context, input: &str, event: PromptEvent| { + if event != PromptEvent::Validate { + return; + } + + let (_, doc) = current!(cx.editor); + let path = match doc.path() { + Some(path) => path.to_path_buf(), + None => { + cx.editor + .set_status("Can't edit breakpoint: document has no path".to_owned()); + return; + } + }; + + let breakpoints = cx.editor.breakpoints.entry(path.clone()).or_default(); + breakpoints.remove(pos); + bp.condition = match input { + "" => None, + input => Some(input.to_owned()), + }; + breakpoints.push(bp.clone()); + + if let Some(debugger) = &mut cx.editor.debugger { + // TODO: handle capabilities correctly again, by filterin breakpoints when emitting + // if breakpoint.condition.is_some() + // && !debugger + // .caps + // .as_ref() + // .unwrap() + // .supports_conditional_breakpoints + // .unwrap_or_default() + // { + // bail!( + // "Can't edit breakpoint: debugger does not support conditional breakpoints" + // ) + // } + // if breakpoint.log_message.is_some() + // && !debugger + // .caps + // .as_ref() + // .unwrap() + // .supports_log_points + // .unwrap_or_default() + // { + // bail!("Can't edit breakpoint: debugger does not support logpoints") + // } + let request = debugger.set_breakpoints(path, breakpoints.clone()); + if let Err(e) = block_on(request) { + cx.editor + .set_status(format!("Failed to set breakpoints: {:?}", e)) + } + } + }, + condition, + ); + + cx.push_layer(Box::new(prompt)); + } +} + pub fn dap_switch_thread(cx: &mut Context) { thread_picker(cx, |editor, thread| { block_on(select_thread_id(editor, thread.id, true)); |