diff --git a/.continue/rules/rules.yaml b/.continue/rules/rules.yaml new file mode 100644 index 000000000..a5b63ab33 --- /dev/null +++ b/.continue/rules/rules.yaml @@ -0,0 +1,6 @@ +name: Continue Repo rules +version: 1.0.0 +schema: v1 + +mcpServers: + - uses: continuedev/continue-repo-rules diff --git a/core/edit/lazy/applyCodeBlock.ts b/core/edit/lazy/applyCodeBlock.ts index b117c7dea..c533b34e6 100644 --- a/core/edit/lazy/applyCodeBlock.ts +++ b/core/edit/lazy/applyCodeBlock.ts @@ -13,7 +13,7 @@ function canUseInstantApply(filename: string) { export async function applyCodeBlock( oldFile: string, - newFile: string, + newLazyFile: string, filename: string, llm: ILLM, ): Promise<{ @@ -21,11 +21,12 @@ export async function applyCodeBlock( diffLinesGenerator: AsyncGenerator; }> { if (canUseInstantApply(filename)) { - const diffLines = await deterministicApplyLazyEdit( + const diffLines = await deterministicApplyLazyEdit({ oldFile, - newFile, + newLazyFile, filename, - ); + onlyFullFileRewrite: true, + }); if (diffLines !== undefined) { return { diff --git a/core/edit/lazy/deterministic.test.ts b/core/edit/lazy/deterministic.test.ts index 33140a0a5..728c6d8f9 100644 --- a/core/edit/lazy/deterministic.test.ts +++ b/core/edit/lazy/deterministic.test.ts @@ -21,11 +21,11 @@ async function collectDiffs( ): Promise<{ ourDiffs: DiffLine[]; myersDiffs: any }> { const ourDiffs: DiffLine[] = []; - for (const diffLine of (await deterministicApplyLazyEdit( + for (const diffLine of (await deterministicApplyLazyEdit({ oldFile, - newFile, + newLazyFile: newFile, filename, - )) ?? []) { + })) ?? []) { ourDiffs.push(diffLine); } @@ -84,7 +84,7 @@ async function expectDiff(file: string) { } // Skipped while we have `ONLY_FULL_FILE_REWRITE` enabled -describe.skip("deterministicApplyLazyEdit(", () => { +describe("deterministicApplyLazyEdit(", () => { test("no changes", async () => { const file = dedent` function test() { diff --git a/core/edit/lazy/deterministic.ts b/core/edit/lazy/deterministic.ts index b4c6611c9..947f628e4 100644 --- a/core/edit/lazy/deterministic.ts +++ b/core/edit/lazy/deterministic.ts @@ -15,14 +15,6 @@ type AstReplacements = Array<{ replacementNodes: Parser.SyntaxNode[]; }>; -/** - * Using this as a flag to slowly reintroduce lazy applies. - * With this set, we will only attempt to deterministically apply - * when there are no lazy blocks and then just replace the whole file, - * and otherwise never use instant apply - */ -const ONLY_FULL_FILE_REWRITE = true; - const LAZY_COMMENT_REGEX = /\.{3}\s*(.+?)\s*\.{3}/; export function isLazyText(text: string): boolean { return LAZY_COMMENT_REGEX.test(text); @@ -134,11 +126,23 @@ function nodeSurroundedInLazyBlocks( } // TODO: If we don't have high confidence, return undefined to fall back to slower methods -export async function deterministicApplyLazyEdit( - oldFile: string, - newLazyFile: string, - filename: string, -): Promise { +export async function deterministicApplyLazyEdit({ + oldFile, + newLazyFile, + filename, + /** + * Using this as a flag to slowly reintroduce lazy applies. + * With this set, we will only attempt to deterministically apply + * when there are no lazy blocks and then just replace the whole file, + * and otherwise never use instant apply + */ + onlyFullFileRewrite = false, +}: { + oldFile: string; + newLazyFile: string; + filename: string; + onlyFullFileRewrite?: boolean; +}): Promise { const parser = await getParserForFile(filename); if (!parser) { return undefined; @@ -148,8 +152,7 @@ export async function deterministicApplyLazyEdit( let newTree = parser.parse(newLazyFile); let reconstructedNewFile: string | undefined = undefined; - // See comments on `ONLY_FULL_FILE_REWRITE` for context - if (ONLY_FULL_FILE_REWRITE) { + if (onlyFullFileRewrite) { if (!isLazyText(newTree.rootNode.text)) { return myersDiff(oldFile, newLazyFile); } else {