on master help sign in
Support logpoints
5d3c69dDmitry Sharshakov
helix-term/src/commands.rs+44−18
@@ -1924,42 +1924,30 @@ mod cmd {
1924 Ok(())
1924 Ok(())
1925 }
1925 }
1926
1926
1927− fn debug_breakpoint_condition(
1927+ fn impl_edit_breakpoint(
1928 cx: &mut compositor::Context,
1928 cx: &mut compositor::Context,
1929− args: &[&str],
1929+ condition: Option<String>,
1930− _event: PromptEvent,
1930+ log_message: Option<String>,
1931− ) -> anyhow::Result<()> {
1931+ ) {
1932 use helix_lsp::block_on;
1932 use helix_lsp::block_on;
1933
1933
1934− let condition = args.join(" ");
1935− let condition = if condition.is_empty() {
1936− None
1937− } else {
1938− Some(condition)
1939− };
1940−
1941 let (view, doc) = current!(cx.editor);
1934 let (view, doc) = current!(cx.editor);
1942 let text = doc.text().slice(..);
1935 let text = doc.text().slice(..);
1943 let pos = doc.selection(view.id).primary().cursor(text);
1936 let pos = doc.selection(view.id).primary().cursor(text);
1944−
1945 let breakpoint = helix_dap::SourceBreakpoint {
1937 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)
1938 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,
1939 condition,
1940+ log_message,
1948 ..Default::default()
1941 ..Default::default()
1949 };
1942 };
1950−
1951 let path = match doc.path() {
1943 let path = match doc.path() {
1952 Some(path) => path.to_path_buf(),
1944 Some(path) => path.to_path_buf(),
1953 None => {
1945 None => {
1954 cx.editor
1946 cx.editor
1955 .set_error("Can't edit breakpoint: document has no path".to_string());
1947 .set_error("Can't edit breakpoint: document has no path".to_string());
1956− return Ok(());
1948+ return;
1957 }
1949 }
1958 };
1950 };
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 {
1951 if let Some(debugger) = &mut cx.editor.debugger {
1964 let breakpoints = debugger.breakpoints.entry(path.clone()).or_default();
1952 let breakpoints = debugger.breakpoints.entry(path.clone()).or_default();
1965 if let Some(pos) = breakpoints.iter().position(|b| b.line == breakpoint.line) {
1953 if let Some(pos) = breakpoints.iter().position(|b| b.line == breakpoint.line) {
@@ -1972,6 +1960,37 @@ mod cmd {
1972 let _ = block_on(request).unwrap();
1960 let _ = block_on(request).unwrap();
1973 }
1961 }
1974 }
1962 }
1963+ }
1964+
1965+ fn debug_breakpoint_condition(
1966+ cx: &mut compositor::Context,
1967+ args: &[&str],
1968+ _event: PromptEvent,
1969+ ) -> anyhow::Result<()> {
1970+ let condition = args.join(" ");
1971+ let condition = if condition.is_empty() {
1972+ None
1973+ } else {
1974+ Some(condition)
1975+ };
1976+
1977+ impl_edit_breakpoint(cx, condition, None);
1978+ Ok(())
1979+ }
1980+
1981+ fn debug_set_logpoint(
1982+ cx: &mut compositor::Context,
1983+ args: &[&str],
1984+ _event: PromptEvent,
1985+ ) -> anyhow::Result<()> {
1986+ let log_message = args.join(" ");
1987+ let log_message = if log_message.is_empty() {
1988+ None
1989+ } else {
1990+ Some(log_message)
1991+ };
1992+
1993+ impl_edit_breakpoint(cx, None, log_message);
1975 Ok(())
1994 Ok(())
1976 }
1995 }
1977
1996
@@ -2227,6 +2246,13 @@ mod cmd {
2227 doc: "Set current breakpoint condition.",
2246 doc: "Set current breakpoint condition.",
2228 fun: debug_breakpoint_condition,
2247 fun: debug_breakpoint_condition,
2229 completer: None,
2248 completer: None,
2249+ },
2250+ TypableCommand {
2251+ name: "debug-set-logpoint",
2252+ alias: None,
2253+ doc: "Make current breakpoint a log point.",
2254+ fun: debug_set_logpoint,
2255+ completer: None,
2230 }
2256 }
2231 ];
2257 ];
2232
2258
helix-term/src/ui/editor.rs+8
@@ -476,6 +476,8 @@ impl EditorView {
476 {
476 {
477 if breakpoint.condition.is_some() {
477 if breakpoint.condition.is_some() {
478 surface.set_stringn(viewport.x, viewport.y + i as u16, "▲", 1, error);
478 surface.set_stringn(viewport.x, viewport.y + i as u16, "▲", 1, error);
479+ } else if breakpoint.log_message.is_some() {
480+ surface.set_stringn(viewport.x, viewport.y + i as u16, "▲", 1, info);
479 } else {
481 } else {
480 surface.set_stringn(viewport.x, viewport.y + i as u16, "▲", 1, warning);
482 surface.set_stringn(viewport.x, viewport.y + i as u16, "▲", 1, warning);
481 }
483 }
@@ -581,6 +583,12 @@ impl EditorView {
581 .lines,
583 .lines,
582 );
584 );
583 }
585 }
586+ if let Some(log_message) = &breakpoint.log_message {
587+ lines.extend(
588+ Text::styled(log_message, info.add_modifier(Modifier::UNDERLINED))
589+ .lines,
590+ );
591+ }
584 }
592 }
585 }
593 }
586 }
594 }