Read file content under readAction in ToFromOriginalFileMapper

Relates to #EA-212072
This commit is contained in:
Vladimir Dolzhenko
2020-04-14 17:18:28 +02:00
committed by Vladimir Dolzhenko
parent 8ea7fc1d47
commit 67fec903f6
2 changed files with 12 additions and 7 deletions
@@ -21,8 +21,8 @@ open class KotlinExceptionWithAttachments : RuntimeException, ExceptionWithAttac
override fun getAttachments(): Array<Attachment> = attachments.toTypedArray()
fun withAttachment(name: String, content: String?): KotlinExceptionWithAttachments {
attachments.add(Attachment(name, content ?: "<null>"))
fun withAttachment(name: String, content: Any?): KotlinExceptionWithAttachments {
attachments.add(Attachment(name, content?.toString() ?: "<null>"))
return this
}
}
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.idea.completion
import com.intellij.codeInsight.completion.CompletionParameters
import com.intellij.psi.PsiElement
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.idea.util.application.runReadAction
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.psiUtil.startOffset
import org.jetbrains.kotlin.utils.checkWithAttachment
@@ -34,16 +35,20 @@ class ToFromOriginalFileMapper private constructor(
//TODO: lazy initialization?
init {
val originalText = originalFile.text
val syntheticText = syntheticFile.text
val (originalText, syntheticText) = runReadAction {
originalFile.text to syntheticFile.text
}
val originalSubSequence = originalText.take(completionOffset)
val syntheticSubSequence = syntheticText.take(completionOffset)
checkWithAttachment(originalSubSequence == syntheticSubSequence, {
"original subText [len: ${originalSubSequence.length}]" +
" does not match synthetic subText [len: ${syntheticSubSequence.length}]"
" does not match synthetic subText [len: ${syntheticSubSequence.length}], " +
"completionOffset: $completionOffset"
}) {
it.withAttachment("original subText", originalSubSequence.toString())
.withAttachment("synthetic subText", syntheticSubSequence.toString())
it.withAttachment("original subText.kt", originalSubSequence)
.withAttachment("original.kt", originalText)
.withAttachment("synthetic subText.kt", syntheticSubSequence)
.withAttachment("synthetic.kt", syntheticText)
}
syntheticLength = syntheticText.length