mirror of https://github.com/helix-editor/helix
feat(config): add `[workspace-]diagnostics` fields to statusline (#13288)
parent
34aa4d41c6
commit
d24e4fcf0f
|
@ -104,6 +104,8 @@ separator = "│"
|
||||||
mode.normal = "NORMAL"
|
mode.normal = "NORMAL"
|
||||||
mode.insert = "INSERT"
|
mode.insert = "INSERT"
|
||||||
mode.select = "SELECT"
|
mode.select = "SELECT"
|
||||||
|
diagnostics = ["warning", "error"]
|
||||||
|
workspace-diagnostics = ["warning", "error"]
|
||||||
```
|
```
|
||||||
The `[editor.statusline]` key takes the following sub-keys:
|
The `[editor.statusline]` key takes the following sub-keys:
|
||||||
|
|
||||||
|
@ -116,6 +118,8 @@ The `[editor.statusline]` key takes the following sub-keys:
|
||||||
| `mode.normal` | The text shown in the `mode` element for normal mode | `"NOR"` |
|
| `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.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"` |
|
| `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:
|
The following statusline elements can be configured:
|
||||||
|
|
||||||
|
|
|
@ -226,36 +226,58 @@ fn render_diagnostics<F>(context: &mut RenderContext, write: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
||||||
{
|
{
|
||||||
let (warnings, errors) = context
|
use helix_core::diagnostic::Severity;
|
||||||
.doc
|
let (hints, info, warnings, errors) =
|
||||||
.diagnostics()
|
context
|
||||||
.iter()
|
.doc
|
||||||
.fold((0, 0), |mut counts, diag| {
|
.diagnostics()
|
||||||
use helix_core::diagnostic::Severity;
|
.iter()
|
||||||
match diag.severity {
|
.fold((0, 0, 0, 0), |mut counts, diag| {
|
||||||
Some(Severity::Warning) => counts.0 += 1,
|
match diag.severity {
|
||||||
Some(Severity::Error) | None => counts.1 += 1,
|
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
|
||||||
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
counts
|
Severity::Info if info > 0 => {
|
||||||
});
|
write(
|
||||||
|
context,
|
||||||
if warnings > 0 {
|
"●".to_string(),
|
||||||
write(
|
Some(context.editor.theme.get("info")),
|
||||||
context,
|
);
|
||||||
"●".to_string(),
|
write(context, format!(" {} ", info), None);
|
||||||
Some(context.editor.theme.get("warning")),
|
}
|
||||||
);
|
Severity::Warning if warnings > 0 => {
|
||||||
write(context, format!(" {} ", warnings), None);
|
write(
|
||||||
}
|
context,
|
||||||
|
"●".to_string(),
|
||||||
if errors > 0 {
|
Some(context.editor.theme.get("warning")),
|
||||||
write(
|
);
|
||||||
context,
|
write(context, format!(" {} ", warnings), None);
|
||||||
"●".to_string(),
|
}
|
||||||
Some(context.editor.theme.get("error")),
|
Severity::Error if errors > 0 => {
|
||||||
);
|
write(
|
||||||
write(context, format!(" {} ", errors), None);
|
context,
|
||||||
|
"●".to_string(),
|
||||||
|
Some(context.editor.theme.get("error")),
|
||||||
|
);
|
||||||
|
write(context, format!(" {} ", errors), None);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,41 +285,61 @@ fn render_workspace_diagnostics<F>(context: &mut RenderContext, write: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
||||||
{
|
{
|
||||||
let (warnings, errors) =
|
use helix_core::diagnostic::Severity;
|
||||||
context
|
let (hints, info, warnings, errors) = context.editor.diagnostics.values().flatten().fold(
|
||||||
.editor
|
(0, 0, 0, 0),
|
||||||
.diagnostics
|
|mut counts, (diag, _)| {
|
||||||
.values()
|
match diag.severity {
|
||||||
.flatten()
|
Some(DiagnosticSeverity::HINT) | None => counts.0 += 1,
|
||||||
.fold((0, 0), |mut counts, (diag, _)| {
|
Some(DiagnosticSeverity::INFORMATION) => counts.1 += 1,
|
||||||
match diag.severity {
|
Some(DiagnosticSeverity::WARNING) => counts.2 += 1,
|
||||||
Some(DiagnosticSeverity::WARNING) => counts.0 += 1,
|
Some(DiagnosticSeverity::ERROR) => counts.3 += 1,
|
||||||
Some(DiagnosticSeverity::ERROR) | None => counts.1 += 1,
|
_ => {}
|
||||||
_ => {}
|
}
|
||||||
}
|
counts
|
||||||
counts
|
},
|
||||||
});
|
);
|
||||||
|
|
||||||
if warnings > 0 || errors > 0 {
|
if hints > 0 || info > 0 || warnings > 0 || errors > 0 {
|
||||||
write(context, " W ".into(), None);
|
write(context, " W ".into(), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
if warnings > 0 {
|
for sev in &context.editor.config().statusline.workspace_diagnostics {
|
||||||
write(
|
match sev {
|
||||||
context,
|
Severity::Hint if hints > 0 => {
|
||||||
"●".to_string(),
|
write(
|
||||||
Some(context.editor.theme.get("warning")),
|
context,
|
||||||
);
|
"●".to_string(),
|
||||||
write(context, format!(" {} ", warnings), None);
|
Some(context.editor.theme.get("hint")),
|
||||||
}
|
);
|
||||||
|
write(context, format!(" {} ", hints), None);
|
||||||
if errors > 0 {
|
}
|
||||||
write(
|
Severity::Info if info > 0 => {
|
||||||
context,
|
write(
|
||||||
"●".to_string(),
|
context,
|
||||||
Some(context.editor.theme.get("error")),
|
"●".to_string(),
|
||||||
);
|
Some(context.editor.theme.get("info")),
|
||||||
write(context, format!(" {} ", errors), None);
|
);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -497,6 +497,8 @@ pub struct StatusLineConfig {
|
||||||
pub right: Vec<StatusLineElement>,
|
pub right: Vec<StatusLineElement>,
|
||||||
pub separator: String,
|
pub separator: String,
|
||||||
pub mode: ModeConfig,
|
pub mode: ModeConfig,
|
||||||
|
pub diagnostics: Vec<Severity>,
|
||||||
|
pub workspace_diagnostics: Vec<Severity>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for StatusLineConfig {
|
impl Default for StatusLineConfig {
|
||||||
|
@ -521,6 +523,8 @@ impl Default for StatusLineConfig {
|
||||||
],
|
],
|
||||||
separator: String::from("│"),
|
separator: String::from("│"),
|
||||||
mode: ModeConfig::default(),
|
mode: ModeConfig::default(),
|
||||||
|
diagnostics: vec![Severity::Warning, Severity::Error],
|
||||||
|
workspace_diagnostics: vec![Severity::Warning, Severity::Error],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue