Skip to content

Commit 3ab61c4

Browse files
committed
fix: instant streaming for jetbrains
1 parent d227a57 commit 3ab61c4

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/ApplyToFileHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class ApplyToFileHandler(
8383
val diffStreamHandler = createDiffStreamHandler(editorUtils.editor, startLine, endLine)
8484
diffStreamService.register(diffStreamHandler, editorUtils.editor)
8585

86-
diffStreamHandler.instantApplyMyersDiff(currentContent, newContent)
86+
diffStreamHandler.instantApplyDiffLines(currentContent, newContent)
8787
}
8888

8989
private fun notifyStreamStarted() {

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/DiffStreamHandler.kt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,13 @@ class DiffStreamHandler(
149149
) { response ->
150150
if (!isRunning) return@request
151151

152-
val diffLines = response as List<Map<String, Any>>
152+
val diffLines = parseDiffLinesResponse(response) ?: run {
153+
println("Error: Invalid response format for getDiffLines")
154+
ApplicationManager.getApplication().invokeLater {
155+
setClosed()
156+
}
157+
return@request
158+
}
153159

154160
ApplicationManager.getApplication().invokeLater {
155161
WriteCommandAction.runWriteCommandAction(project) {
@@ -171,6 +177,22 @@ class DiffStreamHandler(
171177
}
172178
}
173179

180+
private fun parseDiffLinesResponse(response: Any?): List<Map<String, Any>>? {
181+
if (response !is List<*>) return null
182+
183+
val result = mutableListOf<Map<String, Any>>()
184+
for (item in response) {
185+
if (item !is Map<*, *>) return null
186+
187+
val type = item["type"] as? String ?: return null
188+
val line = item["line"] as? String ?: return null
189+
190+
result.add(mapOf("type" to type, "line" to line))
191+
}
192+
193+
return result
194+
}
195+
174196
private fun applyAllDiffLines(diffLines: List<Map<String, Any>>) {
175197
var currentLine = startLine
176198

0 commit comments

Comments
 (0)