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

Configuration for diagnostic icons #12060

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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: 4 additions & 2 deletions helix-term/src/ui/statusline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,12 @@ where
counts
});

let icons = context.editor.config().diagnostic_icons;

if warnings > 0 {
write(
context,
"●".to_string(),
icons.warning.to_string(),
Some(context.editor.theme.get("warning")),
);
write(context, format!(" {} ", warnings), None);
Expand All @@ -252,7 +254,7 @@ where
if errors > 0 {
write(
context,
"●".to_string(),
icons.error.to_string(),
Some(context.editor.theme.get("error")),
);
write(context, format!(" {} ", errors), None);
Expand Down
21 changes: 21 additions & 0 deletions helix-view/src/annotations/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@ pub enum DiagnosticFilter {
Enable(Severity),
}

/// The icon (character) to use for each [`Diagnostic`] level.
#[derive(Debug, Serialize, Deserialize, Copy, Clone, Eq, PartialEq, PartialOrd, Ord)]
#[serde(default, deny_unknown_fields)]
pub struct DiagnosticIcons {
pub error: char,
pub warning: char,
pub info: char,
pub hint: char,
}

impl Default for DiagnosticIcons {
fn default() -> Self {
Self {
error: '●',
warning: '●',
info: '●',
hint: '●',
}
}
}

impl<'de> Deserialize<'de> for DiagnosticFilter {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
Expand Down
4 changes: 3 additions & 1 deletion helix-view/src/editor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
annotations::diagnostics::{DiagnosticFilter, InlineDiagnosticsConfig},
annotations::diagnostics::{DiagnosticFilter, DiagnosticIcons, InlineDiagnosticsConfig},
document::{
DocumentOpenError, DocumentSavedEventFuture, DocumentSavedEventResult, Mode, SavePoint,
},
Expand Down Expand Up @@ -345,6 +345,7 @@ pub struct Config {
/// Display diagnostic below the line they occur.
pub inline_diagnostics: InlineDiagnosticsConfig,
pub end_of_line_diagnostics: DiagnosticFilter,
pub diagnostic_icons: DiagnosticIcons,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq, PartialOrd, Ord)]
Expand Down Expand Up @@ -982,6 +983,7 @@ impl Default for Config {
jump_label_alphabet: ('a'..='z').collect(),
inline_diagnostics: InlineDiagnosticsConfig::default(),
end_of_line_diagnostics: DiagnosticFilter::Disable,
diagnostic_icons: DiagnosticIcons::default(),
}
}
}
Expand Down
20 changes: 12 additions & 8 deletions helix-view/src/gutter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,19 @@ impl GutterType {
}

pub fn diagnostic<'doc>(
_editor: &'doc Editor,
editor: &'doc Editor,
doc: &'doc Document,
_view: &View,
theme: &Theme,
_is_focused: bool,
) -> GutterFn<'doc> {
let warning = theme.get("warning");
let error = theme.get("error");
let info = theme.get("info");
let hint = theme.get("hint");
let icons = &editor.config().diagnostic_icons;

let warning = (theme.get("warning"), icons.warning);
let error = (theme.get("error"), icons.error);
let info = (theme.get("info"), icons.info);
let hint = (theme.get("hint"), icons.hint);

let diagnostics = &doc.diagnostics;

Box::new(
Expand All @@ -74,13 +77,14 @@ pub fn diagnostic<'doc>(
.any(|ls| ls.id() == d.provider)
});
diagnostics_on_line.max_by_key(|d| d.severity).map(|d| {
write!(out, "●").ok();
match d.severity {
let (style, indicator) = match d.severity {
Some(Severity::Error) => error,
Some(Severity::Warning) | None => warning,
Some(Severity::Info) => info,
Some(Severity::Hint) => hint,
}
};
out.push(indicator);
style
})
},
)
Expand Down