zed
zed copied to clipboard
`rust-analyzer` won't stop checking and indexing
Summary
With Zed nightly, rust-analyzer gets into a loop where it repeatedly re-checks and re-indexes the projeect.
Description
While working on a project with Zed nightly, rust-analyzer starts checking and indexing as soon as it's done. The loop means that error underlines keep flickering in-and-out and LSP features don't work. Trying out rust-analyzer with other editors on the same project (helix and VSCode) doesn't reproduce the problem.
I see a lot of content modified in Zed.log:
2025-06-03T11:35:58-04:00 WARN [project::lsp_store] Get hover via rust-analyzer failed: content modified
2025-06-03T11:35:58-04:00 WARN [project::lsp_store] Get definition via rust-analyzer failed: content modified
2025-06-03T11:35:58-04:00 ERROR [project] Get hover via rust-analyzer failed: content modified
2025-06-03T11:36:44-04:00 WARN [project::lsp_store] Get definition via rust-analyzer failed: content modified
2025-06-03T11:37:38-04:00 INFO [db] Opening main db
2025-06-03T11:37:38-04:00 WARN [project::lsp_store] Get type definition via rust-analyzer failed: content modified
2025-06-03T11:37:52-04:00 WARN [project::lsp_store] Get code actions via rust-analyzer failed: content modified
and the lsp RPC logs are flying by at a pretty rapid rate while my mouse/keyboard are untouched.
Here's the start of my LSP Server Info:
* Server: rust-analyzer (id 2)
* Binary: LanguageServerBinary {
path: "/Users/benl/Library/Application Support/Zed/languages/rust-analyzer/rust-analyzer-2025-06-02",
arguments: [],
...
Zed Version and System Specs
Zed: v0.189.4 (Zed Preview) OS: macOS 15.5.0 Memory: 48 GiB Architecture: aarch64
I spent some time looking at this yesterday and it seems like this is a bad interaction between generated code and Zed's file watching. I'm using prost to generate code and save it in src/pb/. Those files get removed and re-generated on every cargo check or cargo build by my build.rs. It seems like this is getting everything into a loop where rust-analyzer check changes the files, which makes Zed immediately ask rust-analyzer to re-check the project.
I don't have a repro I can share, but my build.rs looks somethign like this:
let glob_path = base_dir.as_ref().join("**/*.proto");
let proto_paths = glob::glob(glob_path.to_str().expect("base_dir was invalid utf-8"))
.expect("generated invalid glob pattern")
.flatten()
.collect();
match std::fs::remove_dir_all("src/pb") {
Ok(()) => (),
Err(e) if e.kind() == ErrorKind::NotFound => (),
Err(e) => return Err(e),
}
std::fs::create_dir_all("src/pb")?;
prost_build::Config::new()
// a bunch of stuff elided here...
.out_dir("src/pb")
.compile_protos(proto_paths, include_paths);
Same here for ... -- Zed 0.192.6 -- PHP -- macOS (MacBook M4)
Indexing never ends and stops at 59.05%.
When it gets stuck at 59 %, hovering classes, methods etc. does not work anymore. No hovercards are shown and right-click functions like "Go to Defintion" etc. does not work in this case which makes the Zed editor useless.
This seems to be fixed in my case (Zed 0.195.4).
This is a rust-analyzer issue and it's kind of known there (though I don't recall if there was an issue for that). Build scripts deleting and re-creating files like that outside the out dir causes r-a to re-index.