diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_project_model/src/cargo_workspace.rs | 8 | ||||
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 28 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/load_cargo.rs | 11 | ||||
-rw-r--r-- | crates/rust-analyzer/src/config.rs | 4 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 1 | ||||
-rw-r--r-- | crates/rust-analyzer/src/world.rs | 18 |
6 files changed, 19 insertions, 51 deletions
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index eeeb10233..97fa48b8b 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs | |||
@@ -39,6 +39,9 @@ pub struct CargoFeatures { | |||
39 | 39 | ||
40 | /// Runs cargo check on launch to figure out the correct values of OUT_DIR | 40 | /// Runs cargo check on launch to figure out the correct values of OUT_DIR |
41 | pub load_out_dirs_from_check: bool, | 41 | pub load_out_dirs_from_check: bool, |
42 | |||
43 | /// Fine grained controls for additional `OUT_DIR` env variables | ||
44 | pub out_dir_overrides: FxHashMap<PackageId, PathBuf>, | ||
42 | } | 45 | } |
43 | 46 | ||
44 | impl Default for CargoFeatures { | 47 | impl Default for CargoFeatures { |
@@ -48,6 +51,7 @@ impl Default for CargoFeatures { | |||
48 | all_features: true, | 51 | all_features: true, |
49 | features: Vec::new(), | 52 | features: Vec::new(), |
50 | load_out_dirs_from_check: false, | 53 | load_out_dirs_from_check: false, |
54 | out_dir_overrides: FxHashMap::default(), | ||
51 | } | 55 | } |
52 | } | 56 | } |
53 | } | 57 | } |
@@ -191,6 +195,10 @@ impl CargoWorkspace { | |||
191 | if cargo_features.load_out_dirs_from_check { | 195 | if cargo_features.load_out_dirs_from_check { |
192 | out_dir_by_id = load_out_dirs(cargo_toml, cargo_features); | 196 | out_dir_by_id = load_out_dirs(cargo_toml, cargo_features); |
193 | } | 197 | } |
198 | // We explicitly extend afterwards to allow overriding the value returned by cargo | ||
199 | out_dir_by_id.extend( | ||
200 | cargo_features.out_dir_overrides.iter().map(|(id, path)| (id.clone(), path.clone())), | ||
201 | ); | ||
194 | 202 | ||
195 | let mut pkg_by_id = FxHashMap::default(); | 203 | let mut pkg_by_id = FxHashMap::default(); |
196 | let mut packages = Arena::default(); | 204 | let mut packages = Arena::default(); |
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 43f834253..b2c3e576d 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -177,7 +177,6 @@ impl ProjectWorkspace { | |||
177 | pub fn to_crate_graph( | 177 | pub fn to_crate_graph( |
178 | &self, | 178 | &self, |
179 | default_cfg_options: &CfgOptions, | 179 | default_cfg_options: &CfgOptions, |
180 | additional_out_dirs: &FxHashMap<String, PathBuf>, | ||
181 | extern_source_roots: &FxHashMap<PathBuf, ExternSourceId>, | 180 | extern_source_roots: &FxHashMap<PathBuf, ExternSourceId>, |
182 | load: &mut dyn FnMut(&Path) -> Option<FileId>, | 181 | load: &mut dyn FnMut(&Path) -> Option<FileId>, |
183 | ) -> CrateGraph { | 182 | ) -> CrateGraph { |
@@ -251,15 +250,8 @@ impl ProjectWorkspace { | |||
251 | opts | 250 | opts |
252 | }; | 251 | }; |
253 | 252 | ||
254 | let mut env = Env::default(); | 253 | let env = Env::default(); |
255 | let mut extern_source = ExternSource::default(); | 254 | let extern_source = ExternSource::default(); |
256 | if let Some(path) = additional_out_dirs.get(krate.name(&sysroot)) { | ||
257 | env.set("OUT_DIR", path.to_string_lossy().to_string()); | ||
258 | if let Some(extern_source_id) = extern_source_roots.get(path) { | ||
259 | extern_source.set_extern_path(&path, *extern_source_id); | ||
260 | } | ||
261 | } | ||
262 | |||
263 | let crate_id = crate_graph.add_crate_root( | 255 | let crate_id = crate_graph.add_crate_root( |
264 | file_id, | 256 | file_id, |
265 | Edition::Edition2018, | 257 | Edition::Edition2018, |
@@ -310,19 +302,11 @@ impl ProjectWorkspace { | |||
310 | }; | 302 | }; |
311 | let mut env = Env::default(); | 303 | let mut env = Env::default(); |
312 | let mut extern_source = ExternSource::default(); | 304 | let mut extern_source = ExternSource::default(); |
313 | if let Some(out_dir) = dbg!(pkg.out_dir(cargo)) { | 305 | if let Some(out_dir) = pkg.out_dir(cargo) { |
306 | // FIXME: We probably mangle non UTF-8 paths here, figure out a better solution | ||
314 | env.set("OUT_DIR", out_dir.to_string_lossy().to_string()); | 307 | env.set("OUT_DIR", out_dir.to_string_lossy().to_string()); |
315 | if let Some(extern_source_id) = | 308 | if let Some(&extern_source_id) = extern_source_roots.get(out_dir) { |
316 | dbg!(dbg!(&extern_source_roots).get(out_dir)) | 309 | extern_source.set_extern_path(&out_dir, extern_source_id); |
317 | { | ||
318 | extern_source.set_extern_path(&out_dir, *extern_source_id); | ||
319 | } | ||
320 | } else { | ||
321 | if let Some(path) = additional_out_dirs.get(pkg.name(&cargo)) { | ||
322 | env.set("OUT_DIR", path.to_string_lossy().to_string()); | ||
323 | if let Some(extern_source_id) = extern_source_roots.get(path) { | ||
324 | extern_source.set_extern_path(&path, *extern_source_id); | ||
325 | } | ||
326 | } | 310 | } |
327 | } | 311 | } |
328 | let crate_id = crate_graph.add_crate_root( | 312 | let crate_id = crate_graph.add_crate_root( |
diff --git a/crates/rust-analyzer/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs index 7d75b991d..af61d1e0a 100644 --- a/crates/rust-analyzer/src/cli/load_cargo.rs +++ b/crates/rust-analyzer/src/cli/load_cargo.rs | |||
@@ -53,19 +53,14 @@ pub(crate) fn load_cargo( | |||
53 | }; | 53 | }; |
54 | 54 | ||
55 | // FIXME: outdirs? | 55 | // FIXME: outdirs? |
56 | let outdirs = FxHashMap::default(); | ||
57 | let extern_source_roots = FxHashMap::default(); | 56 | let extern_source_roots = FxHashMap::default(); |
58 | 57 | ||
59 | let crate_graph = ws.to_crate_graph( | 58 | let crate_graph = |
60 | &default_cfg_options, | 59 | ws.to_crate_graph(&default_cfg_options, &extern_source_roots, &mut |path: &Path| { |
61 | &outdirs, | ||
62 | &extern_source_roots, | ||
63 | &mut |path: &Path| { | ||
64 | let vfs_file = vfs.load(path); | 60 | let vfs_file = vfs.load(path); |
65 | log::debug!("vfs file {:?} -> {:?}", path, vfs_file); | 61 | log::debug!("vfs file {:?} -> {:?}", path, vfs_file); |
66 | vfs_file.map(vfs_file_to_id) | 62 | vfs_file.map(vfs_file_to_id) |
67 | }, | 63 | }); |
68 | ); | ||
69 | log::debug!("crate graph: {:?}", crate_graph); | 64 | log::debug!("crate graph: {:?}", crate_graph); |
70 | 65 | ||
71 | let source_roots = roots | 66 | let source_roots = roots |
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 6b9a11a87..103b2b53c 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs | |||
@@ -48,9 +48,6 @@ pub struct ServerConfig { | |||
48 | /// Fine grained feature flags to disable specific features. | 48 | /// Fine grained feature flags to disable specific features. |
49 | pub feature_flags: FxHashMap<String, bool>, | 49 | pub feature_flags: FxHashMap<String, bool>, |
50 | 50 | ||
51 | /// Fine grained controls for additional `OUT_DIR` env variables | ||
52 | pub additional_out_dirs: FxHashMap<String, String>, | ||
53 | |||
54 | pub rustfmt_args: Vec<String>, | 51 | pub rustfmt_args: Vec<String>, |
55 | 52 | ||
56 | /// Cargo feature configurations. | 53 | /// Cargo feature configurations. |
@@ -76,7 +73,6 @@ impl Default for ServerConfig { | |||
76 | cargo_watch_all_targets: true, | 73 | cargo_watch_all_targets: true, |
77 | with_sysroot: true, | 74 | with_sysroot: true, |
78 | feature_flags: FxHashMap::default(), | 75 | feature_flags: FxHashMap::default(), |
79 | additional_out_dirs: FxHashMap::default(), | ||
80 | cargo_features: Default::default(), | 76 | cargo_features: Default::default(), |
81 | rustfmt_args: Vec::new(), | 77 | rustfmt_args: Vec::new(), |
82 | vscode_lldb: false, | 78 | vscode_lldb: false, |
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 1fefc66aa..a8a5894d2 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -204,7 +204,6 @@ pub fn main_loop( | |||
204 | Watch(!config.use_client_watching), | 204 | Watch(!config.use_client_watching), |
205 | options, | 205 | options, |
206 | feature_flags, | 206 | feature_flags, |
207 | config.additional_out_dirs, | ||
208 | ) | 207 | ) |
209 | }; | 208 | }; |
210 | 209 | ||
diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs index 63e913047..c4244fee2 100644 --- a/crates/rust-analyzer/src/world.rs +++ b/crates/rust-analyzer/src/world.rs | |||
@@ -82,7 +82,6 @@ impl WorldState { | |||
82 | watch: Watch, | 82 | watch: Watch, |
83 | options: Options, | 83 | options: Options, |
84 | feature_flags: FeatureFlags, | 84 | feature_flags: FeatureFlags, |
85 | additional_out_dirs: FxHashMap<String, String>, | ||
86 | ) -> WorldState { | 85 | ) -> WorldState { |
87 | let mut change = AnalysisChange::new(); | 86 | let mut change = AnalysisChange::new(); |
88 | 87 | ||
@@ -105,8 +104,7 @@ impl WorldState { | |||
105 | })); | 104 | })); |
106 | } | 105 | } |
107 | 106 | ||
108 | let mut extern_dirs: FxHashSet<_> = | 107 | let mut extern_dirs = FxHashSet::default(); |
109 | additional_out_dirs.iter().map(|(_, path)| (PathBuf::from(path))).collect(); | ||
110 | for ws in workspaces.iter() { | 108 | for ws in workspaces.iter() { |
111 | extern_dirs.extend(ws.out_dirs()); | 109 | extern_dirs.extend(ws.out_dirs()); |
112 | } | 110 | } |
@@ -152,21 +150,9 @@ impl WorldState { | |||
152 | vfs_file.map(|f| FileId(f.0)) | 150 | vfs_file.map(|f| FileId(f.0)) |
153 | }; | 151 | }; |
154 | 152 | ||
155 | let additional_out_dirs: FxHashMap<String, PathBuf> = additional_out_dirs | ||
156 | .into_iter() | ||
157 | .map(|(name, path)| (name, PathBuf::from(&path))) | ||
158 | .collect(); | ||
159 | |||
160 | workspaces | 153 | workspaces |
161 | .iter() | 154 | .iter() |
162 | .map(|ws| { | 155 | .map(|ws| ws.to_crate_graph(&default_cfg_options, &extern_source_roots, &mut load)) |
163 | ws.to_crate_graph( | ||
164 | &default_cfg_options, | ||
165 | &additional_out_dirs, | ||
166 | &extern_source_roots, | ||
167 | &mut load, | ||
168 | ) | ||
169 | }) | ||
170 | .for_each(|graph| { | 156 | .for_each(|graph| { |
171 | crate_graph.extend(graph); | 157 | crate_graph.extend(graph); |
172 | }); | 158 | }); |