aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_project_model')
-rw-r--r--crates/ra_project_model/src/lib.rs36
1 files changed, 28 insertions, 8 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index bcf12460d..a6274709d 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -14,7 +14,7 @@ use std::{
14 14
15use anyhow::{bail, Context, Result}; 15use anyhow::{bail, Context, Result};
16use ra_cfg::CfgOptions; 16use ra_cfg::CfgOptions;
17use ra_db::{CrateGraph, CrateId, CrateName, Edition, Env, FileId}; 17use ra_db::{CrateGraph, CrateName, Edition, Env, ExternSource, ExternSourceId, FileId};
18use rustc_hash::FxHashMap; 18use rustc_hash::FxHashMap;
19use serde_json::from_reader; 19use serde_json::from_reader;
20 20
@@ -162,10 +162,10 @@ impl ProjectWorkspace {
162 pub fn to_crate_graph( 162 pub fn to_crate_graph(
163 &self, 163 &self,
164 default_cfg_options: &CfgOptions, 164 default_cfg_options: &CfgOptions,
165 outdirs: &FxHashMap<String, (ExternSourceId, String)>,
165 load: &mut dyn FnMut(&Path) -> Option<FileId>, 166 load: &mut dyn FnMut(&Path) -> Option<FileId>,
166 ) -> (CrateGraph, FxHashMap<CrateId, String>) { 167 ) -> CrateGraph {
167 let mut crate_graph = CrateGraph::default(); 168 let mut crate_graph = CrateGraph::default();
168 let mut names = FxHashMap::default();
169 match self { 169 match self {
170 ProjectWorkspace::Json { project } => { 170 ProjectWorkspace::Json { project } => {
171 let mut crates = FxHashMap::default(); 171 let mut crates = FxHashMap::default();
@@ -186,13 +186,18 @@ impl ProjectWorkspace {
186 } 186 }
187 opts 187 opts
188 }; 188 };
189
190 // FIXME: No crate name in json definition such that we cannot add OUT_DIR to env
189 crates.insert( 191 crates.insert(
190 crate_id, 192 crate_id,
191 crate_graph.add_crate_root( 193 crate_graph.add_crate_root(
192 file_id, 194 file_id,
193 edition, 195 edition,
196 // FIXME json definitions can store the crate name
197 None,
194 cfg_options, 198 cfg_options,
195 Env::default(), 199 Env::default(),
200 Default::default(),
196 ), 201 ),
197 ); 202 );
198 } 203 }
@@ -230,14 +235,22 @@ impl ProjectWorkspace {
230 opts 235 opts
231 }; 236 };
232 237
238 let mut env = Env::default();
239 let mut extern_source = ExternSource::default();
240 if let Some((id, path)) = outdirs.get(krate.name(&sysroot)) {
241 env.set("OUT_DIR", path.clone());
242 extern_source.set_extern_path(&path, *id);
243 }
244
233 let crate_id = crate_graph.add_crate_root( 245 let crate_id = crate_graph.add_crate_root(
234 file_id, 246 file_id,
235 Edition::Edition2018, 247 Edition::Edition2018,
248 Some(krate.name(&sysroot).to_string()),
236 cfg_options, 249 cfg_options,
237 Env::default(), 250 env,
251 extern_source,
238 ); 252 );
239 sysroot_crates.insert(krate, crate_id); 253 sysroot_crates.insert(krate, crate_id);
240 names.insert(crate_id, krate.name(&sysroot).to_string());
241 } 254 }
242 } 255 }
243 for from in sysroot.crates() { 256 for from in sysroot.crates() {
@@ -274,13 +287,20 @@ impl ProjectWorkspace {
274 opts.insert_features(pkg.features(&cargo).iter().map(Into::into)); 287 opts.insert_features(pkg.features(&cargo).iter().map(Into::into));
275 opts 288 opts
276 }; 289 };
290 let mut env = Env::default();
291 let mut extern_source = ExternSource::default();
292 if let Some((id, path)) = outdirs.get(pkg.name(&cargo)) {
293 env.set("OUT_DIR", path.clone());
294 extern_source.set_extern_path(&path, *id);
295 }
277 let crate_id = crate_graph.add_crate_root( 296 let crate_id = crate_graph.add_crate_root(
278 file_id, 297 file_id,
279 edition, 298 edition,
299 Some(pkg.name(&cargo).to_string()),
280 cfg_options, 300 cfg_options,
281 Env::default(), 301 env,
302 extern_source,
282 ); 303 );
283 names.insert(crate_id, pkg.name(&cargo).to_string());
284 if tgt.kind(&cargo) == TargetKind::Lib { 304 if tgt.kind(&cargo) == TargetKind::Lib {
285 lib_tgt = Some(crate_id); 305 lib_tgt = Some(crate_id);
286 pkg_to_lib_crate.insert(pkg, crate_id); 306 pkg_to_lib_crate.insert(pkg, crate_id);
@@ -381,7 +401,7 @@ impl ProjectWorkspace {
381 } 401 }
382 } 402 }
383 } 403 }
384 (crate_graph, names) 404 crate_graph
385 } 405 }
386 406
387 pub fn workspace_root_for(&self, path: &Path) -> Option<&Path> { 407 pub fn workspace_root_for(&self, path: &Path) -> Option<&Path> {