Skip to content

Commit 2397a38

Browse files
committed
refactor(devti): improve diff request handling for AI suggestions
- Use EmptyContent for the 'before' content in SimpleDiffRequest - Remove redundant getOrCreateDirectory call - Update diff request title and labels for better clarity
1 parent 9250f8b commit 2397a38

File tree

5 files changed

+13
-17
lines changed

5 files changed

+13
-17
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,15 +382,15 @@ open class SketchToolWindow(
382382
else -> null
383383
} ?: return@map null
384384

385-
panel.border = JBEmptyBorder(4)
385+
panel.border = JBEmptyBorder(0, 4, 0, 4)
386386
panel
387387
}.filterNotNull()
388388

389389
if (panels.isEmpty()) return null
390390

391391
val blockedPanel = JPanel(VerticalLayout(JBUI.scale(0))).apply {
392392
this.isOpaque = true
393-
this.border = JBEmptyBorder(4)
393+
this.border = JBEmptyBorder(0, 4, 0, 4)
394394
panels.forEach { this.add(it) }
395395
}
396396

core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/code/CodeHighlightSketch.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ open class CodeHighlightSketch(
4444
val fileName: String? = null,
4545
val withLeftRightBorder: Boolean = true,
4646
val showToolbar: Boolean = true
47-
) : JBPanel<CodeHighlightSketch>(VerticalLayout(4)), DataProvider, LangSketch, Disposable {
47+
) : JBPanel<CodeHighlightSketch>(VerticalLayout(2)), DataProvider, LangSketch, Disposable {
4848
private val devinLineThreshold = 10
4949
private val minDevinLineThreshold = 1
5050
private var isDevIns = false
@@ -74,9 +74,9 @@ open class CodeHighlightSketch(
7474
val editor = EditorUtil.createCodeViewerEditor(project, text, ideaLanguage, fileName, this)
7575

7676
border = if (withLeftRightBorder) {
77-
JBEmptyBorder(8, 8, 8, 8)
77+
JBEmptyBorder(4, 4, 4, 4)
7878
} else {
79-
JBEmptyBorder(8, 0, 0, 0)
79+
JBEmptyBorder(4, 0, 0, 0)
8080
}
8181

8282
editor.component.isOpaque = true

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import javax.swing.JComponent
3636
import javax.swing.JPanel
3737

3838
class DiffLangSketch(private val myProject: Project, private var patchContent: String) : ExtensionLangSketch {
39-
private val mainPanel: JPanel = JPanel(VerticalLayout(5))
39+
private val mainPanel: JPanel = JPanel(VerticalLayout(2))
4040
private val myHeaderPanel: JPanel = JPanel(BorderLayout())
4141
private val shelfExecutor = ApplyPatchDefaultExecutor(myProject)
4242
private val myReader: PatchReader? = PatchReader(patchContent).also {
@@ -61,7 +61,7 @@ class DiffLangSketch(private val myProject: Project, private var patchContent: S
6161
mainPanel.add(myHeaderPanel)
6262
}
6363

64-
mainPanel.border = JBUI.Borders.compound(JBUI.Borders.empty(0, 10))
64+
mainPanel.border = JBUI.Borders.compound(JBUI.Borders.empty(0, 4))
6565

6666
ApplicationManager.getApplication().invokeLater {
6767
if (filePatches.isEmpty()) {
@@ -92,17 +92,13 @@ class DiffLangSketch(private val myProject: Project, private var patchContent: S
9292
return@invokeLater
9393
}
9494

95-
// try {
9695
filePatches.forEach { patch ->
9796
val diffPanel = createDiffPanel(patch)
9897
if (diffPanel != null) {
9998
mainPanel.add(diffPanel.getComponent())
10099
mainPanel.revalidate()
101100
}
102101
}
103-
// } catch (e: Exception) {
104-
// AutoDevNotifications.error(myProject, "Failed to create diff panel: ${e.message}")
105-
// }
106102
}
107103
}
108104

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class SingleFileDiffSketch(
101101

102102
val filepathLabel = JBLabel(fileName).apply {
103103
icon = currentFile.fileType.icon
104-
border = BorderFactory.createEmptyBorder(2, 10, 2, 10)
104+
border = BorderFactory.createEmptyBorder(2, 4, 2, 4)
105105

106106
val originalColor = foreground
107107
val hoverColor = AutoDevColors.FILE_HOVER_COLOR // Extracted from inline JBColor definition
@@ -116,14 +116,14 @@ class SingleFileDiffSketch(
116116
cursor = java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.HAND_CURSOR)
117117
border = BorderFactory.createCompoundBorder(
118118
BorderFactory.createMatteBorder(0, 0, 1, 0, hoverColor),
119-
BorderFactory.createEmptyBorder(2, 10, 1, 10)
119+
BorderFactory.createEmptyBorder(2, 4, 1, 4)
120120
)
121121
}
122122

123123
override fun mouseExited(e: MouseEvent?) {
124124
foreground = originalColor
125125
cursor = java.awt.Cursor.getDefaultCursor()
126-
border = BorderFactory.createEmptyBorder(2, 10, 2, 10)
126+
border = BorderFactory.createEmptyBorder(2, 4, 2, 4)
127127
}
128128
})
129129
}
@@ -163,7 +163,7 @@ class SingleFileDiffSketch(
163163
patchActionPanel = JPanel(BorderLayout()).apply {
164164
add(filePanel, BorderLayout.WEST)
165165
add(actionPanel, BorderLayout.EAST)
166-
border = BorderFactory.createEmptyBorder(5, 5, 5, 5)
166+
border = BorderFactory.createEmptyBorder(4, 4, 4, 4)
167167
}
168168

169169
val fileContainer = JPanel(BorderLayout(10, 10)).also {

core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/plan/PlanLangSketch.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class PlanLangSketch(
2121
private var content: String,
2222
private var agentTaskItems: MutableList<AgentTaskEntry>,
2323
private val isInToolwindow: Boolean = false
24-
) : JBPanel<PlanLangSketch>(BorderLayout(JBUI.scale(8), 0)), ExtensionLangSketch {
24+
) : JBPanel<PlanLangSketch>(BorderLayout(JBUI.scale(0), 0)), ExtensionLangSketch {
2525
private val contentPanel = JPanel(VerticalLayout(JBUI.scale(0)))
2626
val scrollPane: JBScrollPane
2727
private val toolbarFactory = PlanToolbarFactory(project)
@@ -30,7 +30,7 @@ class PlanLangSketch(
3030
init {
3131
if (!isInToolwindow) {
3232
add(toolbarFactory.createToolbar(this), BorderLayout.NORTH)
33-
border = JBUI.Borders.empty(8)
33+
border = JBUI.Borders.empty(4)
3434
}
3535

3636
renderPlan()

0 commit comments

Comments
 (0)