aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Walter2022-05-20 01:30:28 +0000
committerGitHub2022-05-20 01:30:28 +0000
commit776686ab2471419b9c9aac8507e8d301f450389a (patch)
treefb9c6ca38dda82e94d8917ef3d9d93c50e20bce8
parent09f9f70576830c328af37b73f96286d80ecf20f9 (diff)
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
-rw-r--r--book/src/themes.md6
-rw-r--r--helix-term/src/ui/editor.rs25
-rw-r--r--theme.toml4
3 files changed, 31 insertions, 4 deletions
diff --git a/book/src/themes.md b/book/src/themes.md
index e73aedc9..97955cb7 100644
--- a/book/src/themes.md
+++ b/book/src/themes.md
@@ -234,6 +234,10 @@ These scopes are used for theming the editor interface.
| `error` | Diagnostics error (gutter) |
| `info` | Diagnostics info (gutter) |
| `hint` | Diagnostics hint (gutter) |
-| `diagnostic` | For text in editing area |
+| `diagnostic` | Diagnostics fallback style (editing area) |
+| `diagnostic.hint` | Diagnostics hint (editing area) |
+| `diagnostic.info` | Diagnostics info (editing area) |
+| `diagnostic.warning` | Diagnostics warning (editing area) |
+| `diagnostic.error` | Diagnostics error (editing area) |
[rulers-config]: ./configuration.md#editor-section
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index 52e58163..85028e2f 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -247,17 +247,36 @@ impl EditorView {
doc: &Document,
theme: &Theme,
) -> Vec<(usize, std::ops::Range<usize>)> {
- let diagnostic_scope = theme
- .find_scope_index("diagnostic")
+ use helix_core::diagnostic::Severity;
+ let get_scope_of = |scope| {
+ theme
+ .find_scope_index(scope)
+ // get one of the themes below as fallback values
+ .or_else(|| theme.find_scope_index("diagnostic"))
.or_else(|| theme.find_scope_index("ui.cursor"))
.or_else(|| theme.find_scope_index("ui.selection"))
.expect(
"at least one of the following scopes must be defined in the theme: `diagnostic`, `ui.cursor`, or `ui.selection`",
- );
+ )
+ };
+
+ // basically just queries the theme color defined in the config
+ let hint = get_scope_of("diagnostic.hint");
+ let info = get_scope_of("diagnostic.info");
+ let warning = get_scope_of("diagnostic.warning");
+ let error = get_scope_of("diagnostic.error");
+ let r#default = get_scope_of("diagnostic"); // this is a bit redundant but should be fine
doc.diagnostics()
.iter()
.map(|diagnostic| {
+ let diagnostic_scope = match diagnostic.severity {
+ Some(Severity::Info) => info,
+ Some(Severity::Hint) => hint,
+ Some(Severity::Warning) => warning,
+ Some(Severity::Error) => error,
+ _ => r#default,
+ };
(
diagnostic_scope,
diagnostic.range.start..diagnostic.range.end,
diff --git a/theme.toml b/theme.toml
index 31ecd32e..2e6da866 100644
--- a/theme.toml
+++ b/theme.toml
@@ -67,6 +67,10 @@ label = "honey"
"ui.menu.selected" = { fg = "revolver", bg = "white" }
diagnostic = { modifiers = ["underlined"] }
+# "diagnostic.hint" = { fg = "revolver", bg = "lilac" }
+# "diagnostic.info" = { fg = "revolver", bg = "lavender" }
+# "diagnostic.warning" = { fg = "revolver", bg = "honey" }
+# "diagnostic.error" = { fg = "revolver", bg = "apricot" }
warning = "lightning"
error = "apricot"