Mercurial > forks > helix
changeset 6723:b3aca2ce55eb
feat(config): add `[workspace-]diagnostics` fields to statusline (#13288)
author | RoloEdits <RoloEdits@gmail.com> |
---|---|
date | Tue, 08 Apr 2025 11:58:14 -0700 |
parents | f0f819395ec1 |
children | e816d3ad61cf |
files | book/src/editor.md helix-term/src/ui/statusline.rs helix-view/src/editor.rs |
diffstat | 3 files changed, 110 insertions(+), 60 deletions(-) [+] |
line wrap: on
line diff
--- a/book/src/editor.md Tue Apr 08 09:54:12 2025 -0700 +++ b/book/src/editor.md Tue Apr 08 11:58:14 2025 -0700 @@ -104,6 +104,8 @@ mode.normal = "NORMAL" mode.insert = "INSERT" mode.select = "SELECT" +diagnostics = ["warning", "error"] +workspace-diagnostics = ["warning", "error"] ``` The `[editor.statusline]` key takes the following sub-keys: @@ -116,6 +118,8 @@ | `mode.normal` | The text shown in the `mode` element for normal mode | `"NOR"` | | `mode.insert` | The text shown in the `mode` element for insert mode | `"INS"` | | `mode.select` | The text shown in the `mode` element for select mode | `"SEL"` | +| `diagnostics` | A list of severities which are displayed for the current buffer | `["warning", "error"]` | +| `workspace-diagnostics` | A list of severities which are displayed for the workspace | `["warning", "error"]` | The following statusline elements can be configured:
--- a/helix-term/src/ui/statusline.rs Tue Apr 08 09:54:12 2025 -0700 +++ b/helix-term/src/ui/statusline.rs Tue Apr 08 11:58:14 2025 -0700 @@ -226,36 +226,58 @@ where F: Fn(&mut RenderContext, String, Option<Style>) + Copy, { - let (warnings, errors) = context - .doc - .diagnostics() - .iter() - .fold((0, 0), |mut counts, diag| { - use helix_core::diagnostic::Severity; - match diag.severity { - Some(Severity::Warning) => counts.0 += 1, - Some(Severity::Error) | None => counts.1 += 1, - _ => {} - } - counts - }); + use helix_core::diagnostic::Severity; + let (hints, info, warnings, errors) = + context + .doc + .diagnostics() + .iter() + .fold((0, 0, 0, 0), |mut counts, diag| { + match diag.severity { + Some(Severity::Hint) | None => counts.0 += 1, + Some(Severity::Info) => counts.1 += 1, + Some(Severity::Warning) => counts.2 += 1, + Some(Severity::Error) => counts.3 += 1, + } + counts + }); - if warnings > 0 { - write( - context, - "●".to_string(), - Some(context.editor.theme.get("warning")), - ); - write(context, format!(" {} ", warnings), None); - } - - if errors > 0 { - write( - context, - "●".to_string(), - Some(context.editor.theme.get("error")), - ); - write(context, format!(" {} ", errors), None); + for sev in &context.editor.config().statusline.diagnostics { + match sev { + Severity::Hint if hints > 0 => { + write( + context, + "●".to_string(), + Some(context.editor.theme.get("hint")), + ); + write(context, format!(" {} ", hints), None); + } + Severity::Info if info > 0 => { + write( + context, + "●".to_string(), + Some(context.editor.theme.get("info")), + ); + write(context, format!(" {} ", info), None); + } + Severity::Warning if warnings > 0 => { + write( + context, + "●".to_string(), + Some(context.editor.theme.get("warning")), + ); + write(context, format!(" {} ", warnings), None); + } + Severity::Error if errors > 0 => { + write( + context, + "●".to_string(), + Some(context.editor.theme.get("error")), + ); + write(context, format!(" {} ", errors), None); + } + _ => {} + } } } @@ -263,41 +285,61 @@ where F: Fn(&mut RenderContext, String, Option<Style>) + Copy, { - let (warnings, errors) = - context - .editor - .diagnostics - .values() - .flatten() - .fold((0, 0), |mut counts, (diag, _)| { - match diag.severity { - Some(DiagnosticSeverity::WARNING) => counts.0 += 1, - Some(DiagnosticSeverity::ERROR) | None => counts.1 += 1, - _ => {} - } - counts - }); + use helix_core::diagnostic::Severity; + let (hints, info, warnings, errors) = context.editor.diagnostics.values().flatten().fold( + (0, 0, 0, 0), + |mut counts, (diag, _)| { + match diag.severity { + Some(DiagnosticSeverity::HINT) | None => counts.0 += 1, + Some(DiagnosticSeverity::INFORMATION) => counts.1 += 1, + Some(DiagnosticSeverity::WARNING) => counts.2 += 1, + Some(DiagnosticSeverity::ERROR) => counts.3 += 1, + _ => {} + } + counts + }, + ); - if warnings > 0 || errors > 0 { + if hints > 0 || info > 0 || warnings > 0 || errors > 0 { write(context, " W ".into(), None); } - if warnings > 0 { - write( - context, - "●".to_string(), - Some(context.editor.theme.get("warning")), - ); - write(context, format!(" {} ", warnings), None); - } - - if errors > 0 { - write( - context, - "●".to_string(), - Some(context.editor.theme.get("error")), - ); - write(context, format!(" {} ", errors), None); + for sev in &context.editor.config().statusline.workspace_diagnostics { + match sev { + Severity::Hint if hints > 0 => { + write( + context, + "●".to_string(), + Some(context.editor.theme.get("hint")), + ); + write(context, format!(" {} ", hints), None); + } + Severity::Info if info > 0 => { + write( + context, + "●".to_string(), + Some(context.editor.theme.get("info")), + ); + write(context, format!(" {} ", info), None); + } + Severity::Warning if warnings > 0 => { + write( + context, + "●".to_string(), + Some(context.editor.theme.get("warning")), + ); + write(context, format!(" {} ", warnings), None); + } + Severity::Error if errors > 0 => { + write( + context, + "●".to_string(), + Some(context.editor.theme.get("error")), + ); + write(context, format!(" {} ", errors), None); + } + _ => {} + } } }
--- a/helix-view/src/editor.rs Tue Apr 08 09:54:12 2025 -0700 +++ b/helix-view/src/editor.rs Tue Apr 08 11:58:14 2025 -0700 @@ -497,6 +497,8 @@ pub right: Vec<StatusLineElement>, pub separator: String, pub mode: ModeConfig, + pub diagnostics: Vec<Severity>, + pub workspace_diagnostics: Vec<Severity>, } impl Default for StatusLineConfig { @@ -521,6 +523,8 @@ ], separator: String::from("│"), mode: ModeConfig::default(), + diagnostics: vec![Severity::Warning, Severity::Error], + workspace_diagnostics: vec![Severity::Warning, Severity::Error], } } }