Skip to content

Commit 46b4c10

Browse files
committed
feat(processors): refactor ThreadProcessor to use suspend functions and improve shell command execution #379
1 parent b15489c commit 46b4c10

File tree

4 files changed

+8
-21
lines changed

4 files changed

+8
-21
lines changed

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/ast/action/PatternFuncProcessor.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import cc.unitmesh.devti.language.processor.CaptureProcessor
2323
import cc.unitmesh.devti.language.processor.ForeignFunctionProcessor
2424
import cc.unitmesh.devti.util.findFile
2525
import cc.unitmesh.devti.util.readText
26+
import com.intellij.execution.ui.ConsoleViewContentType
2627
import kotlinx.coroutines.CoroutineScope
2728
import kotlinx.coroutines.launch
2829
import java.io.File

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/processor/ThreadProcessor.kt

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import cc.unitmesh.devti.language.actions.DevInsRunFileAction
44
import cc.unitmesh.devti.language.ast.action.PatternActionFuncDef
55
import cc.unitmesh.devti.language.ast.action.PatternProcessor
66
import cc.unitmesh.devti.language.compiler.error.DEVINS_ERROR
7+
import cc.unitmesh.devti.language.processor.shell.ShireShellCommandRunner
78
import cc.unitmesh.devti.language.provider.http.HttpHandler
89
import cc.unitmesh.devti.language.provider.http.HttpHandlerType
910
import cc.unitmesh.devti.language.psi.DevInFile
@@ -17,14 +18,12 @@ import com.intellij.psi.PsiFile
1718
import com.intellij.psi.PsiManager
1819
import com.intellij.sh.psi.ShFile
1920
import com.intellij.sh.run.ShRunner
20-
import cc.unitmesh.devti.language.processor.shell.ShireShellCommandRunner
21-
import java.util.concurrent.CompletableFuture
2221

2322

2423
object ThreadProcessor : PatternProcessor {
2524
override val type: PatternActionFuncDef = PatternActionFuncDef.THREAD
2625

27-
fun execute(
26+
suspend fun execute(
2827
myProject: Project, fileName: String, variablesName: Array<String>, variableTable: MutableMap<String, Any?>,
2928
): String {
3029
val file = myProject.lookupFile(fileName) ?: return "File not found: $fileName"
@@ -46,6 +45,7 @@ object ThreadProcessor : PatternProcessor {
4645
PsiManager.getInstance(myProject).findFile(file)
4746
} ?: return "Failed to find PSI file for $fileName"
4847

48+
// console.print("Prepare for running ${configuration.name}...\n", ConsoleViewContentType.NORMAL_OUTPUT)
4949
when (psiFile) {
5050
is DevInFile -> {
5151
return when (val output = variableTable["output"]) {
@@ -93,24 +93,11 @@ object ThreadProcessor : PatternProcessor {
9393
}
9494
}
9595

96-
private fun executeShFile(psiFile: ShFile, myProject: Project, processVariables: Map<String, String>): String {
96+
suspend fun executeShFile(psiFile: ShFile, myProject: Project, processVariables: Map<String, String>): String {
9797
val virtualFile = psiFile.virtualFile
98-
val shRunner = ApplicationManager.getApplication().getService(ShRunner::class.java)
99-
?: return "$DEVINS_ERROR: Shell runner not found"
100-
101-
val future = CompletableFuture<String>()
102-
ApplicationManager.getApplication().invokeLater {
103-
if (shRunner.isAvailable(myProject)) {
104-
try {
105-
val output = ShireShellCommandRunner.runShellCommand(virtualFile, myProject, processVariables)
106-
future.complete(output)
107-
} catch (t: Throwable) {
108-
future.completeExceptionally(t)
109-
}
110-
}
111-
}
98+
ApplicationManager.getApplication().getService(ShRunner::class.java) ?: return "$DEVINS_ERROR: Shell runner not found"
11299

113-
return future.get()
100+
return ShireShellCommandRunner.runShellCommand(virtualFile, myProject, processVariables)
114101
}
115102

116103
private fun executeTask(

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/run/runner/ShireConsoleView.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import java.awt.BorderLayout
2020
import javax.swing.JComponent
2121

2222
class ShireConsoleView(private val executionConsole: ShireExecutionConsole) : DevInConsoleViewBase(executionConsole) {
23-
2423
override fun getComponent(): JComponent = myPanel
2524

2625
private var myPanel: NonOpaquePanel = NonOpaquePanel(BorderLayout())

exts/devins-lang/src/main/resources/cc.unitmesh.devti.language.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198

199199
<!-- Shire Context Action Group -->
200200
<group id="ShireContextActionGroup"
201-
popup="true" text="Shire Action" description="Shire context action group"
201+
popup="true" text="AutoDev DevIns Action" description="AutoDev DevIns context action group"
202202
class="cc.unitmesh.devti.language.actions.context.ShireContextMenuActionGroup"
203203
icon="cc.unitmesh.devti.AutoDevIcons.AI_COPILOT" searchable="false">
204204

0 commit comments

Comments
 (0)