User: rednesto Date: 17 Dec 23 12:14 Revision: e89003cc551cb26022cc4c96fba4832c14e85815 Summary: Fix minecraft-dev/mcdev-error-report#586 Because we are delegating isWritable to the backing file, setContent fails when called in the init block. To fix that we have to use a factory function and provide the full text in the constructor. TeamCity URL: https://ci.mcdev.io/viewModification.html?tab=vcsModificationFiles&modId=8907&personal=false Index: src/main/kotlin/nbt/NbtVirtualFile.kt =================================================================== --- src/main/kotlin/nbt/NbtVirtualFile.kt (revision 2f32b1f09351c5991f0bec2d0b187c21c8f4868f) +++ src/main/kotlin/nbt/NbtVirtualFile.kt (revision e89003cc551cb26022cc4c96fba4832c14e85815) @@ -24,10 +24,10 @@ import com.demonwav.mcdev.nbt.editor.CompressionSelection import com.demonwav.mcdev.nbt.editor.NbtToolbar import com.demonwav.mcdev.nbt.lang.NbttFile -import com.demonwav.mcdev.nbt.lang.NbttFileType import com.demonwav.mcdev.nbt.lang.NbttLanguage import com.demonwav.mcdev.util.runReadActionAsync import com.demonwav.mcdev.util.runWriteTaskLater +import com.intellij.lang.Language import com.intellij.notification.Notification import com.intellij.notification.NotificationType import com.intellij.openapi.fileEditor.impl.IdeDocumentHistoryImpl @@ -41,43 +41,42 @@ import java.util.concurrent.TimeUnit import java.util.zip.GZIPOutputStream -class NbtVirtualFile(private val backingFile: VirtualFile, private val project: Project) : - LightVirtualFile(backingFile.name + ".nbtt", NbttFileType, ""), - IdeDocumentHistoryImpl.SkipFromDocumentHistory { +fun NbtVirtualFile(backingFile: VirtualFile, project: Project): NbtVirtualFile { + var language: Language = NbttLanguage - val isCompressed: Boolean - lateinit var toolbar: NbtToolbar - val parseSuccessful: Boolean - - init { - originalFile = backingFile - language = NbttLanguage - - var text: String + var text: String - var tempCompressed: Boolean - var tempParseSuccessful: Boolean + var compressed: Boolean + var parseSuccessful: Boolean - try { - val (rootCompound, isCompressed) = Nbt.buildTagTree(backingFile.inputStream, TimeUnit.SECONDS.toMillis(10)) - text = rootCompound.toString() + try { + val (rootCompound, isCompressed) = Nbt.buildTagTree(backingFile.inputStream, TimeUnit.SECONDS.toMillis(10)) + text = rootCompound.toString() - tempCompressed = isCompressed - tempParseSuccessful = true + compressed = isCompressed + parseSuccessful = true - } catch (e: MalformedNbtFileException) { - text = MCDevBundle("nbt.lang.errors.wrapped_error_message", e.message) + } catch (e: MalformedNbtFileException) { + text = MCDevBundle("nbt.lang.errors.wrapped_error_message", e.message) - tempCompressed = false - tempParseSuccessful = false + compressed = false + parseSuccessful = false - } + } - this.isCompressed = tempCompressed - this.parseSuccessful = tempParseSuccessful - - if (!this.parseSuccessful) { + if (!parseSuccessful) { - language = PlainTextLanguage.INSTANCE - } + language = PlainTextLanguage.INSTANCE + } - setContent(this, text, false) + return NbtVirtualFile(backingFile, project, language, text, compressed, parseSuccessful) - } +} +class NbtVirtualFile( + private val backingFile: VirtualFile, + private val project: Project, + language: Language, + text: String, + val isCompressed: Boolean, + val parseSuccessful: Boolean, +) : LightVirtualFile(backingFile.name + ".nbtt", language, text), IdeDocumentHistoryImpl.SkipFromDocumentHistory { + + lateinit var toolbar: NbtToolbar + override fun refresh(asynchronous: Boolean, recursive: Boolean, postRunnable: Runnable?) { backingFile.refresh(asynchronous, recursive, postRunnable) }