Skip to content

Commit 4e54a2f

Browse files
committed
refactor: sse message parsing
1 parent 01d6b51 commit 4e54a2f

File tree

5 files changed

+535
-226
lines changed

5 files changed

+535
-226
lines changed

src/main/kotlin/ee/carlrobert/codegpt/toolwindow/chat/editor/state/EditorStateManager.kt

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@ import com.intellij.openapi.editor.ex.EditorEx
77
import com.intellij.openapi.project.Project
88
import com.intellij.openapi.vfs.LocalFileSystem
99
import com.intellij.openapi.vfs.VirtualFile
10-
import com.intellij.openapi.vfs.readText
11-
import ee.carlrobert.codegpt.CodeGPTKeys
1210
import ee.carlrobert.codegpt.completions.AutoApplyParameters
1311
import ee.carlrobert.codegpt.completions.CompletionRequestService
1412
import ee.carlrobert.codegpt.toolwindow.chat.editor.ResponseEditorPanel
1513
import ee.carlrobert.codegpt.toolwindow.chat.editor.ResponseEditorPanel.Companion.RESPONSE_EDITOR_STATE_KEY
16-
import ee.carlrobert.codegpt.toolwindow.chat.editor.RetryListener
14+
import ee.carlrobert.codegpt.toolwindow.chat.editor.AutoApplyListener
1715
import ee.carlrobert.codegpt.toolwindow.chat.editor.diff.DiffEditorManager
1816
import ee.carlrobert.codegpt.toolwindow.chat.editor.factory.EditorFactory
1917
import ee.carlrobert.codegpt.toolwindow.chat.parser.Code
2018
import ee.carlrobert.codegpt.toolwindow.chat.parser.Segment
21-
import ee.carlrobert.codegpt.toolwindow.chat.parser.SseMessageParser
2219

2320
@Service(Service.Level.PROJECT)
2421
class EditorStateManager(private val project: Project) {
@@ -42,22 +39,13 @@ class EditorStateManager(private val project: Project) {
4239
return state
4340
}
4441

45-
fun handleRetryForFailedSearch(replaceContent: String) {
46-
val editor = currentState?.editor ?: return
47-
val virtualFile =
48-
CodeGPTKeys.TOOLWINDOW_EDITOR_FILE_DETAILS.get(editor)?.virtualFile ?: return
49-
50-
getCodeEditsAsync(replaceContent, virtualFile, editor)
51-
}
52-
5342
fun getCodeEditsAsync(
5443
content: String,
5544
virtualFile: VirtualFile,
5645
editor: EditorEx,
5746
) {
5847
val params = AutoApplyParameters(content, virtualFile)
59-
val messageParser = SseMessageParser()
60-
val listener = RetryListener(project, messageParser, this) { newEditor ->
48+
val listener = AutoApplyListener(project, this) { newEditor ->
6149
val responseEditorPanel = editor.component.parent as? ResponseEditorPanel
6250
?: throw IllegalStateException("Expected parent to be ResponseEditorPanel")
6351
responseEditorPanel.replaceEditor(editor, newEditor)

src/main/kotlin/ee/carlrobert/codegpt/toolwindow/chat/parser/Segment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ data class SearchReplace(
3939
val replace: String,
4040
override val language: String,
4141
override val filePath: String?
42-
) : Segment(search, language, filePath)
42+
) : Segment(replace, language, filePath)

0 commit comments

Comments
 (0)