Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate colors for different diagnostics types #2437

Merged
merged 3 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion book/src/themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 22 additions & 3 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions theme.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down