diff --git a/core/edit/lazy/deterministic.test.ts b/core/edit/lazy/deterministic.test.ts index ca3a1c40c..c061bf681 100644 --- a/core/edit/lazy/deterministic.test.ts +++ b/core/edit/lazy/deterministic.test.ts @@ -120,7 +120,11 @@ describe("deterministicApplyLazyEdit(", () => { expect(myersDiffs).toEqual([]); }); - test.only("tabs vs. spaces differences are ignored", async () => { + test.only("fastapi", async () => { + await expectDiff("fastapi.py"); + }); + + test.only("calculator exp", async () => { await expectDiff("fastapi.py"); }); }); diff --git a/core/edit/lazy/streamLazyApply.ts b/core/edit/lazy/streamLazyApply.ts index 9d667ea57..a9378bfa3 100644 --- a/core/edit/lazy/streamLazyApply.ts +++ b/core/edit/lazy/streamLazyApply.ts @@ -14,6 +14,7 @@ export async function* streamLazyApply( filename: string, newCode: string, llm: ILLM, + fastLlm: ILLM, ): AsyncGenerator { const promptFactory = lazyApplyPromptForModel(llm.model, llm.providerName); if (!promptFactory) { @@ -33,19 +34,21 @@ export async function* streamLazyApply( oldCode, linesBefore, linesAfter, - llm, + fastLlm, )) { yield line; } // let r = getReplacementByMatching(oldCode, linesBefore, linesAfter); // if (r) { - // return r; - // } - // r = await getReplacementWithLlm(oldCode, linesBefore, linesAfter, llm); - // if (r) { - // return r; + // for (let line of r.split("\n")) { + // yield line; + // } // } + // // r = await getReplacementWithLlm(oldCode, linesBefore, linesAfter, llm); + // // if (r) { + // // return r; + // // } // return "// NO REPLACEMENT FOUND"; } diff --git a/core/edit/lazy/test-examples/calculator-exp.js.diff b/core/edit/lazy/test-examples/calculator-exp.js.diff new file mode 100644 index 000000000..1652cfc22 --- /dev/null +++ b/core/edit/lazy/test-examples/calculator-exp.js.diff @@ -0,0 +1,99 @@ +class Calculator { + constructor() { + this.result = 0; + } + + add(number) { + this.result += number; + return this; + } + + subtract(number) { + this.result -= number; + return this; + } + + multiply(number) { + this.result *= number; + return this; + } + + divide(number) { + if (number === 0) { + throw new Error("Cannot divide by zero"); + } + this.result /= number; + return this; + } + + getResult() { + return this.result; + } + + reset() { + this.result = 0; + return this; + } +} + +--- + +class Calculator { + constructor() { + this.result = 0; + } + + // ... same ... + + exp(a) { + this.result = Math.pow(this.result, a); + return this; + } + + // ... same ... +} + +--- + +class Calculator { + constructor() { + this.result = 0; + } + + add(number) { + this.result += number; + return this; + } + + subtract(number) { + this.result -= number; + return this; + } + + multiply(number) { + this.result *= number; + return this; + } + + divide(number) { + if (number === 0) { + throw new Error("Cannot divide by zero"); + } + this.result /= number; + return this; + } ++ ++ exp(a) { ++ this.result = Math.pow(this.result, a); ++ return this; ++ } + + getResult() { + return this.result; + } + + reset() { + this.result = 0; + return this; + } +} \ No newline at end of file diff --git a/extensions/vscode/src/extension/VsCodeMessenger.ts b/extensions/vscode/src/extension/VsCodeMessenger.ts index a3dd065e7..c72ac3785 100644 --- a/extensions/vscode/src/extension/VsCodeMessenger.ts +++ b/extensions/vscode/src/extension/VsCodeMessenger.ts @@ -1,3 +1,4 @@ +import { ILLM } from "core"; import { ConfigHandler } from "core/config/ConfigHandler"; import { streamLazyApply } from "core/edit/lazy/streamLazyApply"; import { @@ -147,12 +148,23 @@ export class VsCodeMessenger { return; } + let fastLlm: ILLM | undefined; + if (config.experimental?.modelRoles?.repoMapFileSelection) { + fastLlm = config.models.find( + (model) => + model.title === + config.experimental?.modelRoles?.repoMapFileSelection, + ); + } + 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 verticalDiffManager = await this.verticalDiffManagerPromise; verticalDiffManager.streamDiffLines(diffLines);