Skip to content

Commit 53f1c25

Browse files
committed
feat(diff): improve diff viewer layout and auto-command handling #352
- Wrap diff viewer in panel with controlled height (25% of parent) - Refactor auto-commands into dynamic builder function - Remove unused imports and simplify code structure The changes improve UI consistency and make command handling more flexible.
1 parent 3a8606e commit 53f1c25

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand.*
55
import cc.unitmesh.devti.observer.agent.AgentStateService
66
import cc.unitmesh.devti.provider.devins.LanguageProcessor
77
import cc.unitmesh.devti.provider.toolchain.ToolchainFunctionProvider
8+
import cc.unitmesh.devti.settings.coder.coderSetting
89
import cc.unitmesh.devti.util.parser.CodeFence
910
import com.intellij.openapi.application.ApplicationManager
10-
import com.intellij.openapi.application.invokeLater
1111
import com.intellij.openapi.application.runReadAction
1212
import com.intellij.openapi.components.Service
1313
import com.intellij.openapi.components.service
1414
import com.intellij.openapi.diagnostic.logger
1515
import com.intellij.openapi.project.Project
1616
import com.intellij.psi.PsiFileFactory
17-
import kotlinx.coroutines.runBlocking
1817

1918
@Service(Service.Level.PROJECT)
2019
class AutoSketchMode(val project: Project) {
@@ -37,7 +36,7 @@ class AutoSketchMode(val project: Project) {
3736

3837
val language = CodeFence.findLanguage("DevIn")
3938
commands += devinCodeFence.mapNotNull {
40-
val psiFile = runReadAction { PsiFileFactory.getInstance(project).createFileFromText(language, it.text) }
39+
val psiFile = runReadAction { PsiFileFactory.getInstance(project).createFileFromText(language, it.text) }
4140
?: return@mapNotNull null
4241

4342
LanguageProcessor.devin()?.transpileCommand(project, psiFile) ?: emptyList()
@@ -71,27 +70,31 @@ class AutoSketchMode(val project: Project) {
7170
listener?.manualSend(text)
7271
}
7372

74-
private fun hasReadCommand(fence: CodeFence): Boolean = AUTOABLE_COMMANDS.any { command ->
73+
private fun hasReadCommand(fence: CodeFence): Boolean = buildAutoCommands().any { command ->
7574
fence.text.contains("/" + command.commandName + ":")
7675
}
7776

78-
val AUTOABLE_COMMANDS =
79-
setOf(
77+
private fun buildAutoCommands(): Set<BuiltinCommand> {
78+
val of = mutableSetOf(
8079
DIR,
8180
LOCAL_SEARCH,
8281
FILE,
8382
REV,
8483
STRUCTURE,
8584
SYMBOL,
86-
DATABASE, // should be handle in run sql
8785
RELATED,
8886
RIPGREP_SEARCH,
8987
RULE,
9088
BROWSE,
91-
PATCH,
92-
WRITE
9389
)
9490

91+
of += setOf(
92+
PATCH, DATABASE, WRITE
93+
)
94+
95+
return of
96+
}
97+
9598
private suspend fun hasToolchainFunctionCommand(fence: CodeFence): Boolean {
9699
val toolchainCmds = ToolchainFunctionProvider.all().map { it.funcNames() }.flatten()
97100
return toolchainCmds.any {

core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/patch/SingleFileDiffSketch.kt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,24 @@ class SingleFileDiffSketch(
180180
override fun requestFocusInWindow() = Unit
181181
}, diffRequest)
182182
diffViewer.init()
183-
return diffViewer.component
183+
184+
val wrapperPanel = JPanel(BorderLayout())
185+
wrapperPanel.add(diffViewer.component, BorderLayout.CENTER)
186+
187+
// Set preferred height to 25% of parent (will be determined when laid out)
188+
// with a minimum of 200 pixels
189+
wrapperPanel.preferredSize = java.awt.Dimension(
190+
wrapperPanel.preferredSize.width,
191+
maxOf(200, (mainPanel.height * 0.25).toInt())
192+
)
193+
194+
// Set maximum height to prevent excessive growth
195+
wrapperPanel.maximumSize = java.awt.Dimension(
196+
Int.MAX_VALUE,
197+
maxOf(200, (mainPanel.height * 0.25).toInt())
198+
)
199+
200+
return wrapperPanel
184201
}
185202

186203
private fun createActionButtons(
@@ -381,3 +398,4 @@ fun saveText(file: VirtualFile, text: String) {
381398
}
382399
}
383400
}
401+

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ settings.autodev.coder.enableAutoRunTerminal=Enable auto run terminal
133133
settings.autodev.coder.enableAutoLintCode=Enable auto lint patch code
134134
settings.autodev.coder.enableRenderWebview=Enable render chat in WebView
135135
settings.autodev.coder.enableAutoScrollInSketch=Enable AutoScroll in Sketch
136+
settings.autodev.coder.enableDiffViewer=Enable Diff Viewer in Sketch
136137
shell.command.suggestion.action.default.text=How to check out a branch?
137138
batch.nothing.to.testing=Nothing to AutoTest
138139
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
@@ -125,6 +125,7 @@ settings.autodev.coder.enableAutoRunTerminal=启用自动运行终端(有风
125125
settings.autodev.coder.enableAutoLintCode=启用自动修复 Lint 代码
126126
settings.autodev.coder.enableRenderWebview=在聊天页面中启用渲染 WebView
127127
settings.autodev.coder.enableAutoScrollInSketch=在 Sketch 中启用自动滚动
128+
settings.autodev.coder.enableDiffViewer=在 Sketch 中启用 Diff 视图
128129
shell.command.suggestion.action.default.text=如何创建一个新的分支?
129130
batch.nothing.to.testing=没有要 AutoTest 的内容
130131
intentions.chat.code.test.verify=验证测试中

0 commit comments

Comments
 (0)