setup and clear next edit window manager on optInContinueFeature, pass context to vscode messenger
This commit is contained in:
parent
66a1dc92de
commit
1ef84a0e66
2 changed files with 35 additions and 90 deletions
|
|
@ -43,7 +43,6 @@ import { VsCodeMessenger } from "./VsCodeMessenger";
|
|||
|
||||
import { AutocompleteCodeSnippet } from "core/autocomplete/snippets/types";
|
||||
import { RecentlyEditedRange } from "core/autocomplete/util/types";
|
||||
import setupNextEditWindowManager from "../activation/NextEditWindowManager";
|
||||
import { getDefinitionsFromLsp } from "../autocomplete/lsp";
|
||||
import { VsCodeIdeUtils } from "../util/ideUtils";
|
||||
import type { VsCodeWebviewProtocol } from "../webviewProtocol";
|
||||
|
|
@ -129,6 +128,7 @@ export class VsCodeExtension {
|
|||
configHandlerPromise,
|
||||
this.workOsAuthProvider,
|
||||
this.editDecorationManager,
|
||||
context,
|
||||
);
|
||||
|
||||
this.core = new Core(inProcessMessenger, this.ide);
|
||||
|
|
@ -468,95 +468,6 @@ export class VsCodeExtension {
|
|||
void this.core.invoke("config/ideSettingsUpdate", settings);
|
||||
}
|
||||
});
|
||||
|
||||
// const ACCEPT_NEXT_EDIT_COMMAND = "nextEditWindow.acceptNextEdit";
|
||||
// const acceptNextEditCommand = vscode.commands.registerCommand(
|
||||
// ACCEPT_NEXT_EDIT_COMMAND,
|
||||
// () => {
|
||||
// this.core.invoke("applyToFile", )
|
||||
// NextEditWindowManager.getInstance().hideAllTooltips();
|
||||
// },
|
||||
// );
|
||||
// context.subscriptions.push(acceptNextEditCommand);
|
||||
|
||||
setupNextEditWindowManager(context, {
|
||||
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);
|
||||
|
||||
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);
|
||||
// });
|
||||
// }
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
static continueVirtualDocumentScheme = EXTENSION_NAME;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@ import {
|
|||
import { stripImages } from "core/util/messageContent";
|
||||
import * as vscode from "vscode";
|
||||
|
||||
import setupNextEditWindowManager, {
|
||||
NextEditWindowManager,
|
||||
} from "../activation/NextEditWindowManager";
|
||||
import { ApplyManager } from "../apply";
|
||||
import { VerticalDiffManager } from "../diff/vertical/manager";
|
||||
import { addCurrentSelectionToEdit } from "../quickEdit/AddCurrentSelection";
|
||||
|
|
@ -82,6 +85,7 @@ export class VsCodeMessenger {
|
|||
private readonly configHandlerPromise: Promise<ConfigHandler>,
|
||||
private readonly workOsAuthProvider: WorkOsAuthProvider,
|
||||
private readonly editDecorationManager: EditDecorationManager,
|
||||
private readonly context: vscode.ExtensionContext,
|
||||
) {
|
||||
/** WEBVIEW ONLY LISTENERS **/
|
||||
this.onWebview("showFile", (msg) => {
|
||||
|
|
@ -249,6 +253,36 @@ export class VsCodeMessenger {
|
|||
editDecorationManager.clear();
|
||||
});
|
||||
|
||||
this.onWebview("optInContinueFeature", async (msg) => {
|
||||
if (msg.data.optIn) {
|
||||
// Set up next edit window manager only for Continue team members
|
||||
setupNextEditWindowManager(context, {
|
||||
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);
|
||||
|
||||
return await editor.edit((editBuilder) => {
|
||||
editBuilder.replace(editRange, diff);
|
||||
});
|
||||
},
|
||||
});
|
||||
} else {
|
||||
NextEditWindowManager.clearInstance();
|
||||
}
|
||||
});
|
||||
|
||||
/** PASS THROUGH FROM WEBVIEW TO CORE AND BACK **/
|
||||
WEBVIEW_TO_CORE_PASS_THROUGH.forEach((messageType) => {
|
||||
this.onWebview(messageType, async (msg) => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue