Skip to content

Commit

Permalink
fix(error-handling): ensure correct line range calculation in ErrorMe…
Browse files Browse the repository at this point in the history
…ssageProcessor

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.
  • Loading branch information
phodal committed Mar 26, 2024
1 parent 37e4b89 commit fc47e49
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,19 @@ object ErrorMessageProcessor {
val editor = consoleEditor ?: getConsoleEditor(project) ?: return null
val document = editor.document

var end = if (lineTo == null) {
document.lineCount - 1
} else {
if (lineTo >= document.lineCount - 1) document.lineCount - 1 else lineTo
}

if(lineFrom >= document.lineCount) {
end = document.lineCount - 1
}

val textRange = TextRange(
document.getLineStartOffset(lineFrom),
document.getLineEndOffset(lineTo ?: (document.lineCount - 1))
document.getLineEndOffset(end)
)

return document.getText(textRange)
Expand Down

0 comments on commit fc47e49

Please sign in to comment.