From f9cdb2afe29045723d2ad14eaea371eddf3107fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Sun, 27 Jun 2021 00:14:59 +0900 Subject: [PATCH] Turn diagnostics rendering into span injection too --- helix-term/src/ui/editor.rs | 26 ++++++++++++++------------ theme.toml | 2 ++ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index c737b3cee..4c2ec440b 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -340,6 +340,20 @@ impl EditorView { Box::new(highlights) }; + // diagnostic injection + let diagnostic_scope = theme.find_scope_index("diagnostic").unwrap_or(cursor_scope); + let spans_ = doc + .diagnostics() + .iter() + .map(|diagnostic| { + ( + diagnostic_scope, + diagnostic.range.start..diagnostic.range.end, + ) + }) + .collect(); + let highlights = Box::new(merge(highlights, spans_)); + 'outer: for event in highlights { match event { HighlightEvent::HighlightStart(span) => { @@ -412,18 +426,6 @@ impl EditorView { continue; } - // ugh,interleave highlight spans with diagnostic spans - let is_diagnostic = doc.diagnostics().iter().any(|diagnostic| { - diagnostic.range.start <= char_index - && diagnostic.range.end > char_index - }); - - let style = if is_diagnostic { - style.add_modifier(Modifier::UNDERLINED) - } else { - style - }; - surface.set_string( viewport.x + visual_x - view.first_col as u16, viewport.y + line, diff --git a/theme.toml b/theme.toml index bf99fb7a5..129005714 100644 --- a/theme.toml +++ b/theme.toml @@ -60,6 +60,8 @@ "ui.menu.selected" = { fg = "#281733", bg = "#ffffff" } # revolver +"diagnostic" = { modifiers = ["underlined"] } + "warning" = "#ffcd1c" "error" = "#f47868" "info" = "#6F44F0"