diff --git a/core/edit/lazy/deterministic.test.ts b/core/edit/lazy/deterministic.test.ts index e47ae3e37..bcefdb8ba 100644 --- a/core/edit/lazy/deterministic.test.ts +++ b/core/edit/lazy/deterministic.test.ts @@ -1,7 +1,7 @@ import fs from "node:fs"; // @ts-ignore no typings available -import { changed, diff as myersDiff } from "myers-diff"; +import { diff as myersDiff } from "myers-diff"; import path from "node:path"; import { DiffLine, DiffLineType } from "../.."; import { dedent } from "../../util"; @@ -36,25 +36,11 @@ async function collectDiffs( return { ourDiffs, myersDiffs }; } -function getMyersDiffType(diff: any): MyersDiffTypes | undefined { - if (changed(diff.rhs) && !changed(diff.lhs)) { - return "new"; - } - - if (!changed(diff.rhs) && changed(diff.lhs)) { - return "old"; - } - - if (changed(diff.rhs) && changed(diff.lhs)) { - return "modification"; - } - - return undefined; -} - function displayDiff(diff: DiffLine[]) { return diff - .map(({ type, line }) => `${UNIFIED_DIFF_SYMBOLS[type]} ${line}`) + .map(({ type, line }) => + type === "same" ? line : `${UNIFIED_DIFF_SYMBOLS[type]} ${line}`, + ) .join("\n"); } @@ -129,19 +115,19 @@ describe("deterministicApplyLazyEdit(", () => { expect(myersDiffs).toEqual([]); }); - test("fastapi", async () => { + test.skip("fastapi", async () => { await expectDiff("fastapi.py"); }); - test("calculator exp", async () => { + test.skip("calculator exp", async () => { await expectDiff("calculator-exp.js"); }); - test.only("calculator exp2", async () => { + test("calculator exp2", async () => { await expectDiff("calculator-exp2.js"); }); - test("calculator comments", async () => { + test.skip("calculator comments", async () => { await expectDiff("calculator-comments.js"); }); }); diff --git a/core/edit/lazy/deterministic.ts b/core/edit/lazy/deterministic.ts index 296bf0e56..400293017 100644 --- a/core/edit/lazy/deterministic.ts +++ b/core/edit/lazy/deterministic.ts @@ -86,7 +86,7 @@ function nodesAreSimilar(a: Parser.SyntaxNode, b: Parser.SyntaxNode): boolean { } if ( - a.children[0]?.text === b.children[0]?.text && + a.namedChildren[0]?.text === b.namedChildren[0]?.text && a.children[1]?.text === b.children[1]?.text ) { return true; @@ -96,7 +96,7 @@ function nodesAreSimilar(a: Parser.SyntaxNode, b: Parser.SyntaxNode): boolean { const lineOneB = b.text.split("\n")[0]; const levDist = distance(lineOneA, lineOneB); - return levDist / Math.min(lineOneA.length, lineOneB.length) <= 0.25; + return levDist / Math.min(lineOneA.length, lineOneB.length) <= 0.2; } function nodesAreExact(a: Parser.SyntaxNode, b: Parser.SyntaxNode): boolean { @@ -149,7 +149,6 @@ function diffNodes( // Enter "lazy mode" isLazy = true; currentLazyBlockNode = R; - R.startIndex; rightChildren.shift(); continue; } diff --git a/core/edit/lazy/test-examples/calculator-comments.js.diff b/core/edit/lazy/test-examples/calculator-comments.js.diff index da4c6f5bc..5aa52aead 100644 --- a/core/edit/lazy/test-examples/calculator-comments.js.diff +++ b/core/edit/lazy/test-examples/calculator-comments.js.diff @@ -83,47 +83,47 @@ class Calculator { --- - class Calculator { - constructor() { - this.result = 0; - } +class Calculator { + constructor() { + this.result = 0; + } + // Adds the given number to the result - add(number) { - this.result += number; - return this; - } + add(number) { + this.result += number; + return this; + } + // Subtracts the given number from the result - subtract(number) { - this.result -= number; - return this; - } + subtract(number) { + this.result -= number; + return this; + } + // Multiplies the result by the given number - multiply(number) { - this.result *= number; - return this; - } + multiply(number) { + this.result *= number; + return this; + } + // Divides the result by the given number + // Throws an error if attempting to divide by zero - divide(number) { - if (number === 0) { - throw new Error("Cannot divide by zero"); - } - this.result /= number; - return this; - } + divide(number) { + if (number === 0) { + throw new Error("Cannot divide by zero"); + } + this.result /= number; + return this; + } + // Returns the current result - getResult() { - return this.result; - } + getResult() { + return this.result; + } + // Resets the result to zero - reset() { - this.result = 0; - return this; - } - } \ No newline at end of file + reset() { + this.result = 0; + return this; + } +} \ No newline at end of file diff --git a/core/edit/lazy/test-examples/calculator-exp.js.diff b/core/edit/lazy/test-examples/calculator-exp.js.diff index 1652cfc22..b01b3bdbb 100644 --- a/core/edit/lazy/test-examples/calculator-exp.js.diff +++ b/core/edit/lazy/test-examples/calculator-exp.js.diff @@ -55,45 +55,45 @@ class Calculator { --- -class Calculator { - constructor() { - this.result = 0; - } + class Calculator { + constructor() { + this.result = 0; + } - add(number) { - this.result += number; - return this; - } + add(number) { + this.result += number; + return this; + } - subtract(number) { - this.result -= number; - return this; - } + subtract(number) { + this.result -= number; + return this; + } - multiply(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; - } + 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; - } + getResult() { + return this.result; + } - reset() { - this.result = 0; - return this; - } -} \ No newline at end of file + reset() { + this.result = 0; + return this; + } + } \ No newline at end of file diff --git a/core/edit/lazy/test-examples/calculator-exp2.js.diff b/core/edit/lazy/test-examples/calculator-exp2.js.diff index a580f5ee1..b845f5e5b 100644 --- a/core/edit/lazy/test-examples/calculator-exp2.js.diff +++ b/core/edit/lazy/test-examples/calculator-exp2.js.diff @@ -86,8 +86,8 @@ class Calculator { return this; } + -+ exp(a) { -+ this.result = Math.pow(this.result, a); ++ exp(number) { ++ this.result = Math.pow(this.result, number); + return this; + } } \ No newline at end of file diff --git a/core/edit/lazy/test-examples/fastapi.py.diff b/core/edit/lazy/test-examples/fastapi.py.diff index 0bf713ae7..12d60c3b3 100644 --- a/core/edit/lazy/test-examples/fastapi.py.diff +++ b/core/edit/lazy/test-examples/fastapi.py.diff @@ -25,13 +25,13 @@ def read_landing_page(): - from fastapi import FastAPI + from fastapi import FastAPI, HTTPException - app = FastAPI() +app = FastAPI() - @app.get("/") - def read_root(): - return {"Hello": "World"} +@app.get("/") +def read_root(): + return {"Hello": "World"} - @app.get("/landing") - def read_landing_page(): +@app.get("/landing") +def read_landing_page(): - return {"message": "Welcome to the landing page"} + raise HTTPException(status_code=404, detail="Page not found") \ No newline at end of file