Skip to content

Commit c46fd9e

Browse files
committed
feat(ui): add AI-assisted commit dialog with diff viewer
Implement enhanced commit UI with visual diff preview, issue selector, and AI-generated commit messages. Add serialization annotations to EditRequest data class and remove redundant comments from CodeHighlightSketch for improved code clarity. Related to #408
1 parent f8ff261 commit c46fd9e

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

core/src/main/kotlin/cc/unitmesh/devti/command/EditFileCommand.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import com.intellij.openapi.project.Project
1212
import com.intellij.openapi.project.guessProjectDir
1313
import com.intellij.openapi.vfs.VirtualFile
1414
import com.intellij.openapi.diff.impl.patch.TextFilePatch
15+
import kotlinx.serialization.SerialName
16+
import kotlinx.serialization.Serializable
1517
import org.yaml.snakeyaml.LoaderOptions
1618
import org.yaml.snakeyaml.Yaml
1719
import org.yaml.snakeyaml.constructor.SafeConstructor
@@ -126,9 +128,13 @@ class EditFileCommand(private val project: Project) {
126128
}
127129
}
128130

131+
@Serializable
129132
data class EditRequest(
133+
@SerialName("target_file")
130134
val targetFile: String,
135+
@SerialName("instructions")
131136
val instructions: String,
137+
@SerialName("code_edit")
132138
val codeEdit: String
133139
)
134140

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ open class CodeHighlightSketch(
6060
private var isDevIns = false
6161
private var collapsedPanel: JPanel? = null
6262
private var previewLabel: JBLabel? = null // 存储预览标签的引用
63-
private var isCollapsed = true // 默认折叠状态
63+
private var isCollapsed = true
6464
private var actionButton: ActionButton? = null
6565
private var isComplete = isUser
6666
private var hasProcessedDevInCommands = false
@@ -115,12 +115,10 @@ open class CodeHighlightSketch(
115115
editorFragment = EditorFragment(editor, editorLineThreshold, previewEditor)
116116
}
117117

118-
// 检查是否需要折叠视图
119118
val needsCollapsedView = shouldUseCollapsedView()
120119
if (needsCollapsedView) {
121120
setupCollapsedView(text)
122121
} else {
123-
// 直接添加编辑器内容,不使用折叠
124122
add(editorFragment!!.getContent())
125123
isCollapsed = false
126124
}
@@ -229,7 +227,6 @@ open class CodeHighlightSketch(
229227
actionButtonPresentation.icon = AllIcons.General.ArrowRight
230228
return ActionButton(
231229
DumbAwareAction.create {
232-
// 普通编辑器的按钮行为,可以根据需要扩展
233230
},
234231
actionButtonPresentation,
235232
"AutoDevToolbar",
@@ -323,7 +320,6 @@ open class CodeHighlightSketch(
323320
override fun updateViewText(text: String, complete: Boolean) {
324321
isComplete = complete
325322

326-
// Initialize editor if not already done and text is not empty
327323
if (!hasSetupAction && text.trim().isNotEmpty()) {
328324
initEditor(text)
329325
}
@@ -339,8 +335,6 @@ open class CodeHighlightSketch(
339335
val normalizedText = StringUtil.convertLineSeparators(text)
340336
try {
341337
document?.replaceString(0, document.textLength, normalizedText)
342-
343-
// Update collapsed panel preview text if applicable
344338
if (previewLabel != null && shouldUseCollapsedView()) {
345339
val firstLine = normalizedText.lines().firstOrNull() ?: ""
346340
previewLabel!!.text = firstLine
@@ -349,22 +343,18 @@ open class CodeHighlightSketch(
349343
logger<CodeHighlightSketch>().error("Error updating editor text", e)
350344
}
351345

352-
// Update action button icon state
353346
updateActionButtonIcon()
354347

355348
val lineCount = document?.lineCount ?: 0
356349
if (lineCount > editorLineThreshold) {
357350
editorFragment?.updateExpandCollapseLabel()
358351
}
359352

360-
// Auto-collapse view when complete (only for collapsible views)
361-
// 注意:现在 shouldUseCollapsedView() 已经考虑了 isUser 和 isDevIns 状态
362353
if (complete && !isCollapsed && shouldUseCollapsedView()) {
363354
toggleEditorVisibility()
364355
}
365356
}
366357

367-
// Process DevIn commands when complete (only once)
368358
if (complete && !isUser && ideaLanguage?.displayName == "DevIn") {
369359
processDevInCommands(text)
370360
hasProcessedDevInCommands = true

0 commit comments

Comments
 (0)