Support editing breakpoint condition with right click

This commit is contained in:
Dmitry Sharshakov 2021-09-05 08:14:17 +03:00
parent 1befbd076c
commit 3b0ec750ff
2 changed files with 97 additions and 60 deletions

View File

@ -1,6 +1,8 @@
use super::{align_view, Align, Context, Editor}; use super::{align_view, Align, Context, Editor};
use crate::{ use crate::{
commands, commands,
compositor::Compositor,
job::Callback,
ui::{FilePicker, Picker, Prompt, PromptEvent}, ui::{FilePicker, Picker, Prompt, PromptEvent},
}; };
use helix_core::Selection; use helix_core::Selection;
@ -479,69 +481,79 @@ pub fn dap_terminate(cx: &mut Context) {
pub fn dap_edit_condition(cx: &mut Context) { pub fn dap_edit_condition(cx: &mut Context) {
if let Some((pos, mut bp)) = commands::cmd::get_breakpoint_at_current_line(cx.editor) { if let Some((pos, mut bp)) = commands::cmd::get_breakpoint_at_current_line(cx.editor) {
let condition = bp.condition.clone(); let callback = Box::pin(async move {
let prompt = Prompt::new( let call: Callback =
"condition: ".into(), Box::new(move |_editor: &mut Editor, compositor: &mut Compositor| {
None, let condition = bp.condition.clone();
|_input: &str| Vec::new(), let prompt = Prompt::new(
move |cx: &mut crate::compositor::Context, input: &str, event: PromptEvent| { "condition: ".into(),
if event != PromptEvent::Validate { None,
return; |_input: &str| Vec::new(),
} move |cx: &mut crate::compositor::Context,
input: &str,
event: PromptEvent| {
if event != PromptEvent::Validate {
return;
}
let (_, doc) = current!(cx.editor); let (_, doc) = current!(cx.editor);
let path = match doc.path() { let path = match doc.path() {
Some(path) => path.to_path_buf(), Some(path) => path.to_path_buf(),
None => { None => {
cx.editor cx.editor.set_status(
.set_status("Can't edit breakpoint: document has no path".to_owned()); "Can't edit breakpoint: document has no path".to_owned(),
return; );
} return;
}; }
};
let breakpoints = cx.editor.breakpoints.entry(path.clone()).or_default(); let breakpoints =
breakpoints.remove(pos); cx.editor.breakpoints.entry(path.clone()).or_default();
bp.condition = match input { breakpoints.remove(pos);
"" => None, bp.condition = match input {
input => Some(input.to_owned()), "" => None,
}; input => Some(input.to_owned()),
breakpoints.push(bp.clone()); };
breakpoints.push(bp.clone());
if let Some(debugger) = &mut cx.editor.debugger { if let Some(debugger) = &mut cx.editor.debugger {
// TODO: handle capabilities correctly again, by filterin breakpoints when emitting // TODO: handle capabilities correctly again, by filterin breakpoints when emitting
// if breakpoint.condition.is_some() // if breakpoint.condition.is_some()
// && !debugger // && !debugger
// .caps // .caps
// .as_ref() // .as_ref()
// .unwrap() // .unwrap()
// .supports_conditional_breakpoints // .supports_conditional_breakpoints
// .unwrap_or_default() // .unwrap_or_default()
// { // {
// bail!( // bail!(
// "Can't edit breakpoint: debugger does not support conditional breakpoints" // "Can't edit breakpoint: debugger does not support conditional breakpoints"
// ) // )
// } // }
// if breakpoint.log_message.is_some() // if breakpoint.log_message.is_some()
// && !debugger // && !debugger
// .caps // .caps
// .as_ref() // .as_ref()
// .unwrap() // .unwrap()
// .supports_log_points // .supports_log_points
// .unwrap_or_default() // .unwrap_or_default()
// { // {
// bail!("Can't edit breakpoint: debugger does not support logpoints") // bail!("Can't edit breakpoint: debugger does not support logpoints")
// } // }
let request = debugger.set_breakpoints(path, breakpoints.clone()); let request = debugger.set_breakpoints(path, breakpoints.clone());
if let Err(e) = block_on(request) { if let Err(e) = block_on(request) {
cx.editor cx.editor
.set_status(format!("Failed to set breakpoints: {:?}", e)) .set_status(format!("Failed to set breakpoints: {:?}", e))
} }
} }
}, },
condition, condition,
); );
compositor.push(Box::new(prompt));
cx.push_layer(Box::new(prompt)); });
Ok(call)
});
cx.jobs.callback(callback);
} }
} }

View File

@ -1073,6 +1073,31 @@ impl EditorView {
EventResult::Consumed(None) EventResult::Consumed(None)
} }
MouseEvent {
kind: MouseEventKind::Up(MouseButton::Right),
row,
column,
..
} => {
let result = cxt.editor.tree.views().find_map(|(view, _focus)| {
view.gutter_coords_at_screen_coords(row, column)
.map(|coords| (coords.0, coords.1, view.id))
});
if let Some((line, _, view_id)) = result {
cxt.editor.tree.focus = view_id;
let doc = &mut cxt.editor.documents[cxt.editor.tree.get(view_id).doc];
if let Ok(pos) = doc.text().try_line_to_char(line) {
doc.set_selection(view_id, Selection::point(pos));
commands::Command::dap_edit_condition.execute(cxt);
return EventResult::Consumed(None);
}
}
EventResult::Ignored
}
MouseEvent { MouseEvent {
kind: MouseEventKind::Up(MouseButton::Middle), kind: MouseEventKind::Up(MouseButton::Middle),
row, row,