diff options
Diffstat (limited to 'src/dotty/tools/dotc/util')
-rw-r--r-- | src/dotty/tools/dotc/util/SourceFile.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/util/SourcePosition.scala | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/util/SourceFile.scala b/src/dotty/tools/dotc/util/SourceFile.scala index 8bd0ecfd6..1d4c9c2ab 100644 --- a/src/dotty/tools/dotc/util/SourceFile.scala +++ b/src/dotty/tools/dotc/util/SourceFile.scala @@ -97,7 +97,7 @@ case class SourceFile(file: AbstractFile, content: Array[Char]) extends interfac private lazy val lineIndices: Array[Int] = calculateLineIndices(content) /** Map line to offset of first character in line */ - def lineToOffset(index : Int): Int = lineIndices(index) + def lineToOffset(index: Int): Int = lineIndices(index) /** A cache to speed up offsetToLine searches to similar lines */ private var lastLine = 0 diff --git a/src/dotty/tools/dotc/util/SourcePosition.scala b/src/dotty/tools/dotc/util/SourcePosition.scala index 68a9b6403..d0f9cb887 100644 --- a/src/dotty/tools/dotc/util/SourcePosition.scala +++ b/src/dotty/tools/dotc/util/SourcePosition.scala @@ -14,6 +14,17 @@ extends interfaces.SourcePosition { def point: Int = pos.point /** The line of the position, starting at 0 */ def line: Int = source.offsetToLine(point) + + /** The lines of the position */ + def lines: List[Int] = + List.range(source.offsetToLine(start), source.offsetToLine(end)) match { + case Nil => line :: Nil + case xs => xs + } + + def lineContent(lineNumber: Int): String = + source.lineContent(source.lineToOffset(lineNumber)) + /** The column of the position, starting at 0 */ def column: Int = source.column(point) |