on master help sign in
Use diagnostic.severity to distinguish between error colors.
commit9dcfe25e4a1868a4936194faf1d753d91d85430a authorBlaž Hrastnik <blaz@mxxn.io> dateThu 11 Mar 2021, 16:31 (6 years ago) parentc7ccb43
5 files changed+43−6
helix-core/src/diagnostic.rs+8 helix-core/src/lib.rs+1−1 helix-term/src/application.rs+13−3 helix-term/src/ui/editor.rs+18−2 helix-view/src/theme.rs+3
helix-core/src/diagnostic.rs+8
@@ -1,7 +1,15 @@
11use crate::Range;
22
3+pub enum Severity {
4+ Error,
5+ Warning,
6+ Info,
7+ Hint,
8+}
9+
310pub struct Diagnostic {
411 pub range: (usize, usize),
512 pub line: usize,
613 pub message: String,
14+ pub severity: Option<Severity>,
715}
helix-core/src/lib.rs+1−1
@@ -1,6 +1,6 @@
11#![allow(unused)]
22pub mod comment;
3−mod diagnostic;
3+pub mod diagnostic;
44pub mod graphemes;
55mod history;
66pub mod indent;
helix-term/src/application.rs+13−3
@@ -139,15 +139,25 @@ impl Application {
139139 .diagnostics
140140 .into_iter()
141141 .map(|diagnostic| {
142− use helix_lsp::util::lsp_pos_to_pos;
142+ use helix_core::diagnostic::Severity::*;
143+ use helix_core::{diagnostic::Severity, Diagnostic};
144+ use helix_lsp::{lsp, util::lsp_pos_to_pos};
145+ use lsp::DiagnosticSeverity;
143146 let start = lsp_pos_to_pos(doc, diagnostic.range.start);
144147 let end = lsp_pos_to_pos(doc, diagnostic.range.end);
145148
146− helix_core::Diagnostic {
149+ Diagnostic {
147150 range: (start, end),
148151 line: diagnostic.range.start.line as usize,
149152 message: diagnostic.message,
150− // severity
153+ severity: diagnostic.severity.map(
154+ |severity| match severity {
155+ DiagnosticSeverity::Error => Error,
156+ DiagnosticSeverity::Warning => Warning,
157+ DiagnosticSeverity::Information => Info,
158+ DiagnosticSeverity::Hint => Hint,
159+ },
160+ ),
151161 // code
152162 // source
153163 }
helix-term/src/ui/editor.rs+18−2
@@ -283,10 +283,26 @@ impl EditorView {
283283
284284 let style: Style = theme.get("ui.linenr");
285285 let warning: Style = theme.get("warning");
286+ let error: Style = theme.get("error");
287+ let info: Style = theme.get("info");
288+ let hint: Style = theme.get("hint");
289+
286290 let last_line = view.last_line();
287291 for (i, line) in (view.first_line..last_line).enumerate() {
288− if view.doc.diagnostics.iter().any(|d| d.line == line) {
289− surface.set_stringn(viewport.x - OFFSET, viewport.y + i as u16, "●", 1, warning);
292+ use helix_core::diagnostic::Severity;
293+ if let Some(diagnostic) = view.doc.diagnostics.iter().find(|d| d.line == line) {
294+ surface.set_stringn(
295+ viewport.x - OFFSET,
296+ viewport.y + i as u16,
297+ "●",
298+ 1,
299+ match diagnostic.severity {
300+ Some(Severity::Error) => error,
301+ Some(Severity::Warning) | None => warning,
302+ Some(Severity::Info) => info,
303+ Some(Severity::Hint) => hint,
304+ },
305+ );
290306 }
291307
292308 surface.set_stringn(
helix-view/src/theme.rs+3
@@ -160,6 +160,9 @@ impl Default for Theme {
160160 "ui.popup" => Style::default().bg(Color::Rgb(40, 23, 51)), // revolver
161161
162162 "warning" => Style::default().fg(Color::Rgb(255, 205, 28)),
163+ "error" => Style::default().fg(Color::Rgb(244, 120, 104)),
164+ "info" => Style::default().fg(Color::Rgb(111, 68, 240)),
165+ "hint" => Style::default().fg(Color::Rgb(204, 204, 204)),
163166 };
164167
165168 let scopes = mapping.keys().map(ToString::to_string).collect();