Unnamed repository; edit this file 'description' to name the repository.
Auto merge of #18192 - darichey:read-buildfile-into-vfs, r=Veykril
Include buildfiles in VFS We subscribe to `textDocument/didSave` for `filesToWatch`, but the VFS doesn't contain those files. Before https://github.com/rust-lang/rust-analyzer/pull/18105, this would bring down the server. Now, it's only a benign error logged: ``` ERROR notification handler failed handler=textDocument/didSave error=file not found: /foo/bar/TARGETS ``` It's benign, because we will also receive a `workspace/didChangeWatchedFiles` for the file which will invalidate and load it. Explicitly include the buildfiles in the VFS to prevent the handler from erroring.
bors 2024-09-28
parent 68f3e4d · parent 85ca217 · commit 546339a
-rw-r--r--crates/load-cargo/src/lib.rs5
-rw-r--r--crates/project-model/src/workspace.rs11
2 files changed, 16 insertions, 0 deletions
diff --git a/crates/load-cargo/src/lib.rs b/crates/load-cargo/src/lib.rs
index baa4517423..2ffefa1730 100644
--- a/crates/load-cargo/src/lib.rs
+++ b/crates/load-cargo/src/lib.rs
@@ -265,6 +265,11 @@ impl ProjectFolders {
entries.push(manifest.to_owned());
}
+ for buildfile in ws.buildfiles() {
+ file_set_roots.push(VfsPath::from(buildfile.to_owned()));
+ entries.push(buildfile.to_owned());
+ }
+
// In case of detached files we do **not** look for a rust-analyzer.toml.
if !matches!(ws.kind, ProjectWorkspaceKind::DetachedFile { .. }) {
let ws_root = ws.workspace_root();
diff --git a/crates/project-model/src/workspace.rs b/crates/project-model/src/workspace.rs
index 17b40a87cd..c05c03340e 100644
--- a/crates/project-model/src/workspace.rs
+++ b/crates/project-model/src/workspace.rs
@@ -539,6 +539,17 @@ impl ProjectWorkspace {
}
}
+ pub fn buildfiles(&self) -> Vec<AbsPathBuf> {
+ match &self.kind {
+ ProjectWorkspaceKind::Json(project) => project
+ .crates()
+ .filter_map(|(_, krate)| krate.build.as_ref().map(|build| build.build_file.clone()))
+ .map(AbsPathBuf::assert)
+ .collect(),
+ _ => vec![],
+ }
+ }
+
pub fn find_sysroot_proc_macro_srv(&self) -> anyhow::Result<AbsPathBuf> {
self.sysroot.discover_proc_macro_srv()
}