Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 780c0f3

Browse files
committedDec 4, 2024·
Prefer workspace for root_module path
1 parent 02ba512 commit 780c0f3

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed
 

‎test/rust_analyzer/generated_srcs_test/rust_project_json_test.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ mod tests {
4848
.find(|c| &c.display_name == "generated_srcs")
4949
.unwrap();
5050
assert!(gen.root_module.starts_with("/"));
51-
assert!(gen.root_module.ends_with("/lib.rs"));
51+
assert!(gen
52+
.root_module
53+
.ends_with("rules_rust_test_rust_analyzer/lib.rs"));
5254

5355
let include_dirs = &gen.source.as_ref().unwrap().include_dirs;
5456
assert!(include_dirs.len() == 1);

‎tools/rust_analyzer/aquery.rs

+9
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,15 @@ fn consolidate_crate_specs(crate_specs: Vec<CrateSpec>) -> anyhow::Result<BTreeS
208208
existing.proc_macro_dylib_path.replace(dylib_path.clone());
209209
}
210210
}
211+
212+
// Prefer using workspace for root_module path if possible.
213+
// A test crate might get an __EXEC_ROOT__-based root_module when depending
214+
// on a library crate with mixed generated sources, for example.
215+
if existing.root_module.starts_with("__EXEC_ROOT__")
216+
&& spec.root_module.starts_with("__WORKSPACE__")
217+
{
218+
existing.root_module = spec.root_module;
219+
}
211220
} else {
212221
consolidated_specs.insert(spec.crate_id.clone(), spec);
213222
}

0 commit comments

Comments
 (0)
Please sign in to comment.