Fix source range tests: support "undefined" offsets

This commit is contained in:
Dmitry Petrov
2017-04-13 10:04:36 +03:00
parent 40e09a39c1
commit a840cf7643
3 changed files with 25 additions and 2 deletions
@@ -41,11 +41,13 @@ class PsiSourceManager : SourceManager {
}
override fun getLineNumber(offset: Int): Int {
if (offset < 0) return -1
val index = lineStartOffsets.binarySearch(offset)
return if (index >= 0) index else -index - 2
}
override fun getColumnNumber(offset: Int): Int {
if (offset < 0) return -1
val lineNumber = getLineNumber(offset)
return offset - lineStartOffsets[lineNumber]
}