From f55b1d1e19cb960c7ce99f15c88ce4b214d568dd Mon Sep 17 00:00:00 2001 From: rezural Date: Tue, 22 Jun 2021 08:59:57 +1000 Subject: [PATCH] add extra include paths, if target's path is manually set in Cargo.toml to be --- crates/project_model/src/workspace.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/crates/project_model/src/workspace.rs b/crates/project_model/src/workspace.rs index e67ba2bd928..5c178785d80 100644 --- a/crates/project_model/src/workspace.rs +++ b/crates/project_model/src/workspace.rs @@ -234,6 +234,23 @@ pub fn to_roots(&self, build_data: Option<&BuildDataResult>) -> Vec .and_then(|it| it.out_dir.clone()), ); + // In case target's path is manually set in Cargo.toml to be + // outside the package root, add its parent as an extra include. + // An example of this situation would look like this: + // + // ```toml + // [lib] + // path = "../../src/lib.rs" + // ``` + let extra_targets = cargo[pkg] + .targets + .iter() + .filter(|&&tgt| cargo[tgt].kind == TargetKind::Lib) + .filter_map(|&tgt| cargo[tgt].root.parent()) + .map(|tgt| tgt.normalize().to_path_buf()) + .filter(|path| !path.starts_with(pkg_root.clone())); + include.extend(extra_targets); + let mut exclude = vec![pkg_root.join(".git")]; if is_member { exclude.push(pkg_root.join("target")); -- 2.44.0