Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: catch text range index exceptions #17

Merged
merged 2 commits into from
May 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.intellij.openapi.roots.ProjectFileIndex
import com.intellij.openapi.util.TextRange
import com.intellij.profile.codeInspection.InspectionProfileManager
import com.intellij.psi.PsiFile
import java.lang.IndexOutOfBoundsException

/**
* An external annotator that runs `haml-lint` against open editor files and annotates them with any returned offenses.
Expand Down Expand Up @@ -111,10 +112,14 @@ class HamlLintExternalAnnotator : ExternalAnnotator<HamlLintExternalAnnotatorInf
if (lineIndex >= document.lineCount) return null
var startOffset = document.getLineStartOffset(lineIndex)
var endOffset = document.getLineEndOffset(lineIndex)
val documentText = document.charsSequence
while (documentText[endOffset] == ' ' && startOffset < endOffset) endOffset--
while (documentText[startOffset] == ' ' && startOffset < endOffset) startOffset++
return TextRange(startOffset, endOffset)
return try {
val documentText = document.charsSequence
while (documentText[endOffset] == ' ' && startOffset < endOffset) endOffset--
while (documentText[startOffset] == ' ' && startOffset < endOffset) startOffset++
TextRange(startOffset, endOffset)
} catch (e: IndexOutOfBoundsException) {
null
}
}

/**
Expand Down