diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/DiffStreamHandler.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/DiffStreamHandler.kt index 0a6b33496..3f25b87cb 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/DiffStreamHandler.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/DiffStreamHandler.kt @@ -109,14 +109,14 @@ class DiffStreamHandler( } updateProgressHighlighters(type) - - // Since we only call onLastDiffLine() when we reach a "same" line, we need to handle the case where - // we reach EOF while in a diff block, since we won't encounter a "same" line. - if (curLine.index >= editor.document.lineCount - 1) { - curLine.diffBlock?.onLastDiffLine() - } } catch (e: Exception) { - println("Error handling diff line: ${curLine.index}, $type, $text, ${e.message}") + println( + "Error handling diff line - " + + "Line index: ${curLine.index}, " + + "Line type: $type, " + + "Line text: $text, " + + "Error message: ${e.message}" + ) } } @@ -139,7 +139,7 @@ class DiffStreamHandler( val diffBlock = VerticalDiffBlock( editor, project, curLine.index, ::handleDiffBlockAcceptOrReject ) - + diffBlocks.add(diffBlock) return diffBlock @@ -251,9 +251,12 @@ class DiffStreamHandler( } private fun handleFinishedResponse() { - onFinish() - ApplicationManager.getApplication().invokeLater { + // Since we only call onLastDiffLine() when we reach a "same" line, we need to handle the case where + // the last line in the diff stream is in the middle of a diff block. + curLine.diffBlock?.onLastDiffLine() + + onFinish() cleanupProgressHighlighters() } } @@ -267,9 +270,12 @@ class DiffStreamHandler( private fun handleDiffLineResponse(parsed: Map<*, *>) { val data = parsed["content"] as Map<*, *> val diffLineType = getDiffLineType(data["type"] as String) + val lineText = data["line"] as String - WriteCommandAction.runWriteCommandAction(project) { - handleDiffLine(diffLineType, data["line"] as String) + ApplicationManager.getApplication().invokeLater { + WriteCommandAction.runWriteCommandAction(project) { + handleDiffLine(diffLineType, lineText) + } } } diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt index bd1ac8072..3b23640cc 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt @@ -48,7 +48,7 @@ fun makeTextArea(): JTextArea { isOpaque = false background = GetTheme().getSecondaryDark() maximumSize = Dimension(400, Short.MAX_VALUE.toInt()) - margin = JBUI.insets(6, 8, 6, 4) + margin = JBUI.insets(6, 8, 2, 4) font = UIUtil.getFontWithFallback("Arial", Font.PLAIN, MAIN_FONT_SIZE) preferredSize = Dimension(400, 75) } diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/VerticalDiffBlock.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/VerticalDiffBlock.kt index 2990b72e8..a84bf7f9b 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/VerticalDiffBlock.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/VerticalDiffBlock.kt @@ -29,6 +29,7 @@ class VerticalDiffBlock( private val rejectButton: JButton private var deletionInlay: Disposable? = null private var textArea: JTextArea? = null // Used for calculation of the text area height when rendering buttons + private var hasRenderedDiffBlock: Boolean = false private val editorComponentInlaysManager = EditorComponentInlaysManager.from(editor, false) private val greenKey = createTextAttributesKey("CONTINUE_DIFF_NEW_LINE", 0x3000FF00, editor) @@ -81,11 +82,19 @@ class VerticalDiffBlock( } fun onLastDiffLine() { + // Handles the case where we are invoking one last time on last line of diff stream, but the block has + // already been rendered + if (hasRenderedDiffBlock) { + return + } + if (deletedLines.size > 0) { renderDeletedLinesInlay() } renderButtons() + + hasRenderedDiffBlock = true } fun handleReject() {