-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvscode-diff-wrapper.js
More file actions
62 lines (52 loc) · 1.54 KB
/
vscode-diff-wrapper.js
File metadata and controls
62 lines (52 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env node
const { AdvancedLinesDiffComputer } = require('vscode-diff');
async function readInput() {
let input = '';
process.stdin.setEncoding('utf8');
return new Promise((resolve) => {
process.stdin.on('data', (chunk) => {
input += chunk;
});
process.stdin.on('end', () => {
try {
resolve(JSON.parse(input));
} catch (e) {
console.log(JSON.stringify({
success: false,
error: "Failed to parse input: " + e.message
}));
process.exit(1);
}
});
});
}
async function main() {
try {
const { original, modified, options = {} } = await readInput();
// VSCode partial-diff default settings
const diffOptions = {
ignoreTrimWhitespace: options.ignoreTrimWhitespace || false,
computeMoves: false, // Better for indentation changes
maxComputationTimeMs: options.maxComputationTimeMs || 5000
};
const diffComputer = new AdvancedLinesDiffComputer();
const result = diffComputer.computeDiff(original, modified, diffOptions);
// Output result with innerChanges
console.log(JSON.stringify({
success: true,
changes: result.changes.map(change => ({
originalRange: change.originalRange,
modifiedRange: change.modifiedRange,
innerChanges: change.innerChanges || []
})),
moves: result.moves || []
}));
} catch (error) {
console.log(JSON.stringify({
success: false,
error: error.message
}));
process.exit(1);
}
}
main();