Skip to content

Commit a9d0d7d

Browse files
committed
refactor(diff): remove unused diff-related code and simplify diff handling
- Remove unused imports and commented-out code in `SingleFileDiffView.kt`. - Simplify diff handling by directly calling `viewDiffAction` instead of `showDiff`. - Clean up `DiffStreamHandler.kt` by removing unnecessary code.
1 parent 8e848c6 commit a9d0d7d

File tree

2 files changed

+1
-69
lines changed

2 files changed

+1
-69
lines changed

core/src/main/kotlin/cc/unitmesh/devti/diff/DiffStreamHandler.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ class DiffStreamHandler(
222222
}
223223
}
224224

225-
226225
private fun createDiffBlock(): VerticalDiffBlock {
227226
val diffBlock = VerticalDiffBlock(
228227
editor, project, curLine.index, ::handleDiffBlockAcceptOrReject, ::acceptAll

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

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import cc.unitmesh.devti.sketch.ui.LangSketch
66
import cc.unitmesh.devti.template.GENIUS_CODE
77
import cc.unitmesh.devti.template.TemplateRender
88
import cc.unitmesh.devti.template.context.TemplateContext
9-
import com.intellij.diff.editor.ChainDiffVirtualFile
10-
import com.intellij.diff.editor.DiffEditorTabFilesManager
119
import com.intellij.diff.editor.DiffVirtualFileBase
1210
import com.intellij.icons.AllIcons
1311
import com.intellij.lang.Language
@@ -30,7 +28,6 @@ import com.intellij.ui.JBColor
3028
import com.intellij.ui.components.JBLabel
3129
import com.intellij.ui.components.panels.HorizontalLayout
3230
import com.intellij.ui.components.panels.VerticalLayout
33-
import com.intellij.util.ui.UIUtil
3431
import java.awt.BorderLayout
3532
import java.awt.event.MouseAdapter
3633
import java.awt.event.MouseEvent
@@ -128,50 +125,6 @@ class SingleFileDiffView(
128125
mainPanel.add(contentPanel)
129126
}
130127

131-
private fun showDiff() {
132-
viewDiffAction()
133-
// if (diffFile != null) {
134-
// showDiffFile(diffFile!!)
135-
// return true
136-
// }
137-
//
138-
// val document = FileDocumentManager.getInstance().getDocument(currentFile) ?: return false
139-
// val appliedPatch = GenericPatchApplier.apply(document.text, patch.hunks)
140-
// ?: return false
141-
//
142-
// val newText = appliedPatch.patchedText
143-
// val diffFactory = DiffContentFactoryEx.getInstanceEx()
144-
// val currentDocContent = diffFactory.create(myProject, currentFile)
145-
// val newDocContent = diffFactory.create(newText)
146-
//
147-
// val diffRequest =
148-
// SimpleDiffRequest(
149-
// "Shire Diff - ${patch.beforeFileName}",
150-
// currentDocContent,
151-
// newDocContent,
152-
// "Original",
153-
// "AI generated"
154-
// )
155-
//
156-
// val producer = SimpleDiffRequestProducer.create(currentFile.path) {
157-
// diffRequest
158-
// }
159-
//
160-
// val chain = SimpleDiffRequestChain.fromProducer(producer)
161-
// runInEdt {
162-
// diffFile = ChainDiffVirtualFile(chain, "Diff")
163-
// showDiffFile(diffFile!!)
164-
// }
165-
//
166-
// return true
167-
}
168-
169-
private val diffEditorTabFilesManager = DiffEditorTabFilesManager.getInstance(myProject)
170-
171-
private fun showDiffFile(diffFile: ChainDiffVirtualFile) {
172-
diffEditorTabFilesManager.showDiffFile(diffFile, true)
173-
}
174-
175128
private fun createActionButtons(): List<JButton> {
176129
val undoManager = UndoManager.getInstance(myProject)
177130
val fileEditor = FileEditorManager.getInstance(myProject).getSelectedEditor(currentFile)
@@ -196,7 +149,7 @@ class SingleFileDiffView(
196149

197150
addMouseListener(object : MouseAdapter() {
198151
override fun mouseClicked(e: MouseEvent?) {
199-
showDiff()
152+
this@SingleFileDiffView.viewDiffAction()
200153
}
201154
})
202155
}
@@ -248,26 +201,6 @@ class SingleFileDiffView(
248201
return listOf(rollback, viewDiffButton, runStreamButton, repairButton)
249202
}
250203

251-
private fun showStreamDiff() {
252-
FileEditorManager.getInstance(myProject).openFile(currentFile, true)
253-
val editor = FileEditorManager.getInstance(myProject).selectedTextEditor ?: return
254-
val newText = appliedPatch!!.patchedText
255-
256-
val diffStreamHandler = DiffStreamHandler(
257-
myProject,
258-
editor = editor,
259-
0,
260-
oldCode.lines().size,
261-
onClose = {
262-
},
263-
onFinish = {
264-
265-
})
266-
267-
diffStreamHandler.normalDiff(oldCode, newText)
268-
}
269-
270-
271204
override fun getViewText(): String = currentFile.readText()
272205

273206
override fun updateViewText(text: String) {}

0 commit comments

Comments
 (0)