on master help sign in
Support conditional breakpoints
commitf247858055ee17e6d4a61d7284548febe1d7f54d authorDmitry Sharshakov <d3dx12.xx@gmail.com> dateSun 22 Aug 2021, 15:06 (5 years ago) parent3197c25
2 files changed+65−2
helix-term/src/commands.rs+58 helix-term/src/ui/editor.rs+7−2
helix-term/src/commands.rs+58
@@ -1924,6 +1924,57 @@ mod cmd {
19241924 Ok(())
19251925 }
19261926
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+
19271978 pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
19281979 TypableCommand {
19291980 name: "quit",
@@ -2169,6 +2220,13 @@ mod cmd {
21692220 doc: "Evaluate expression in current debug context.",
21702221 fun: debug_eval,
21712222 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,
21722230 }
21732231 ];
21742232
helix-term/src/ui/editor.rs+7−2
@@ -472,8 +472,13 @@ impl EditorView {
472472 let selected = cursors.contains(&line);
473473
474474 if let Some(bps) = breakpoints.as_ref() {
475− if bps.iter().any(|breakpoint| breakpoint.line - 1 == line) {
476− surface.set_stringn(viewport.x, viewport.y + i as u16, "▲", 1, warning);
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 {
480+ surface.set_stringn(viewport.x, viewport.y + i as u16, "▲", 1, warning);
481+ }
477482 }
478483 }
479484