aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-11-30 08:55:40 +0000
committerBlaž Hrastnik2021-11-30 08:56:00 +0000
commit30ac5869dfc514696085063f5c84d4be1aebf781 (patch)
treef9d217bc5ce3b48967f56310834373f6d124472f /helix-view/src
parent8ffafb826faa75c76f74af3350d73adceb24e81d (diff)
dap: Extract diagnostics gutter into gutters.rs
Diffstat (limited to 'helix-view/src')
-rw-r--r--helix-view/src/gutter.rs62
-rw-r--r--helix-view/src/view.rs6
2 files changed, 66 insertions, 2 deletions
diff --git a/helix-view/src/gutter.rs b/helix-view/src/gutter.rs
index 8dc243c3..ab5c6d16 100644
--- a/helix-view/src/gutter.rs
+++ b/helix-view/src/gutter.rs
@@ -1,6 +1,9 @@
use std::fmt::Write;
-use crate::{graphics::Style, Document, Editor, Theme, View};
+use crate::{
+ graphics::{Color, Modifier, Style},
+ Document, Editor, Theme, View,
+};
pub type GutterFn<'doc> = Box<dyn Fn(usize, bool, &mut String) -> Option<Style> + 'doc>;
pub type Gutter =
@@ -93,3 +96,60 @@ const fn abs_diff(a: usize, b: usize) -> usize {
b - a
}
}
+
+pub fn breakpoints<'doc>(
+ editor: &'doc Editor,
+ doc: &'doc Document,
+ _view: &View,
+ theme: &Theme,
+ _is_focused: bool,
+ _width: usize,
+) -> GutterFn<'doc> {
+ let warning = theme.get("warning");
+ let error = theme.get("error");
+ let info = theme.get("info");
+
+ let breakpoints = doc
+ .path()
+ .and_then(|path| editor.breakpoints.get(path))
+ .unwrap();
+
+ Box::new(move |line: usize, _selected: bool, out: &mut String| {
+ let breakpoint = breakpoints
+ .iter()
+ .find(|breakpoint| breakpoint.line == line);
+
+ let breakpoint = match breakpoint {
+ Some(b) => b,
+ None => return None,
+ };
+
+ let mut style = if breakpoint.condition.is_some() && breakpoint.log_message.is_some() {
+ error.add_modifier(Modifier::UNDERLINED)
+ } else if breakpoint.condition.is_some() {
+ error
+ } else if breakpoint.log_message.is_some() {
+ info
+ } else {
+ warning
+ };
+
+ 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)
+ }
+ };
+
+ // TODO: also handle breakpoints only present in the user struct
+ let sym = if breakpoint.verified { "▲" } else { "⊚" };
+ write!(out, "{}", sym).unwrap();
+ Some(style)
+ })
+}
diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs
index 78b3eb24..7a2d255a 100644
--- a/helix-view/src/view.rs
+++ b/helix-view/src/view.rs
@@ -64,7 +64,11 @@ impl JumpList {
}
}
-const GUTTERS: &[(Gutter, usize)] = &[(gutter::diagnostic, 1), (gutter::line_number, 5)];
+const GUTTERS: &[(Gutter, usize)] = &[
+ (gutter::breakpoints, 1),
+ (gutter::diagnostic, 1),
+ (gutter::line_number, 5),
+];
#[derive(Debug)]
pub struct View {