Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions crates/plotnik-lib/src/diagnostics/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub enum DiagnosticKind {
InvalidChildType,

// Often consequences of earlier errors
UnnamedDefNotLast,
UnnamedDef,
}

impl DiagnosticKind {
Expand Down Expand Up @@ -119,7 +119,7 @@ impl DiagnosticKind {
/// Consequence errors - often caused by earlier parse errors.
/// These get suppressed when any root-cause or structural error exists.
pub fn is_consequence_error(&self) -> bool {
matches!(self, Self::UnnamedDefNotLast)
matches!(self, Self::UnnamedDef)
}

/// Base message for this diagnostic kind, used when no custom message is provided.
Expand Down Expand Up @@ -189,7 +189,7 @@ impl DiagnosticKind {
Self::InvalidChildType => "node type not valid as child",

// Structural
Self::UnnamedDefNotLast => "only the last definition can be unnamed",
Self::UnnamedDef => "definitions must be named",
}
}

Expand Down Expand Up @@ -229,8 +229,8 @@ impl DiagnosticKind {
"type annotations use `::`, not `:` — {}".to_string()
}

// Named def ordering
Self::UnnamedDefNotLast => "only the last definition can be unnamed — {}".to_string(),
// Named def
Self::UnnamedDef => "definitions must be named — {}".to_string(),

// Standard pattern: fallback + context
_ => format!("{}; {{}}", self.fallback_message()),
Expand Down
2 changes: 1 addition & 1 deletion crates/plotnik-lib/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl Diagnostics {
/// 1. Containment: when error A's suppression_range contains error B's display range,
/// and A has higher priority, suppress B (only for structural errors)
/// 2. Same position: when spans start at the same position, root-cause errors suppress structural ones
/// 3. Consequence errors (UnnamedDefNotLast) suppressed when any other error exists
/// 3. Consequence errors (UnnamedDef) suppressed when any other error exists
/// 4. Adjacent: when error A ends exactly where error B starts, A suppresses B
pub(crate) fn filtered(&self) -> Vec<DiagnosticMessage> {
if self.messages.is_empty() {
Expand Down
20 changes: 10 additions & 10 deletions crates/plotnik-lib/src/diagnostics/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,23 +271,23 @@ fn diagnostic_kind_default_severity() {
Severity::Error
);
assert_eq!(
DiagnosticKind::UnnamedDefNotLast.default_severity(),
DiagnosticKind::UnnamedDef.default_severity(),
Severity::Error
);
}

#[test]
fn diagnostic_kind_suppression_order() {
// Higher priority (earlier in enum) suppresses lower priority (later in enum)
assert!(DiagnosticKind::UnclosedTree.suppresses(&DiagnosticKind::UnnamedDefNotLast));
assert!(DiagnosticKind::UnclosedTree.suppresses(&DiagnosticKind::UnnamedDef));
assert!(DiagnosticKind::UnclosedTree.suppresses(&DiagnosticKind::UndefinedReference));
assert!(DiagnosticKind::ExpectedExpression.suppresses(&DiagnosticKind::UnnamedDefNotLast));
assert!(DiagnosticKind::ExpectedExpression.suppresses(&DiagnosticKind::UnnamedDef));

// Same kind doesn't suppress itself
assert!(!DiagnosticKind::UnclosedTree.suppresses(&DiagnosticKind::UnclosedTree));

// Lower priority doesn't suppress higher priority
assert!(!DiagnosticKind::UnnamedDefNotLast.suppresses(&DiagnosticKind::UnclosedTree));
assert!(!DiagnosticKind::UnnamedDef.suppresses(&DiagnosticKind::UnclosedTree));
}

#[test]
Expand Down Expand Up @@ -364,7 +364,7 @@ fn filtered_no_suppression_disjoint_spans() {
#[test]
fn filtered_suppresses_lower_priority_contained() {
let mut diagnostics = Diagnostics::new();
// Higher priority error (UnclosedTree) contains lower priority (UnnamedDefNotLast)
// Higher priority error (UnclosedTree) contains lower priority (UnnamedDef)
diagnostics
.report(
DiagnosticKind::UnclosedTree,
Expand All @@ -373,7 +373,7 @@ fn filtered_suppresses_lower_priority_contained() {
.emit();
diagnostics
.report(
DiagnosticKind::UnnamedDefNotLast,
DiagnosticKind::UnnamedDef,
TextRange::new(5.into(), 15.into()),
)
.emit();
Expand All @@ -386,10 +386,10 @@ fn filtered_suppresses_lower_priority_contained() {
#[test]
fn filtered_consequence_suppressed_by_structural() {
let mut diagnostics = Diagnostics::new();
// Consequence error (UnnamedDefNotLast) suppressed when structural error (UnclosedTree) exists
// Consequence error (UnnamedDef) suppressed when structural error (UnclosedTree) exists
diagnostics
.report(
DiagnosticKind::UnnamedDefNotLast,
DiagnosticKind::UnnamedDef,
TextRange::new(0.into(), 20.into()),
)
.emit();
Expand Down Expand Up @@ -418,7 +418,7 @@ fn filtered_same_span_higher_priority_wins() {
.emit();
diagnostics
.report(
DiagnosticKind::UnnamedDefNotLast,
DiagnosticKind::UnnamedDef,
TextRange::new(0.into(), 10.into()),
)
.emit();
Expand Down Expand Up @@ -448,7 +448,7 @@ fn render_filtered() {
.emit();
diagnostics
.report(
DiagnosticKind::UnnamedDefNotLast,
DiagnosticKind::UnnamedDef,
TextRange::new(5.into(), 15.into()),
)
.message("unnamed def")
Expand Down
Loading