Skip to content

Commit 23684da

Browse files
committed
chore: fix doc and demo
1 parent d874900 commit 23684da

6 files changed

Lines changed: 19 additions & 154 deletions

File tree

.github/workflows/tests.yml

Whitespace-only changes.

README.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,8 @@ five`;
2121

2222
const docModified = doc.replace(/t/g, "T") + "\nSix";
2323

24-
const diffResult = linesDiffComputers
25-
.getDefault()
26-
.computeDiff(doc, docModified, {
27-
computeMoves: true,
28-
ignoreTrimWhitespace: true,
29-
maxComputationTimeMs: 100,
30-
});
24+
const codiff = new Codiff();
25+
const result = codiff.computeDiff(doc, docmodified);
3126
```
3227

3328
diff result:
@@ -102,8 +97,9 @@ diff result:
10297
]
10398
}
10499
],
105-
"moves": [],
106-
"hitTimeout": false
100+
"quitEarly": false,
101+
"identical": false,
102+
"moves": []
107103
}
108104
```
109105

packages/codiff/src/diff/defaultDocumentDiffProvider.ts

Lines changed: 0 additions & 121 deletions
This file was deleted.

packages/codiff/src/diff/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export * from "./documentDiffProvider.js";
2-
export * from "./defaultDocumentDiffProvider.js";
32
export * from "./legacyLinesDiffComputer.js";
43
export * from "./linesDiffComputer.js";
54
export * from "./linesDiffComputers.js";

packages/codiff/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from "./common/index.js";
22
export * from "./diff/index.js";
3+
export * from "./codiff.js";

packages/playground/src/App.tsx

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect, useState } from "react";
22
import CodeMirror from "@uiw/react-codemirror";
33
import "./App.css";
4-
import { linesDiffComputers } from "codiff";
4+
import { Codiff } from "codiff";
55
import { Change, Chunk } from "@codemirror/merge";
66
import { Text } from "@codemirror/state";
77
import { generateSimilarCode } from "./util";
@@ -11,16 +11,12 @@ import { json } from "@codemirror/lang-json";
1111
const Original = CodeMirrorMerge.Original;
1212
const Modified = CodeMirrorMerge.Modified;
1313

14+
const codiff = new Codiff();
15+
1416
const overrideBuild = () => {
1517
const buildChunks = (a: Text, b: Text): readonly Chunk[] => {
1618
console.log("diff compute");
17-
const result = linesDiffComputers
18-
.getDefault()
19-
.computeDiff(a.toJSON(), b.toJSON(), {
20-
computeMoves: true,
21-
ignoreTrimWhitespace: true,
22-
maxComputationTimeMs: 100,
23-
});
19+
const result = codiff.computeDiff(a.toString(), b.toString());
2420
return result.changes.map<Chunk>((item) => {
2521
const getPosition = (text: Text, from: number, to: number) => {
2622
if (from === to) {
@@ -36,13 +32,13 @@ const overrideBuild = () => {
3632
const origin = getPosition(
3733
a,
3834
item.original.startLineNumber,
39-
item.original.endLineNumberExclusive,
35+
item.original.endLineNumberExclusive
4036
);
4137

4238
const modified = getPosition(
4339
b,
4440
item.modified.startLineNumber,
45-
item.modified.endLineNumberExclusive,
41+
item.modified.endLineNumberExclusive
4642
);
4743

4844
const nonNegative = (a: number) => {
@@ -55,25 +51,25 @@ const overrideBuild = () => {
5551
a.line(inner.originalRange.startLineNumber).from +
5652
inner.originalRange.startColumn -
5753
1 -
58-
origin.from,
54+
origin.from
5955
),
6056
toA: nonNegative(
6157
a.line(inner.originalRange.endLineNumber).from +
6258
inner.originalRange.endColumn -
6359
1 -
64-
origin.from,
60+
origin.from
6561
),
6662
fromB: nonNegative(
6763
b.line(inner.modifiedRange.startLineNumber).from +
6864
inner.modifiedRange.startColumn -
6965
1 -
70-
modified.from,
66+
modified.from
7167
),
7268
toB: nonNegative(
7369
b.line(inner.modifiedRange.endLineNumber).from +
7470
inner.modifiedRange.endColumn -
7571
1 -
76-
modified.from,
72+
modified.from
7773
),
7874
};
7975
});
@@ -83,7 +79,7 @@ const overrideBuild = () => {
8379
origin.from,
8480
origin.to + 1,
8581
modified.from,
86-
modified.to + 1,
82+
modified.to + 1
8783
);
8884
return chunk;
8985
});
@@ -118,21 +114,15 @@ function App() {
118114
const handleGenerate = () => {
119115
const { codeA: origin, codeB: modified } = generateSimilarCode(
120116
maxLine,
121-
maxDiff,
117+
maxDiff
122118
);
123119
setOrigin(origin);
124120
setModified(modified);
125121
};
126122

127123
useEffect(() => {
128124
const start = performance.now();
129-
const result = linesDiffComputers
130-
.getDefault()
131-
.computeDiff(origin.split("\n"), modified.split("\n"), {
132-
computeMoves: true,
133-
ignoreTrimWhitespace: true,
134-
maxComputationTimeMs: 100,
135-
});
125+
const result = codiff.computeDiff(origin, modified);
136126
const end = performance.now();
137127
setDiffms((end - start).toFixed(3));
138128
setDiff(JSON.stringify(result, undefined, 2));

0 commit comments

Comments
 (0)