Skip to content

Commit 69bdf4a

Browse files
committed
Add failing test for the xdg config being inherited
1 parent 47c7d45 commit 69bdf4a

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2195,7 +2195,7 @@ enum AdjustmentHintsDef {
21952195
Reborrow,
21962196
}
21972197

2198-
#[derive(Serialize, Deserialize, Debug, Clone)]
2198+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
21992199
#[serde(untagged)]
22002200
enum DiscriminantHintsDef {
22012201
#[serde(with = "true_or_always")]

crates/rust-analyzer/src/config/tree.rs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ pub enum ConfigTreeError {
3838
pub struct ConfigChanges {
3939
ra_toml_changes: Vec<vfs::ChangedFile>,
4040
/// - `None` => no change
41-
/// - `Some(None)` => the XDG_CONFIG_HOME rust-analyzer.toml file was deleted
42-
/// - `Some(Some(...))` => the XDG_CONFIG_HOME rust-analyzer.toml file was updated
43-
xdg_config_change: Option<Option<Arc<ConfigInput>>>,
44-
/// - `None` => no change
4541
/// - `Some(None)` => the client config was removed / reset or something
4642
/// - `Some(Some(...))` => the client config was updated
4743
client_change: Option<Option<Arc<ConfigInput>>>,
@@ -318,22 +314,12 @@ impl ConfigTree {
318314
errors: &mut Vec<ConfigTreeError>,
319315
) {
320316
let mut scratch_errors = Vec::new();
321-
let ConfigChanges { client_change, ra_toml_changes, xdg_config_change, parent_changes } =
322-
changes;
317+
let ConfigChanges { client_change, ra_toml_changes, parent_changes } = changes;
323318

324319
if let Some(change) = client_change {
325320
self.client_config = change;
326321
}
327322

328-
if let Some(change) = xdg_config_change {
329-
let node = self
330-
.tree
331-
.get_mut(self.xdg_config_node_id)
332-
.expect("client_config node should exist");
333-
node.get_mut().input = change;
334-
self.invalidate_subtree(self.xdg_config_node_id);
335-
}
336-
337323
for ConfigParentChange { file_id, parent } in parent_changes {
338324
let node_id = self.ensure_node(file_id);
339325
let parent_node_id = match parent {
@@ -455,5 +441,34 @@ mod tests {
455441
assert_eq!(local.completion_autoimport_enable, false);
456442
// from client
457443
assert_eq!(local.semanticHighlighting_strings_enable, false);
444+
445+
vfs.set_file_id_contents(
446+
xdg_config_file_id,
447+
Some(
448+
r#"
449+
# default is "never"
450+
[inlayHints.discriminantHints]
451+
enable = "always"
452+
"#
453+
.to_string()
454+
.into_bytes(),
455+
),
456+
);
457+
458+
let changes = ConfigChanges {
459+
ra_toml_changes: vfs.take_changes(),
460+
parent_changes: vec![],
461+
client_change: None,
462+
};
463+
dbg!(config_tree.apply_changes(changes, &vfs));
464+
465+
let local2 = config_tree.read_config(crate_a).unwrap();
466+
// should have recomputed
467+
assert!(!Arc::ptr_eq(&local, &local2));
468+
469+
assert_eq!(
470+
local.inlayHints_discriminantHints_enable,
471+
crate::config::DiscriminantHintsDef::Always
472+
);
458473
}
459474
}

0 commit comments

Comments
 (0)