Skip to content

Commit 8921fc8

Browse files
committed
fix(devti): handle multi-hunk patches in DiffLangSketch
- Update DiffLangSketch to properly handle patches with multiple hunks - Add getChunkText function to consolidate patch text handling- Modify createErrorSketch and createSingleFileDiffSketch to use getChunkText
1 parent 6ed91c3 commit 8921fc8

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,15 @@ class DiffLangSketch(private val myProject: Project, private var patchContent: S
109109
patch.beforeFileName != null -> {
110110
val originFile = myProject.findFile(patch.beforeFileName!!) ?: LightVirtualFile(
111111
patch.beforeFileName!!,
112-
patch.singleHunkPatchText
112+
getChunkText(patch)
113113
)
114114
createSingleFileDiffSketch(originFile, patch)
115115
}
116116

117117
patch.afterFileName != null -> {
118118
val virtualFile = myProject.findFile(patch.afterFileName!!) ?: LightVirtualFile(
119119
patch.afterFileName!!,
120-
patch.singleHunkPatchText
120+
getChunkText(patch)
121121
)
122122
createSingleFileDiffSketch(virtualFile, patch)
123123
}
@@ -130,10 +130,18 @@ class DiffLangSketch(private val myProject: Project, private var patchContent: S
130130

131131
private fun createErrorSketch(patch: TextFilePatch): SingleFileDiffSketch {
132132
val fileName = patch.beforeFileName ?: ""
133-
val virtualFile = LightVirtualFile(fileName, patch.singleHunkPatchText)
133+
val virtualFile = LightVirtualFile(fileName, getChunkText(patch))
134134
return createSingleFileDiffSketch(virtualFile, patch)
135135
}
136136

137+
private fun getChunkText(patch: TextFilePatch): String {
138+
if (patch.hunks.size > 1) {
139+
return patch.hunks.joinToString("\n") { it.toString() }
140+
}
141+
142+
return patch.singleHunkPatchText
143+
}
144+
137145
private fun createSingleFileDiffSketch(virtualFile: VirtualFile, patch: TextFilePatch): SingleFileDiffSketch {
138146
return SingleFileDiffSketch(myProject, virtualFile, patch, ::handleViewDiffAction).apply {
139147
this.onComplete("")

0 commit comments

Comments
 (0)