Handle diff3-style merge correctly#27405
Conversation
|
@katemihalikova, thanks for your PR! By analyzing the history of the files in this pull request, we identified @pprice to be a potential reviewer. |
|
@katemihalikova, |
|
@kieferrm Not sure who owns the merge extension, hence assigning this to you. Please re-assign it to the right person. Thanks. |
pprice
left a comment
There was a problem hiding this comment.
🎉 Thank you @katemihalikova LGTM! @chrmarti / @kieferrm can give final approval.
I tested Kate's fork locally, and everything appears to be working great.
There was a problem hiding this comment.
Nit; might as well mark commonAncestors as optional e.g. commonAncestors?
There was a problem hiding this comment.
- Marked as optional
There was a problem hiding this comment.
Nit; Could be condensed to
const tokenAfterCurrentBlock = scanned.commonAncestors || scanned.splitter; There was a problem hiding this comment.
If, for some reason, we ended up with:
<<<<<<< HEAD
Foo
||||||| common
foo
||||||| common
fooo
=======
blah
>>>>>>> incoming
We will end up extending the "current" content over the first merge ancestor block. If we encounter two blocks of ||||||| I think there are two thing we could do:
- Favorable: Don't overwrite
currentConflict.commonAncestors, just leave it with the first occurrence, this way the current content block will span the correct range. (e.g.else if (currentConflict && !currentConflict.commonAncestors && line.text.startsWith(commonAncestorsMarker)) - Break out of scanning (like we do if we encounter a start marker before an end marker), so we don't provide any decoration if we are unsure what to do.
FWIW I think this is also true of existing ======= scanning...
There was a problem hiding this comment.
- Incorporated the first solution for both markers, now we are using just the first token of each type, just like TypeScript does.
Fixes pprice/vscode-better-merge#23
|
I've resolved the conflict. |
|
Thanks for your contribution @katemihalikova. I will add the workbench colors on top. One corner case is with multiple common ancestors where these have only a single header decoration. With some background colors applied this looks like: Would adding one header and one content decoration for each common ancestor improve on this? |
|
Yeah that makes sense, I'll add it. |
|
@chrmarti The last commit added support for multiple common ancestors blocks: (background colors are not included) |
|
Thanks @katemihalikova ! |


Fixes pprice/vscode-better-merge#23.
I'm using
merge.conflictStyle = diff3git setting, but the style (Current/Common ancestors/Incoming) is not supported in VS Code. In the new merge extension (#27150), the Common ancestors block is merged together with the Current block. This PR adds that support. Asdiff3is a superset of the default git conflict style, I've modified the original algorithm to support both styles. The same fix was also proposed by @spiffytech in the original issue.