Skip to content

Commit 597ccf5

Browse files
committed
feat(core): add option to enable auto run terminal commands #335
- Add enableAutoRunTerminal checkbox to AutoDevCoderConfigurable - Add enableAutoRunTerminal property to AutoDevCoderSettingService- Add translation for new setting in AutoDevBundle properties - Implement auto run terminal functionality in TerminalSketchProvider
1 parent bdc272e commit 597ccf5

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

core/src/main/kotlin/cc/unitmesh/devti/settings/coder/AutoDevCoderConfigurable.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class AutoDevCoderConfigurable(private val project: Project) : BoundConfigurable
3030
private val teamPromptsField = JTextField()
3131
private val trimCodeBeforeSend = JCheckBox()
3232
private val enableAutoRepairDiff = JCheckBox()
33+
private val enableAutoRunTerminal = JCheckBox()
3334

3435

3536
val settings = project.service<AutoDevCoderSettingService>()
@@ -126,6 +127,15 @@ class AutoDevCoderConfigurable(private val project: Project) : BoundConfigurable
126127
)
127128
}
128129

130+
row(jLabel("settings.autodev.coder.enableAutoRunTerminal")) {
131+
fullWidthCell(enableAutoRunTerminal)
132+
.bind(
133+
componentGet = { it.isSelected },
134+
componentSet = { component, value -> component.isSelected = value },
135+
prop = state::enableAutoRunTerminal.toMutableProperty()
136+
)
137+
}
138+
129139
row(jLabel("settings.external.team.prompts.path")) {
130140
fullWidthCell(teamPromptsField)
131141
.bind(
@@ -147,6 +157,7 @@ class AutoDevCoderConfigurable(private val project: Project) : BoundConfigurable
147157
it.enableExportAsMcpServer = state.enableExportAsMcpServer
148158
it.enableObserver = state.enableObserver
149159
it.enableAutoRepairDiff = state.enableAutoRepairDiff
160+
it.enableAutoRunTerminal = state.enableAutoRunTerminal
150161
}
151162
}
152163
}

