Skip to content

Commit 4cf2fe6

Browse files
committed
feat(sketch): add send functionality and enableInSketch flag
- Add `send()` method to `AutoDevInputSection` and call it in `SketchToolWindow`. - Introduce `enableInSketch` flag to control command availability in sketch. - Refactor terminal UI layout and simplify terminal output handling.
1 parent c352e9a commit 4cf2fe6

File tree

6 files changed

+51
-17
lines changed

6 files changed

+51
-17
lines changed

core/src/main/kotlin/cc/unitmesh/devti/devin/dataprovider/BuiltinCommand.kt

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,18 @@ enum class BuiltinCommand(
1111
val icon: Icon,
1212
val hasCompletion: Boolean = false,
1313
val requireProps: Boolean = false,
14+
val enableInSketch: Boolean = true
1415
) {
1516
FILE("file", "Read the content of a file by project relative path", AllIcons.Actions.Copy, true, true),
16-
REV("rev", "Read git changes by sha hash; For other git operations, it is recommended to use native git commands", AllIcons.Vcs.History, true, true),
17+
REV(
18+
"rev",
19+
"Read git changes by sha hash; For other git operations, it is recommended to use native git commands",
20+
AllIcons.Vcs.History,
21+
true,
22+
true,
23+
enableInSketch = false
24+
),
25+
1726
/**
1827
* Every language will have a symbol completion, which is the most basic completion, for example,
1928
* - Java: [com.intellij.codeInsight.completion.JavaKeywordCompletion]
@@ -27,20 +36,44 @@ enum class BuiltinCommand(
2736
true,
2837
true
2938
),
30-
WRITE("write", "Write content to a file with markdown code block, /write:path/to/file:L1-L2", AllIcons.Actions.Edit, true, true),
31-
PATCH("patch", "Apply GNU unified diff format structure patch to a file, /patch:path/to/file", AllIcons.Vcs.Patch_file, false),
39+
WRITE(
40+
"write",
41+
"Write content to a file with markdown code block, /write:path/to/file:L1-L2",
42+
AllIcons.Actions.Edit,
43+
true,
44+
true
45+
),
46+
PATCH(
47+
"patch",
48+
"Apply GNU unified diff format structure patch to a file, /patch:path/to/file",
49+
AllIcons.Vcs.Patch_file,
50+
false
51+
),
3252
RUN("run", "Run the IDE's built-in command, like build tool, test.", AllIcons.Actions.Execute, true, true),
33-
SHELL("shell", "Execute a shell command and collect (ProcessBuild) the result", AllIcons.Debugger.Console, true, true),
53+
SHELL(
54+
"shell",
55+
"Execute a shell command and collect (ProcessBuild) the result",
56+
AllIcons.Debugger.Console,
57+
true,
58+
true
59+
),
3460
COMMIT("commit", "Do commit with current workspace with some messages.", AllIcons.Vcs.CommitNode, false),
3561
FILE_FUNC(
3662
"file-func",
3763
"Read the name of a file, support for: " + FileFunc.values().joinToString(",") { it.funcName },
3864
AllIcons.Actions.GroupByFile,
3965
true,
40-
true
66+
true,
67+
enableInSketch = false,
4168
),
4269
BROWSE("browse", "Fetch the content of a given URL.", AllIcons.Toolwindows.WebToolWindow, false, true),
43-
REFACTOR("refactor", "Refactor the content of a file, only support for rename, safeDelete and move.", AutoDevIcons.Idea, true, true),
70+
REFACTOR(
71+
"refactor",
72+
"Refactor the content of a file, only support for rename, safeDelete and move.",
73+
AutoDevIcons.Idea,
74+
true,
75+
true
76+
),
4477
STRUCTURE(
4578
"structure",
4679
"Get the structure of a file with AST/PSI",

core/src/main/kotlin/cc/unitmesh/devti/gui/chat/ui/AutoDevInputSection.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,10 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
285285
IdeTooltipManager.getInstance().show(tooltip, true)
286286
}
287287

288+
fun send() {
289+
editorListeners.multicaster.onSubmit(this, AutoDevInputTrigger.Button)
290+
}
291+
288292
fun showSendButton() {
289293
(buttonPanel.layout as? CardLayout)?.show(buttonPanel, "Send")
290294
buttonPanel.isEnabled = true

core/src/main/kotlin/cc/unitmesh/devti/sketch/SketchToolWindow.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ class SketchToolWindow(val project: Project, val editor: Editor?, private val sh
280280

281281
fun sendInput(text: String) {
282282
shireInput.text += "\n" + text
283+
shireInput.send()
283284
}
284285

285286
private fun scrollToBottom() {

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInsSketchToolchainProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class DevInsSketchToolchainProvider : SketchToolchainProvider {
99
/// we need to ignore some bad case for llm
1010
return BuiltinCommand.all()
1111
.filter {
12-
it != BuiltinCommand.REV
12+
it.enableInSketch
1313
}
1414
.map {
1515
val example = BuiltinCommand.example(it)

exts/devins-lang/src/main/resources/agent/toolExamples/commit.devin

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
Execute git commit with commit message
12
/commit
23
```markdown
34
follow Conventional Commits, like feat: add 'graphiteWidth' option

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import com.intellij.openapi.ui.popup.JBPopupFactory
2323
import com.intellij.openapi.ui.popup.util.MinimizeButton
2424
import com.intellij.openapi.wm.ToolWindowManager
2525
import com.intellij.terminal.JBTerminalWidget
26+
import com.intellij.ui.components.panels.VerticalLayout
2627
import com.intellij.util.ui.JBUI
2728
import org.jetbrains.plugins.terminal.LocalTerminalDirectRunner
2829
import java.awt.BorderLayout
@@ -51,12 +52,6 @@ class TerminalLangSketchProvider : LanguageSketchProvider {
5152
it.preferredSize = Dimension(it.preferredSize.width, 120)
5253
}
5354

54-
val sb = StringBuilder()
55-
terminalWidget?.addMessageFilter { line, _ ->
56-
sb.append(line)
57-
null
58-
}
59-
6055
panelLayout = object : JPanel(BorderLayout()) {
6156
init {
6257
add(JLabel("Terminal").also {
@@ -65,7 +60,7 @@ class TerminalLangSketchProvider : LanguageSketchProvider {
6560

6661
add(terminalWidget!!.component, BorderLayout.CENTER)
6762

68-
val buttonPanel = JPanel(BorderLayout())
63+
val buttonPanel = JPanel(VerticalLayout(JBUI.scale(10)))
6964
val runButton = JButton(AllIcons.Toolwindows.ToolWindowRun)
7065
.apply {
7166
addMouseListener(executeShellScriptOnClick(project, content))
@@ -74,7 +69,7 @@ class TerminalLangSketchProvider : LanguageSketchProvider {
7469
val sendButton = JButton("Send to Sketch").apply {
7570
addMouseListener(object : MouseAdapter() {
7671
override fun mouseClicked(e: MouseEvent?) {
77-
val output = sb.toString()
72+
val output = terminalWidget!!.text
7873
sendToSketch(project, output)
7974
}
8075
})
@@ -84,9 +79,9 @@ class TerminalLangSketchProvider : LanguageSketchProvider {
8479
addMouseListener(executePopup(terminalWidget, project))
8580
}
8681

87-
buttonPanel.add(runButton, BorderLayout.WEST)
82+
buttonPanel.add(runButton)
8883
buttonPanel.add(sendButton)
89-
buttonPanel.add(popupButton, BorderLayout.EAST)
84+
buttonPanel.add(popupButton)
9085
add(buttonPanel, BorderLayout.SOUTH)
9186
}
9287
}

0 commit comments

Comments
 (0)