Improved Logging

This commit is contained in:
2026-04-09 21:56:53 +02:00
parent 8f0b8a5d66
commit 9e13bb9bab
6 changed files with 249 additions and 46 deletions
+51
View File
@@ -36,6 +36,39 @@ type ValidationReport struct {
Diagnostics []Diagnostic
}
func (r ValidationReport) SummaryLines(maxPaths int) []string {
type key struct {
severity Severity
message string
}
groups := map[key][]string{}
order := make([]key, 0)
for _, diagnostic := range r.Diagnostics {
k := key{severity: diagnostic.Severity, message: diagnostic.Message}
if _, ok := groups[k]; !ok {
order = append(order, k)
}
groups[k] = append(groups[k], diagnostic.Path)
}
slices.SortFunc(order, func(a, b key) int {
if a.severity != b.severity {
if a.severity == SeverityError {
return -1
}
return 1
}
return strings.Compare(a.message, b.message)
})
lines := make([]string, 0, len(order))
for _, k := range order {
paths := append([]string(nil), groups[k]...)
slices.Sort(paths)
paths = slices.Compact(paths)
lines = append(lines, formatDiagnosticSummaryLine(string(k.severity), k.message, paths, maxPaths))
}
return lines
}
func (r ValidationReport) HasErrors() bool {
for _, diagnostic := range r.Diagnostics {
if diagnostic.Severity == SeverityError {
@@ -65,6 +98,24 @@ func (r ValidationReport) WarningCount() int {
return count
}
func formatDiagnosticSummaryLine(prefix, message string, paths []string, maxPaths int) string {
if len(paths) == 0 {
return fmt.Sprintf("%s: %s", prefix, message)
}
if maxPaths <= 0 {
maxPaths = 3
}
display := paths
if len(display) > maxPaths {
display = display[:maxPaths]
}
location := strings.Join(display, ", ")
if len(paths) > len(display) {
location += fmt.Sprintf(", and %d more", len(paths)-len(display))
}
return fmt.Sprintf("%s: %s [%s]", prefix, message, location)
}
type BuildResult struct {
Mode string
Output2DADir string