on master help sign in
Mouse command for editing logpoint
8a60904Dmitry Sharshakov
helix-term/src/commands.rs+1
@@ -318,6 +318,7 @@ impl Command {
318 dap_variables, "List variables",
318 dap_variables, "List variables",
319 dap_terminate, "End debug session",
319 dap_terminate, "End debug session",
320 dap_edit_condition, "Edit condition of the breakpoint on the current line",
320 dap_edit_condition, "Edit condition of the breakpoint on the current line",
321+ dap_edit_log, "Edit log message of the breakpoint on the current line",
321 dap_switch_thread, "Switch current thread",
322 dap_switch_thread, "Switch current thread",
322 dap_switch_stack_frame, "Switch stack frame",
323 dap_switch_stack_frame, "Switch stack frame",
323 shell_pipe, "Pipe selections through shell command",
324 shell_pipe, "Pipe selections through shell command",
helix-term/src/commands/dap.rs+78
@@ -557,6 +557,84 @@ pub fn dap_edit_condition(cx: &mut Context) {
557 }
557 }
558}
558}
559
559
560+pub fn dap_edit_log(cx: &mut Context) {
561+ if let Some((pos, mut bp)) = commands::cmd::get_breakpoint_at_current_line(cx.editor) {
562+ let callback = Box::pin(async move {
563+ let call: Callback =
564+ Box::new(move |_editor: &mut Editor, compositor: &mut Compositor| {
565+ let log_message = bp.log_message.clone();
566+ let prompt = Prompt::new(
567+ "log message: ".into(),
568+ None,
569+ |_input: &str| Vec::new(),
570+ move |cx: &mut crate::compositor::Context,
571+ input: &str,
572+ event: PromptEvent| {
573+ if event != PromptEvent::Validate {
574+ return;
575+ }
576+
577+ let (_, doc) = current!(cx.editor);
578+ let path = match doc.path() {
579+ Some(path) => path.to_path_buf(),
580+ None => {
581+ cx.editor.set_status(
582+ "Can't edit breakpoint: document has no path".to_owned(),
583+ );
584+ return;
585+ }
586+ };
587+
588+ let breakpoints =
589+ cx.editor.breakpoints.entry(path.clone()).or_default();
590+ breakpoints.remove(pos);
591+ bp.log_message = match input {
592+ "" => None,
593+ input => Some(input.to_owned()),
594+ };
595+ breakpoints.push(bp.clone());
596+
597+ if let Some(debugger) = &mut cx.editor.debugger {
598+ // TODO: handle capabilities correctly again, by filterin breakpoints when emitting
599+ // if breakpoint.condition.is_some()
600+ // && !debugger
601+ // .caps
602+ // .as_ref()
603+ // .unwrap()
604+ // .supports_conditional_breakpoints
605+ // .unwrap_or_default()
606+ // {
607+ // bail!(
608+ // "Can't edit breakpoint: debugger does not support conditional breakpoints"
609+ // )
610+ // }
611+ // if breakpoint.log_message.is_some()
612+ // && !debugger
613+ // .caps
614+ // .as_ref()
615+ // .unwrap()
616+ // .supports_log_points
617+ // .unwrap_or_default()
618+ // {
619+ // bail!("Can't edit breakpoint: debugger does not support logpoints")
620+ // }
621+ let request = debugger.set_breakpoints(path, breakpoints.clone());
622+ if let Err(e) = block_on(request) {
623+ cx.editor
624+ .set_status(format!("Failed to set breakpoints: {:?}", e))
625+ }
626+ }
627+ },
628+ log_message,
629+ );
630+ compositor.push(Box::new(prompt));
631+ });
632+ Ok(call)
633+ });
634+ cx.jobs.callback(callback);
635+ }
636+}
637+
560pub fn dap_switch_thread(cx: &mut Context) {
638pub fn dap_switch_thread(cx: &mut Context) {
561 thread_picker(cx, |editor, thread| {
639 thread_picker(cx, |editor, thread| {
562 block_on(select_thread_id(editor, thread.id, true));
640 block_on(select_thread_id(editor, thread.id, true));
helix-term/src/ui/editor.rs+6−1
@@ -1077,6 +1077,7 @@ impl EditorView {
1077 kind: MouseEventKind::Up(MouseButton::Right),
1077 kind: MouseEventKind::Up(MouseButton::Right),
1078 row,
1078 row,
1079 column,
1079 column,
1080+ modifiers,
1080 ..
1081 ..
1081 } => {
1082 } => {
1082 let result = cxt.editor.tree.views().find_map(|(view, _focus)| {
1083 let result = cxt.editor.tree.views().find_map(|(view, _focus)| {
@@ -1090,7 +1091,11 @@ impl EditorView {
1090 let doc = &mut cxt.editor.documents[cxt.editor.tree.get(view_id).doc];
1091 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 if let Ok(pos) = doc.text().try_line_to_char(line) {
1092 doc.set_selection(view_id, Selection::point(pos));
1093 doc.set_selection(view_id, Selection::point(pos));
1094+ if modifiers == crossterm::event::KeyModifiers::ALT {
1095+ commands::Command::dap_edit_log.execute(cxt);
1096+ } else {
1093− commands::Command::dap_edit_condition.execute(cxt);
1097+ commands::Command::dap_edit_condition.execute(cxt);
1098+ }
1094
1099
1095 return EventResult::Consumed(None);
1100 return EventResult::Consumed(None);
1096 }
1101 }