Preserve composition conflict claimant order
This commit is contained in:
@@ -88,7 +88,9 @@ func (a *diagnosticAccumulator) loadError() *LoadError {
|
||||
func canonicalDiagnostics(diagnostics []Diagnostic) []Diagnostic {
|
||||
canonical := cloneDiagnostics(diagnostics)
|
||||
for i := range canonical {
|
||||
slices.SortFunc(canonical[i].Related, compareLocation)
|
||||
if canonical[i].Code != CodeComposeConflict {
|
||||
slices.SortFunc(canonical[i].Related, compareLocation)
|
||||
}
|
||||
}
|
||||
type orderedDiagnostic struct {
|
||||
diagnostic Diagnostic
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"io"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@@ -110,6 +111,44 @@ func TestCanonicalDiagnosticsSortEscapedPaths(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanonicalDiagnosticsPreservesCompositionClaimantOrder(t *testing.T) {
|
||||
composition := Diagnostic{
|
||||
Code: CodeComposeConflict,
|
||||
Severity: SeverityError,
|
||||
Path: Keys("value"),
|
||||
Primary: &Location{SourceID: "source-4"},
|
||||
Related: []Location{
|
||||
{SourceID: "source-5"},
|
||||
{SourceID: "source-3"},
|
||||
},
|
||||
}
|
||||
other := Diagnostic{
|
||||
Code: "decode.type",
|
||||
Severity: SeverityError,
|
||||
Path: Keys("other"),
|
||||
Related: []Location{
|
||||
{SourceID: "source-5"},
|
||||
{SourceID: "source-3"},
|
||||
},
|
||||
}
|
||||
|
||||
canonical := canonicalDiagnostics([]Diagnostic{composition, other})
|
||||
var compositionResult, genericResult Diagnostic
|
||||
for _, diagnostic := range canonical {
|
||||
if diagnostic.Code == CodeComposeConflict {
|
||||
compositionResult = diagnostic
|
||||
} else {
|
||||
genericResult = diagnostic
|
||||
}
|
||||
}
|
||||
if got := []string{compositionResult.Related[0].SourceID, compositionResult.Related[1].SourceID}; !slices.Equal(got, []string{"source-5", "source-3"}) {
|
||||
t.Fatalf("composition related locations = %v, want claimant order", got)
|
||||
}
|
||||
if got := []string{genericResult.Related[0].SourceID, genericResult.Related[1].SourceID}; !slices.Equal(got, []string{"source-3", "source-5"}) {
|
||||
t.Fatalf("generic related locations = %v, want sorted order", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteDiagnosticsEscapesControls(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user