Skip to content

Commit f69d83e

Browse files
committed
internal: Fix test_loading_rust_analyzer when rust-project.json is present
load_workspace_at() looks at parent directories. If rust-analyzer is in a directory (e.g. a monorepo) where a parent directory contains a rust-project.json, that configuration wins over the Cargo.toml and the test fails. One easy way of testing this is deliberately writing an invalid JSON file to the parent directory. ``` $ echo '{' > ../rust-project.json $ cargo t -p load-cargo ---- tests::test_loading_rust_analyzer stdout ---- thread 'tests::test_loading_rust_analyzer' (38576150) panicked at crates/load-cargo/src/lib.rs:756:81: called `Result::unwrap()` on an `Err` value: Failed to load the project at /Users/wilfred/src/rust-project.json Caused by: 0: Failed to deserialize json file /Users/wilfred/src/rust-project.json 1: EOF while parsing an object at line 2 column 0 ``` Instead, explicitly load the cargo workspace so the presence of a rust-project.json never changes the result of the test. AI disclosure: Written with help from Claude.
1 parent 129a4b1 commit f69d83e

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

crates/load-cargo/src/lib.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,16 +744,25 @@ mod tests {
744744

745745
#[test]
746746
fn test_loading_rust_analyzer() {
747-
let path = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap().parent().unwrap();
747+
let cargo_toml_path = Path::new(env!("CARGO_MANIFEST_DIR"))
748+
.parent()
749+
.unwrap()
750+
.parent()
751+
.unwrap()
752+
.join("Cargo.toml");
753+
let cargo_toml_path = AbsPathBuf::assert_utf8(cargo_toml_path);
754+
let manifest = ProjectManifest::from_manifest_file(cargo_toml_path).unwrap();
755+
748756
let cargo_config = CargoConfig { set_test: true, ..CargoConfig::default() };
749757
let load_cargo_config = LoadCargoConfig {
750758
load_out_dirs_from_check: false,
751759
with_proc_macro_server: ProcMacroServerChoice::None,
752760
prefill_caches: false,
753761
proc_macro_processes: 1,
754762
};
763+
let workspace = ProjectWorkspace::load(manifest, &cargo_config, &|_| {}).unwrap();
755764
let (db, _vfs, _proc_macro) =
756-
load_workspace_at(path, &cargo_config, &load_cargo_config, &|_| {}).unwrap();
765+
load_workspace(workspace, &cargo_config.extra_env, &load_cargo_config).unwrap();
757766

758767
let n_crates = db.all_crates().len();
759768
// RA has quite a few crates, but the exact count doesn't matter

0 commit comments

Comments
 (0)