feat: getCodeDiff - #52
Merged
Merged
Conversation
DoneDeal0
force-pushed
the
getCodeDiff
branch
3 times, most recently
from
September 4, 2026 20:05
41216f0 to
ef85b9d
Compare
DoneDeal0
force-pushed
the
getCodeDiff
branch
3 times, most recently
from
September 18, 2026 08:21
55ff03e to
7035492
Compare
DoneDeal0
marked this pull request as ready for review
September 18, 2026 10:47
DoneDeal0
force-pushed
the
getCodeDiff
branch
from
September 19, 2026 09:03
7035492 to
4b47f2e
Compare
DoneDeal0
force-pushed
the
getCodeDiff
branch
from
September 19, 2026 09:22
4b47f2e to
3434611
Compare
|
🎉 This PR is included in version 4.3.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GETCODEDIFF
Compares two codes and returns a structured diff: lines first, then the tokens of each changed line. Whitespace is kept, so indentation changes are reported too.
To diff files, read them first:
getCodeDiff(await previousFile.text(), await currentFile.text()).FORMAT
Input
Output
Lines start at 1.
lineisnullif the line was deleted,previousLineisnullif it was added.diffholds the token changes of anupdatedline.USAGE
Input
Output
{ type: "code", + status: "updated", diff: [ { + value: "const MAX_LENGTH = 320;", + previousValue: "const MAX = 280;", line: 1, previousLine: 1, + status: "updated", diff: [ { value: "const", status: "equal" }, + { value: " MAX_LENGTH", previousValue: " MAX", status: "updated" }, { value: " =", status: "equal" }, + { value: " 320", previousValue: " 280", status: "updated" }, { value: ";", status: "equal" }, ], }, { value: "", previousValue: "", line: 2, previousLine: 2, status: "equal", }, { value: "function preview(post) {", previousValue: "function preview(post) {", line: 3, previousLine: 3, status: "equal", }, { + value: " const text = post.body;", + previousValue: " return post.body;", line: 4, previousLine: 4, + status: "updated", diff: [ + { value: " const", previousValue: " return", status: "updated" }, + { value: " text", status: "added" }, + { value: " =", status: "added" }, { value: " post", status: "equal" }, { value: ".", status: "equal" }, { value: "body", status: "equal" }, { value: ";", status: "equal" }, ], }, { + value: " return text.slice(0, MAX_LENGTH);", line: 5, previousLine: null, + status: "added", }, { value: "}", previousValue: "}", line: 6, previousLine: 5, status: "equal", }, ], }