Skip to content

Commit fc47e49

Browse files
committed
fix(error-handling): ensure correct line range calculation in ErrorMessageProcessor
Previously, the line range calculation in `ErrorMessageProcessor` could result in incorrect offsets when `lineTo` was not specified or when it exceeded the number of lines in the document. This commit fixes the issue by introducing a new calculation that takes into account the presence and validity of `lineTo`, ensuring that the text range is always correctly determined.
1 parent 37e4b89 commit fc47e49

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/main/kotlin/com/intellij/temporary/error/ErrorMessageProcessor.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,19 @@ object ErrorMessageProcessor {
4141
val editor = consoleEditor ?: getConsoleEditor(project) ?: return null
4242
val document = editor.document
4343

44+
var end = if (lineTo == null) {
45+
document.lineCount - 1
46+
} else {
47+
if (lineTo >= document.lineCount - 1) document.lineCount - 1 else lineTo
48+
}
49+
50+
if(lineFrom >= document.lineCount) {
51+
end = document.lineCount - 1
52+
}
53+
4454
val textRange = TextRange(
4555
document.getLineStartOffset(lineFrom),
46-
document.getLineEndOffset(lineTo ?: (document.lineCount - 1))
56+
document.getLineEndOffset(end)
4757
)
4858

4959
return document.getText(textRange)

0 commit comments

Comments
 (0)