From 1c5a125beb35725ccc2ade005db9870db734bf23 Mon Sep 17 00:00:00 2001 From: qjerome Date: Wed, 8 Jan 2025 11:20:08 +0100 Subject: [PATCH 1/3] refactor: struct holding cargo cfgs settings --- crates/rust-analyzer/src/config.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 30f0031905f1..1fe8d0ce4209 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -571,12 +571,10 @@ config_data! { /// avoid checking unnecessary things. cargo_buildScripts_useRustcWrapper: bool = true, /// List of cfg options to enable with the given values. - cargo_cfgs: FxHashMap> = { - let mut m = FxHashMap::default(); - m.insert("debug_assertions".to_owned(), None); - m.insert("miri".to_owned(), None); - m - }, + cargo_cfgs: Vec = { + vec!["debug_assertion".into(), "miri".into()] + } + , /// Extra arguments that are passed to every cargo invocation. cargo_extraArgs: Vec = vec![], /// Extra environment variables that will be set when running cargo, rustc @@ -1944,6 +1942,17 @@ impl Config { global: CfgDiff::new( self.cargo_cfgs(source_root) .iter() + // parse any cfg setting formatted as key=value + .map(|s| { + let mut sp = s.splitn(2, "="); + let key = sp.next(); + let val = sp.next(); + (key, val) + }) + // we filter out anything with a None key + .filter(|(key, _)| key.is_some()) + // unwrap cannot panic here as we are sure key is Some + .map(|(key, val)| (key.unwrap(), val)) .map(|(key, val)| match val { Some(val) => CfgAtom::KeyValue { key: Symbol::intern(key), From e9a13ab6d795c0672530db048f308c6beba747c5 Mon Sep 17 00:00:00 2001 From: qjerome Date: Wed, 8 Jan 2025 14:47:21 +0100 Subject: [PATCH 2/3] fix: autogenerate files --- docs/user/generated_config.adoc | 8 ++++---- editors/code/package.json | 13 ++++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc index 5b86766aa8ea..c6f5852f87ff 100644 --- a/docs/user/generated_config.adoc +++ b/docs/user/generated_config.adoc @@ -94,10 +94,10 @@ avoid checking unnecessary things. -- Default: ---- -{ - "miri": null, - "debug_assertions": null -} +[ + "debug_assertion", + "miri" +] ---- List of cfg options to enable with the given values. diff --git a/editors/code/package.json b/editors/code/package.json index 80246bf3feac..6cb74a94a00c 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -791,11 +791,14 @@ "properties": { "rust-analyzer.cargo.cfgs": { "markdownDescription": "List of cfg options to enable with the given values.", - "default": { - "miri": null, - "debug_assertions": null - }, - "type": "object" + "default": [ + "debug_assertion", + "miri" + ], + "type": "array", + "items": { + "type": "string" + } } } }, From cc7fb1945d997430d29d7a95044e7755f25e53d6 Mon Sep 17 00:00:00 2001 From: qjerome Date: Wed, 8 Jan 2025 14:47:46 +0100 Subject: [PATCH 3/3] =?UTF-8?q?fix:=C2=A0requested=20changed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/rust-analyzer/src/config.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 1fe8d0ce4209..051871020af7 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -573,8 +573,7 @@ config_data! { /// List of cfg options to enable with the given values. cargo_cfgs: Vec = { vec!["debug_assertion".into(), "miri".into()] - } - , + }, /// Extra arguments that are passed to every cargo invocation. cargo_extraArgs: Vec = vec![], /// Extra environment variables that will be set when running cargo, rustc @@ -1942,17 +1941,13 @@ impl Config { global: CfgDiff::new( self.cargo_cfgs(source_root) .iter() - // parse any cfg setting formatted as key=value - .map(|s| { + // parse any cfg setting formatted as key=value or just key (without value) + .filter_map(|s| { let mut sp = s.splitn(2, "="); let key = sp.next(); let val = sp.next(); - (key, val) + key.map(|key| (key, val)) }) - // we filter out anything with a None key - .filter(|(key, _)| key.is_some()) - // unwrap cannot panic here as we are sure key is Some - .map(|(key, val)| (key.unwrap(), val)) .map(|(key, val)| match val { Some(val) => CfgAtom::KeyValue { key: Symbol::intern(key),