Use diagnostic.severity to distinguish between error colors.

pull/8/head
Blaž Hrastnik 4 years ago
parent c7ccb432ef
commit 9dcfe25e4a

@ -1,7 +1,15 @@
use crate::Range;
pub enum Severity {
Error,
Warning,
Info,
Hint,
}
pub struct Diagnostic {
pub range: (usize, usize),
pub line: usize,
pub message: String,
pub severity: Option<Severity>,
}

@ -1,6 +1,6 @@
#![allow(unused)]
pub mod comment;
mod diagnostic;
pub mod diagnostic;
pub mod graphemes;
mod history;
pub mod indent;

@ -139,15 +139,25 @@ impl Application {
.diagnostics
.into_iter()
.map(|diagnostic| {
use helix_lsp::util::lsp_pos_to_pos;
use helix_core::diagnostic::Severity::*;
use helix_core::{diagnostic::Severity, Diagnostic};
use helix_lsp::{lsp, util::lsp_pos_to_pos};
use lsp::DiagnosticSeverity;
let start = lsp_pos_to_pos(doc, diagnostic.range.start);
let end = lsp_pos_to_pos(doc, diagnostic.range.end);
helix_core::Diagnostic {
Diagnostic {
range: (start, end),
line: diagnostic.range.start.line as usize,
message: diagnostic.message,
// severity
severity: diagnostic.severity.map(
|severity| match severity {
DiagnosticSeverity::Error => Error,
DiagnosticSeverity::Warning => Warning,
DiagnosticSeverity::Information => Info,
DiagnosticSeverity::Hint => Hint,
},
),
// code
// source
}

@ -283,10 +283,26 @@ impl EditorView {
let style: Style = theme.get("ui.linenr");
let warning: Style = theme.get("warning");
let error: Style = theme.get("error");
let info: Style = theme.get("info");
let hint: Style = theme.get("hint");
let last_line = view.last_line();
for (i, line) in (view.first_line..last_line).enumerate() {
if view.doc.diagnostics.iter().any(|d| d.line == line) {
surface.set_stringn(viewport.x - OFFSET, viewport.y + i as u16, "●", 1, warning);
use helix_core::diagnostic::Severity;
if let Some(diagnostic) = view.doc.diagnostics.iter().find(|d| d.line == line) {
surface.set_stringn(
viewport.x - OFFSET,
viewport.y + i as u16,
"●",
1,
match diagnostic.severity {
Some(Severity::Error) => error,
Some(Severity::Warning) | None => warning,
Some(Severity::Info) => info,
Some(Severity::Hint) => hint,
},
);
}
surface.set_stringn(

@ -160,6 +160,9 @@ impl Default for Theme {
"ui.popup" => Style::default().bg(Color::Rgb(40, 23, 51)), // revolver
"warning" => Style::default().fg(Color::Rgb(255, 205, 28)),
"error" => Style::default().fg(Color::Rgb(244, 120, 104)),
"info" => Style::default().fg(Color::Rgb(111, 68, 240)),
"hint" => Style::default().fg(Color::Rgb(204, 204, 204)),
};
let scopes = mapping.keys().map(ToString::to_string).collect();

Loading…
Cancel
Save