on master help sign in
Support editing breakpoint condition with right click
commit3b0ec750ff7348c60a60164ca54237c5b4acd694 authorDmitry Sharshakov <d3dx12.xx@gmail.com> dateSun 5 Sep 2021, 08:14 (5 years ago) parent1befbd0
2 files changed+100−63
helix-term/src/commands/dap.rs+75−63 helix-term/src/ui/editor.rs+25
helix-term/src/commands/dap.rs+75−63
@@ -1,6 +1,8 @@
11use super::{align_view, Align, Context, Editor};
22use crate::{
33 commands,
4+ compositor::Compositor,
5+ job::Callback,
46 ui::{FilePicker, Picker, Prompt, PromptEvent},
57};
68use helix_core::Selection;
@@ -479,69 +481,79 @@ pub fn dap_terminate(cx: &mut Context) {
479481
480482pub fn dap_edit_condition(cx: &mut Context) {
481483 if let Some((pos, mut bp)) = commands::cmd::get_breakpoint_at_current_line(cx.editor) {
482− let condition = bp.condition.clone();
483− let prompt = Prompt::new(
484− "condition: ".into(),
485− None,
486− |_input: &str| Vec::new(),
487− move |cx: &mut crate::compositor::Context, input: &str, event: PromptEvent| {
488− if event != PromptEvent::Validate {
489− return;
490− }
491−
492− let (_, doc) = current!(cx.editor);
493− let path = match doc.path() {
494− Some(path) => path.to_path_buf(),
495− None => {
496− cx.editor
497− .set_status("Can't edit breakpoint: document has no path".to_owned());
498− return;
499− }
500− };
501−
502− let breakpoints = cx.editor.breakpoints.entry(path.clone()).or_default();
503− breakpoints.remove(pos);
504− bp.condition = match input {
505− "" => None,
506− input => Some(input.to_owned()),
507− };
508− breakpoints.push(bp.clone());
509−
510− if let Some(debugger) = &mut cx.editor.debugger {
511− // TODO: handle capabilities correctly again, by filterin breakpoints when emitting
512− // if breakpoint.condition.is_some()
513− // && !debugger
514− // .caps
515− // .as_ref()
516− // .unwrap()
517− // .supports_conditional_breakpoints
518− // .unwrap_or_default()
519− // {
520− // bail!(
521− // "Can't edit breakpoint: debugger does not support conditional breakpoints"
522− // )
523− // }
524− // if breakpoint.log_message.is_some()
525− // && !debugger
526− // .caps
527− // .as_ref()
528− // .unwrap()
529− // .supports_log_points
530− // .unwrap_or_default()
531− // {
532− // bail!("Can't edit breakpoint: debugger does not support logpoints")
533− // }
534− let request = debugger.set_breakpoints(path, breakpoints.clone());
535− if let Err(e) = block_on(request) {
536− cx.editor
537− .set_status(format!("Failed to set breakpoints: {:?}", e))
538− }
539− }
540− },
541− condition,
542− );
543−
544− cx.push_layer(Box::new(prompt));
484+ let callback = Box::pin(async move {
485+ let call: Callback =
486+ Box::new(move |_editor: &mut Editor, compositor: &mut Compositor| {
487+ let condition = bp.condition.clone();
488+ let prompt = Prompt::new(
489+ "condition: ".into(),
490+ None,
491+ |_input: &str| Vec::new(),
492+ move |cx: &mut crate::compositor::Context,
493+ input: &str,
494+ event: PromptEvent| {
495+ if event != PromptEvent::Validate {
496+ return;
497+ }
498+
499+ let (_, doc) = current!(cx.editor);
500+ let path = match doc.path() {
501+ Some(path) => path.to_path_buf(),
502+ None => {
503+ cx.editor.set_status(
504+ "Can't edit breakpoint: document has no path".to_owned(),
505+ );
506+ return;
507+ }
508+ };
509+
510+ let breakpoints =
511+ cx.editor.breakpoints.entry(path.clone()).or_default();
512+ breakpoints.remove(pos);
513+ bp.condition = match input {
514+ "" => None,
515+ input => Some(input.to_owned()),
516+ };
517+ breakpoints.push(bp.clone());
518+
519+ if let Some(debugger) = &mut cx.editor.debugger {
520+ // TODO: handle capabilities correctly again, by filterin breakpoints when emitting
521+ // if breakpoint.condition.is_some()
522+ // && !debugger
523+ // .caps
524+ // .as_ref()
525+ // .unwrap()
526+ // .supports_conditional_breakpoints
527+ // .unwrap_or_default()
528+ // {
529+ // bail!(
530+ // "Can't edit breakpoint: debugger does not support conditional breakpoints"
531+ // )
532+ // }
533+ // if breakpoint.log_message.is_some()
534+ // && !debugger
535+ // .caps
536+ // .as_ref()
537+ // .unwrap()
538+ // .supports_log_points
539+ // .unwrap_or_default()
540+ // {
541+ // bail!("Can't edit breakpoint: debugger does not support logpoints")
542+ // }
543+ let request = debugger.set_breakpoints(path, breakpoints.clone());
544+ if let Err(e) = block_on(request) {
545+ cx.editor
546+ .set_status(format!("Failed to set breakpoints: {:?}", e))
547+ }
548+ }
549+ },
550+ condition,
551+ );
552+ compositor.push(Box::new(prompt));
553+ });
554+ Ok(call)
555+ });
556+ cx.jobs.callback(callback);
545557 }
546558}
547559
helix-term/src/ui/editor.rs+25
@@ -1073,6 +1073,31 @@ impl EditorView {
10731073 EventResult::Consumed(None)
10741074 }
10751075
1076+ MouseEvent {
1077+ kind: MouseEventKind::Up(MouseButton::Right),
1078+ row,
1079+ column,
1080+ ..
1081+ } => {
1082+ let result = cxt.editor.tree.views().find_map(|(view, _focus)| {
1083+ view.gutter_coords_at_screen_coords(row, column)
1084+ .map(|coords| (coords.0, coords.1, view.id))
1085+ });
1086+
1087+ if let Some((line, _, view_id)) = result {
1088+ cxt.editor.tree.focus = view_id;
1089+
1090+ let doc = &mut cxt.editor.documents[cxt.editor.tree.get(view_id).doc];
1091+ if let Ok(pos) = doc.text().try_line_to_char(line) {
1092+ doc.set_selection(view_id, Selection::point(pos));
1093+ commands::Command::dap_edit_condition.execute(cxt);
1094+
1095+ return EventResult::Consumed(None);
1096+ }
1097+ }
1098+ EventResult::Ignored
1099+ }
1100+
10761101 MouseEvent {
10771102 kind: MouseEventKind::Up(MouseButton::Middle),
10781103 row,