Skip to main content

diagnostic_severity_for

Function diagnostic_severity_for 

Source
pub const fn diagnostic_severity_for(
    severity: VulnSeverity,
) -> DiagnosticSeverity
Expand description

Maps a VulnSeverity to the [DiagnosticSeverity] used to render it.

Critical/High and Unknown cap at WARNING rather than ERROR: ERROR conventionally means “this file is broken”, and a valid manifest declaring a real-but-vulnerable dependency is not a parse error. Unknown -> WARNING (not HINT) reflects that a record this could not grade is not evidence of low risk.

§Examples

// `severity` is a private module; this function is re-exported publicly
// as `deps_core::osv::diagnostic_severity_for`.
use deps_core::osv::VulnSeverity;
use deps_core::osv::diagnostic_severity_for as to_diagnostic_severity;
use tower_lsp_server::ls_types::DiagnosticSeverity;

assert_eq!(to_diagnostic_severity(VulnSeverity::Critical), DiagnosticSeverity::WARNING);
assert_eq!(to_diagnostic_severity(VulnSeverity::Low), DiagnosticSeverity::INFORMATION);
assert_eq!(to_diagnostic_severity(VulnSeverity::Unknown), DiagnosticSeverity::WARNING);