detect when instant apply allowed
This commit is contained in:
parent
3daff07168
commit
08b75d52be
6 changed files with 48 additions and 19 deletions
31
core/edit/lazy/applyCodeBlock.ts
Normal file
31
core/edit/lazy/applyCodeBlock.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import path from "path";
|
||||
import { DiffLine, ILLM } from "../..";
|
||||
import { generateLines } from "../../diff/util";
|
||||
import { supportedLanguages } from "../../util/treeSitter";
|
||||
import { deterministicApplyLazyEdit } from "./deterministic";
|
||||
import { streamLazyApply } from "./streamLazyApply";
|
||||
|
||||
function canUseInstantApply(filename: string) {
|
||||
const fileExtension = path.extname(filename).toLowerCase().slice(1);
|
||||
return supportedLanguages[fileExtension] !== undefined;
|
||||
}
|
||||
|
||||
export async function applyCodeBlock(
|
||||
oldFile: string,
|
||||
newFile: string,
|
||||
filename: string,
|
||||
llm: ILLM,
|
||||
fastLlm: ILLM,
|
||||
): Promise<[boolean, AsyncGenerator<DiffLine>]> {
|
||||
if (canUseInstantApply(filename)) {
|
||||
const diffLines = await deterministicApplyLazyEdit(
|
||||
oldFile,
|
||||
newFile,
|
||||
filename,
|
||||
);
|
||||
const diffGenerator = generateLines(diffLines!);
|
||||
return [true, diffGenerator];
|
||||
} else {
|
||||
return [false, streamLazyApply(oldFile, filename, newFile, llm, fastLlm)];
|
||||
}
|
||||
}
|
||||
|
|
@ -140,7 +140,7 @@ describe("deterministicApplyLazyEdit(", () => {
|
|||
await expectDiff("top-level-same.js");
|
||||
});
|
||||
|
||||
test.skip("gui add toggle", async () => {
|
||||
test("gui add toggle", async () => {
|
||||
await expectDiff("gui.js");
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -349,8 +349,8 @@
|
|||
},
|
||||
{
|
||||
"command": "continue.applyCodeFromChat",
|
||||
"mac": "alt+l",
|
||||
"key": "alt+l"
|
||||
"mac": "alt+a",
|
||||
"key": "alt+a"
|
||||
}
|
||||
],
|
||||
"submenus": [
|
||||
|
|
|
|||
|
|
@ -177,7 +177,10 @@ export class VerticalPerLineDiffManager {
|
|||
}
|
||||
}
|
||||
|
||||
async streamDiffLines(diffStream: AsyncGenerator<DiffLine>) {
|
||||
async streamDiffLines(
|
||||
diffStream: AsyncGenerator<DiffLine>,
|
||||
instant: boolean,
|
||||
) {
|
||||
vscode.commands.executeCommand("setContext", "continue.diffVisible", true);
|
||||
|
||||
// Get the current editor filepath/range
|
||||
|
|
@ -204,7 +207,9 @@ export class VerticalPerLineDiffManager {
|
|||
filepath,
|
||||
startLine,
|
||||
endLine,
|
||||
{},
|
||||
{
|
||||
instant,
|
||||
},
|
||||
);
|
||||
|
||||
if (!diffHandler) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { ILLM } from "core";
|
||||
import { ConfigHandler } from "core/config/ConfigHandler";
|
||||
import { generateLines } from "core/diff/util";
|
||||
import { deterministicApplyLazyEdit2 } from "core/edit/lazy/deterministic2";
|
||||
import { applyCodeBlock } from "core/edit/lazy/applyCodeBlock";
|
||||
import {
|
||||
FromCoreProtocol,
|
||||
FromWebviewProtocol,
|
||||
|
|
@ -160,21 +159,15 @@ export class VsCodeMessenger {
|
|||
fastLlm ??= llm;
|
||||
|
||||
// Generate the diff and pass through diff manager
|
||||
// const diffLines = streamLazyApply(
|
||||
// editor.document.getText(),
|
||||
// getBasename(editor.document.fileName),
|
||||
// msg.data.text,
|
||||
// llm,
|
||||
// fastLlm,
|
||||
// );
|
||||
const diffLines = await deterministicApplyLazyEdit2(
|
||||
const [instant, diffLines] = await applyCodeBlock(
|
||||
editor.document.getText(),
|
||||
msg.data.text,
|
||||
getBasename(editor.document.fileName),
|
||||
llm,
|
||||
fastLlm,
|
||||
);
|
||||
const diffGenerator = generateLines(diffLines!);
|
||||
const verticalDiffManager = await this.verticalDiffManagerPromise;
|
||||
verticalDiffManager.streamDiffLines(diffGenerator);
|
||||
verticalDiffManager.streamDiffLines(diffLines, instant);
|
||||
});
|
||||
|
||||
this.onWebview("showTutorial", async (msg) => {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { ContinueConfig, IDE } from "core";
|
||||
import { IDE } from "core";
|
||||
import { walkDir } from "core/indexing/walkDir";
|
||||
import { Telemetry } from "core/util/posthog";
|
||||
import * as vscode from "vscode";
|
||||
|
|
@ -215,7 +215,7 @@ export class QuickEdit {
|
|||
);
|
||||
|
||||
this.editorWhenOpened = editor;
|
||||
this.previousInput = existingHandler?.input;
|
||||
this.previousInput = existingHandler?.options.input;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue