Skip to content

Commit 072c25d

Browse files
committed
refactor: format code
1 parent 3822e24 commit 072c25d

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

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

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,16 @@ class AgentStateService(val project: Project) {
7676
val beforePath = patch.beforeName
7777
val afterPath = patch.afterName
7878

79-
val fileStatus = if (patch.isNewFile) {
80-
FileStatus.ADDED
81-
} else if (patch.isDeletedFile) {
82-
FileStatus.DELETED
83-
} else {
84-
FileStatus.MODIFIED
79+
val fileStatus = when {
80+
patch.isNewFile -> {
81+
FileStatus.ADDED
82+
}
83+
patch.isDeletedFile -> {
84+
FileStatus.DELETED
85+
}
86+
else -> {
87+
FileStatus.MODIFIED
88+
}
8589
}
8690

8791
val beforeFilePath = VcsUtil.getFilePath(getAbsolutePath(baseDir, beforePath), false)
@@ -105,21 +109,24 @@ class AgentStateService(val project: Project) {
105109
override fun getVirtualFile(): VirtualFile? = afterFilePath.virtualFile
106110
override fun getFile(): FilePath = afterFilePath
107111
override fun getContent(): @NonNls String? {
108-
if (patch.isNewFile) {
109-
return patch.singleHunkPatchText
110-
}
111-
112-
if (patch.isDeletedFile) {
113-
return null
114-
}
115-
116-
val localContent: String = loadLocalContent()
117-
val appliedPatch = GenericPatchApplier.apply(localContent, patch.hunks)
118-
if (appliedPatch != null) {
119-
return appliedPatch.patchedText
112+
when {
113+
patch.isNewFile -> {
114+
return patch.singleHunkPatchText
115+
}
116+
patch.isDeletedFile -> {
117+
return null
118+
}
119+
else -> {
120+
val localContent: String = loadLocalContent()
121+
val appliedPatch = GenericPatchApplier.apply(localContent, patch.hunks)
122+
/// sometimes llm will return a wrong patch which the content is not correct
123+
if (appliedPatch != null) {
124+
return appliedPatch.patchedText
125+
}
126+
127+
return patch.singleHunkPatchText
128+
}
120129
}
121-
/// sometimes llm will return a wrong patch which the content is not correct
122-
return patch.singleHunkPatchText
123130
}
124131

125132
@Throws(VcsException::class)

0 commit comments

Comments
 (0)