///|
fn shift_source_span(span : SourceSpan, offset : Int) -> SourceSpan {
  { start: span.start + offset, end: span.end + offset }
}

///|
fn shift_roman_diagnostic(
  diagnostic : RomanDiagnostic,
  offset : Int,
) -> RomanDiagnostic {
  { ..diagnostic, span: shift_source_span(diagnostic.span, offset) }
}

///|
fn sort_document_diagnostics(
  input : Array[RomanDiagnostic],
) -> Array[RomanDiagnostic] {
  let sorted : Array[RomanDiagnostic] = []
  for diagnostic in input {
    sorted.push(diagnostic)
    let mut index = sorted.length() - 1
    while index > 0 && sorted[index - 1].span.start > sorted[index].span.start {
      let previous = sorted[index - 1]
      sorted[index - 1] = sorted[index]
      sorted[index] = previous
      index = index - 1
    }
  }
  sorted
}