mirror of
https://github.com/helix-editor/helix.git
synced 2025-01-19 13:37:06 +04:00
dap: Extract diagnostics gutter into gutters.rs
This commit is contained in:
parent
8ffafb826f
commit
30ac5869df
@ -17,7 +17,7 @@
|
||||
};
|
||||
use helix_view::{
|
||||
document::{Mode, SCRATCH_BUFFER_NAME},
|
||||
graphics::{Color, CursorKind, Modifier, Rect, Style},
|
||||
graphics::{CursorKind, Modifier, Rect, Style},
|
||||
info::Info,
|
||||
input::KeyEvent,
|
||||
keyboard::{KeyCode, KeyModifiers},
|
||||
@ -419,68 +419,6 @@ pub fn render_gutter(
|
||||
.map(|range| range.cursor_line(text))
|
||||
.collect();
|
||||
|
||||
use helix_view::editor::Config;
|
||||
use helix_view::gutter::GutterFn;
|
||||
fn breakpoints<'doc>(
|
||||
editor: &'doc Editor,
|
||||
doc: &'doc Document,
|
||||
_view: &View,
|
||||
theme: &Theme,
|
||||
_config: &Config,
|
||||
_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
|
||||
use std::fmt::Write;
|
||||
let sym = if breakpoint.verified { "▲" } else { "⊚" };
|
||||
write!(out, "{}", sym).unwrap();
|
||||
Some(style)
|
||||
})
|
||||
}
|
||||
|
||||
// let mut stack_frame: Option<&StackFrame> = None;
|
||||
// if let Some(path) = doc.path() {
|
||||
// if let Some(debugger) = debugger {
|
||||
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
@ -64,7 +64,11 @@ pub fn remove(&mut self, doc_id: &DocumentId) {
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user