on master help sign in
Separate colors for different diagnostics types (#2437)

* feat(theme): add separate diagnostic colors This commit adds separate diagnostic highlight colors for the different types of LSP severities. If the severity type doesn't exist or is unknown, we use some fallback coloring which was in use before this commit. Some initial color options were also added in the theme.toml Resolves issue #2157 * feat(theme): add docs for new diagnostic options * feat(theme): adjust defaults & reduce redundancy - the different colors for different diagnostic severities are now disabled in the default theme, instead diagnostics are just generally underlined (as prior to the changes of this feature) - the theme querying is now done once instead of every iteration in the loop of processing every diagnostic message

commit776686ab2471419b9c9aac8507e8d301f450389a authorRobert Walter <26892280+RobWalt@users.noreply.github.com> dateFri 20 May 2022, 03:30 (4 years ago) parent09f9f70
3 files changed+31−4
book/src/themes.md+5−1 helix-term/src/ui/editor.rs+22−3 theme.toml+4
book/src/themes.md+5−1
@@ -234,6 +234,10 @@ These scopes are used for theming the editor interface.
234234| `error` | Diagnostics error (gutter) |
235235| `info` | Diagnostics info (gutter) |
236236| `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) |
238242
239243[rulers-config]: ./configuration.md#editor-section
helix-term/src/ui/editor.rs+22−3
@@ -247,17 +247,36 @@ impl EditorView {
247247 doc: &Document,
248248 theme: &Theme,
249249 ) -> Vec<(usize, std::ops::Range<usize>)> {
250− let diagnostic_scope = theme
251− .find_scope_index("diagnostic")
250+ use helix_core::diagnostic::Severity;
251+ let get_scope_of = |scope| {
252+ theme
253+ .find_scope_index(scope)
254+ // get one of the themes below as fallback values
255+ .or_else(|| theme.find_scope_index("diagnostic"))
252256 .or_else(|| theme.find_scope_index("ui.cursor"))
253257 .or_else(|| theme.find_scope_index("ui.selection"))
254258 .expect(
255259 "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
257269
258270 doc.diagnostics()
259271 .iter()
260272 .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+ };
261280 (
262281 diagnostic_scope,
263282 diagnostic.range.start..diagnostic.range.end,
theme.toml+4
@@ -67,6 +67,10 @@ label = "honey"
6767"ui.menu.selected" = { fg = "revolver", bg = "white" }
6868
6969diagnostic = { 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" }
7074
7175warning = "lightning"
7276error = "apricot"