aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe MASSOLIN <[email protected]>2020-04-26 23:11:04 +0100
committerChristophe MASSOLIN <[email protected]>2020-04-26 23:11:04 +0100
commitb7edffe244581b428a4b4da4ff6a08ab461b018f (patch)
tree0f59a9f3e952181b25a99374ace25f7165dafb56
parent5671bacfa66a9d83daa1cc42f72ec8701412ccdc (diff)
Started rust-analyzer.cargo.defaultTarget implementation
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs12
-rw-r--r--crates/rust-analyzer/src/config.rs1
-rw-r--r--editors/code/package.json8
3 files changed, 21 insertions, 0 deletions
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs
index 362ee30fe..810833b64 100644
--- a/crates/ra_project_model/src/cargo_workspace.rs
+++ b/crates/ra_project_model/src/cargo_workspace.rs
@@ -43,6 +43,11 @@ impl ops::Index<Target> for CargoWorkspace {
43} 43}
44 44
45#[derive(Clone, Debug, PartialEq, Eq)] 45#[derive(Clone, Debug, PartialEq, Eq)]
46pub struct RustcConfig {
47 pub default_target: Option<String>,
48}
49
50#[derive(Clone, Debug, PartialEq, Eq)]
46pub struct CargoConfig { 51pub struct CargoConfig {
47 /// Do not activate the `default` feature. 52 /// Do not activate the `default` feature.
48 pub no_default_features: bool, 53 pub no_default_features: bool,
@@ -56,6 +61,9 @@ pub struct CargoConfig {
56 61
57 /// Runs cargo check on launch to figure out the correct values of OUT_DIR 62 /// Runs cargo check on launch to figure out the correct values of OUT_DIR
58 pub load_out_dirs_from_check: bool, 63 pub load_out_dirs_from_check: bool,
64
65 /// rustc config
66 pub rustc: RustcConfig,
59} 67}
60 68
61impl Default for CargoConfig { 69impl Default for CargoConfig {
@@ -65,6 +73,7 @@ impl Default for CargoConfig {
65 all_features: true, 73 all_features: true,
66 features: Vec::new(), 74 features: Vec::new(),
67 load_out_dirs_from_check: false, 75 load_out_dirs_from_check: false,
76 rustc: RustcConfig { default_target: None },
68 } 77 }
69 } 78 }
70} 79}
@@ -160,6 +169,9 @@ impl CargoWorkspace {
160 if let Some(parent) = cargo_toml.parent() { 169 if let Some(parent) = cargo_toml.parent() {
161 meta.current_dir(parent); 170 meta.current_dir(parent);
162 } 171 }
172 if let Some(target) = cargo_features.rustc.default_target.as_ref() {
173 meta.other_options(&[String::from("--filter-platform"), target.clone()]);
174 }
163 let meta = meta.exec().with_context(|| { 175 let meta = meta.exec().with_context(|| {
164 format!("Failed to run `cargo metadata --manifest-path {}`", cargo_toml.display()) 176 format!("Failed to run `cargo metadata --manifest-path {}`", cargo_toml.display())
165 })?; 177 })?;
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 715eddadb..908208ece 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -134,6 +134,7 @@ impl Config {
134 set(value, "/cargo/allFeatures", &mut self.cargo.all_features); 134 set(value, "/cargo/allFeatures", &mut self.cargo.all_features);
135 set(value, "/cargo/features", &mut self.cargo.features); 135 set(value, "/cargo/features", &mut self.cargo.features);
136 set(value, "/cargo/loadOutDirsFromCheck", &mut self.cargo.load_out_dirs_from_check); 136 set(value, "/cargo/loadOutDirsFromCheck", &mut self.cargo.load_out_dirs_from_check);
137 set(value, "/cargo/rustc/defaultTarget", &mut self.cargo.rustc.default_target);
137 138
138 match get(value, "/procMacro/enable") { 139 match get(value, "/procMacro/enable") {
139 Some(true) => { 140 Some(true) => {
diff --git a/editors/code/package.json b/editors/code/package.json
index b8aaa07d8..fe330fb43 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -237,6 +237,14 @@
237 "default": false, 237 "default": false,
238 "markdownDescription": "Run `cargo check` on startup to get the correct value for package OUT_DIRs" 238 "markdownDescription": "Run `cargo check` on startup to get the correct value for package OUT_DIRs"
239 }, 239 },
240 "rust-analyzer.cargo.rustc.defaultTarget": {
241 "type": [
242 "null",
243 "string"
244 ],
245 "default": null,
246 "description": "Specify the default target"
247 },
240 "rust-analyzer.rustfmt.extraArgs": { 248 "rust-analyzer.rustfmt.extraArgs": {
241 "type": "array", 249 "type": "array",
242 "items": { 250 "items": {