use super::types::{EditorFinding, EditorSeverity};
pub fn meets_threshold(sev: EditorSeverity, threshold: &str) -> bool {
let floor = EditorSeverity::from_id(threshold);
sev.rank() >= floor.rank()
}
pub fn emit_finding(f: &EditorFinding, source: Option<uuid::Uuid>) {
use crate::pane::output::{kinds, Lifetime, Message, Severity as OutSev};
let severity = match f.severity {
EditorSeverity::Concern => OutSev::Contradiction,
EditorSeverity::Note => OutSev::Warning,
EditorSeverity::Praise => OutSev::Info,
};
let mut msg = Message::new(
kinds::INNER_EDITOR_OBSERVATION,
severity,
Lifetime::UntilActedOn,
serde_json::json!({
"text": f.observation,
"observation_en": f.observation_en,
"category": f.category.id(),
"label": f.category.label(),
"severity_label": f.severity.label(),
"evidence": f.evidence,
"conditional": f.conditional,
"suppressed_by": f.suppressed_by,
"provenance": "inner-editor",
}),
);
if let Some(id) = source {
msg = msg.with_source_paragraph(id);
}
crate::pane::output::emit(&msg);
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn threshold_hides_praise_at_default_note() {
assert!(!meets_threshold(EditorSeverity::Praise, "note"));
assert!(meets_threshold(EditorSeverity::Note, "note"));
assert!(meets_threshold(EditorSeverity::Concern, "note"));
assert!(meets_threshold(EditorSeverity::Praise, "praise"));
assert!(!meets_threshold(EditorSeverity::Note, "concern"));
assert!(meets_threshold(EditorSeverity::Concern, "concern"));
assert!(!meets_threshold(EditorSeverity::Praise, "garbage"));
}
}