@@ -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