From 7f0200eac67df40731e31ef6a6010612e3e48fc7 Mon Sep 17 00:00:00 2001 From: RobWalt Date: Sun, 8 May 2022 23:45:36 +0200 Subject: [PATCH 1/3] 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 --- helix-term/src/ui/editor.rs | 17 ++++++++++++++--- theme.toml | 4 ++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 52e581632d7a..a51e2c9bd538 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -247,17 +247,28 @@ impl EditorView { doc: &Document, theme: &Theme, ) -> Vec<(usize, std::ops::Range)> { - let diagnostic_scope = theme - .find_scope_index("diagnostic") + use helix_core::diagnostic::Severity; + let get_diagnostic_subscope_colors = |maybe_severity: Option| { + let full_scope = match maybe_severity { + Some(Severity::Hint) => "diagnostic.hint", + Some(Severity::Info) => "diagnostic.info", + Some(Severity::Warning) => "diagnostic.warning", + Some(Severity::Error) => "diagnostic.error", + None => "diagnostic", + }; + theme + .find_scope_index(full_scope) .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`", - ); + ) + }; doc.diagnostics() .iter() .map(|diagnostic| { + let diagnostic_scope = get_diagnostic_subscope_colors(diagnostic.severity); ( diagnostic_scope, diagnostic.range.start..diagnostic.range.end, diff --git a/theme.toml b/theme.toml index 31ecd32e41ed..f70377ab8078 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" From 59315f5240afa822e5596f01440bdaf883154b24 Mon Sep 17 00:00:00 2001 From: RobWalt Date: Sun, 8 May 2022 23:56:25 +0200 Subject: [PATCH 2/3] feat(theme): add docs for new diagnostic options --- book/src/themes.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/book/src/themes.md b/book/src/themes.md index e73aedc94430..97955cb71a9c 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 From 3b2489524d12111cf82a342ebd4559c061f8850d Mon Sep 17 00:00:00 2001 From: RobWalt Date: Wed, 11 May 2022 08:26:33 +0200 Subject: [PATCH 3/3] 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 --- helix-term/src/ui/editor.rs | 28 ++++++++++++++++++---------- theme.toml | 8 ++++---- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index a51e2c9bd538..85028e2ff123 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -248,16 +248,11 @@ impl EditorView { theme: &Theme, ) -> Vec<(usize, std::ops::Range)> { use helix_core::diagnostic::Severity; - let get_diagnostic_subscope_colors = |maybe_severity: Option| { - let full_scope = match maybe_severity { - Some(Severity::Hint) => "diagnostic.hint", - Some(Severity::Info) => "diagnostic.info", - Some(Severity::Warning) => "diagnostic.warning", - Some(Severity::Error) => "diagnostic.error", - None => "diagnostic", - }; + let get_scope_of = |scope| { theme - .find_scope_index(full_scope) + .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( @@ -265,10 +260,23 @@ impl EditorView { ) }; + // 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 = get_diagnostic_subscope_colors(diagnostic.severity); + 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 f70377ab8078..2e6da866d90c 100644 --- a/theme.toml +++ b/theme.toml @@ -67,10 +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" } +# "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"