* 🎨 refactor out react context * 🎨 refactor local storage * 🎨 refactor IdeMessenger * 🔥 removing unused files * 🚚 move scripts * ✅ setup VSCode integration testing * 🎨 fix test-related stuff * 🚧 testing * 🎨 tweak terminal cmd+L * 🧑💻 install biome in core * 🎨 run biome check on core * 🎨 run biome check in vscode * 🎨 run biome check in binary * 🧑💻 global biome config * 🎨 run biome check on core * 🎨 run biome check in vscode * 🎨 fix a few biome warnings * 🚧 WIP on protocols * 🚧 progress, organizing, about to remove webviewCore protocol * 🚧 now running * 🚧 move indexing code to core * 🚧 WIP on JetBrains indexing implementation * 🎨 finish listDir * 🚧 gui fixes * 🏷️ update IMessenger.on return type * 🐛 fix jetbrains types + IDE detection * 🧑💻 set up debugging for binary with TcpMessenger * 👷 fix prepackage.js * 🧑💻 turn off debug mode for intellij * 🐛 merge fixes * 🐛 fixes after refactor * 🐛 merge fixes * 💄 increase font size in JB * 🔀 merge changes * 🩹 small fixes * 🐛 fix jetbrains build * 🩹 more jetbrains fixes * 🎨 jetbrains improvements * 🐛 fix lancedb prob in jetbrains build * 👷 update jetbrains build process * ✨ intellij problems context provider * 👷 add script utils file * 💚 fix jetbrains build regression * 🎨 dynamic import transformers.js * 🩹 small jetbrains updates * ✨ folder context provider in jetbrains * 🎨 many more jetbrains improvements * 🔀 merge fixes * ⚡️ small improvements * 🎨 tell users transformers.js not supported * 🎨 trial updates * 📝 update jetbrains readmej * ⚡️ only use smaller context for local autocomplete models * ⚡️ improve bracket filter * ✨ global .continue/.prompts folder * 💄 improved model setup process * 🥅 display VSCode req errs
150 lines
3.3 KiB
TypeScript
150 lines
3.3 KiB
TypeScript
import { streamDiff } from "../diff/streamDiff.js";
|
|
|
|
const oldCode = [
|
|
`A
|
|
B`,
|
|
`A
|
|
B
|
|
C`,
|
|
`A
|
|
B
|
|
C
|
|
A
|
|
B
|
|
B
|
|
A`,
|
|
`function mergeSortAlgorithm() {
|
|
// TODO: implement
|
|
}`,
|
|
`function mergeSortAlgorithm() {
|
|
// TODO: implement
|
|
}`,
|
|
];
|
|
|
|
const newCode = [
|
|
`C
|
|
D`,
|
|
`D
|
|
E
|
|
C
|
|
F
|
|
C`,
|
|
`C
|
|
B
|
|
A
|
|
B
|
|
A
|
|
C`,
|
|
`function mergeSortAlgorithm(arr: number[]): number[] {
|
|
if (arr.length <= 1) {
|
|
return arr;
|
|
}
|
|
|
|
const middle = Math.floor(arr.length / 2);
|
|
const left = arr.slice(0, middle);
|
|
const right = arr.slice(middle);
|
|
|
|
return merge(mergeSortAlgorithm(left), mergeSortAlgorithm(right));
|
|
}
|
|
|
|
function merge(left: number[], right: number[]): number[] {
|
|
let resultArray = [], leftIndex = 0, rightIndex = 0;
|
|
|
|
while (leftIndex < left.length && rightIndex < right.length) {
|
|
if (left[leftIndex] < right[rightIndex]) {
|
|
resultArray.push(left[leftIndex]);
|
|
leftIndex++;
|
|
} else {
|
|
resultArray.push(right[rightIndex]);
|
|
rightIndex++;
|
|
}
|
|
}
|
|
|
|
return resultArray
|
|
.concat(left.slice(leftIndex))
|
|
.concat(right.slice(rightIndex));
|
|
}`,
|
|
`function mergeSortAlgorithm(array) {
|
|
if (array.length <= 1) {
|
|
return array;
|
|
}
|
|
|
|
const mid = Math.floor(array.length / 2);
|
|
const left = array.slice(0, mid);
|
|
const right = array.slice(mid);
|
|
|
|
return merge(mergeSortAlgorithm(left), mergeSortAlgorithm(right));
|
|
}
|
|
|
|
function merge(left, right) {
|
|
let resultArray = [], leftIndex = 0, rightIndex = 0;
|
|
|
|
while (leftIndex < left.length && rightIndex < right.length) {
|
|
if (left[leftIndex] < right[rightIndex]) {
|
|
resultArray.push(left[leftIndex]);
|
|
leftIndex++;
|
|
} else {
|
|
resultArray.push(right[rightIndex]);
|
|
rightIndex++;
|
|
}
|
|
}
|
|
|
|
return resultArray
|
|
.concat(left.slice(leftIndex))
|
|
.concat(right.slice(rightIndex));
|
|
}
|
|
`,
|
|
];
|
|
|
|
async function* generateLines(lines: string[]): AsyncGenerator<string> {
|
|
for (const line of lines) {
|
|
yield line;
|
|
}
|
|
}
|
|
|
|
describe("streamDiff", () => {
|
|
for (let i = 0; i < oldCode.length; i++) {
|
|
test(`outputs valid diff #${i}`, async () => {
|
|
const oldLines = oldCode[i].split("\n");
|
|
const newLines = newCode[i].split("\n");
|
|
|
|
const diff = [];
|
|
for await (const diffLine of streamDiff(
|
|
oldLines,
|
|
generateLines(newLines),
|
|
)) {
|
|
diff.push(diffLine);
|
|
}
|
|
|
|
console.log(
|
|
diff
|
|
.map((dl) => {
|
|
return (
|
|
(dl.type === "old" ? "- " : dl.type === "new" ? "+ " : " ") +
|
|
dl.line
|
|
);
|
|
})
|
|
.join("\n"),
|
|
);
|
|
|
|
const numSame = diff.filter((dl) => dl.type === "same").length;
|
|
const numOld = diff.filter((dl) => dl.type === "old").length;
|
|
const numNew = diff.filter((dl) => dl.type === "new").length;
|
|
|
|
// Check that every line is represented
|
|
expect(oldLines.length).toEqual(numOld + numSame);
|
|
expect(newLines.length).toEqual(numNew + numSame);
|
|
|
|
// Check that there are no red lines immediately following green (they should always be above)
|
|
for (let i = 1; i < diff.length; i++) {
|
|
if (diff[i].type === "old" && diff[i - 1].type === "new") {
|
|
throw new Error(
|
|
`Found red '${diff[i].line}' immediately after green line '${
|
|
diff[i - 1].line
|
|
}`,
|
|
);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|