Skip to content

Commit

Permalink
feat(devins-lang): optimize directory creation and add runInEdt for s…
Browse files Browse the repository at this point in the history
…moother execution #146

This commit optimizes the directory creation logic in WriteInsCommand.kt and introduces runInEdt for smoother execution in DevInsProcessProcessor.kt.
  • Loading branch information
phodal committed Apr 14, 2024
1 parent f0cfaa7 commit 7724a74
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Expand Up @@ -39,7 +39,7 @@ class WriteInsCommand(val myProject: Project, val argument: String, val content:
parentDir = projectDir
for (dir in parentDirs) {
if (dir.isEmpty()) continue
parentDir = parentDir?.createChildDirectory(this, dir)
parentDir = runWriteAction { parentDir?.createChildDirectory(this, dir) }
}

if (parentDir == null) {
Expand Down
Expand Up @@ -9,6 +9,7 @@ import cc.unitmesh.devti.language.psi.DevInVisitor
import cc.unitmesh.devti.provider.ContextPrompter
import cc.unitmesh.devti.util.parser.Code
import com.intellij.execution.process.ProcessEvent
import com.intellij.openapi.application.runInEdt
import com.intellij.openapi.application.runReadAction
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
Expand Down Expand Up @@ -58,7 +59,9 @@ class DevInsProcessProcessor(val project: Project) {
val code = Code.parse(conversationService.getLlmResponse(scriptPath))
val isDevInCode = code.language == DevInLanguage.INSTANCE
if (isDevInCode) {
executeTask(DevInFile.fromString(project, code.text))
runInEdt {
executeTask(DevInFile.fromString(project, code.text))
}
}

when {
Expand Down Expand Up @@ -88,11 +91,13 @@ class DevInsProcessProcessor(val project: Project) {
val compiledResult = DevInsCompiler(project, newScript).compile()
val prompt = compiledResult.output

sendToChatWindow(project, ChatActionType.CHAT) { panel, service ->
service.handlePromptAndResponse(panel, object : ContextPrompter() {
override fun displayPrompt(): String = prompt
override fun requestPrompt(): String = prompt
}, null, true)
if (compiledResult.hasError) {
sendToChatWindow(project, ChatActionType.CHAT) { panel, service ->
service.handlePromptAndResponse(panel, object : ContextPrompter() {
override fun displayPrompt(): String = prompt
override fun requestPrompt(): String = prompt
}, null, true)
}
}
}

Expand Down

0 comments on commit 7724a74

Please sign in to comment.