on master help sign in
editor: support setExceptionBreakpoints
commit0e51e5fbaf6eeffa25b8660b96f2486174671492 authorDmitry Sharshakov <d3dx12.xx@gmail.com> dateSun 26 Sep 2021, 10:24 (5 years ago) parentbf53aff
5 files changed+73
helix-dap/src/client.rs+13 helix-dap/src/types.rs+23 helix-term/src/commands.rs+2 helix-term/src/commands/dap.rs+33 helix-term/src/keymap.rs+2
helix-dap/src/client.rs+13
@@ -399,4 +399,17 @@ impl Client {
399399
400400 self.request::<requests::Evaluate>(args).await
401401 }
402+
403+ pub async fn set_exception_breakpoints(
404+ &mut self,
405+ filters: Vec<String>,
406+ ) -> Result<Option<Vec<Breakpoint>>> {
407+ let args = requests::SetExceptionBreakpointsArguments { filters };
408+
409+ let response = self
410+ .request::<requests::SetExceptionBreakpoints>(args)
411+ .await;
412+
413+ Ok(response.ok().map(|r| r.breakpoints).unwrap_or_default())
414+ }
402415}
helix-dap/src/types.rs+23
@@ -515,6 +515,29 @@ pub mod requests {
515515 type Result = EvaluateResponse;
516516 const COMMAND: &'static str = "evaluate";
517517 }
518+
519+ #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
520+ #[serde(rename_all = "camelCase")]
521+ pub struct SetExceptionBreakpointsArguments {
522+ pub filters: Vec<String>,
523+ // pub filterOptions: Option<Vec<ExceptionFilterOptions>>, // needs capability
524+ // pub exceptionOptions: Option<Vec<ExceptionOptions>>, // needs capability
525+ }
526+
527+ #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
528+ #[serde(rename_all = "camelCase")]
529+ pub struct SetExceptionBreakpointsResponse {
530+ pub breakpoints: Option<Vec<Breakpoint>>,
531+ }
532+
533+ #[derive(Debug)]
534+ pub enum SetExceptionBreakpoints {}
535+
536+ impl Request for SetExceptionBreakpoints {
537+ type Arguments = SetExceptionBreakpointsArguments;
538+ type Result = SetExceptionBreakpointsResponse;
539+ const COMMAND: &'static str = "setExceptionBreakpoints";
540+ }
518541}
519542
520543// Events
helix-term/src/commands.rs+2
@@ -335,6 +335,8 @@ impl Command {
335335 dap_edit_log, "Edit log message of the breakpoint on the current line",
336336 dap_switch_thread, "Switch current thread",
337337 dap_switch_stack_frame, "Switch stack frame",
338+ dap_enable_exceptions, "Enable exception breakpoints",
339+ dap_disable_exceptions, "Disable exception breakpoints",
338340 shell_pipe, "Pipe selections through shell command",
339341 shell_pipe_to, "Pipe selections into shell command, ignoring command output",
340342 shell_insert_output, "Insert output of shell command before each selection",
helix-term/src/commands/dap.rs+33
@@ -513,6 +513,39 @@ pub fn dap_terminate(cx: &mut Context) {
513513 cx.editor.debugger = None;
514514}
515515
516+pub fn dap_enable_exceptions(cx: &mut Context) {
517+ let debugger = match &mut cx.editor.debugger {
518+ Some(debugger) => debugger,
519+ None => return,
520+ };
521+
522+ let filters = match &debugger.capabilities().exception_breakpoint_filters {
523+ Some(filters) => filters.clone(),
524+ None => return,
525+ };
526+
527+ if let Err(e) = block_on(
528+ debugger.set_exception_breakpoints(filters.iter().map(|f| f.filter.clone()).collect()),
529+ ) {
530+ cx.editor
531+ .set_error(format!("Failed to set up exception breakpoints: {:?}", e));
532+ return;
533+ }
534+}
535+
536+pub fn dap_disable_exceptions(cx: &mut Context) {
537+ let debugger = match &mut cx.editor.debugger {
538+ Some(debugger) => debugger,
539+ None => return,
540+ };
541+
542+ if let Err(e) = block_on(debugger.set_exception_breakpoints(vec![])) {
543+ cx.editor
544+ .set_error(format!("Failed to set up exception breakpoints: {:?}", e));
545+ return;
546+ }
547+}
548+
516549pub fn dap_edit_condition(cx: &mut Context) {
517550 if let Some((pos, mut bp)) = commands::cmd::get_breakpoint_at_current_line(cx.editor) {
518551 let callback = Box::pin(async move {
helix-term/src/keymap.rs+2
@@ -557,6 +557,8 @@ impl Default for Keymaps {
557557 "f" => dap_switch_stack_frame,
558558 // sl, sb
559559 },
560+ "e" => dap_enable_exceptions,
561+ "E" => dap_disable_exceptions,
560562 },
561563 "w" => { "Window"
562564 "C-w" | "w" => rotate_view,