Conversation
Replace the flawed two-way diff-match-patch patch_apply logic with a proper three-way merge (like Git's diff3) across all merge code paths. Problem: The original code used dmp.patch_make(A,B) + dmp.patch_apply(patches, C) which silently corrupted or lost local edits when both local and remote changed the same region. No conflict detection existed (#353, #180). Changes: - src/utils/threeWayMerge.ts: line-level three-way merge engine that computes edit hunks from base->local and base->remote, detects overlapping hunks as conflicts, emits standard Git conflict markers (<<<<<<<, =======, >>>>>>>) that VS Code natively understands. - src/core/remoteFileSystemProvider.ts: writeFile() uses three-way merge. On conflict, writes markers + warns, preserves server state in _otBase field for correct post-resolution OT op computation. Zero duplication — existing OT update code reused via _otBase. - src/scm/localReplicaSCM.ts: overwrite() uses three-way merge. On conflict, writes markers locally only, blocks remote push. - src/api/socketioAlt.ts: edited-handler uses three-way merge. Removed unused DiffMatchPatch import. - test/threeWayMerge.test.ts: 29 unit tests covering trivial merges, one-side changes, non-overlapping auto-merge, 5 conflict scenarios, LaTeX content, and 3 post-conflict OT correctness invariants. Fixes #353, fixes #180
01c8c71 to
776073f
Compare
|
I'm subscribing to follow this PR because it will be a life-changing upgrade to this extension. I'm using the overleaf github integration to work with my students because it is the only safe mode to use both VSCode and Overleaf IMHO. But if this PR passes and works as planned, it will be a major step. Please, do it as soon as possible, but do it carefully. I'm looking forward to using Overleaf Workshop after this PR gets implemented. |
|
I would like to test this version, but I don't have experience with |
|
I've managed to compile. I was trying on a debian stable VM and there were issues with old versions of npm. Now with debian testing it worked. I'll install the extension now with the code from this branch and I'll report here next week. |
|
It is not working. I've opened the same overleaf project on browser and vscode. Edits on the browser appear near-instantaneously on vscode and seems fine. The issue happens when I do this:
|
Problem
When both a local user and the remote Overleaf server edit the same file, the
extension's sync/merge logic silently overwrites local changes with the
remote version. No conflict detection, no user notification, no chance to
recover lost work.
This is reported in:
Root cause: all three merge code paths used a flawed two-way
dmp.patch_applypattern:diff-match-patch'spatch_applydoes fuzzy matching and can produce garbled results when local and remote edits overlap — with zero indication that data was lost.Solution
Replaced all merge paths with a proper three-way merge (diff3-style) engine, analogous to what Git uses internally.
New:
src/utils/threeWayMerge.tsA line-level three-way merge that:
base→localandbase→remoteusing DMP's line-mode diff<<<<<<< Local/=======/>>>>>>> Remote) that VS Code natively understands and provides a merge-conflict resolution UI fortryTrivialMerge()fast-path (O(1)) covers ~95% of real-world saves: only one side changed, or both made the same editUpdated code paths
src/core/remoteFileSystemProvider.tswriteFile()— three-way merge; on conflict, writes markers to disk, shows warning, skips OT update to prevent corrupted server statesrc/scm/localReplicaSCM.tsoverwrite()— three-way merge; on conflict, writes markers to local only, warns user, blocks push to remotesrc/api/socketioAlt.tseditedhandler — three-way merge; warns on conflict; removed unused DMP importTests:
test/threeWayMerge.test.ts26 unit tests, all passing:
Algorithm
Behavior change summary
Verification
npm run compile— ✅ passes (full project + chat-view sub-project)test/threeWayMerge.test.ts— ✅ 26/26 tests passIssues Closed