Avoid requesting line number for bad offset (EA-87678)
Example of stack trace: java.lang.IndexOutOfBoundsException: Wrong offset: 14847. Should be in range: [0, 14846] at com.intellij.openapi.editor.impl.LineSet.findLineIndex(LineSet.java:141) at com.intellij.openapi.editor.impl.DocumentImpl.getLineNumber(DocumentImpl.java:919) at org.jetbrains.kotlin.idea.refactoring.KotlinRefactoringUtilKt.getLineCount(kotlinRefactoringUtil.kt:344) at org.jetbrains.kotlin.idea.debugger.KotlinPositionManager.getSourcePosition(KotlinPositionManager.kt:125)
This commit is contained in:
@@ -340,10 +340,12 @@ fun PsiElement.getLineCount(): Int {
|
|||||||
if (doc != null) {
|
if (doc != null) {
|
||||||
val spaceRange = textRange ?: TextRange.EMPTY_RANGE
|
val spaceRange = textRange ?: TextRange.EMPTY_RANGE
|
||||||
|
|
||||||
val startLine = doc.getLineNumber(spaceRange.startOffset)
|
if (spaceRange.endOffset <= doc.textLength) {
|
||||||
val endLine = doc.getLineNumber(spaceRange.endOffset)
|
val startLine = doc.getLineNumber(spaceRange.startOffset)
|
||||||
|
val endLine = doc.getLineNumber(spaceRange.endOffset)
|
||||||
|
|
||||||
return endLine - startLine
|
return endLine - startLine
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (text ?: "").count { it == '\n' } + 1
|
return (text ?: "").count { it == '\n' } + 1
|
||||||
|
|||||||
Reference in New Issue
Block a user