Skip to content

Commit 546339a

Browse files
committed
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 #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.
2 parents 68f3e4d + 85ca217 commit 546339a

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

crates/load-cargo/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ impl ProjectFolders {
265265
entries.push(manifest.to_owned());
266266
}
267267

268+
for buildfile in ws.buildfiles() {
269+
file_set_roots.push(VfsPath::from(buildfile.to_owned()));
270+
entries.push(buildfile.to_owned());
271+
}
272+
268273
// In case of detached files we do **not** look for a rust-analyzer.toml.
269274
if !matches!(ws.kind, ProjectWorkspaceKind::DetachedFile { .. }) {
270275
let ws_root = ws.workspace_root();

crates/project-model/src/workspace.rs

+11
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,17 @@ impl ProjectWorkspace {
539539
}
540540
}
541541

542+
pub fn buildfiles(&self) -> Vec<AbsPathBuf> {
543+
match &self.kind {
544+
ProjectWorkspaceKind::Json(project) => project
545+
.crates()
546+
.filter_map(|(_, krate)| krate.build.as_ref().map(|build| build.build_file.clone()))
547+
.map(AbsPathBuf::assert)
548+
.collect(),
549+
_ => vec![],
550+
}
551+
}
552+
542553
pub fn find_sysroot_proc_macro_srv(&self) -> anyhow::Result<AbsPathBuf> {
543554
self.sysroot.discover_proc_macro_srv()
544555
}

0 commit comments

Comments
 (0)