KMT-1199 [compose resources] create the accessors' file in case it doesn't exist already

(cherry picked from commit 61a9e21dfafc83cbfe561ff691ff44045caf6ffc)

IJ-CR-173052

GitOrigin-RevId: a11662926b387e5348bfc53f8b60a06fb8f7d159
This commit is contained in:
Alexandru Resiga
2025-08-19 17:21:34 +02:00
committed by intellij-monorepo-bot
parent 5dde42b63a
commit 9bcf4da444

View File

@@ -8,6 +8,8 @@ import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.util.concurrency.annotations.RequiresWriteLock
import java.nio.file.Path
import java.util.*
import kotlin.io.path.createFile
import kotlin.io.path.exists
import kotlin.io.path.invariantSeparatorsPathString
private const val ITEMS_PER_FILE_LIMIT = 100
@@ -111,6 +113,7 @@ private suspend fun getChunkFileSpec(
@RequiresWriteLock
private suspend fun writeAccessors(moduleDir: String, fileName: String, content: String): Unit = writeAction {
val path = Path.of(moduleDir, fileName)
if (!path.exists()) path.createFile()
val documentManager = FileDocumentManager.getInstance()
val document = path.toVirtualFile()?.let { virtualFile -> documentManager.getDocument(virtualFile) } ?: return@writeAction
runUndoTransparentWriteAction { document.setText(content) }