aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src/gutter.rs
diff options
context:
space:
mode:
authorFilip Dutescu2023-03-29 03:52:19 +0000
committerGitHub2023-03-29 03:52:19 +0000
commitd59b80514e15d26f280a9b0dbd18afac08578638 (patch)
treee660c1c765404925f29465e4fb303e7b6fea2165 /helix-view/src/gutter.rs
parentbbcdcd04a5f6c02c14d73d6bd0f53099b1fcb765 (diff)
feat(debug): highlight current line (#5957)
Add new theme highlight keys, for setting the colour of the breakpoint character and the current line at which execution has been paused at. The two new keys are `ui.highlight.frameline` and `ui.debug.breakpoint`. Highlight according to those keys, both the line at which debugging is paused at and the breakpoint indicator. Add an indicator for the current line at which execution is paused at, themed by the `ui.debug.active` theme scope. Update various themes to showcase how the new functionality works. Better icons are dependent on #2869, and as such will be handled in the future, once it lands. Closes: #5952 Signed-off-by: Filip Dutescu <filip.dutescu@gmail.com>
Diffstat (limited to 'helix-view/src/gutter.rs')
-rw-r--r--helix-view/src/gutter.rs60
1 files changed, 42 insertions, 18 deletions
diff --git a/helix-view/src/gutter.rs b/helix-view/src/gutter.rs
index 36e8e16a..3ecae919 100644
--- a/helix-view/src/gutter.rs
+++ b/helix-view/src/gutter.rs
@@ -2,7 +2,7 @@ use std::fmt::Write;
use crate::{
editor::GutterType,
- graphics::{Color, Style, UnderlineStyle},
+ graphics::{Style, UnderlineStyle},
Document, Editor, Theme, View,
};
@@ -245,9 +245,9 @@ pub fn breakpoints<'doc>(
theme: &Theme,
_is_focused: bool,
) -> GutterFn<'doc> {
- let warning = theme.get("warning");
let error = theme.get("error");
let info = theme.get("info");
+ let breakpoint_style = theme.get("ui.debug.breakpoint");
let breakpoints = doc.path().and_then(|path| editor.breakpoints.get(path));
@@ -265,30 +265,52 @@ pub fn breakpoints<'doc>(
.iter()
.find(|breakpoint| breakpoint.line == line)?;
- let mut style = if breakpoint.condition.is_some() && breakpoint.log_message.is_some() {
+ let style = if breakpoint.condition.is_some() && breakpoint.log_message.is_some() {
error.underline_style(UnderlineStyle::Line)
} else if breakpoint.condition.is_some() {
error
} else if breakpoint.log_message.is_some() {
info
} else {
- warning
+ breakpoint_style
};
- if !breakpoint.verified {
- // Faded colors
- style = if let Some(Color::Rgb(r, g, b)) = style.fg {
- style.fg(Color::Rgb(
- ((r as f32) * 0.4).floor() as u8,
- ((g as f32) * 0.4).floor() as u8,
- ((b as f32) * 0.4).floor() as u8,
- ))
- } else {
- style.fg(Color::Gray)
- }
- };
+ let sym = if breakpoint.verified { "●" } else { "◯" };
+ write!(out, "{}", sym).unwrap();
+ Some(style)
+ },
+ )
+}
+
+fn execution_pause_indicator<'doc>(
+ editor: &'doc Editor,
+ doc: &'doc Document,
+ theme: &Theme,
+ is_focused: bool,
+) -> GutterFn<'doc> {
+ let style = theme.get("ui.debug.active");
+ let current_stack_frame = editor.current_stack_frame();
+ let frame_line = current_stack_frame.map(|frame| frame.line - 1);
+ let frame_source_path = current_stack_frame.map(|frame| {
+ frame
+ .source
+ .as_ref()
+ .and_then(|source| source.path.as_ref())
+ });
+ let should_display_for_current_doc =
+ doc.path().is_some() && frame_source_path.unwrap_or(None) == doc.path();
+
+ Box::new(
+ move |line: usize, _selected: bool, first_visual_line: bool, out: &mut String| {
+ if !first_visual_line
+ || !is_focused
+ || line != frame_line?
+ || !should_display_for_current_doc
+ {
+ return None;
+ }
- let sym = if breakpoint.verified { "▲" } else { "⊚" };
+ let sym = "▶";
write!(out, "{}", sym).unwrap();
Some(style)
},
@@ -304,9 +326,11 @@ pub fn diagnostics_or_breakpoints<'doc>(
) -> GutterFn<'doc> {
let mut diagnostics = diagnostic(editor, doc, view, theme, is_focused);
let mut breakpoints = breakpoints(editor, doc, view, theme, is_focused);
+ let mut execution_pause_indicator = execution_pause_indicator(editor, doc, theme, is_focused);
Box::new(move |line, selected, first_visual_line: bool, out| {
- breakpoints(line, selected, first_visual_line, out)
+ execution_pause_indicator(line, selected, first_visual_line, out)
+ .or_else(|| breakpoints(line, selected, first_visual_line, out))
.or_else(|| diagnostics(line, selected, first_visual_line, out))
})
}