mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
Patch cargo script root files back to manifest
This commit is contained in:
parent
0b24599cf9
commit
46f05543a2
4 changed files with 26 additions and 16 deletions
|
@ -379,11 +379,12 @@ impl CargoWorkspace {
|
||||||
let is_local = source.is_none();
|
let is_local = source.is_none();
|
||||||
let is_member = ws_members.contains(&id);
|
let is_member = ws_members.contains(&id);
|
||||||
|
|
||||||
|
let manifest = AbsPathBuf::assert(manifest_path);
|
||||||
let pkg = packages.alloc(PackageData {
|
let pkg = packages.alloc(PackageData {
|
||||||
id: id.repr.clone(),
|
id: id.repr.clone(),
|
||||||
name,
|
name,
|
||||||
version,
|
version,
|
||||||
manifest: AbsPathBuf::assert(manifest_path).try_into().unwrap(),
|
manifest: manifest.clone().try_into().unwrap(),
|
||||||
targets: Vec::new(),
|
targets: Vec::new(),
|
||||||
is_local,
|
is_local,
|
||||||
is_member,
|
is_member,
|
||||||
|
@ -406,11 +407,22 @@ impl CargoWorkspace {
|
||||||
for meta_tgt in meta_targets {
|
for meta_tgt in meta_targets {
|
||||||
let cargo_metadata::Target { name, kind, required_features, src_path, .. } =
|
let cargo_metadata::Target { name, kind, required_features, src_path, .. } =
|
||||||
meta_tgt;
|
meta_tgt;
|
||||||
|
let kind = TargetKind::new(&kind);
|
||||||
let tgt = targets.alloc(TargetData {
|
let tgt = targets.alloc(TargetData {
|
||||||
package: pkg,
|
package: pkg,
|
||||||
name,
|
name,
|
||||||
root: AbsPathBuf::assert(src_path),
|
root: if kind == TargetKind::Bin
|
||||||
kind: TargetKind::new(&kind),
|
&& 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,
|
required_features,
|
||||||
});
|
});
|
||||||
pkg_data.targets.push(tgt);
|
pkg_data.targets.push(tgt);
|
||||||
|
|
|
@ -437,7 +437,7 @@ impl ProjectWorkspace {
|
||||||
detached_files: Vec<AbsPathBuf>,
|
detached_files: Vec<AbsPathBuf>,
|
||||||
config: &CargoConfig,
|
config: &CargoConfig,
|
||||||
) -> Vec<anyhow::Result<ProjectWorkspace>> {
|
) -> Vec<anyhow::Result<ProjectWorkspace>> {
|
||||||
dbg!(detached_files
|
detached_files
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|detached_file| {
|
.map(|detached_file| {
|
||||||
let dir = detached_file
|
let dir = detached_file
|
||||||
|
@ -508,7 +508,7 @@ impl ProjectWorkspace {
|
||||||
cargo_script,
|
cargo_script,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.collect())
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs the build scripts for this [`ProjectWorkspace`].
|
/// Runs the build scripts for this [`ProjectWorkspace`].
|
||||||
|
@ -822,7 +822,7 @@ impl ProjectWorkspace {
|
||||||
} => (
|
} => (
|
||||||
if let Some(cargo) = cargo_script {
|
if let Some(cargo) = cargo_script {
|
||||||
cargo_to_crate_graph(
|
cargo_to_crate_graph(
|
||||||
load,
|
&mut |path| load(path),
|
||||||
None,
|
None,
|
||||||
cargo,
|
cargo,
|
||||||
sysroot.as_ref().ok(),
|
sysroot.as_ref().ok(),
|
||||||
|
|
|
@ -718,9 +718,7 @@ pub fn ws_to_crate_graph(
|
||||||
let mut toolchains = Vec::default();
|
let mut toolchains = Vec::default();
|
||||||
let e = Err(Arc::from("missing layout"));
|
let e = Err(Arc::from("missing layout"));
|
||||||
for ws in workspaces {
|
for ws in workspaces {
|
||||||
dbg!(ws);
|
|
||||||
let (other, mut crate_proc_macros) = ws.to_crate_graph(&mut load, extra_env);
|
let (other, mut crate_proc_macros) = ws.to_crate_graph(&mut load, extra_env);
|
||||||
dbg!(&other);
|
|
||||||
let num_layouts = layouts.len();
|
let num_layouts = layouts.len();
|
||||||
let num_toolchains = toolchains.len();
|
let num_toolchains = toolchains.len();
|
||||||
let (ProjectWorkspace::Cargo { toolchain, target_layout, .. }
|
let (ProjectWorkspace::Cargo { toolchain, target_layout, .. }
|
||||||
|
|
|
@ -139,10 +139,10 @@ version = "0.1.0"
|
||||||
pub struct SpecialHashMap2;
|
pub struct SpecialHashMap2;
|
||||||
//- /src/lib.rs
|
//- /src/lib.rs
|
||||||
#!/usr/bin/env -S cargo +nightly -Zscript
|
#!/usr/bin/env -S cargo +nightly -Zscript
|
||||||
//! ---cargo
|
---cargo
|
||||||
//! [dependencies]
|
[dependencies]
|
||||||
//! dependency = { path = "../dependency" }
|
dependency = { path = "../dependency" }
|
||||||
//! ---
|
---
|
||||||
use dependency::Spam;
|
use dependency::Spam;
|
||||||
use dependency2::Spam;
|
use dependency2::Spam;
|
||||||
"#,
|
"#,
|
||||||
|
@ -178,10 +178,10 @@ use dependency2::Spam;
|
||||||
server.write_file_and_save(
|
server.write_file_and_save(
|
||||||
"src/lib.rs",
|
"src/lib.rs",
|
||||||
r#"#!/usr/bin/env -S cargo +nightly -Zscript
|
r#"#!/usr/bin/env -S cargo +nightly -Zscript
|
||||||
//! ---cargo
|
---cargo
|
||||||
//! [dependencies]
|
[dependencies]
|
||||||
//! dependency2 = { path = "../dependency2" }
|
dependency2 = { path = "../dependency2" }
|
||||||
//! ---
|
---
|
||||||
use dependency::Spam;
|
use dependency::Spam;
|
||||||
use dependency2::Spam;
|
use dependency2::Spam;
|
||||||
"#
|
"#
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue