Skip to content

Commit de1042a

Browse files
committed
Make columns start at 0.
Lines already start at 0, so columns should, too.
1 parent d00572d commit de1042a

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/dotty/tools/dotc/reporting/ConsoleReporter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ConsoleReporter(
2525
printMessage(pos.lineContents.stripLineEnd)
2626

2727
def printColumnMarker(pos: SourcePosition) =
28-
if (pos.exists) { printMessage(" " * (pos.column - 1) + "^") }
28+
if (pos.exists) { printMessage(" " * pos.column + "^") }
2929

3030
/** Prints the message. */
3131
def printMessage(msg: String): Unit = { writer.print(msg + "\n"); writer.flush() }

src/dotty/tools/dotc/util/SourceFile.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ case class SourceFile(file: AbstractFile, content: Array[Char]) {
7272
def positionInUltimateSource(position: SourcePosition): SourcePosition =
7373
SourcePosition(underlying, position.pos shift start)
7474

75-
def isLineBreak(idx: Int) =
75+
private def isLineBreak(idx: Int) =
7676
if (idx >= length) false else {
7777
val ch = content(idx)
7878
// don't identify the CR in CR LF as a line break, since LF will do.
7979
if (ch == CR) (idx + 1 == length) || (content(idx + 1) != LF)
8080
else isLineBreakChar(ch)
8181
}
8282

83-
def calculateLineIndices(cs: Array[Char]) = {
83+
private def calculateLineIndices(cs: Array[Char]) = {
8484
val buf = new ArrayBuffer[Int]
8585
buf += 0
8686
for (i <- 0 until cs.length) if (isLineBreak(i)) buf += i + 1
@@ -103,25 +103,29 @@ case class SourceFile(file: AbstractFile, content: Array[Char]) {
103103
lastLine
104104
}
105105

106+
/** The index of the first character of the line containing position `offset` */
106107
def startOfLine(offset: Int): Int = {
107108
require(offset >= 0)
108109
lineToOffset(offsetToLine(offset))
109110
}
110111

112+
/** The start index of the line following the one containing position `offset` */
111113
def nextLine(offset: Int): Int =
112114
lineToOffset(offsetToLine(offset) + 1 min lineIndices.length - 1)
113115

116+
/** The contents of the line containing position `offset` */
114117
def lineContents(offset: Int): String =
115118
content.slice(startOfLine(offset), nextLine(offset)).mkString
116119

120+
/** The column corresponding to `offset`, starting at 0 */
117121
def column(offset: Int): Int = {
118122
var idx = startOfLine(offset)
119123
var col = 0
120124
while (idx != offset) {
121-
col += (if (content(idx) == '\t') tabInc - col % tabInc else 1)
125+
col += (if (content(idx) == '\t') (tabInc - col) % tabInc else 1)
122126
idx += 1
123127
}
124-
col + 1
128+
col
125129
}
126130

127131
override def toString = file.toString

0 commit comments

Comments
 (0)