use super::*;
pub(in crate::app) fn format_diagnostics(
diags: &[(crate::lsp::manager::DiagnosticSeverity, String)],
) -> Option<String> {
use crate::lsp::manager::DiagnosticSeverity;
if diags.is_empty() {
return None;
}
let rank = |s: &DiagnosticSeverity| match s {
DiagnosticSeverity::Error => 0,
DiagnosticSeverity::Warning => 1,
DiagnosticSeverity::Information => 2,
DiagnosticSeverity::Hint => 3,
};
let label = |s: &DiagnosticSeverity| match s {
DiagnosticSeverity::Error => "Error",
DiagnosticSeverity::Warning => "Warning",
DiagnosticSeverity::Information => "Info",
DiagnosticSeverity::Hint => "Hint",
};
let mut ordered: Vec<&(DiagnosticSeverity, String)> = diags.iter().collect();
ordered.sort_by_key(|(s, _)| rank(s));
Some(
ordered
.iter()
.map(|(s, m)| format!("{}: {}", label(s), m))
.collect::<Vec<_>>()
.join("\n\n"),
)
}
pub(in crate::app) fn compose_hover(
diagnostic: Option<&str>,
hover: Option<&str>,
) -> Option<String> {
match (diagnostic, hover) {
(Some(d), Some(h)) => Some(format!("{d}\n{HOVER_DIVIDER}\n{h}")),
(Some(d), None) => Some(d.to_string()),
(None, Some(h)) => Some(h.to_string()),
(None, None) => None,
}
}