Repair reversed D&D evidence ranges
This commit is contained in:
@@ -63,6 +63,29 @@ func (o SourceRefOrder) EarliestValid(refs []source.SourceRef) (int, bool) {
|
||||
return earliest, found
|
||||
}
|
||||
|
||||
// OrderEndpoints returns an owned copy of refs with each resolvable range
|
||||
// ordered by document position. References outside the indexed source, or
|
||||
// whose endpoints cannot both be resolved, remain unchanged so validators can
|
||||
// diagnose them.
|
||||
func (o SourceRefOrder) OrderEndpoints(refs []source.SourceRef) []source.SourceRef {
|
||||
if refs == nil {
|
||||
return nil
|
||||
}
|
||||
ordered := append([]source.SourceRef{}, refs...)
|
||||
for index := range ordered {
|
||||
ref := &ordered[index]
|
||||
if ref.SourceID != o.sourceID || ref.StartUnitID <= 0 || ref.EndUnitID <= 0 {
|
||||
continue
|
||||
}
|
||||
start, startOK := o.index.Position(ref.StartUnitID)
|
||||
end, endOK := o.index.Position(ref.EndUnitID)
|
||||
if startOK && endOK && start > end {
|
||||
ref.StartUnitID, ref.EndUnitID = ref.EndUnitID, ref.StartUnitID
|
||||
}
|
||||
}
|
||||
return ordered
|
||||
}
|
||||
|
||||
// Canonicalize returns an owned, stable-sorted, exactly de-duplicated copy of
|
||||
// refs. It deliberately preserves invalid references for diagnostics.
|
||||
func (o SourceRefOrder) Canonicalize(refs []source.SourceRef) []source.SourceRef {
|
||||
|
||||
Reference in New Issue
Block a user