Support conditional breakpoints

pull/574/head
Dmitry Sharshakov 3 years ago
parent 3197c2536e
commit f247858055
No known key found for this signature in database
GPG Key ID: 471FD32E15FD8473

@ -1924,6 +1924,57 @@ mod cmd {
Ok(())
}
fn debug_breakpoint_condition(
cx: &mut compositor::Context,
args: &[&str],
_event: PromptEvent,
) -> anyhow::Result<()> {
use helix_lsp::block_on;
let condition = args.join(" ");
let condition = if condition.len() > 0 {
Some(condition)
} else {
None
};
let (view, doc) = current!(cx.editor);
let text = doc.text().slice(..);
let pos = doc.selection(view.id).primary().cursor(text);
let breakpoint = helix_dap::SourceBreakpoint {
line: text.char_to_line(pos) + 1, // convert from 0-indexing to 1-indexing (TODO: could set debugger to 0-indexing on init)
condition,
..Default::default()
};
let path = match doc.path() {
Some(path) => path.to_path_buf(),
None => {
cx.editor
.set_error("Can't edit breakpoint: document has no path".to_string());
return Ok(());
}
};
// TODO: need to map breakpoints over edits and update them?
// we shouldn't really allow editing while debug is running though
if let Some(debugger) = &mut cx.editor.debugger {
let breakpoints = debugger.breakpoints.entry(path.clone()).or_default();
if let Some(pos) = breakpoints.iter().position(|b| b.line == breakpoint.line) {
breakpoints.remove(pos);
breakpoints.push(breakpoint);
let breakpoints = breakpoints.clone();
let request = debugger.set_breakpoints(path, breakpoints);
let _ = block_on(request).unwrap();
}
}
Ok(())
}
pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
TypableCommand {
name: "quit",
@ -2169,6 +2220,13 @@ mod cmd {
doc: "Evaluate expression in current debug context.",
fun: debug_eval,
completer: None,
},
TypableCommand {
name: "debug-breakpoint-condition",
alias: None,
doc: "Set current breakpoint condition.",
fun: debug_breakpoint_condition,
completer: None,
}
];

@ -472,8 +472,13 @@ impl EditorView {
let selected = cursors.contains(&line);
if let Some(bps) = breakpoints.as_ref() {
if bps.iter().any(|breakpoint| breakpoint.line - 1 == line) {
surface.set_stringn(viewport.x, viewport.y + i as u16, "▲", 1, warning);
if let Some(breakpoint) = bps.iter().find(|breakpoint| breakpoint.line - 1 == line)
{
if breakpoint.condition.is_some() {
surface.set_stringn(viewport.x, viewport.y + i as u16, "▲", 1, error);
} else {
surface.set_stringn(viewport.x, viewport.y + i as u16, "▲", 1, warning);
}
}
}

Loading…
Cancel
Save