Skip to content

feat(editor): detect and resolve external file conflicts - #330

Merged
fcoury-oai merged 1 commit into
mainfrom
fcoury/external-file-conflicts
Aug 23, 2026
Merged

fcoury-oai merged 1 commit into
mainfrom
fcoury/external-file-conflicts

Conversation

@fcoury-oai

Copy link
Copy Markdown
Collaborator

Why

The save-time protection already prevents Red from silently overwriting files changed outside the editor, but users still discover conflicts only when they try to save. Clean buffers do not follow external changes, dirty buffers have no persistent conflict indicator, and agent writes can replace unsaved edits before persistence fails.

What changed

  • Watch every named, non-scratch buffer with native filesystem notifications and a metadata-polling fallback; verify suspected changes against the exact last-loaded or saved file contents.
  • Automatically reload clean buffers through undoable editor transactions while preserving focus, cursor position, and LSP/plugin notifications; retain deleted files and unsaved edits instead of discarding either version.
  • Surface external modifications and deletions through warning notifications, [CONFLICT] / [DELETED] statusline markers, buffer metadata, and plugin events.
  • Add :diffdisk with a safe-by-default conflict comparison, explicit :w! / :w! <file> overrides, and guidance for :e! or saving local changes elsewhere.
  • Reject agent writes before mutation when the backing file changed or the proposed edit overlaps unsaved human changes, while allowing edits to unrelated ranges.

How to Test

  1. Open an existing file in Red without editing it, change the file from another terminal, and verify Red reloads the new contents automatically without marking the buffer dirty. Undo once and verify the previous contents remain recoverable.
  2. Make an unsaved edit in Red, modify the same file externally, and verify the statusline shows [CONFLICT]. Run :w and confirm both the external file contents and local buffer contents remain unchanged.
  3. Run :diffdisk and verify it displays both versions. Press Enter to accept the default Keep edits action and confirm nothing is overwritten; reopen the comparison and choose Overwrite, or run :w!, to explicitly replace the file and clear the conflict.
  4. Delete an open file externally and verify [DELETED] remains visible without discarding the buffer. Save to a new path with :w <file> and confirm the deleted source is not recreated.
  5. Run cargo test --lib file_watch, cargo test --test editing forced_write, and cargo test --test editing disk_conflict_comparison_defaults_to_preserving_both_versions to cover watching, explicit overwrite, and the safe-default comparison flow.

Validated on the PR branch: 2,372 library tests and 483 editor/LSP integration tests pass; formatting and cargo clippy --all-targets --all-features -- -D warnings are clean. The same change rebased locally onto current main also passes 2,385 library tests and all 483 editor/LSP integration tests.

@fcoury
fcoury force-pushed the fcoury/external-file-conflicts branch from 8e22d6a to 9d8ac08 Compare August 23, 2026 17:48
@fcoury-oai
fcoury-oai merged commit 0c27121 into main Aug 23, 2026
10 checks passed
@fcoury-oai
fcoury-oai deleted the fcoury/external-file-conflicts branch August 23, 2026 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant