From f58ed8858a151bddbec2c002f5a77ebc7d7a748b Mon Sep 17 00:00:00 2001 From: Luo Tim Date: Wed, 3 Jul 2024 23:33:01 +0800 Subject: [PATCH] Use runInEdt instead of invokeLater in createNewFile handler --- src/main/kotlin/ai/devchat/core/handlers/NewSrcFile.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/ai/devchat/core/handlers/NewSrcFile.kt b/src/main/kotlin/ai/devchat/core/handlers/NewSrcFile.kt index f8719a9..df433ec 100644 --- a/src/main/kotlin/ai/devchat/core/handlers/NewSrcFile.kt +++ b/src/main/kotlin/ai/devchat/core/handlers/NewSrcFile.kt @@ -6,6 +6,7 @@ import ai.devchat.plugin.currentProject import com.alibaba.fastjson.JSONObject import com.intellij.lang.Language import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.application.runInEdt import com.intellij.openapi.fileEditor.FileEditorManager import com.intellij.psi.PsiFile import com.intellij.psi.PsiFileFactory @@ -20,9 +21,9 @@ class NewSrcFile(requestAction: String, metadata: JSONObject?, payload: JSONObje override fun action() { val content = payload!!.getString("content") val language = payload!!.getString("language") - ApplicationManager.getApplication().invokeLater { - val project = currentProject ?: return@invokeLater - val dir = FileEditorManager.getInstance(project).selectedEditor?.file?.parent ?: return@invokeLater + runInEdt { + val project = currentProject ?: return@runInEdt + val dir = FileEditorManager.getInstance(project).selectedEditor?.file?.parent ?: return@runInEdt ApplicationManager.getApplication().runWriteAction { val psiDirectory = PsiManager.getInstance(project).findDirectory(dir) ?: return@runWriteAction val (fileLanguage, ext) = getLanguageByName(language) ?: return@runWriteAction