diff --git a/crates/project-model/src/cargo_workspace.rs b/crates/project-model/src/cargo_workspace.rs index 7bba987f7d..ff7cf144aa 100644 --- a/crates/project-model/src/cargo_workspace.rs +++ b/crates/project-model/src/cargo_workspace.rs @@ -379,11 +379,12 @@ impl CargoWorkspace { let is_local = source.is_none(); let is_member = ws_members.contains(&id); + let manifest = AbsPathBuf::assert(manifest_path); let pkg = packages.alloc(PackageData { id: id.repr.clone(), name, version, - manifest: AbsPathBuf::assert(manifest_path).try_into().unwrap(), + manifest: manifest.clone().try_into().unwrap(), targets: Vec::new(), is_local, is_member, @@ -406,11 +407,22 @@ impl CargoWorkspace { for meta_tgt in meta_targets { let cargo_metadata::Target { name, kind, required_features, src_path, .. } = meta_tgt; + let kind = TargetKind::new(&kind); let tgt = targets.alloc(TargetData { package: pkg, name, - root: AbsPathBuf::assert(src_path), - kind: TargetKind::new(&kind), + root: if kind == TargetKind::Bin + && manifest.extension().is_some_and(|ext| ext == "rs") + { + // cargo strips the script part of a cargo script away and places the + // modified manifest file into a special target dir which is then used as + // the source path. We don't want that, we want the original here so map it + // back + manifest.clone() + } else { + AbsPathBuf::assert(src_path) + }, + kind, required_features, }); pkg_data.targets.push(tgt); diff --git a/crates/project-model/src/workspace.rs b/crates/project-model/src/workspace.rs index dca2c8d739..7709f99b2e 100644 --- a/crates/project-model/src/workspace.rs +++ b/crates/project-model/src/workspace.rs @@ -437,7 +437,7 @@ impl ProjectWorkspace { detached_files: Vec, config: &CargoConfig, ) -> Vec> { - dbg!(detached_files + detached_files .into_iter() .map(|detached_file| { let dir = detached_file @@ -508,7 +508,7 @@ impl ProjectWorkspace { cargo_script, }) }) - .collect()) + .collect() } /// Runs the build scripts for this [`ProjectWorkspace`]. @@ -822,7 +822,7 @@ impl ProjectWorkspace { } => ( if let Some(cargo) = cargo_script { cargo_to_crate_graph( - load, + &mut |path| load(path), None, cargo, sysroot.as_ref().ok(), diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index 84db3c6720..557faaf84c 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs @@ -718,9 +718,7 @@ pub fn ws_to_crate_graph( let mut toolchains = Vec::default(); let e = Err(Arc::from("missing layout")); for ws in workspaces { - dbg!(ws); let (other, mut crate_proc_macros) = ws.to_crate_graph(&mut load, extra_env); - dbg!(&other); let num_layouts = layouts.len(); let num_toolchains = toolchains.len(); let (ProjectWorkspace::Cargo { toolchain, target_layout, .. } diff --git a/crates/rust-analyzer/tests/slow-tests/main.rs b/crates/rust-analyzer/tests/slow-tests/main.rs index 715fed5fef..22d8b6bdf1 100644 --- a/crates/rust-analyzer/tests/slow-tests/main.rs +++ b/crates/rust-analyzer/tests/slow-tests/main.rs @@ -139,10 +139,10 @@ version = "0.1.0" pub struct SpecialHashMap2; //- /src/lib.rs #!/usr/bin/env -S cargo +nightly -Zscript -//! ---cargo -//! [dependencies] -//! dependency = { path = "../dependency" } -//! --- +---cargo +[dependencies] +dependency = { path = "../dependency" } +--- use dependency::Spam; use dependency2::Spam; "#, @@ -178,10 +178,10 @@ use dependency2::Spam; server.write_file_and_save( "src/lib.rs", r#"#!/usr/bin/env -S cargo +nightly -Zscript -//! ---cargo -//! [dependencies] -//! dependency2 = { path = "../dependency2" } -//! --- +---cargo +[dependencies] +dependency2 = { path = "../dependency2" } +--- use dependency::Spam; use dependency2::Spam; "#