Precompute canonical paths before sorting
This commit is contained in:
@@ -85,15 +85,32 @@ func canonicalDiagnostics(diagnostics []Diagnostic) []Diagnostic {
|
||||
for i := range canonical {
|
||||
slices.SortFunc(canonical[i].Related, compareLocation)
|
||||
}
|
||||
slices.SortFunc(canonical, compareDiagnostic)
|
||||
type orderedDiagnostic struct {
|
||||
diagnostic Diagnostic
|
||||
pointer string
|
||||
}
|
||||
ordered := make([]orderedDiagnostic, len(canonical))
|
||||
for i, diagnostic := range canonical {
|
||||
ordered[i] = orderedDiagnostic{diagnostic: diagnostic, pointer: diagnostic.Path.String()}
|
||||
}
|
||||
slices.SortFunc(ordered, func(left, right orderedDiagnostic) int {
|
||||
return compareDiagnosticWithPaths(left.diagnostic, right.diagnostic, left.pointer, right.pointer)
|
||||
})
|
||||
for i, item := range ordered {
|
||||
canonical[i] = item.diagnostic
|
||||
}
|
||||
return canonical
|
||||
}
|
||||
|
||||
func compareDiagnostic(left, right Diagnostic) int {
|
||||
return compareDiagnosticWithPaths(left, right, left.Path.String(), right.Path.String())
|
||||
}
|
||||
|
||||
func compareDiagnosticWithPaths(left, right Diagnostic, leftPath, rightPath string) int {
|
||||
if order := compareOptionalLocation(left.Primary, right.Primary); order != 0 {
|
||||
return order
|
||||
}
|
||||
if order := cmp.Compare(left.Path.String(), right.Path.String()); order != 0 {
|
||||
if order := cmp.Compare(leftPath, rightPath); order != 0 {
|
||||
return order
|
||||
}
|
||||
if order := cmp.Compare(left.Code, right.Code); order != 0 {
|
||||
|
||||
Reference in New Issue
Block a user