@@ -3,7 +3,6 @@ package cc.unitmesh.devti.sketch.ui.code
3
3
import cc.unitmesh.devti.AutoDevBundle
4
4
import cc.unitmesh.devti.AutoDevIcons
5
5
import cc.unitmesh.devti.AutoDevNotifications
6
- import cc.unitmesh.devti.command.EditFileCommand
7
6
import cc.unitmesh.devti.command.dataprovider.BuiltinCommand
8
7
import cc.unitmesh.devti.gui.chat.ui.AutoInputService
9
8
import cc.unitmesh.devti.provider.BuildSystemProvider
@@ -25,6 +24,7 @@ import com.intellij.openapi.actionSystem.impl.ActionButton
25
24
import com.intellij.openapi.application.ReadAction
26
25
import com.intellij.openapi.application.runInEdt
27
26
import com.intellij.openapi.application.runReadAction
27
+ import com.intellij.openapi.application.runWriteAction
28
28
import com.intellij.openapi.command.WriteCommandAction
29
29
import com.intellij.openapi.diagnostic.logger
30
30
import com.intellij.openapi.editor.Document
@@ -38,7 +38,6 @@ import com.intellij.openapi.project.Project
38
38
import com.intellij.openapi.util.Disposer
39
39
import com.intellij.openapi.util.text.StringUtil
40
40
import com.intellij.openapi.vfs.VirtualFile
41
- import com.intellij.psi.PsiFile
42
41
import com.intellij.psi.PsiManager
43
42
import com.intellij.ui.JBColor
44
43
import com.intellij.ui.components.JBLabel
@@ -139,7 +138,6 @@ open class CodeHighlightSketch(
139
138
}
140
139
141
140
142
-
143
141
private val plainText = PlainTextLanguage .INSTANCE .displayName
144
142
145
143
private val devinLanguageId = " devin"
@@ -517,22 +515,26 @@ private fun CodeHighlightSketch.handleExecutionResult(result: String?, button: J
517
515
}
518
516
519
517
private suspend fun executeEditFileCommand (project : Project , currentText : String , callback : (String? ) -> Unit ) {
518
+ var file: VirtualFile ? = null
520
519
try {
521
520
val newFileName = " DevIn-${System .currentTimeMillis()} .devin"
522
521
val language = Language .findLanguageByID(" DevIn" )
523
- val file = ScratchRootType .getInstance()
522
+ file = ScratchRootType .getInstance()
524
523
.createScratchFile(project, newFileName, language, currentText)
525
524
526
525
if (file == null ) return callback(" DEVINS_ERROR: Failed to create scratch file" )
527
526
528
527
val psiFile = runReadAction { PsiManager .getInstance(project).findFile(file)!! }
529
528
530
- RunService .provider(project, file)
531
- ?.runFile(project, file, psiFile, isFromToolAction = true )
532
- ? : RunService .runInCli(project, psiFile)
533
- ? : AutoDevNotifications .notify(project, " No run service found for ${file.name} " )
529
+ runWriteAction {
530
+ RunService .provider(project, file)
531
+ ?.runFileAsync(project, file, psiFile)
532
+ ? : AutoDevNotifications .notify(project, " No run service found for ${file.name} " )
533
+ }
534
534
} catch (e: Exception ) {
535
535
callback(" DEVINS_ERROR: ${e.message} " )
536
+ } finally {
537
+ file?.delete(project)
536
538
}
537
539
}
538
540
0 commit comments