Skip to content

Commit

Permalink
Fix local configs allowing to contain global changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed May 3, 2024
1 parent 521b462 commit 424b012
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ pub struct Config {
root_ratoml: Option<GlobalLocalConfigInput>,

/// For every `SourceRoot` there can be at most one RATOML file.
ratoml_files: FxHashMap<SourceRootId, GlobalLocalConfigInput>,
ratoml_files: FxHashMap<SourceRootId, LocalConfigInput>,

/// Clone of the value that is stored inside a `GlobalState`.
source_root_parent_map: Arc<FxHashMap<SourceRootId, SourceRootId>>,
Expand Down Expand Up @@ -757,7 +757,7 @@ impl Config {
if let Ok(change) = toml::from_str(&text) {
config.ratoml_files.insert(
source_root_id,
GlobalLocalConfigInput::from_toml(change, &mut toml_errors),
LocalConfigInput::from_toml(&change, &mut toml_errors),
);
}
}
Expand Down Expand Up @@ -2469,12 +2469,18 @@ macro_rules! _impl_for_config_data {
while let Some(source_root_id) = par {
par = self.source_root_parent_map.get(&source_root_id).copied();
if let Some(config) = self.ratoml_files.get(&source_root_id) {
if let Some(value) = config.local.$field.as_ref() {
if let Some(value) = config.$field.as_ref() {
return value;
}
}
}

if let Some(root_path_ratoml) = self.root_ratoml.as_ref() {
if let Some(v) = root_path_ratoml.local.$field.as_ref() {
return &v;
}
}

if let Some(v) = self.client_config.local.$field.as_ref() {
return &v;
}
Expand Down Expand Up @@ -2605,7 +2611,7 @@ macro_rules! _config_data {
)*}
}

fn from_toml(toml: &mut toml::Table, error_sink: &mut Vec<(String, toml::de::Error)>) -> Self {
fn from_toml(toml: &toml::Table, error_sink: &mut Vec<(String, toml::de::Error)>) -> Self {
Self {$(
$field: get_field_toml::<$ty>(
toml,
Expand Down Expand Up @@ -2674,7 +2680,6 @@ impl FullConfigInput {
GlobalConfigInput::schema_fields(&mut fields);
LocalConfigInput::schema_fields(&mut fields);
ClientConfigInput::schema_fields(&mut fields);
// HACK: sort the fields, so the diffs on the generated docs/schema are smaller
fields.sort_by_key(|&(x, ..)| x);
fields
}
Expand All @@ -2700,12 +2705,12 @@ struct GlobalLocalConfigInput {

impl GlobalLocalConfigInput {
fn from_toml(
mut toml: toml::Table,
toml: toml::Table,
error_sink: &mut Vec<(String, toml::de::Error)>,
) -> GlobalLocalConfigInput {
GlobalLocalConfigInput {
global: GlobalConfigInput::from_toml(&mut toml, error_sink),
local: LocalConfigInput::from_toml(&mut toml, error_sink),
global: GlobalConfigInput::from_toml(&toml, error_sink),
local: LocalConfigInput::from_toml(&toml, error_sink),
}
}
}
Expand All @@ -2723,14 +2728,11 @@ fn get_field_toml<T: DeserializeOwned>(
let subkeys = field.split('_');
let mut v = val;
for subkey in subkeys {
if let Some(val) = v.get(subkey) {
if let Some(map) = val.as_table() {
v = map;
} else {
return Some(toml::Value::try_into(val.clone()).map_err(|e| (e, v)));
}
let val = v.get(subkey)?;
if let Some(map) = val.as_table() {
v = map;
} else {
return None;
return Some(toml::Value::try_into(val.clone()).map_err(|e| (e, v)));
}
}
None
Expand Down

0 comments on commit 424b012

Please sign in to comment.