core/src/main/kotlin/cc/unitmesh/devti/settings/coder/AutoDevCoderSettingService.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class AutoDevCoderSettingService(
2929
var noChatHistory by property(false)
3030
var trimCodeBeforeSend by property(false)
3131
var enableRenameSuggestion by property(false)
32+
var enableAutoRunTerminal by property(false)
3233
var teamPromptsDir by property("prompts") { it.isEmpty() }
3334

3435
override fun copy(): AutoDevCoderSettings {

core/src/main/resources/messages/AutoDevBundle_en.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ prompts.autodev.generateReleaseNote= generate release note
129129
prompts.autodev.generateTestData=Generate API test request (with `http request` code block) based on given {0} code and request/response info. So that we can use it to test for APIs.
130130
settings.autodev.coder.enableRenameSuggestion=Enable Rename suggestion
131131
settings.autodev.coder.enableAutoRepairDiff=Enable auto repair diff
132+
settings.autodev.coder.enableAutoRunTerminal=Enable auto run terminal
132133
shell.command.suggestion.action.default.text=How to check out a branch?
133134
batch.nothing.to.testing=Nothing to AutoTest
134135
intentions.chat.code.test.verify=Verify test

core/src/main/resources/messages/AutoDevBundle_zh.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ prompts.autodev.generateReleaseNote=生成发布说明
129129
prompts.autodev.generateTestData=基于给定的 {0} 代码和请求/响应信息生成 API 测试请求(使用 markdown 代码块)。这样我们就可以用它来测试 API
130130
settings.autodev.coder.enableRenameSuggestion=启用重命名建议
131131
settings.autodev.coder.enableAutoRepairDiff=启用自动修复 diff
132+
settings.autodev.coder.enableAutoRunTerminal=启用自动运行终端(有风险)
132133
shell.command.suggestion.action.default.text=如何创建一个新的分支?
133134
batch.nothing.to.testing=没有要 AutoTest 的内容
134135
intentions.chat.code.test.verify=验证测试中

exts/ext-terminal/src/main/kotlin/cc/unitmesh/terminal/sketch/TerminalSketchProvider.kt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cc.unitmesh.terminal.sketch
33
import cc.unitmesh.devti.AutoDevBundle
44
import cc.unitmesh.devti.AutoDevIcons
55
import cc.unitmesh.devti.AutoDevNotifications
6+
import cc.unitmesh.devti.settings.coder.coderSetting
67
import cc.unitmesh.devti.sketch.SketchToolWindow
78
import cc.unitmesh.devti.sketch.run.ProcessExecutor
89
import cc.unitmesh.devti.sketch.run.UIUpdatingWriter
@@ -17,6 +18,7 @@ import com.intellij.openapi.actionSystem.ActionManager
1718
import com.intellij.openapi.actionSystem.AnAction
1819
import com.intellij.openapi.actionSystem.AnActionEvent
1920
import com.intellij.openapi.actionSystem.DefaultActionGroup
21+
import com.intellij.openapi.actionSystem.DataContext
2022
import com.intellij.openapi.application.ApplicationManager
2123
import com.intellij.openapi.fileEditor.FileEditorManager
2224
import com.intellij.openapi.project.Project
@@ -52,6 +54,8 @@ class TerminalSketchProvider : LanguageSketchProvider {
5254

5355

5456
class TerminalLangSketch(val project: Project, var content: String) : ExtensionLangSketch {
57+
val enableAutoRunTerminal = project.coderSetting.state.enableAutoRunTerminal
58+
5559
var terminalWidget: JBTerminalWidget? = null
5660
var mainPanel: JPanel? = null
5761
val actionGroup = DefaultActionGroup(createConsoleActions())
@@ -68,7 +72,6 @@ class TerminalLangSketch(val project: Project, var content: String) : ExtensionL
6872
add(codeSketch.getComponent(), BorderLayout.CENTER)
6973
}
7074

71-
// Add result display component
7275
val resultSketch = CodeHighlightSketch(project, "", CodeFence.findLanguage("bash"))
7376
val resultPanel = JPanel(BorderLayout()).apply {
7477
add(resultSketch.getComponent(), BorderLayout.CENTER)
@@ -88,12 +91,14 @@ class TerminalLangSketch(val project: Project, var content: String) : ExtensionL
8891
it.border = JBUI.Borders.customLine(UIUtil.getBoundsColor(), 1, 1, 1, 1)
8992
}
9093

94+
private lateinit var executeAction: TerminalExecuteAction
95+
9196
init {
9297
val projectDir = project.guessProjectDir()?.path
9398
val terminalRunner = LocalTerminalDirectRunner.createTerminalRunner(project)
9499

95100
terminalWidget = terminalRunner.createTerminalWidget(this, projectDir, true).also {
96-
it.preferredSize = Dimension(it.preferredSize.width, 120)
101+
it.preferredSize = Dimension(it.preferredSize.width, 80)
97102
}
98103

99104
codeSketch.getComponent().border = JBUI.Borders.empty()
@@ -113,7 +118,7 @@ class TerminalLangSketch(val project: Project, var content: String) : ExtensionL
113118
}
114119

115120
fun createConsoleActions(): List<AnAction> {
116-
val executeAction = TerminalExecuteAction()
121+
executeAction = TerminalExecuteAction()
117122

118123
val copyAction = object :
119124
AnAction("Copy", AutoDevBundle.message("sketch.terminal.copy.text"), AllIcons.Actions.Copy) {
@@ -203,8 +208,20 @@ class TerminalLangSketch(val project: Project, var content: String) : ExtensionL
203208

204209
override fun onDoneStream(allText: String) {
205210
if (content.lines().size > 1) return
211+
206212
ApplicationManager.getApplication().invokeLater {
207213
terminalWidget!!.terminalStarter?.sendString(content, false)
214+
215+
if (enableAutoRunTerminal && ::executeAction.isInitialized) {
216+
executeAction.actionPerformed(
217+
AnActionEvent.createFromAnAction(
218+
executeAction,
219+
null,
220+
"AutoExecuteTerminal",
221+
DataContext.EMPTY_CONTEXT
222+
)
223+
)
224+
}
208225
}
209226
}
210227

0 commit comments

Comments
 (0)