on master help sign in
Support editing breakpoint condition with right click
3b0ec75Dmitry Sharshakov
helix-term/src/commands/dap.rs+75−63
@@ -1,6 +1,8 @@
1use super::{align_view, Align, Context, Editor};
1use super::{align_view, Align, Context, Editor};
2use crate::{
2use crate::{
3 commands,
3 commands,
4+ compositor::Compositor,
5+ job::Callback,
4 ui::{FilePicker, Picker, Prompt, PromptEvent},
6 ui::{FilePicker, Picker, Prompt, PromptEvent},
5};
7};
6use helix_core::Selection;
8use helix_core::Selection;
@@ -479,69 +481,79 @@ pub fn dap_terminate(cx: &mut Context) {
479
481
480pub fn dap_edit_condition(cx: &mut Context) {
482pub fn dap_edit_condition(cx: &mut Context) {
481 if let Some((pos, mut bp)) = commands::cmd::get_breakpoint_at_current_line(cx.editor) {
483 if let Some((pos, mut bp)) = commands::cmd::get_breakpoint_at_current_line(cx.editor) {
484+ let callback = Box::pin(async move {
485+ let call: Callback =
486+ Box::new(move |_editor: &mut Editor, compositor: &mut Compositor| {
482− let condition = bp.condition.clone();
487+ let condition = bp.condition.clone();
483− let prompt = Prompt::new(
488+ let prompt = Prompt::new(
484− "condition: ".into(),
489+ "condition: ".into(),
485− None,
490+ None,
486− |_input: &str| Vec::new(),
491+ |_input: &str| Vec::new(),
487− move |cx: &mut crate::compositor::Context, input: &str, event: PromptEvent| {
492+ move |cx: &mut crate::compositor::Context,
493+ input: &str,
494+ event: PromptEvent| {
488− if event != PromptEvent::Validate {
495+ if event != PromptEvent::Validate {
489− return;
496+ return;
490− }
497+ }
491−
498+
492− let (_, doc) = current!(cx.editor);
499+ let (_, doc) = current!(cx.editor);
493− let path = match doc.path() {
500+ let path = match doc.path() {
494− Some(path) => path.to_path_buf(),
501+ Some(path) => path.to_path_buf(),
495− None => {
502+ None => {
496− cx.editor
503+ cx.editor.set_status(
497− .set_status("Can't edit breakpoint: document has no path".to_owned());
504+ "Can't edit breakpoint: document has no path".to_owned(),
505+ );
498− return;
506+ return;
499− }
507+ }
500− };
508+ };
501−
509+
510+ let breakpoints =
502− let breakpoints = cx.editor.breakpoints.entry(path.clone()).or_default();
511+ cx.editor.breakpoints.entry(path.clone()).or_default();
503− breakpoints.remove(pos);
512+ breakpoints.remove(pos);
504− bp.condition = match input {
513+ bp.condition = match input {
505− "" => None,
514+ "" => None,
506− input => Some(input.to_owned()),
515+ input => Some(input.to_owned()),
507− };
516+ };
508− breakpoints.push(bp.clone());
517+ breakpoints.push(bp.clone());
509−
518+
510− if let Some(debugger) = &mut cx.editor.debugger {
519+ if let Some(debugger) = &mut cx.editor.debugger {
511− // TODO: handle capabilities correctly again, by filterin breakpoints when emitting
520+ // TODO: handle capabilities correctly again, by filterin breakpoints when emitting
512− // if breakpoint.condition.is_some()
521+ // if breakpoint.condition.is_some()
513− // && !debugger
522+ // && !debugger
514− // .caps
523+ // .caps
515− // .as_ref()
524+ // .as_ref()
516− // .unwrap()
525+ // .unwrap()
517− // .supports_conditional_breakpoints
526+ // .supports_conditional_breakpoints
518− // .unwrap_or_default()
527+ // .unwrap_or_default()
519− // {
528+ // {
520− // bail!(
529+ // bail!(
521− // "Can't edit breakpoint: debugger does not support conditional breakpoints"
530+ // "Can't edit breakpoint: debugger does not support conditional breakpoints"
522− // )
531+ // )
523− // }
532+ // }
524− // if breakpoint.log_message.is_some()
533+ // if breakpoint.log_message.is_some()
525− // && !debugger
534+ // && !debugger
526− // .caps
535+ // .caps
527− // .as_ref()
536+ // .as_ref()
528− // .unwrap()
537+ // .unwrap()
529− // .supports_log_points
538+ // .supports_log_points
530− // .unwrap_or_default()
539+ // .unwrap_or_default()
531− // {
540+ // {
532− // bail!("Can't edit breakpoint: debugger does not support logpoints")
541+ // bail!("Can't edit breakpoint: debugger does not support logpoints")
533− // }
542+ // }
534− let request = debugger.set_breakpoints(path, breakpoints.clone());
543+ let request = debugger.set_breakpoints(path, breakpoints.clone());
535− if let Err(e) = block_on(request) {
544+ if let Err(e) = block_on(request) {
536− cx.editor
545+ cx.editor
537− .set_status(format!("Failed to set breakpoints: {:?}", e))
546+ .set_status(format!("Failed to set breakpoints: {:?}", e))
538− }
547+ }
539− }
548+ }
540− },
549+ },
541− condition,
550+ condition,
542− );
551+ );
543−
544− cx.push_layer(Box::new(prompt));
552+ compositor.push(Box::new(prompt));
553+ });
554+ Ok(call)
555+ });
556+ cx.jobs.callback(callback);
545 }
557 }
546}
558}
547
559
helix-term/src/ui/editor.rs+25
@@ -1073,6 +1073,31 @@ impl EditorView {
1073 EventResult::Consumed(None)
1073 EventResult::Consumed(None)
1074 }
1074 }
1075
1075
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+
1076 MouseEvent {
1101 MouseEvent {
1077 kind: MouseEventKind::Up(MouseButton::Middle),
1102 kind: MouseEventKind::Up(MouseButton::Middle),
1078 row,
1103 row,