on master help sign in
Separate colors for different diagnostics types (#2437)
776686aRobert Walter
book/src/themes.md+5−1
@@ -234,6 +234,10 @@ These scopes are used for theming the editor interface.
234| `error` | Diagnostics error (gutter) |
234| `error` | Diagnostics error (gutter) |
235| `info` | Diagnostics info (gutter) |
235| `info` | Diagnostics info (gutter) |
236| `hint` | Diagnostics hint (gutter) |
236| `hint` | Diagnostics hint (gutter) |
237−| `diagnostic` | For text in editing area |
237+| `diagnostic` | Diagnostics fallback style (editing area) |
238+| `diagnostic.hint` | Diagnostics hint (editing area) |
239+| `diagnostic.info` | Diagnostics info (editing area) |
240+| `diagnostic.warning` | Diagnostics warning (editing area) |
241+| `diagnostic.error` | Diagnostics error (editing area) |
238
242
239[rulers-config]: ./configuration.md#editor-section
243[rulers-config]: ./configuration.md#editor-section
helix-term/src/ui/editor.rs+22−3
@@ -247,17 +247,36 @@ impl EditorView {
247 doc: &Document,
247 doc: &Document,
248 theme: &Theme,
248 theme: &Theme,
249 ) -> Vec<(usize, std::ops::Range<usize>)> {
249 ) -> Vec<(usize, std::ops::Range<usize>)> {
250− let diagnostic_scope = theme
250+ use helix_core::diagnostic::Severity;
251+ let get_scope_of = |scope| {
252+ theme
251− .find_scope_index("diagnostic")
253+ .find_scope_index(scope)
254+ // get one of the themes below as fallback values
255+ .or_else(|| theme.find_scope_index("diagnostic"))
252 .or_else(|| theme.find_scope_index("ui.cursor"))
256 .or_else(|| theme.find_scope_index("ui.cursor"))
253 .or_else(|| theme.find_scope_index("ui.selection"))
257 .or_else(|| theme.find_scope_index("ui.selection"))
254 .expect(
258 .expect(
255 "at least one of the following scopes must be defined in the theme: `diagnostic`, `ui.cursor`, or `ui.selection`",
259 "at least one of the following scopes must be defined in the theme: `diagnostic`, `ui.cursor`, or `ui.selection`",
256− );
260+ )
261+ };
262+
263+ // basically just queries the theme color defined in the config
264+ let hint = get_scope_of("diagnostic.hint");
265+ let info = get_scope_of("diagnostic.info");
266+ let warning = get_scope_of("diagnostic.warning");
267+ let error = get_scope_of("diagnostic.error");
268+ let r#default = get_scope_of("diagnostic"); // this is a bit redundant but should be fine
257
269
258 doc.diagnostics()
270 doc.diagnostics()
259 .iter()
271 .iter()
260 .map(|diagnostic| {
272 .map(|diagnostic| {
273+ let diagnostic_scope = match diagnostic.severity {
274+ Some(Severity::Info) => info,
275+ Some(Severity::Hint) => hint,
276+ Some(Severity::Warning) => warning,
277+ Some(Severity::Error) => error,
278+ _ => r#default,
279+ };
261 (
280 (
262 diagnostic_scope,
281 diagnostic_scope,
263 diagnostic.range.start..diagnostic.range.end,
282 diagnostic.range.start..diagnostic.range.end,
theme.toml+4
@@ -67,6 +67,10 @@ label = "honey"
67"ui.menu.selected" = { fg = "revolver", bg = "white" }
67"ui.menu.selected" = { fg = "revolver", bg = "white" }
68
68
69diagnostic = { modifiers = ["underlined"] }
69diagnostic = { modifiers = ["underlined"] }
70+# "diagnostic.hint" = { fg = "revolver", bg = "lilac" }
71+# "diagnostic.info" = { fg = "revolver", bg = "lavender" }
72+# "diagnostic.warning" = { fg = "revolver", bg = "honey" }
73+# "diagnostic.error" = { fg = "revolver", bg = "apricot" }
70
74
71warning = "lightning"
75warning = "lightning"
72error = "apricot"
76error = "apricot"