@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.psi.KtDeclaration
3434import org.jetbrains.kotlin.psi.KtDestructuringDeclaration
3535import org.jetbrains.kotlin.psi.KtDestructuringDeclarationEntry
3636import org.jetbrains.kotlin.psi.KtEnumEntry
37+ import org.jetbrains.kotlin.psi.KtEnumEntrySuperclassReferenceExpression
3738import org.jetbrains.kotlin.psi.KtExpression
3839import org.jetbrains.kotlin.psi.KtFile
3940import org.jetbrains.kotlin.psi.KtForExpression
@@ -191,6 +192,10 @@ class KotlinAnalysisIndexer(
191192 super .visitSimpleNameExpression(expression)
192193 val referencedName = expression.getReferencedName()
193194 if (referencedName == " this" || referencedName == " super" ) return
195+ // The synthetic superclass reference of an enum entry initializer
196+ // (`HEARTS('h')`) has no source token of its own: its "name element"
197+ // is the whole enum class.
198+ if (expression is KtEnumEntrySuperclassReferenceExpression ) return
194199 val target = with (session) { expression.mainReference.resolveToSymbol() } ? : return
195200 val range = expression.getReferencedNameElement().textRange
196201
@@ -922,9 +927,9 @@ internal class LineIndex(private val text: String) {
922927 }
923928
924929 /* *
925- * Occurrence anchors are always single-line, like in scip-kotlinc : multiline declarations are
926- * collapsed onto their start line with the end character measured from that line's start . The
927- * true extent lives in the enclosing range.
930+ * Occurrence anchors are always single-line: multiline declarations are collapsed onto their
931+ * start line, clamped to that line's end so the range stays within the source . The true extent
932+ * lives in the enclosing range.
928933 */
929934 fun anchorRange (range : TextRange ): ScipRange ? {
930935 if (range.startOffset > text.length || range.endOffset > text.length) return null
@@ -933,12 +938,18 @@ internal class LineIndex(private val text: String) {
933938 if (startLine == endLine) {
934939 return ScipRange .singleLine(startLine, startCharacter, endCharacter)
935940 }
936- val flattenedEnd = range.endOffset - lineStart(startLine)
937- return ScipRange .singleLine(startLine, startCharacter, flattenedEnd)
941+ return ScipRange .singleLine(startLine, startCharacter, lineLength(startLine))
938942 }
939943
940944 private fun lineStart (line : Int ): Int = lineStartOffsets[line]
941945
946+ /* * Length of [line] excluding its trailing newline. */
947+ private fun lineLength (line : Int ): Int {
948+ val end =
949+ if (line + 1 < lineStartOffsets.size) lineStartOffsets[line + 1 ] - 1 else text.length
950+ return end - lineStart(line)
951+ }
952+
942953 private fun position (offset : Int ): Pair <Int , Int > {
943954 var line = Arrays .binarySearch(lineStartOffsets, offset)
944955 if (line < 0 ) line = - line - 2
0 commit comments