Skip to content

Commit a6960fb

Browse files
committed
simplify
1 parent 0a658c4 commit a6960fb

File tree

1 file changed

+32
-41
lines changed

1 file changed

+32
-41
lines changed

crates/project_model/src/workspace.rs

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,8 @@ impl ProjectWorkspace {
7070
format!("Failed to deserialize json file {}", project_json.display())
7171
})?;
7272
let project_location = project_json.parent().unwrap().to_path_buf();
73-
let project = ProjectJson::new(&project_location, data);
74-
let sysroot = match &project.sysroot_src {
75-
Some(path) => Some(Sysroot::load(path)?),
76-
None => None,
77-
};
78-
ProjectWorkspace::Json { project, sysroot }
73+
let project_json = ProjectJson::new(&project_location, data);
74+
ProjectWorkspace::load_inline(project_json)?
7975
}
8076
ProjectManifest::CargoToml(cargo_toml) => {
8177
let cargo_version = utf8_stdout({
@@ -150,43 +146,38 @@ impl ProjectWorkspace {
150146
})
151147
}))
152148
.collect::<Vec<_>>(),
153-
ProjectWorkspace::Cargo { cargo, sysroot, rustc } => {
154-
let roots = cargo
155-
.packages()
156-
.map(|pkg| {
157-
let is_member = cargo[pkg].is_member;
158-
let pkg_root = cargo[pkg].root().to_path_buf();
159-
160-
let mut include = vec![pkg_root.clone()];
161-
include.extend(cargo[pkg].out_dir.clone());
162-
163-
let mut exclude = vec![pkg_root.join(".git")];
164-
if is_member {
165-
exclude.push(pkg_root.join("target"));
166-
} else {
167-
exclude.push(pkg_root.join("tests"));
168-
exclude.push(pkg_root.join("examples"));
169-
exclude.push(pkg_root.join("benches"));
170-
}
171-
PackageRoot { is_member, include, exclude }
172-
})
173-
.chain(sysroot.crates().map(|krate| PackageRoot {
149+
ProjectWorkspace::Cargo { cargo, sysroot, rustc } => cargo
150+
.packages()
151+
.map(|pkg| {
152+
let is_member = cargo[pkg].is_member;
153+
let pkg_root = cargo[pkg].root().to_path_buf();
154+
155+
let mut include = vec![pkg_root.clone()];
156+
include.extend(cargo[pkg].out_dir.clone());
157+
158+
let mut exclude = vec![pkg_root.join(".git")];
159+
if is_member {
160+
exclude.push(pkg_root.join("target"));
161+
} else {
162+
exclude.push(pkg_root.join("tests"));
163+
exclude.push(pkg_root.join("examples"));
164+
exclude.push(pkg_root.join("benches"));
165+
}
166+
PackageRoot { is_member, include, exclude }
167+
})
168+
.chain(sysroot.crates().map(|krate| PackageRoot {
169+
is_member: false,
170+
include: vec![sysroot[krate].root_dir().to_path_buf()],
171+
exclude: Vec::new(),
172+
}))
173+
.chain(rustc.into_iter().flat_map(|rustc| {
174+
rustc.packages().map(move |krate| PackageRoot {
174175
is_member: false,
175-
include: vec![sysroot[krate].root_dir().to_path_buf()],
176+
include: vec![rustc[krate].root().to_path_buf()],
176177
exclude: Vec::new(),
177-
}));
178-
if let Some(rustc_packages) = rustc {
179-
roots
180-
.chain(rustc_packages.packages().map(|krate| PackageRoot {
181-
is_member: false,
182-
include: vec![rustc_packages[krate].root().to_path_buf()],
183-
exclude: Vec::new(),
184-
}))
185-
.collect()
186-
} else {
187-
roots.collect()
188-
}
189-
}
178+
})
179+
}))
180+
.collect(),
190181
}
191182
}
192183

0 commit comments

Comments
 (0)