Preserve literal ordering for foreign source references

This commit is contained in:
2026-07-24 14:25:02 +00:00
parent bef3d1359d
commit 83fde83a58
2 changed files with 5 additions and 5 deletions

View File

@@ -38,7 +38,7 @@ func (o SourceRefOrder) Less(left, right source.SourceRef) bool {
if lessEndpoint(positions, left.StartUnitID, right.StartUnitID) { if lessEndpoint(positions, left.StartUnitID, right.StartUnitID) {
return true return true
} }
if lessEndpoint(o.positions, right.StartUnitID, left.StartUnitID) { if lessEndpoint(positions, right.StartUnitID, left.StartUnitID) {
return false return false
} }
return lessEndpoint(positions, left.EndUnitID, right.EndUnitID) return lessEndpoint(positions, left.EndUnitID, right.EndUnitID)

View File

@@ -15,13 +15,13 @@ func TestSourceRefOrderUsesDocumentOrderAndLiteralFallbacks(t *testing.T) {
{SourceID: doc.ID, StartUnitID: 10, EndUnitID: 10}, {SourceID: doc.ID, StartUnitID: 10, EndUnitID: 10},
{SourceID: doc.ID, StartUnitID: 999, EndUnitID: 999}, {SourceID: doc.ID, StartUnitID: 999, EndUnitID: 999},
{SourceID: doc.ID, StartUnitID: 30, EndUnitID: 30}, {SourceID: doc.ID, StartUnitID: 30, EndUnitID: 30},
{SourceID: "other", StartUnitID: 20, EndUnitID: 20}, {SourceID: "other", StartUnitID: 30, EndUnitID: 1},
{SourceID: "other", StartUnitID: 10, EndUnitID: 10}, {SourceID: "other", StartUnitID: 10, EndUnitID: 2},
} }
got := order.Canonicalize(refs) got := order.Canonicalize(refs)
want := []source.SourceRef{ want := []source.SourceRef{
{SourceID: "other", StartUnitID: 10, EndUnitID: 10}, {SourceID: "other", StartUnitID: 10, EndUnitID: 2},
{SourceID: "other", StartUnitID: 20, EndUnitID: 20}, {SourceID: "other", StartUnitID: 30, EndUnitID: 1},
{SourceID: doc.ID, StartUnitID: 30, EndUnitID: 30}, {SourceID: doc.ID, StartUnitID: 30, EndUnitID: 30},
{SourceID: doc.ID, StartUnitID: 10, EndUnitID: 10}, {SourceID: doc.ID, StartUnitID: 10, EndUnitID: 10},
{SourceID: doc.ID, StartUnitID: 999, EndUnitID: 999}, {SourceID: doc.ID, StartUnitID: 999, EndUnitID: 999},