Skip to content

Handle buffers' files changing on disk from outside of Zed - #54

Merged
maxbrunsfeld merged 11 commits into
masterfrom
file-changed-on-disk
May 13, 2021
Merged

Handle buffers' files changing on disk from outside of Zed#54
maxbrunsfeld merged 11 commits into
masterfrom
file-changed-on-disk

Conversation

@maxbrunsfeld

@maxbrunsfeld maxbrunsfeld commented May 11, 2021

Copy link
Copy Markdown
Collaborator

Fixes #52

  • Allow buffers to observe changes to files' contents with FileHandle::observe_from_model. Before, this callback would only be called when a file was moved or deleted. Now, we store an mtime on each FileHandle so that content changes are also reported.
  • Add a Buffer::set_text_via_diff method that takes a string of new text, computes a corresponding diff in a background thread, and applies that diff to the buffer.
  • When there's an on-disk change to the file of an unmodified buffer, update the buffer to reflect the new contents.
  • Add a has_conflict method to Workspace::Item trait. Use that method to give special visual treatment to buffers that have in-memory changes and on-disk changes since they were loaded. Right now, we show a red dot for these files, instead of a blue dot.
  • When attempting to save a pane item with conflicts, show a confirm dialog saying something like "This file has changed on disk since you started editing it. Do you want to overwrite it?" Only perform the save if the user clicks confirm.

@maxbrunsfeld
maxbrunsfeld force-pushed the file-changed-on-disk branch from fd697c5 to 3fa03c4 Compare May 11, 2021 22:44
@maxbrunsfeld
maxbrunsfeld force-pushed the file-changed-on-disk branch from 3fa03c4 to 040189d Compare May 11, 2021 23:18
@maxbrunsfeld

Copy link
Copy Markdown
Collaborator Author

@nathansobo @as-cii One thing that's currently incomplete in this PR is deciding when we should populate/update the mtime field on a FileHandle. I started by populating it in the BackgroundScanner on FS events, and I wanted to avoid doing IO directly in WorkspaceHandle::file so as not to block the main thread, but perhaps we should always update the handle's mtime in methods like ::save and ::load_history.

@as-cii

as-cii commented May 12, 2021

Copy link
Copy Markdown
Member

Okay, so I think 6240334 should address showing a dialog when there's a conflict when trying to save a file, and ac2168f will take care of refreshing the file handle synchronously on save/load.

048bbc9 also adds a little bit of infrastructure so that we can test prompting via the TestAppContext.

@as-cii
as-cii force-pushed the file-changed-on-disk branch from 265052e to 048bbc9 Compare May 12, 2021 13:21
@maxbrunsfeld
maxbrunsfeld merged commit 0187b6d into master May 13, 2021
@maxbrunsfeld
maxbrunsfeld deleted the file-changed-on-disk branch May 13, 2021 03:19
Anthony-Eid added a commit to Anthony-Eid/zed that referenced this pull request Oct 27, 2024
* Begin integrating languages with DAP

* Add dap status type to activity indicator

Co-authored-by: Remco Smits <djsmits12@gmail.com>

* Show dap status to users

* Change Status enum to use ServerStatus struct in activity indicator

---------

Co-authored-by: Remco Smits <djsmits12@gmail.com>
ShalashaskaOcelot pushed a commit to ShalashaskaOcelot/zed that referenced this pull request Jul 30, 2026
Two user-reported defects:

workspace: saving to a path outside the project showed "Failed to save: no such
worktree" even though the bytes reached disk, and left the item still titled
"Untitled" and detached from its file (bug zed-industries#47). Phase 53 made such a save
create an INVISIBLE worktree, which the worktree store holds only weakly, and
Pane::save_item's strong handle lived inside the `if let` block — so it dropped
before save_task.await and destroyed the worktree mid-save. The notebook's
save_as writes the file and only then opens a buffer, so open_buffer failed and
the `?` skipped the code that records the new path. Hold the worktree until the
save completes.

repl: clicking the sidebar's kernel selector aborted the app with a GPUI
double-lease panic (bug zed-industries#54) — the click listener held a lease and toggled the
picker inline, whose on_open updates the same notebook. Defer the toggle via
window.defer, matching the existing fix for the run-with-no-kernel path, and
give launch_kernel's show the same treatment.

Also fixes a clippy lint in the bug zed-industries#50 regression test.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUB73REGigaN5TCgvSkM2s
ShalashaskaOcelot pushed a commit to ShalashaskaOcelot/zed that referenced this pull request Jul 30, 2026
…tebooks (bug zed-industries#56)

A notebook opened or saved outside the project lives in a single-file worktree
whose abs_path() is the FILE, not a directory. The kernel was spawned with that
path as its working directory, which Windows rejects with ERROR_DIRECTORY
("The directory name is invalid", os error 267) — so no interpreter could start
for such a notebook. Use the file's parent directory when the worktree is a
single file; directory worktrees are unchanged.

Also archives phases 53/55/57 and bugs zed-industries#47/zed-industries#54 as user-confirmed, ticks the
confirmed phase 48 items, and files bug zed-industries#59 (external notebooks not restored
across a restart).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUB73REGigaN5TCgvSkM2s
ShalashaskaOcelot pushed a commit to ShalashaskaOcelot/zed that referenced this pull request Aug 6, 2026
Audited every CHANGELOG claim against the code: all phase and bug entries are
genuinely implemented (symbol checks for each), and every commit hash inside
this shallow clone's history resolves to the work it claims. Nothing needed
pulling out for review.

Fixes found along the way:
- Bugs zed-industries#47 and zed-industries#54 were archived as user-confirmed by c199237 but that commit
  never deleted their bugs.md entries, so both were double-tracked. Removed.
- Bug zed-industries#63 was still "open — needs a decision" although phase 59 implemented the
  decided behaviour. Moved to fix attempted - untested with the fix recorded.
- Bugs zed-industries#7, zed-industries#15 and zed-industries#20 sat at fix attempted - untested with no pointer in the
  testing ledger, so they were invisible there. Added with test recipes.
- Bug zed-industries#56's changelog hash was a transposition (c199273c199237).

Phases 59 and 60 are implementation-complete with only manual tests left, so
their test items move to awaiting_testing.md and the phase files are recorded
in the changelog and deleted. Six phases remain in rotation.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUB73REGigaN5TCgvSkM2s
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
…-on-disk

Handle buffers' files changing on disk from outside of Zed
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.

Detect conflict between file system and buffer contents when file system changes

2 participants