Skip to content

search: Fix deleted files persisting in project search results#50551

Merged
osiewicz merged 3 commits intozed-industries:mainfrom
Dnreikronos:fix-deleted-files-in-search-results
Mar 19, 2026
Merged

search: Fix deleted files persisting in project search results#50551
osiewicz merged 3 commits intozed-industries:mainfrom
Dnreikronos:fix-deleted-files-in-search-results

Conversation

@Dnreikronos
Copy link
Copy Markdown
Contributor

Closes #50524

When a file is deleted while project search results are displayed, the deleted file's buffer was kept alive by the search multibuffer and would reappear on re-search.

Root cause: Search::into_handle() treated buffers without a project_entry_id() (which happens when DiskState::Deleted) as "unnamed buffers" and fed them
directly into the search pipeline. The multibuffer's strong Entity<Buffer> reference kept the buffer alive.

Fix:

  • Filter deleted-file buffers from search candidates in into_handle() and all_loaded_buffers()
  • Subscribe to FileHandleChanged events on the search multibuffer to proactively remove deleted files from existing results

Before you mark this PR as ready for review, make sure that you have:

  • Added a solid test coverage and/or screenshots from doing manual testing
  • Done a self-review taking into account security and performance aspects
  • Aligned any UI changes with the UI checklist

Video:

https://drive.google.com/file/d/1pEz6JywFcZlz8aiXbLOxIdj84SQWLIiF/view?usp=sharing

Release Notes:

  • Fixed deleted files persisting in project search results

   Add test_deleted_file_removed_from_search_results covering proactive
   removal and re-search filtering. Scope the excerpts borrow in a block
   to avoid a dropping_references warning.
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 3, 2026
@prayanshchh
Copy link
Copy Markdown
Contributor

does this fix #28398 (I was hoping to take that one)

@Dnreikronos
Copy link
Copy Markdown
Contributor Author

does this fix #28398 (I was hoping to take that one)

This partially addresses #28398, specifically the part about deleted files persisting in search results. The
other scenario described in #28398 (unsaved/untitled buffers remaining in the multibuffer after being closed
without saving) is not covered by this PR and is still open for contribution.

@osiewicz
Copy link
Copy Markdown
Member

Thank you for your PR!

Subscribe to FileHandleChanged events on the search multibuffer to proactively remove deleted files from existing results

I'm not sure about that behavior, but let's roll with it.

Specifically, I don't think we have a precedent for removing entries from an existing multi-buffer.

Copy link
Copy Markdown
Member

@osiewicz osiewicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice and clean 👍

@Dnreikronos
Copy link
Copy Markdown
Contributor Author

LGTM, nice and clean 👍

First of all, thanks for your time invested @osiewicz!

I adjusted the rustfmt errors. Can you run the tests again?

@osiewicz
Copy link
Copy Markdown
Member

Let's merge this after today's releases to have 2 weeks of baking time on Nightly/Preview.

@Dnreikronos
Copy link
Copy Markdown
Contributor Author

Let's merge this after today's releases to have 2 weeks of baking time on Nightly/Preview.

Yeah, sounds good for me!

@osiewicz osiewicz merged commit 0238d2d into zed-industries:main Mar 19, 2026
29 checks passed
AmaanBilwar pushed a commit to AmaanBilwar/zed that referenced this pull request Mar 20, 2026
…ndustries#50551)

Closes zed-industries#50524

When a file is deleted while project search results are displayed, the
deleted file's buffer was kept alive by the search multibuffer and would
reappear on re-search.

**Root cause:** `Search::into_handle()` treated buffers without a
`project_entry_id()` (which happens when `DiskState::Deleted`) as
"unnamed buffers" and fed them
directly into the search pipeline. The multibuffer's strong
`Entity<Buffer>` reference kept the buffer alive.

**Fix:**
- Filter deleted-file buffers from search candidates in `into_handle()`
and `all_loaded_buffers()`
- Subscribe to `FileHandleChanged` events on the search multibuffer to
proactively remove deleted files from existing results

Before you mark this PR as ready for review, make sure that you have:
- [x] Added a solid test coverage and/or screenshots from doing manual
testing
- [x] Done a self-review taking into account security and performance
aspects
- [ ] Aligned any UI changes with the [UI
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)

### Video:

https://drive.google.com/file/d/1pEz6JywFcZlz8aiXbLOxIdj84SQWLIiF/view?usp=sharing

Release Notes:

- Fixed deleted files persisting in project search results
toshmukhamedov pushed a commit to toshmukhamedov/zed that referenced this pull request Mar 20, 2026
…ndustries#50551)

Closes zed-industries#50524

When a file is deleted while project search results are displayed, the
deleted file's buffer was kept alive by the search multibuffer and would
reappear on re-search.

**Root cause:** `Search::into_handle()` treated buffers without a
`project_entry_id()` (which happens when `DiskState::Deleted`) as
"unnamed buffers" and fed them
directly into the search pipeline. The multibuffer's strong
`Entity<Buffer>` reference kept the buffer alive.

**Fix:**
- Filter deleted-file buffers from search candidates in `into_handle()`
and `all_loaded_buffers()`
- Subscribe to `FileHandleChanged` events on the search multibuffer to
proactively remove deleted files from existing results

Before you mark this PR as ready for review, make sure that you have:
- [x] Added a solid test coverage and/or screenshots from doing manual
testing
- [x] Done a self-review taking into account security and performance
aspects
- [ ] Aligned any UI changes with the [UI
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)

### Video:

https://drive.google.com/file/d/1pEz6JywFcZlz8aiXbLOxIdj84SQWLIiF/view?usp=sharing

Release Notes:

- Fixed deleted files persisting in project search results
AmaanBilwar pushed a commit to AmaanBilwar/zed that referenced this pull request Mar 23, 2026
…ndustries#50551)

Closes zed-industries#50524

When a file is deleted while project search results are displayed, the
deleted file's buffer was kept alive by the search multibuffer and would
reappear on re-search.

**Root cause:** `Search::into_handle()` treated buffers without a
`project_entry_id()` (which happens when `DiskState::Deleted`) as
"unnamed buffers" and fed them
directly into the search pipeline. The multibuffer's strong
`Entity<Buffer>` reference kept the buffer alive.

**Fix:**
- Filter deleted-file buffers from search candidates in `into_handle()`
and `all_loaded_buffers()`
- Subscribe to `FileHandleChanged` events on the search multibuffer to
proactively remove deleted files from existing results

Before you mark this PR as ready for review, make sure that you have:
- [x] Added a solid test coverage and/or screenshots from doing manual
testing
- [x] Done a self-review taking into account security and performance
aspects
- [ ] Aligned any UI changes with the [UI
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)

### Video:

https://drive.google.com/file/d/1pEz6JywFcZlz8aiXbLOxIdj84SQWLIiF/view?usp=sharing

Release Notes:

- Fixed deleted files persisting in project search results
@jrmajor
Copy link
Copy Markdown

jrmajor commented Mar 29, 2026

This was a big issue for me, thanks so much @Dnreikronos!

@Dnreikronos
Copy link
Copy Markdown
Contributor Author

This was a big issue for me, thanks so much @Dnreikronos!

You're welcome, mate!
Any problem, I'm here happy to help!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deleted files are impossible to remove from search results

4 participants