diff --git a/extensions/vscode/src/activation/NextEditWindowManager.ts b/extensions/vscode/src/activation/NextEditWindowManager.ts index 7e6dc2b7a..51f3e73f6 100644 --- a/extensions/vscode/src/activation/NextEditWindowManager.ts +++ b/extensions/vscode/src/activation/NextEditWindowManager.ts @@ -242,10 +242,7 @@ export class NextEditWindowManager { const position = editor.selection.active; let success = false; - const USE_TEXT_APPLIER = false; - // For now we skip using textApplier, because we don't need an apply logic yet. - // In the future we may use this. - if (this.textApplier && USE_TEXT_APPLIER) { + if (this.textApplier) { success = await this.textApplier.applyText(editor, text, position); } else { // applyText already has this, diff --git a/extensions/vscode/src/autocomplete/completionProvider.ts b/extensions/vscode/src/autocomplete/completionProvider.ts index e00c26758..30dfebbca 100644 --- a/extensions/vscode/src/autocomplete/completionProvider.ts +++ b/extensions/vscode/src/autocomplete/completionProvider.ts @@ -15,6 +15,8 @@ import { handleLLMError } from "../util/errorHandling"; import { VsCodeIde } from "../VsCodeIde"; import { VsCodeWebviewProtocol } from "../webviewProtocol"; +import { IS_NEXT_EDIT_ACTIVE } from "core/nextEdit/constants"; +import { NextEditProvider } from "core/nextEdit/NextEditProvider"; import { NextEditWindowManager } from "../activation/NextEditWindowManager"; import { getDefinitionsFromLsp } from "./lsp"; import { RecentlyEditedTracker } from "./recentlyEdited"; @@ -55,7 +57,7 @@ export class ContinueCompletionProvider } private completionProvider: CompletionProvider; - // private nextEditProvider: NextEditProvider; + private nextEditProvider: NextEditProvider; public recentlyVisitedRanges: RecentlyVisitedRangesService; public recentlyEditedTracker: RecentlyEditedTracker; diff --git a/extensions/vscode/src/extension/VsCodeExtension.ts b/extensions/vscode/src/extension/VsCodeExtension.ts index 77515e77d..dc522d4fd 100644 --- a/extensions/vscode/src/extension/VsCodeExtension.ts +++ b/extensions/vscode/src/extension/VsCodeExtension.ts @@ -43,8 +43,6 @@ import { VsCodeMessenger } from "./VsCodeMessenger"; import { AutocompleteCodeSnippet } from "core/autocomplete/snippets/types"; import { RecentlyEditedRange } from "core/autocomplete/util/types"; -import { applyCodeBlock } from "core/edit/lazy/applyCodeBlock"; -import { llmFromProviderAndOptions } from "core/llm/llms"; import setupNextEditWindowManager from "../activation/NextEditWindowManager"; import { getDefinitionsFromLsp } from "../autocomplete/lsp"; import { VsCodeIdeUtils } from "../util/ideUtils"; @@ -482,63 +480,81 @@ export class VsCodeExtension { // context.subscriptions.push(acceptNextEditCommand); setupNextEditWindowManager(context, { - applyText: async (editor, unifiedDiffText, position) => { - const config = await this.configHandler.getSerializedConfig(); - const applyModelDesc = config?.config?.selectedModelByRole.apply; - if (applyModelDesc) { - try { - // We could create an apply message protocol - // this.core.invoke("applyNextEdit", { - // filepath: editor.document.uri.toString(), - // position: position, - // text: text - // }); - const llmOptions = { - ...applyModelDesc, - completionOptions: { - ...applyModelDesc.completionOptions, - model: applyModelDesc.model, - }, - uniqueId: "apply-model-for-next-edit", - }; - const applyModelInstance = llmFromProviderAndOptions( - applyModelDesc.provider, - llmOptions, - ); - const { isInstantApply, diffLinesGenerator } = await applyCodeBlock( - editor.document.getText(), - unifiedDiffText, - editor.document.uri.toString(), - applyModelInstance, - ); - const lines = []; - for await (const line of diffLinesGenerator) { - lines.push(line); - } - // TODO: do some stream rendering logic here. - return true; - } catch (err) { - console.error(`Failed to apply edit: ${err}`); - return false; - } - } else { - // Fallback to verbatim paste if apply model does not exist. - const editableRegionStartLine = Math.max(0, position.line - 5); - const editableRegionEndLine = Math.min( - editor.document.lineCount - 1, - position.line + 5, - ); - const startPos = new vscode.Position(editableRegionStartLine, 0); - const endPosChar = editor.document.lineAt(editableRegionEndLine).text - .length; + applyText: async (editor, diff, position) => { + const editableRegionStartLine = Math.max(0, position.line - 5); + const editableRegionEndLine = Math.min( + editor.document.lineCount - 1, + position.line + 5, + ); + const startPos = new vscode.Position(editableRegionStartLine, 0); + const endPosChar = editor.document.lineAt(editableRegionEndLine).text + .length; - const endPos = new vscode.Position(editableRegionEndLine, endPosChar); - const editRange = new vscode.Range(startPos, endPos); + const endPos = new vscode.Position(editableRegionEndLine, endPosChar); + const editRange = new vscode.Range(startPos, endPos); - return await editor.edit((editBuilder) => { - editBuilder.replace(editRange, unifiedDiffText); - }); - } + return await editor.edit((editBuilder) => { + editBuilder.replace(editRange, diff); + }); + + // use this when we need deps from vscode extension + // const config = await this.configHandler.getSerializedConfig(); + // const applyModelDesc = config?.config?.selectedModelByRole.apply; + // if (applyModelDesc) { + // try { + // // We could create an apply message protocol + // // this.core.invoke("applyNextEdit", { + // // filepath: editor.document.uri.toString(), + // // position: position, + // // text: text + // // }); + // // use this when we need deps from vscode extension + // const llmOptions = { + // ...applyModelDesc, + // completionOptions: { + // ...applyModelDesc.completionOptions, + // model: applyModelDesc.model, + // }, + // uniqueId: "apply-model-for-next-edit", + // }; + // const applyModelInstance = llmFromProviderAndOptions( + // applyModelDesc.provider, + // llmOptions, + // ); + // const { isInstantApply, diffLinesGenerator } = await applyCodeBlock( + // editor.document.getText(), + // unifiedDiffText, + // editor.document.uri.toString(), + // applyModelInstance, + // ); + // const lines = []; + // for await (const line of diffLinesGenerator) { + // lines.push(line); + // } + // // TODO: do some stream rendering logic here. + // return true; + // } catch (err) { + // console.error(`Failed to apply edit: ${err}`); + // return false; + // } + // } else { + // // Fallback to verbatim paste if apply model does not exist. + // const editableRegionStartLine = Math.max(0, position.line - 5); + // const editableRegionEndLine = Math.min( + // editor.document.lineCount - 1, + // position.line + 5, + // ); + // const startPos = new vscode.Position(editableRegionStartLine, 0); + // const endPosChar = editor.document.lineAt(editableRegionEndLine).text + // .length; + + // const endPos = new vscode.Position(editableRegionEndLine, endPosChar); + // const editRange = new vscode.Range(startPos, endPos); + + // return await editor.edit((editBuilder) => { + // editBuilder.replace(editRange, unifiedDiffText); + // }); + // } }, }); }