Skip to content

refactor(statusline): add hint and info for non-workspace diagnostics #13257

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

Closed
Closed
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
48 changes: 34 additions & 14 deletions helix-term/src/ui/statusline.rs
Original file line number Diff line number Diff line change
@@ -226,19 +226,39 @@ fn render_diagnostics<F>(context: &mut RenderContext, write: F)
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
});
let (hints, info, warnings, errors) =
context
.doc
.diagnostics()
.iter()
.fold((0, 0, 0, 0), |mut counts, diag| {
use helix_core::diagnostic::Severity;
match diag.severity {
Some(Severity::Hint) | None => counts.0 += 1,
Some(Severity::Info) => counts.1 += 1,
Some(Severity::Warning) => counts.2 += 1,
Comment on lines +237 to +239
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be consistent we should probably use diag.severity() here so that None becomes Warning -

impl Diagnostic {
#[inline]
pub fn severity(&self) -> Severity {
self.severity.unwrap_or(Severity::Warning)
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason Warning was chosen and not something else like Hint?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure of the context of it. It does make some sense to me that the "default" state of a diagnostic is a warning. I don't think it's very common that language servers omit the severity anyways

Some(Severity::Error) => counts.3 += 1,
}
counts
});

if info > 0 {
write(
context,
"●".to_string(),
Some(context.editor.theme.get("info")),
);
write(context, format!(" {} ", info), None);
}

if hints > 0 {
write(
context,
"●".to_string(),
Some(context.editor.theme.get("hint")),
);
write(context, format!(" {} ", hints), None);
}

if warnings > 0 {
write(
@@ -272,7 +292,7 @@ where
.fold((0, 0), |mut counts, (diag, _)| {
match diag.severity {
Some(DiagnosticSeverity::WARNING) => counts.0 += 1,
Some(DiagnosticSeverity::ERROR) | None => counts.1 += 1,
Some(DiagnosticSeverity::ERROR) => counts.1 += 1,
_ => {}
}
counts