Finalize structured diagnostic aggregation

This commit is contained in:
2026-08-27 16:40:17 +00:00
parent 480680b257
commit 4dbbf68051
112 changed files with 656 additions and 893 deletions

View File

@@ -110,8 +110,8 @@ func (n *Normalizer) Normalize(ctx context.Context, req contracts.TypedNormalize
return contracts.TypedNormalizeResult[dnd.SpellList]{Value: value, Diagnostics: diagnosticGroups}, nil
}
func normalizeSpellList(input dnd.SpellList, catalog spellcatalog.EffectiveCatalog, order shared.SourceRefOrder) (dnd.SpellList, []contracts.Warning) {
var warnings []contracts.Warning
func normalizeSpellList(input dnd.SpellList, catalog spellcatalog.EffectiveCatalog, order shared.SourceRefOrder) (dnd.SpellList, []diagnostics.Finding) {
var warnings []diagnostics.Finding
if input.SpellCasts == nil {
return dnd.SpellList{}, nil
}
@@ -121,7 +121,7 @@ func normalizeSpellList(input dnd.SpellList, catalog spellcatalog.EffectiveCatal
cast := cloneSpellCast(inputCast)
if canonicalName, ok := catalog.Lookup(inputCast.Spell); ok {
if inputCast.Spell != canonicalName {
warnings = append(warnings, contracts.Warning{
warnings = append(warnings, diagnostics.Finding{
Scope: spellCastScope(index),
ReasonCode: ReasonCodeSpellNameCanonicalized,
Message: fmt.Sprintf("input index %d: spell name canonicalized from %q to %q",
@@ -130,7 +130,7 @@ func normalizeSpellList(input dnd.SpellList, catalog spellcatalog.EffectiveCatal
}
cast.Spell = canonicalName
} else {
warnings = append(warnings, contracts.Warning{
warnings = append(warnings, diagnostics.Finding{
Scope: spellCastScope(index),
ReasonCode: ReasonCodeSpellNameUnresolved,
Message: fmt.Sprintf("input index %d: spell name %q could not be resolved in the effective catalog",
@@ -141,7 +141,7 @@ func normalizeSpellList(input dnd.SpellList, catalog spellcatalog.EffectiveCatal
canonicalRefs, orderChanged, duplicateCount := canonicalizeSourceRefs(order, inputCast.SourceRefs)
cast.SourceRefs = canonicalRefs
if orderChanged || duplicateCount > 0 {
warnings = append(warnings, contracts.Warning{
warnings = append(warnings, diagnostics.Finding{
Scope: spellCastScope(index),
ReasonCode: ReasonCodeSourceReferencesNormalized,
Message: fmt.Sprintf("input index %d: source references normalized (original count %d, final count %d, order changed %t, duplicates removed %d)",
@@ -179,7 +179,7 @@ type duplicateGroup struct {
removed []int
}
func collapseDuplicateSpellCasts(input dnd.SpellList, documentIndex source.DocumentIndex, catalog spellcatalog.EffectiveCatalog) (dnd.SpellList, []contracts.Warning) {
func collapseDuplicateSpellCasts(input dnd.SpellList, documentIndex source.DocumentIndex, catalog spellcatalog.EffectiveCatalog) (dnd.SpellList, []diagnostics.Finding) {
if len(input.SpellCasts) == 0 {
return input, nil
}
@@ -221,7 +221,7 @@ func collapseDuplicateSpellCasts(input dnd.SpellList, documentIndex source.Docum
}
}
warnings := make([]contracts.Warning, 0)
warnings := make([]diagnostics.Finding, 0)
for _, group := range groups {
if len(group.removed) == 0 {
continue
@@ -264,7 +264,7 @@ func writeKeyInt(builder *strings.Builder, value int) {
builder.WriteByte(';')
}
func duplicateWarning(retainedIndex int, removed []int) contracts.Warning {
func duplicateWarning(retainedIndex int, removed []int) diagnostics.Finding {
const maxDisplayedIndices = 20
displayed := removed
if len(displayed) > maxDisplayedIndices {
@@ -279,7 +279,7 @@ func duplicateWarning(retainedIndex int, removed []int) contracts.Warning {
if omitted := len(removed) - len(displayed); omitted > 0 {
message += fmt.Sprintf("; %d additional removed input indices omitted", omitted)
}
return contracts.Warning{
return diagnostics.Finding{
Scope: spellCastScope(retainedIndex),
ReasonCode: ReasonCodeDuplicateSpellCastCollapsed,
Message: message,