From 2ffb009e6a7ca87e61f735be7bcbe68a162e5188 Mon Sep 17 00:00:00 2001 From: Matt Rubens Date: Mon, 27 Jan 2025 02:31:38 -0500 Subject: [PATCH] Speed up diff edits --- .changeset/smooth-jokes-hammer.md | 5 ++++ src/integrations/editor/DiffViewProvider.ts | 29 +++++++++------------ 2 files changed, 18 insertions(+), 16 deletions(-) create mode 100644 .changeset/smooth-jokes-hammer.md diff --git a/.changeset/smooth-jokes-hammer.md b/.changeset/smooth-jokes-hammer.md new file mode 100644 index 0000000..f5ba895 --- /dev/null +++ b/.changeset/smooth-jokes-hammer.md @@ -0,0 +1,5 @@ +--- +"roo-cline": patch +--- + +Speed up diff editing (thanks @hannesrudolph!) diff --git a/src/integrations/editor/DiffViewProvider.ts b/src/integrations/editor/DiffViewProvider.ts index 61c4e76..ee24d7d 100644 --- a/src/integrations/editor/DiffViewProvider.ts +++ b/src/integrations/editor/DiffViewProvider.ts @@ -88,7 +88,6 @@ export class DiffViewProvider { if (!isFinal) { accumulatedLines.pop() // remove the last partial line only if it's not the final update } - const diffLines = accumulatedLines.slice(this.streamedLines.length) const diffEditor = this.activeDiffEditor const document = diffEditor?.document @@ -100,21 +99,19 @@ export class DiffViewProvider { const beginningOfDocument = new vscode.Position(0, 0) diffEditor.selection = new vscode.Selection(beginningOfDocument, beginningOfDocument) - for (let i = 0; i < diffLines.length; i++) { - const currentLine = this.streamedLines.length + i - // Replace all content up to the current line with accumulated lines - // This is necessary (as compared to inserting one line at a time) to handle cases where html tags on previous lines are auto closed for example - const edit = new vscode.WorkspaceEdit() - const rangeToReplace = new vscode.Range(0, 0, currentLine + 1, 0) - const contentToReplace = accumulatedLines.slice(0, currentLine + 1).join("\n") + "\n" - edit.replace(document.uri, rangeToReplace, contentToReplace) - await vscode.workspace.applyEdit(edit) - // Update decorations - this.activeLineController.setActiveLine(currentLine) - this.fadedOverlayController.updateOverlayAfterLine(currentLine, document.lineCount) - // Scroll to the current line - this.scrollEditorToLine(currentLine) - } + const endLine = accumulatedLines.length + // Replace all content up to the current line with accumulated lines + const edit = new vscode.WorkspaceEdit() + const rangeToReplace = new vscode.Range(0, 0, endLine + 1, 0) + const contentToReplace = accumulatedLines.slice(0, endLine + 1).join("\n") + "\n" + edit.replace(document.uri, rangeToReplace, contentToReplace) + await vscode.workspace.applyEdit(edit) + // Update decorations + this.activeLineController.setActiveLine(endLine) + this.fadedOverlayController.updateOverlayAfterLine(endLine, document.lineCount) + // Scroll to the current line + this.scrollEditorToLine(endLine) + // Update the streamedLines with the new accumulated content this.streamedLines = accumulatedLines if (isFinal) {