From 2a38fb61c56599cf03abefdeefc0dec0931765b2 Mon Sep 17 00:00:00 2001 From: hitesh-1997 Date: Fri, 10 Jan 2025 04:57:30 +0530 Subject: [PATCH 1/3] feat(auto-edits): fix the suffix duplication on inline accept --- vscode/src/autoedits/renderer/manager.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/vscode/src/autoedits/renderer/manager.ts b/vscode/src/autoedits/renderer/manager.ts index 2e300bb0c5ce..0c1cc59ca949 100644 --- a/vscode/src/autoedits/renderer/manager.ts +++ b/vscode/src/autoedits/renderer/manager.ts @@ -281,9 +281,11 @@ export class AutoEditsDefaultRendererManager implements AutoEditsRendererManager await this.handleDidHideSuggestion(decorator) autoeditAnalyticsLogger.markAsAccepted(activeRequest.requestId) - await editor.edit(editBuilder => { - editBuilder.replace(activeRequest.codeToReplaceData.range, activeRequest.prediction) - }) + if (this.activeRequest && this.hasInlineDecorationOnly()) { + await editor.edit(editBuilder => { + editBuilder.replace(activeRequest.codeToReplaceData.range, activeRequest.prediction) + }) + } } protected async rejectActiveEdit(): Promise { From e95aa77b62ac6d6e25563b2f52c7d09cb8848659 Mon Sep 17 00:00:00 2001 From: Valery Bugakov Date: Fri, 10 Jan 2025 10:38:32 +0800 Subject: [PATCH 2/3] feat(audoedit): precompute `hasInlineDecorationOnly` --- vscode/src/autoedits/renderer/manager.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/vscode/src/autoedits/renderer/manager.ts b/vscode/src/autoedits/renderer/manager.ts index 0c1cc59ca949..2bdccb8c6b97 100644 --- a/vscode/src/autoedits/renderer/manager.ts +++ b/vscode/src/autoedits/renderer/manager.ts @@ -94,7 +94,10 @@ export class AutoEditsDefaultRendererManager implements AutoEditsRendererManager protected fixupController: FixupController ) { this.disposables.push( - vscode.commands.registerCommand('cody.supersuggest.accept', () => this.acceptActiveEdit()), + vscode.commands.registerCommand('cody.supersuggest.accept', () => { + console.log('cody.supersuggest.accept') + this.acceptActiveEdit() + }), vscode.commands.registerCommand('cody.supersuggest.dismiss', () => this.rejectActiveEdit()), vscode.workspace.onDidChangeTextDocument(event => this.onDidChangeTextDocument(event)), vscode.window.onDidChangeTextEditorSelection(event => @@ -270,6 +273,9 @@ export class AutoEditsDefaultRendererManager implements AutoEditsRendererManager protected async acceptActiveEdit(): Promise { const editor = vscode.window.activeTextEditor const { activeRequest, decorator } = this + // Compute this variable before the `handleDidHideSuggestion` call which removes the active request. + const hasInlineDecorationOnly = this.hasInlineDecorationOnly() + if ( !editor || !activeRequest || @@ -281,7 +287,9 @@ export class AutoEditsDefaultRendererManager implements AutoEditsRendererManager await this.handleDidHideSuggestion(decorator) autoeditAnalyticsLogger.markAsAccepted(activeRequest.requestId) - if (this.activeRequest && this.hasInlineDecorationOnly()) { + // We rely on the native VS Code functionality for accepting inline completions items. + // There's no need to manually edit the document. + if (hasInlineDecorationOnly) { await editor.edit(editBuilder => { editBuilder.replace(activeRequest.codeToReplaceData.range, activeRequest.prediction) }) From 6e2c4db053b623183b53c68ceefafbc9665f4008 Mon Sep 17 00:00:00 2001 From: Valery Bugakov Date: Fri, 10 Jan 2025 10:40:10 +0800 Subject: [PATCH 3/3] feat(audoedit): cleanup --- vscode/src/autoedits/renderer/manager.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/vscode/src/autoedits/renderer/manager.ts b/vscode/src/autoedits/renderer/manager.ts index 2bdccb8c6b97..9441b33107ea 100644 --- a/vscode/src/autoedits/renderer/manager.ts +++ b/vscode/src/autoedits/renderer/manager.ts @@ -94,10 +94,7 @@ export class AutoEditsDefaultRendererManager implements AutoEditsRendererManager protected fixupController: FixupController ) { this.disposables.push( - vscode.commands.registerCommand('cody.supersuggest.accept', () => { - console.log('cody.supersuggest.accept') - this.acceptActiveEdit() - }), + vscode.commands.registerCommand('cody.supersuggest.accept', () => this.acceptActiveEdit()), vscode.commands.registerCommand('cody.supersuggest.dismiss', () => this.rejectActiveEdit()), vscode.workspace.onDidChangeTextDocument(event => this.onDidChangeTextDocument(event)), vscode.window.onDidChangeTextEditorSelection(event =>