aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmil Lauridsen <[email protected]>2020-03-16 13:10:13 +0000
committerEmil Lauridsen <[email protected]>2020-03-17 13:47:05 +0000
commitf5a2fcf8f59eda3498bbdcb87568e5ba6b4db8b7 (patch)
tree1ace16a13f74d6165780b8054b0b4e8b43f945c2
parent33c6c7abc6621f8b0cf083a98f7e4788cf4b5b54 (diff)
Change existing OUT_DIR override config to make use of new infrastructure
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs8
-rw-r--r--crates/ra_project_model/src/lib.rs28
-rw-r--r--crates/rust-analyzer/src/cli/load_cargo.rs11
-rw-r--r--crates/rust-analyzer/src/config.rs4
-rw-r--r--crates/rust-analyzer/src/main_loop.rs1
-rw-r--r--crates/rust-analyzer/src/world.rs18
-rw-r--r--editors/code/package.json10
-rw-r--r--editors/code/src/config.ts3
8 files changed, 26 insertions, 57 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
44impl Default for CargoFeatures { 47impl 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 });
diff --git a/editors/code/package.json b/editors/code/package.json
index 188a2f9ca..b4128acf0 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -237,11 +237,6 @@
237 "default": true, 237 "default": true,
238 "description": "Whether to ask for permission before downloading any files from the Internet" 238 "description": "Whether to ask for permission before downloading any files from the Internet"
239 }, 239 },
240 "rust-analyzer.additionalOutDirs": {
241 "type": "object",
242 "default": {},
243 "markdownDescription": "Fine grained controls for OUT_DIR `env!(\"OUT_DIR\")` variable. e.g. `{\"foo\":\"/path/to/foo\"}`, "
244 },
245 "rust-analyzer.serverPath": { 240 "rust-analyzer.serverPath": {
246 "type": [ 241 "type": [
247 "null", 242 "null",
@@ -367,6 +362,11 @@
367 "type": "boolean", 362 "type": "boolean",
368 "default": false, 363 "default": false,
369 "markdownDescription": "Run `cargo check` on startup to get the correct value for package OUT_DIRs" 364 "markdownDescription": "Run `cargo check` on startup to get the correct value for package OUT_DIRs"
365 },
366 "rust-analyzer.cargoFeatures.outDirOverrides": {
367 "type": "object",
368 "default": {},
369 "markdownDescription": "Fine grained controls for OUT_DIR `env!(\"OUT_DIR\")` variable. e.g. `{\"foo 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)\":\"/path/to/foo\"}`, "
370 } 370 }
371 } 371 }
372 }, 372 },
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index 84ec81ecd..c7323f6e9 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -23,6 +23,7 @@ export interface CargoFeatures {
23 allFeatures: boolean; 23 allFeatures: boolean;
24 features: string[]; 24 features: string[];
25 loadOutDirsFromCheck: boolean; 25 loadOutDirsFromCheck: boolean;
26 outDirOverrides: Record<string, string>;
26} 27}
27 28
28export const enum UpdatesChannel { 29export const enum UpdatesChannel {
@@ -203,7 +204,6 @@ export class Config {
203 get excludeGlobs() { return this.cfg.get("excludeGlobs") as string[]; } 204 get excludeGlobs() { return this.cfg.get("excludeGlobs") as string[]; }
204 get useClientWatching() { return this.cfg.get("useClientWatching") as boolean; } 205 get useClientWatching() { return this.cfg.get("useClientWatching") as boolean; }
205 get featureFlags() { return this.cfg.get("featureFlags") as Record<string, boolean>; } 206 get featureFlags() { return this.cfg.get("featureFlags") as Record<string, boolean>; }
206 get additionalOutDirs() { return this.cfg.get("additionalOutDirs") as Record<string, string>; }
207 get rustfmtArgs() { return this.cfg.get("rustfmtArgs") as string[]; } 207 get rustfmtArgs() { return this.cfg.get("rustfmtArgs") as string[]; }
208 get loadOutDirsFromCheck() { return this.cfg.get("loadOutDirsFromCheck") as boolean; } 208 get loadOutDirsFromCheck() { return this.cfg.get("loadOutDirsFromCheck") as boolean; }
209 209
@@ -222,6 +222,7 @@ export class Config {
222 allFeatures: this.cfg.get("cargoFeatures.allFeatures") as boolean, 222 allFeatures: this.cfg.get("cargoFeatures.allFeatures") as boolean,
223 features: this.cfg.get("cargoFeatures.features") as string[], 223 features: this.cfg.get("cargoFeatures.features") as string[],
224 loadOutDirsFromCheck: this.cfg.get("cargoFeatures.loadOutDirsFromCheck") as boolean, 224 loadOutDirsFromCheck: this.cfg.get("cargoFeatures.loadOutDirsFromCheck") as boolean,
225 outDirOverrides: this.cfg.get("cargoFeatures.outDirOverrides") as Record<string, string>,
225 }; 226 };
226 } 227 }
227 228