1
1
package cc.unitmesh.devti.sketch
2
2
3
3
import cc.unitmesh.devti.alignRight
4
+ import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand
4
5
import cc.unitmesh.devti.gui.chat.ChatCodingService
5
6
import cc.unitmesh.devti.gui.chat.message.ChatActionType
6
7
import cc.unitmesh.devti.gui.chat.ui.AutoDevInputSection
@@ -17,6 +18,7 @@ import com.intellij.icons.AllIcons
17
18
import com.intellij.ide.scratch.ScratchRootType
18
19
import com.intellij.openapi.Disposable
19
20
import com.intellij.openapi.application.runInEdt
21
+ import com.intellij.openapi.application.runReadAction
20
22
import com.intellij.openapi.editor.Editor
21
23
import com.intellij.openapi.fileTypes.PlainTextLanguage
22
24
import com.intellij.openapi.project.Project
@@ -78,7 +80,9 @@ class SketchToolWindow(val project: Project, val editor: Editor?, private val sh
78
80
if (showInput) {
79
81
row {
80
82
checkBox(" AI 降临模式(全自动化)" ).apply {
81
- AutoSketchMode .getInstance(project).isEnable = this .component.isSelected
83
+ this .component.addActionListener {
84
+ AutoSketchMode .getInstance(project).isEnable = this .component.isSelected
85
+ }
82
86
}
83
87
}
84
88
}
@@ -99,6 +103,8 @@ class SketchToolWindow(val project: Project, val editor: Editor?, private val sh
99
103
100
104
var handleCancel: ((String ) -> Unit )? = null
101
105
106
+ private val listener = SketchInputListener (project, chatCodingService, this )
107
+
102
108
init {
103
109
contentPanel.add(scrollPanel, BorderLayout .CENTER )
104
110
contentPanel.addKeyListener(object : KeyAdapter () {
@@ -118,7 +124,7 @@ class SketchToolWindow(val project: Project, val editor: Editor?, private val sh
118
124
border = JBUI .Borders .empty(8 )
119
125
}
120
126
121
- shireInput.addListener(SketchInputListener (project, chatCodingService, this ) )
127
+ shireInput.addListener(listener )
122
128
contentPanel.add(shireInput, BorderLayout .SOUTH )
123
129
}
124
130
@@ -252,12 +258,25 @@ class SketchToolWindow(val project: Project, val editor: Editor?, private val sh
252
258
val devinCodeFence = codeFenceList.filter { it.language.displayName == " DevIn" }
253
259
254
260
devinCodeFence.forEach {
261
+ val commands = setOf (
262
+ BuiltinCommand .DIR ,
263
+ BuiltinCommand .LOCAL_SEARCH ,
264
+ BuiltinCommand .REV ,
265
+ BuiltinCommand .STRUCTURE ,
266
+ BuiltinCommand .SYMBOL ,
267
+ BuiltinCommand .DATABASE
268
+ )
269
+ if (commands.any { command -> it.text.contains(" /" + command.commandName + " :" ) }) {
270
+ return listener.manualSend(it.text)
271
+ }
272
+
255
273
val scratchFile = ScratchRootType .getInstance()
256
274
.createScratchFile(project, " sketch.shire" , it.language, it.text)
257
275
? : return
258
276
259
- val psiFile = PsiManager .getInstance(project).findFile(scratchFile)
260
- ? : return
277
+ val psiFile = runReadAction {
278
+ PsiManager .getInstance(project).findFile(scratchFile)
279
+ } ? : return
261
280
262
281
RunService .provider(project, scratchFile)
263
282
?.runFile(project, scratchFile, psiFile, isFromToolAction = true )
0 commit comments