SourceRange.fromOffset constructor

SourceRange.fromOffset(
  1. int offset,
  2. int length,
  3. LineInfo lineInfo
)

Create from offset and length with line info.

Implementation

factory SourceRange.fromOffset(int offset, int length, LineInfo lineInfo) {
  final startLocation = lineInfo.getLocation(offset);
  final endLocation = lineInfo.getLocation(offset + length);
  return SourceRange(
    start: SourcePosition(
      line: startLocation.lineNumber,
      column: startLocation.columnNumber,
    ),
    end: SourcePosition(
      line: endLocation.lineNumber,
      column: endLocation.columnNumber,
    ),
    offset: offset,
    length: length,
  );
}