editor: Fix stale session path for renamed files#52539
Merged
ChristopherBiscardi merged 5 commits intozed-industries:mainfrom Apr 15, 2026
Merged
Conversation
Contributor
Author
|
@ChristopherBiscardi can you activate the CI/CD pipeline for this PR ? Thank you |
ChristopherBiscardi
approved these changes
Apr 15, 2026
Contributor
ChristopherBiscardi
left a comment
There was a problem hiding this comment.
Thanks! This does indeed fix the issue
G36maid
pushed a commit
to G36maid/zed
that referenced
this pull request
Apr 29, 2026
## Context When a file is renamed via the project panel while open in an editor, Zed would restore the old (no longer existing) path on reload . On rename, `language::Buffer` emits `BufferEvent::FileHandleChanged`, which propagates to `multi_buffer::Event::FileHandleChanged` → `EditorEvent::TitleChanged`. However, `should_serialize()` only matched `Saved | DirtyChanged | BufferEdited`, so no re-serialization was triggered and the `editors` DB table retained the stale `abs_path`. The fix adds a dedicated `EditorEvent::FileHandleChanged` variant, emits it alongside `TitleChanged` when the buffer's file handle changes, and adds it to `should_serialize()`. Since `Editor::serialize()` already reads the current path from the buffer at call time, this naturally writes the new path to the DB. Closes zed-industries#51629 ## How to Review Three files edited: - `editor.rs`: splits `FileHandleChanged` into its own arm and emits the new event variant - `items.rs`: adds `FileHandleChanged` to `should_serialize` - `items.rs` (test): `test_file_handle_changed_on_rename` does a full rename via `Project::rename_entry` and asserts the event fires and the buffer path updates ## Self-Review Checklist - [x] I've reviewed my own diff for quality, security, and reliability - [ ] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Release Notes: - Fixed renamed files being reopened with their old path after a restart **Important remark :** This pull request is a follow-up on the review of @SomeoneToIgnore on this pull request, zed-industries#51717, which was inadvertently closed because I mistakenly deleted my previous fork of the zed repo, sorry for any inconvenience caused by this Manual test video below : [Screencast from 2026-03-16 23-28-46.webm](https://github.com/user-attachments/assets/ff2e3259-ae26-4655-83b8-f693e84306d2)
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in 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.
Context
When a file is renamed via the project panel while open in an editor, Zed would restore the old (no longer existing) path on reload .
On rename,
language::BufferemitsBufferEvent::FileHandleChanged, which propagates tomulti_buffer::Event::FileHandleChanged→EditorEvent::TitleChanged. However,should_serialize()only matchedSaved | DirtyChanged | BufferEdited, so no re-serialization was triggered and theeditorsDB table retained the staleabs_path.The fix adds a dedicated
EditorEvent::FileHandleChangedvariant, emits it alongsideTitleChangedwhen the buffer's file handle changes, and adds it toshould_serialize(). SinceEditor::serialize()already reads the current path from the buffer at call time, this naturally writes the new path to the DB.Closes #51629
How to Review
Three files edited:
editor.rs: splitsFileHandleChangedinto its own arm and emits the new event variantitems.rs: addsFileHandleChangedtoshould_serializeitems.rs(test):test_file_handle_changed_on_renamedoes a full rename viaProject::rename_entryand asserts the event fires and the buffer path updatesSelf-Review Checklist
Release Notes:
Important remark :
This pull request is a follow-up on the review of @SomeoneToIgnore on this pull request, #51717, which was inadvertently closed because I mistakenly deleted my previous fork of the zed repo, sorry for any inconvenience caused by this
Manual test video below :
Screencast.from.2026-03-16.23-28-46.webm