-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat: Character-level diffs #273
Merged
Merged
Conversation
This file contains 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
a8f0c37
to
af81545
Compare
a3257ff
to
895ba40
Compare
Up until this commit, `diffsitter` has computed diffs by directing comparing the equality of the text of two nodes. This means that if two nodes had text content that was unequal *at all*, the contents of that *entire* node would be considered a difference. As a concrete example, consider the two snippets: ```rust fn example_a() {} fn example_b() {} ``` The diff would see the text corresponding to the identifiers for each function are different, so the corresponding diff would be: ``` -example_a +example_b ``` Because we just check if `"example_a" == "example_b"`. What we really want is: ``` -a +b ``` We are able to achieve this by breaking up each node into `Entry` objects that correspond to a single unicode grapheme, so when the diffs are computed, they are on a per-grapheme basis rather than at a per-node basis. Of course, the actual diff mechanism is generic, so we only have to modify how the `Entry` object is created, and the diff and hunk construction mechanisms remain unchanged. This PR also adds test cases for medium-length source files.
895ba40
to
c89f395
Compare
afnanenayet
added a commit
that referenced
this pull request
Feb 26, 2022
This reverts commit 879d21c.
afnanenayet
added a commit
that referenced
this pull request
Feb 26, 2022
afnanenayet
added a commit
that referenced
this pull request
Mar 5, 2022
Up until this commit, `diffsitter` has computed diffs by directing comparing the equality of the text of two nodes. This means that if two nodes had text content that was unequal *at all*, the contents of that *entire* node would be considered a difference. As a concrete example, consider the two snippets: ```rust fn example_a() {} fn example_b() {} ``` The diff would see the text corresponding to the identifiers for each function are different, so the corresponding diff would be: ``` -example_a +example_b ``` Because we just check if `"example_a" == "example_b"`. What we really want is: ``` -a +b ``` We are able to achieve this by breaking up each node into `Entry` objects that correspond to a single unicode grapheme, so when the diffs are computed, they are on a per-grapheme basis rather than at a per-node basis. Of course, the actual diff mechanism is generic, so we only have to modify how the `Entry` object is created, and the diff and hunk construction mechanisms remain unchanged. This PR also adds test cases for medium-length source files.
afnanenayet
added a commit
that referenced
this pull request
Mar 5, 2022
Up until this commit, `diffsitter` has computed diffs by directing comparing the equality of the text of two nodes. This means that if two nodes had text content that was unequal *at all*, the contents of that *entire* node would be considered a difference. As a concrete example, consider the two snippets: ```rust fn example_a() {} fn example_b() {} ``` The diff would see the text corresponding to the identifiers for each function are different, so the corresponding diff would be: ``` -example_a +example_b ``` Because we just check if `"example_a" == "example_b"`. What we really want is: ``` -a +b ``` We are able to achieve this by breaking up each node into `Entry` objects that correspond to a single unicode grapheme, so when the diffs are computed, they are on a per-grapheme basis rather than at a per-node basis. Of course, the actual diff mechanism is generic, so we only have to modify how the `Entry` object is created, and the diff and hunk construction mechanisms remain unchanged. This PR also adds test cases for medium-length source files.
# for free
to join this conversation on GitHub.
Already have an account?
# 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.
Up until this commit,
diffsitter
has computed diffs by directingcomparing the equality of the text of two nodes. This means that if two
nodes had text content that was unequal at all, the contents of that
entire node would be considered a difference.
As a concrete example, consider the two snippets:
The diff would see the text corresponding to the identifiers for each
function are different, so the corresponding diff would be:
Because we just check if
"example_a" == "example_b"
. What we reallywant is:
We are able to achieve this by breaking up each node into
Entry
objects that correspond to a single unicode grapheme, so when the diffs
are computed, they are on a per-grapheme basis rather than at a per-node
basis. Of course, the actual diff mechanism is generic, so we only have
to modify how the
Entry
object is created, and the diff and hunkconstruction mechanisms remain unchanged.
This PR also updates the equality check to account for the type of a node, so a
comparison between:
would treat the different
fn
blocks as different based on whether they are akeyword or as part of an identifier.