@@ -2,6 +2,7 @@ package cc.unitmesh.devti.language.compiler.exec
2
2
3
3
import cc.unitmesh.devti.devin.InsCommand
4
4
import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand
5
+ import cc.unitmesh.devti.language.compiler.error.DEVINS_ERROR
5
6
import com.intellij.openapi.application.ApplicationManager
6
7
import com.intellij.openapi.application.runInEdt
7
8
import com.intellij.openapi.diff.impl.patch.FilePatch
@@ -24,34 +25,38 @@ class PatchInsCommand(val myProject: Project, val prop: String, val codeContent:
24
25
FileDocumentManager .getInstance().saveAllDocuments()
25
26
}
26
27
27
- val myReader = PatchReader (codeContent)
28
- myReader.parseAllPatches()
28
+ try {
29
+ val myReader = PatchReader (codeContent)
30
+ myReader.parseAllPatches()
29
31
30
- val filePatches: MutableList <FilePatch > = myReader.allPatches
32
+ val filePatches: MutableList <FilePatch > = myReader.allPatches
31
33
32
- ApplicationManager .getApplication().invokeAndWait {
33
- val matchedPatches = MatchPatchPaths (myProject).execute(filePatches, true )
34
+ ApplicationManager .getApplication().invokeAndWait {
35
+ val matchedPatches = MatchPatchPaths (myProject).execute(filePatches, true )
34
36
35
- val patchGroups = MultiMap <VirtualFile , AbstractFilePatchInProgress <* >>()
36
- for (patchInProgress in matchedPatches) {
37
- patchGroups.putValue(patchInProgress.base, patchInProgress)
38
- }
37
+ val patchGroups = MultiMap <VirtualFile , AbstractFilePatchInProgress <* >>()
38
+ for (patchInProgress in matchedPatches) {
39
+ patchGroups.putValue(patchInProgress.base, patchInProgress)
40
+ }
39
41
40
- if (patchGroups.isEmpty) return @invokeAndWait
41
- // / open file in editor
42
- filePatches.firstOrNull()?.apply {
43
- val file = myProject.guessProjectDir()!! .findFileByRelativePath(this .beforeFileName.toString())
44
- file?.let {
45
- ApplicationManager .getApplication().invokeAndWait {
46
- FileEditorManager .getInstance(myProject).openFile(it, true )
42
+ if (patchGroups.isEmpty) return @invokeAndWait
43
+ // / open file in editor
44
+ filePatches.firstOrNull()?.apply {
45
+ val file = myProject.guessProjectDir()!! .findFileByRelativePath(this .beforeFileName.toString())
46
+ file?.let {
47
+ ApplicationManager .getApplication().invokeAndWait {
48
+ FileEditorManager .getInstance(myProject).openFile(it, true )
49
+ }
47
50
}
48
51
}
52
+
53
+ val additionalInfo = myReader.getAdditionalInfo(ApplyPatchDefaultExecutor .pathsFromGroups(patchGroups))
54
+ ApplyPatchDefaultExecutor (myProject).apply (filePatches, patchGroups, null , prop, additionalInfo)
49
55
}
50
56
51
- val additionalInfo = myReader.getAdditionalInfo(ApplyPatchDefaultExecutor .pathsFromGroups(patchGroups))
52
- ApplyPatchDefaultExecutor (myProject).apply (filePatches, patchGroups, null , prop, additionalInfo)
57
+ return " Applied ${filePatches.size} patches."
58
+ } catch (e: Exception ) {
59
+ return " $DEVINS_ERROR message: " + e.message
53
60
}
54
-
55
- return " Applied ${filePatches.size} patches."
56
61
}
57
62
}
0 commit comments