Add editor.diagnostics-symbol config option

This commit is contained in:
ataractic 2024-08-10 19:18:22 +02:00
parent 91e642ce50
commit 705f35db3c
No known key found for this signature in database
GPG Key ID: B78DC77B6F1ACF19
3 changed files with 12 additions and 6 deletions

View File

@ -240,10 +240,12 @@ fn render_diagnostics<F>(context: &mut RenderContext, write: F)
counts
});
let sym = &context.editor.config().diagnostics_symbol;
if warnings > 0 {
write(
context,
"".to_string(),
sym.to_string(),
Some(context.editor.theme.get("warning")),
);
write(context, format!(" {} ", warnings), None);
@ -252,7 +254,7 @@ fn render_diagnostics<F>(context: &mut RenderContext, write: F)
if errors > 0 {
write(
context,
"".to_string(),
sym.to_string(),
Some(context.editor.theme.get("error")),
);
write(context, format!(" {} ", errors), None);
@ -277,6 +279,7 @@ fn render_workspace_diagnostics<F>(context: &mut RenderContext, write: F)
}
counts
});
let sym = &context.editor.config().diagnostics_symbol;
if warnings > 0 || errors > 0 {
write(context, " W ".into(), None);
@ -285,7 +288,7 @@ fn render_workspace_diagnostics<F>(context: &mut RenderContext, write: F)
if warnings > 0 {
write(
context,
"".to_string(),
sym.to_string(),
Some(context.editor.theme.get("warning")),
);
write(context, format!(" {} ", warnings), None);
@ -294,7 +297,7 @@ fn render_workspace_diagnostics<F>(context: &mut RenderContext, write: F)
if errors > 0 {
write(
context,
"".to_string(),
sym.to_string(),
Some(context.editor.theme.get("error")),
);
write(context, format!(" {} ", errors), None);

View File

@ -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 diagnostics_symbol: char,
}
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq, PartialOrd, Ord)]
@ -979,6 +980,7 @@ fn default() -> Self {
jump_label_alphabet: ('a'..='z').collect(),
inline_diagnostics: InlineDiagnosticsConfig::default(),
end_of_line_diagnostics: DiagnosticFilter::Disable,
diagnostics_symbol: '',
}
}
}

View File

@ -46,7 +46,7 @@ pub fn width(self, view: &View, doc: &Document) -> usize {
}
pub fn diagnostic<'doc>(
_editor: &'doc Editor,
editor: &'doc Editor,
doc: &'doc Document,
_view: &View,
theme: &Theme,
@ -57,6 +57,7 @@ pub fn diagnostic<'doc>(
let info = theme.get("info");
let hint = theme.get("hint");
let diagnostics = &doc.diagnostics;
let sym = editor.config().diagnostics_symbol;
Box::new(
move |line: usize, _selected: bool, first_visual_line: bool, out: &mut String| {
@ -74,7 +75,7 @@ pub fn diagnostic<'doc>(
.any(|ls| ls.id() == d.provider)
});
diagnostics_on_line.max_by_key(|d| d.severity).map(|d| {
write!(out, "").ok();
write!(out, "{}", sym).ok();
match d.severity {
Some(Severity::Error) => error,
Some(Severity::Warning) | None => warning,