on master help sign in
Support conditional breakpoints
f247858Dmitry Sharshakov
helix-term/src/commands.rs+58
@@ -1924,6 +1924,57 @@ mod cmd {
1924 Ok(())
1924 Ok(())
1925 }
1925 }
1926
1926
1927+ fn debug_breakpoint_condition(
1928+ cx: &mut compositor::Context,
1929+ args: &[&str],
1930+ _event: PromptEvent,
1931+ ) -> anyhow::Result<()> {
1932+ use helix_lsp::block_on;
1933+
1934+ let condition = args.join(" ");
1935+ let condition = if condition.len() > 0 {
1936+ Some(condition)
1937+ } else {
1938+ None
1939+ };
1940+
1941+ let (view, doc) = current!(cx.editor);
1942+ let text = doc.text().slice(..);
1943+ let pos = doc.selection(view.id).primary().cursor(text);
1944+
1945+ let breakpoint = helix_dap::SourceBreakpoint {
1946+ line: text.char_to_line(pos) + 1, // convert from 0-indexing to 1-indexing (TODO: could set debugger to 0-indexing on init)
1947+ condition,
1948+ ..Default::default()
1949+ };
1950+
1951+ let path = match doc.path() {
1952+ Some(path) => path.to_path_buf(),
1953+ None => {
1954+ cx.editor
1955+ .set_error("Can't edit breakpoint: document has no path".to_string());
1956+ return Ok(());
1957+ }
1958+ };
1959+
1960+ // TODO: need to map breakpoints over edits and update them?
1961+ // we shouldn't really allow editing while debug is running though
1962+
1963+ if let Some(debugger) = &mut cx.editor.debugger {
1964+ let breakpoints = debugger.breakpoints.entry(path.clone()).or_default();
1965+ if let Some(pos) = breakpoints.iter().position(|b| b.line == breakpoint.line) {
1966+ breakpoints.remove(pos);
1967+ breakpoints.push(breakpoint);
1968+
1969+ let breakpoints = breakpoints.clone();
1970+
1971+ let request = debugger.set_breakpoints(path, breakpoints);
1972+ let _ = block_on(request).unwrap();
1973+ }
1974+ }
1975+ Ok(())
1976+ }
1977+
1927 pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
1978 pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
1928 TypableCommand {
1979 TypableCommand {
1929 name: "quit",
1980 name: "quit",
@@ -2169,6 +2220,13 @@ mod cmd {
2169 doc: "Evaluate expression in current debug context.",
2220 doc: "Evaluate expression in current debug context.",
2170 fun: debug_eval,
2221 fun: debug_eval,
2171 completer: None,
2222 completer: None,
2223+ },
2224+ TypableCommand {
2225+ name: "debug-breakpoint-condition",
2226+ alias: None,
2227+ doc: "Set current breakpoint condition.",
2228+ fun: debug_breakpoint_condition,
2229+ completer: None,
2172 }
2230 }
2173 ];
2231 ];
2174
2232
helix-term/src/ui/editor.rs+7−2
@@ -472,8 +472,13 @@ impl EditorView {
472 let selected = cursors.contains(&line);
472 let selected = cursors.contains(&line);
473
473
474 if let Some(bps) = breakpoints.as_ref() {
474 if let Some(bps) = breakpoints.as_ref() {
475− if bps.iter().any(|breakpoint| breakpoint.line - 1 == line) {
475+ if let Some(breakpoint) = bps.iter().find(|breakpoint| breakpoint.line - 1 == line)
476+ {
477+ if breakpoint.condition.is_some() {
478+ surface.set_stringn(viewport.x, viewport.y + i as u16, "▲", 1, error);
479+ } else {
476− surface.set_stringn(viewport.x, viewport.y + i as u16, "▲", 1, warning);
480+ surface.set_stringn(viewport.x, viewport.y + i as u16, "▲", 1, warning);
481+ }
477 }
482 }
478 }
483 }
479
484