zed
zed copied to clipboard
Deleting files doesn't refresh project search
Summary
If you perform a project search, delete a file/files within Zed that were included in the search, the results in the project search do not disappear. Further, if you then click into the search field and hit enter (to re-search) the files are still there (stale cache?)
Steps to reproduce:
- Have two files (A.txt, B.txt) with the word "hello" in both
- Do project search for "hello", both files show up
- Remove B.txt, project search still shows B.txt
- Click into search field and hit enter, still shows B.txt
Expected Behavior: Should detect when files are deleted and remove results Actual Behavior: Keeps showing files in search even after deletion
Zed Version and System Specs
Zed: v0.187.2 (Zed Preview) OS: macOS 15.4.1 Memory: 18 GiB Architecture: aarch64
Are there any workarounds? I get this issue very often and since quite a while. Restarting the language server doesn't clear that out.
I can reproduce. Closing the project search tab and opening a new one seems to fix the issue. Seems like we are holding on to a buffer reference that keeps the deleted file alive.
Closing as duplicate of:
- https://github.com/zed-industries/zed/issues/28398
@notpeter Hmm, is this really a duplicate? That other ticket is a bug about unsaved buffers and not being able to close the search tab without prompts. This ticket is about deleting existing files and those results still showing up in the search tab, even after resubmitting the search. Seems like two separate issues.
I believe the root cause is the same.
Zed is not correctly notifying the search multibuffer to remove the result when the underlying buffer non-longer exists (either because the file was deleted or because the unsaved buffer was destroyed). The multi-buffer keeps a reference (now stale) which causes incorrect behavior.
If you close the search multi-buffer and then search for hello again it works as expected. If you re-use the project search for something else (foobar) and then search again for hello it works as expected. It's the fact that the project search gets the results of the search before releasing its buffer references that causes the b.txt to stick around -- if we remove the deleted file from the project search multi-buffer, subsequent searches will also be correct.