Skip to content

Commit 7724a74

Browse files
committed
feat(devins-lang): optimize directory creation and add runInEdt for smoother execution #146
This commit optimizes the directory creation logic in WriteInsCommand.kt and introduces runInEdt for smoother execution in DevInsProcessProcessor.kt.
1 parent f0cfaa7 commit 7724a74

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec/WriteInsCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class WriteInsCommand(val myProject: Project, val argument: String, val content:
3939
parentDir = projectDir
4040
for (dir in parentDirs) {
4141
if (dir.isEmpty()) continue
42-
parentDir = parentDir?.createChildDirectory(this, dir)
42+
parentDir = runWriteAction { parentDir?.createChildDirectory(this, dir) }
4343
}
4444

4545
if (parentDir == null) {

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/run/flow/DevInsProcessProcessor.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import cc.unitmesh.devti.language.psi.DevInVisitor
99
import cc.unitmesh.devti.provider.ContextPrompter
1010
import cc.unitmesh.devti.util.parser.Code
1111
import com.intellij.execution.process.ProcessEvent
12+
import com.intellij.openapi.application.runInEdt
1213
import com.intellij.openapi.application.runReadAction
1314
import com.intellij.openapi.components.Service
1415
import com.intellij.openapi.components.service
@@ -58,7 +59,9 @@ class DevInsProcessProcessor(val project: Project) {
5859
val code = Code.parse(conversationService.getLlmResponse(scriptPath))
5960
val isDevInCode = code.language == DevInLanguage.INSTANCE
6061
if (isDevInCode) {
61-
executeTask(DevInFile.fromString(project, code.text))
62+
runInEdt {
63+
executeTask(DevInFile.fromString(project, code.text))
64+
}
6265
}
6366

6467
when {
@@ -88,11 +91,13 @@ class DevInsProcessProcessor(val project: Project) {
8891
val compiledResult = DevInsCompiler(project, newScript).compile()
8992
val prompt = compiledResult.output
9093

91-
sendToChatWindow(project, ChatActionType.CHAT) { panel, service ->
92-
service.handlePromptAndResponse(panel, object : ContextPrompter() {
93-
override fun displayPrompt(): String = prompt
94-
override fun requestPrompt(): String = prompt
95-
}, null, true)
94+
if (compiledResult.hasError) {
95+
sendToChatWindow(project, ChatActionType.CHAT) { panel, service ->
96+
service.handlePromptAndResponse(panel, object : ContextPrompter() {
97+
override fun displayPrompt(): String = prompt
98+
override fun requestPrompt(): String = prompt
99+
}, null, true)
100+
}
96101
}
97102
}
98103

0 commit comments

Comments
 (0)