Skip to content

Commit 5139f8d

Browse files
committed
refactor(terminal): optimize terminal execution actions and UI updates for compatibility issue
- Remove redundant comments and code - Use async action updates instead of immediate updates - Simplify toolbar action updates - Improve error handling in terminal execution - Optimize auto execute action invocation - Fix type resolution in ReactPsiUtil
1 parent 78e5bf1 commit 5139f8d

File tree

3 files changed

+11
-23
lines changed

3 files changed

+11
-23
lines changed

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

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,24 @@ class TerminalExecuteAction(
3535

3636
override fun actionPerformed(e: AnActionEvent) {
3737
if (sketch.isExecuting) {
38-
// 如果正在执行,则停止执行
3938
sketch.currentExecutionJob?.cancel()
4039

4140
ApplicationManager.getApplication().invokeLater {
4241
sketch.isExecuting = false
4342
sketch.titleLabel.icon = null
4443

45-
// 更新UI以反映停止状态
4644
sketch.resultSketch.updateViewText(sketch.lastExecutionResults + "\n\n[执行已手动停止]", true)
4745
sketch.setResultStatus(TerminalExecutionState.TERMINATED)
4846

49-
// 更新工具栏
50-
sketch.actionGroup.update(e)
51-
sketch.toolbar.updateActionsImmediately()
47+
sketch.toolbar.updateActionsAsync()
5248
}
5349
return
5450
}
5551

56-
// 开始执行
5752
sketch.isExecuting = true
5853
sketch.titleLabel.icon = AllIcons.RunConfigurations.TestState.Run
5954

60-
// 更新工具栏以显示停止按钮
61-
sketch.actionGroup.update(e)
62-
sketch.toolbar.updateActionsImmediately()
55+
sketch.toolbar.updateActionsAsync()
6356

6457
sketch.hasExecutionResults = false
6558
sketch.lastExecutionResults = ""
@@ -102,9 +95,7 @@ class TerminalExecuteAction(
10295
sketch.titleLabel.icon = null
10396
sketch.isExecuting = false
10497

105-
// 更新工具栏以显示执行按钮
106-
sketch.actionGroup.update(e)
107-
sketch.toolbar.updateActionsImmediately()
98+
sketch.toolbar.updateActionsAsync()
10899

109100
val success = exitCode == 0
110101
sketch.setResultStatus(
@@ -116,13 +107,11 @@ class TerminalExecuteAction(
116107
AutoDevNotifications.notify(sketch.project, "执行命令时出错: ${ex.message}")
117108
ApplicationManager.getApplication().invokeLater {
118109
stdWriter.setExecuting(false)
119-
// 清除运行图标
110+
120111
sketch.titleLabel.icon = null
121112
sketch.isExecuting = false
122113

123-
// 更新工具栏以显示执行按钮
124-
sketch.actionGroup.update(e)
125-
sketch.toolbar.updateActionsImmediately()
114+
sketch.toolbar.updateActionsAsync()
126115

127116
sketch.resultSketch.updateViewText("${stdWriter.getContent()}\n错误: ${ex.message}", true)
128117
sketch.setResultStatus(TerminalExecutionState.FAILED, ex.message)

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cc.unitmesh.terminal.sketch
22

33
import cc.unitmesh.devti.AutoDevBundle
4+
import cc.unitmesh.devti.AutoDevColors
45
import cc.unitmesh.devti.AutoDevIcons
56
import cc.unitmesh.devti.AutoDevNotifications
67
import cc.unitmesh.devti.settings.coder.coderSetting
@@ -17,7 +18,8 @@ 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
20-
import com.intellij.openapi.actionSystem.DataContext
21+
import com.intellij.openapi.actionSystem.ex.ActionUtil
22+
import com.intellij.openapi.actionSystem.impl.SimpleDataContext
2123
import com.intellij.openapi.application.ApplicationManager
2224
import com.intellij.openapi.fileEditor.FileEditorManager
2325
import com.intellij.openapi.project.Project
@@ -31,6 +33,7 @@ import com.intellij.ui.components.panels.VerticalLayout
3133
import com.intellij.ui.components.panels.Wrapper
3234
import com.intellij.util.ui.JBUI
3335
import com.intellij.util.ui.UIUtil
36+
import kotlinx.coroutines.Job
3437
import java.awt.BorderLayout
3538
import java.awt.Dimension
3639
import java.awt.Toolkit
@@ -41,8 +44,6 @@ import javax.swing.JComponent
4144
import javax.swing.JLabel
4245
import javax.swing.JPanel
4346
import javax.swing.border.LineBorder
44-
import cc.unitmesh.devti.AutoDevColors
45-
import kotlinx.coroutines.Job
4647

4748
class TerminalSketchProvider : LanguageSketchProvider {
4849
override fun isSupported(lang: String): Boolean = lang == "bash" || lang == "shell"
@@ -321,9 +322,7 @@ class TerminalLangSketch(val project: Project, var content: String) : ExtensionL
321322
return@invokeLater
322323
}
323324

324-
val action =
325-
AnActionEvent.createFromAnAction(executeAction, null, "AutoExecuteTerminal", DataContext.EMPTY_CONTEXT)
326-
executeAction.actionPerformed(action)
325+
ActionUtil.invokeAction(executeAction, SimpleDataContext.getProjectContext(project), "AutoExecuteTerminal", null , null)
327326
}
328327
}
329328

javascript/src/main/kotlin/cc/unitmesh/ide/javascript/util/ReactPsiUtil.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ object ReactPsiUtil {
6666
val typeElement = parameter.typeElement ?: return@mapNotNull null
6767
when (typeElement) {
6868
is TypeScriptSingleType -> {
69-
val resolve = typeElement.referenceExpression?.resolve()
69+
val resolve = typeElement.reference?.resolve()
7070
resolve?.text
7171
}
7272

0 commit comments

Comments
 (0)