Repository: helix-editor/helix
File: helix-term/src/ui/statusline.rs (Rust)

Code before:
                    "●".to_string(),
                    Some(context.editor.theme.get("error")),
                );
                write(context, format!(" {} ", errors), None);
            }
            _ => {}
        }
    }
}

fn render_workspace_diagnostics<F>(context: &mut RenderContext, write: F)
where
    F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
{
    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 hints > 0 || info > 0 || warnings > 0 || errors > 0 {
        write(context, " W ".into(), 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);
            }

Review comment (suggestion):
I left `HINT` as third, rather than, for example, just removing this and having this be the `_` fallback, as in the wild, I have seen `hint` more often than `info`. I couldn't profile with enough run to run precision to really gauge what would be better: a branch consolidated vs the frequency of occurrence. Its also possible to just have `info` be the fallback and just have `_ => counts.0 += 1`., but though `hint` matched better as a fallback.

Code after:
                    "●".to_string(),
                    Some(context.editor.theme.get("error")),
                );
                write(context, format!(" {} ", errors), None);
            }
            _ => {}
        }
    }
}

fn render_workspace_diagnostics<F>(context: &mut RenderContext, write: F)
where
    F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
{
    use helix_core::diagnostic::Severity;
    let (hints, info, warnings, errors) = context.editor.diagnostics.values().flatten().fold(
        (0u32, 0u32, 0u32, 0u32),
        |mut counts, (diag, _)| {
            match diag.severity {
                // PERF: For large workspace diagnostics, this loop can be very tight.
                //
                // Most often the diagnostics will be for warnings and errors.
                // Errors should tend to be fixed fast, leaving warnings as the most common.
                Some(DiagnosticSeverity::WARNING) => counts.2 += 1,
                Some(DiagnosticSeverity::ERROR) => counts.3 += 1,
                Some(DiagnosticSeverity::HINT) => counts.0 += 1,
                Some(DiagnosticSeverity::INFORMATION) => counts.1 += 1,
                // Fallback to `hint`.
                _ => counts.0 += 1,
            }
            counts
        },
    );

    if hints > 0 || info > 0 || warnings > 0 || errors > 0 {
        write(context, " W ".into(), 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,