Skip to content

Commit 4ca5a31

Browse files
committed
fix(devtools): improve diff view handling for deleted files and exceptions #352
- Update diff view to show "No Content" for deleted files - Add exception handling to display error messages in diff view - Fix patch application for deleted files - Improve error handling in patch application
1 parent 94a39b3 commit 4ca5a31

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

core/src/main/kotlin/cc/unitmesh/devti/gui/planner/PlannerResultSummary.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,12 @@ class PlannerResultSummary(
114114
private fun showDiffView(change: Change) {
115115
val diffFactory = DiffContentFactoryEx.getInstanceEx()
116116
val oldCode = change.beforeRevision?.content ?: return
117-
val newCode = change.afterRevision?.content ?: return
117+
val newCode = try {
118+
change.afterRevision?.content ?: "No Content"
119+
} catch (e: Exception) {
120+
"Error: ${e.message}"
121+
}
122+
118123
val currentDocContent = diffFactory.create(project, oldCode)
119124
val newDocContent = diffFactory.create(newCode)
120125

core/src/main/kotlin/cc/unitmesh/devti/observer/agent/AgentStateService.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,17 @@ class AgentStateService(val project: Project) {
9797
if (patch.isNewFile) {
9898
return patch.singleHunkPatchText
9999
}
100+
100101
if (patch.isDeletedFile) {
101102
return null
102103
}
103104

104105
val localContent: String = loadLocalContent()
105-
val appliedPatch = GenericPatchApplier.apply(localContent, patch.getHunks())
106+
val appliedPatch = GenericPatchApplier.apply(localContent, patch.hunks)
106107
if (appliedPatch != null) {
107108
return appliedPatch.patchedText
108109
}
110+
109111
throw VcsException(VcsBundle.message("patch.apply.error.conflict"))
110112
}
111113

@@ -121,6 +123,7 @@ class AgentStateService(val project: Project) {
121123
}
122124
}
123125
}
126+
124127
return Change(beforeRevision, afterRevision, fileStatus)
125128
}
126129

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ class SingleFileDiffSketch(
162162
mainPanel.add(myHeaderPanel)
163163
mainPanel.add(contentPanel)
164164

165-
myProject.getService<AgentStateService>(AgentStateService::class.java)
166-
.addToChange(currentFile.toNioPath(), patch)
167-
168165
if (myProject.coderSetting.state.enableDiffViewer && appliedPatch?.status == ApplyPatchStatus.SUCCESS) {
166+
myProject.getService<AgentStateService>(AgentStateService::class.java)
167+
.addToChange(currentFile.toNioPath(), patch)
168+
169169
invokeLater {
170170
val diffPanel = createDiffViewer(oldCode, newCode)
171171
mainPanel.add(diffPanel)
@@ -380,6 +380,9 @@ class SingleFileDiffSketch(
380380
}
381381
}
382382

383+
myProject.getService<AgentStateService>(AgentStateService::class.java)
384+
.addToChange(currentFile.toNioPath(), patch)
385+
383386
createActionButtons(currentFile, appliedPatch, patch, isRepaired = true).let { actions ->
384387
actionPanel.removeAll()
385388
actions.forEach { button ->

0 commit comments

Comments
 (0)