Skip to content

Commit

Permalink
Use runInEdt instead of invokeLater in createNewFile handler
Browse files Browse the repository at this point in the history
  • Loading branch information
pplam committed Jul 3, 2024
1 parent 0104d90 commit f58ed88
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/main/kotlin/ai/devchat/core/handlers/NewSrcFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f58ed88

Please sign in to comment.