Create artificial scopes for the optional value and mandatory value.

This commit is contained in:
Tom Alexander 2023-10-11 19:13:45 -04:00
parent dff7550038
commit 8bc942a26f
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 13 additions and 3 deletions

View File

@ -460,7 +460,7 @@ pub(crate) fn compare_property_list_of_list_of_list_of_ast_nodes<
(Some(value), Some(rust_value)) => (value, rust_value),
};
let mut child_status: Vec<DiffEntry<'b, 's>> = Vec::with_capacity(rust_value.len());
let mut full_status: Vec<DiffEntry<'b, 's>> = Vec::with_capacity(rust_value.len());
// Iterate the outer lists
for (value, (rust_optional, rust_value)) in value.iter().zip(rust_value.iter()) {
@ -481,6 +481,7 @@ pub(crate) fn compare_property_list_of_list_of_list_of_ast_nodes<
// Compare optional value
if let Some(rust_optional) = rust_optional {
let mut child_status: Vec<DiffEntry<'b, 's>> = Vec::with_capacity(rust_value.len());
if rust_optional.len() != middle_value.len() {
let this_status = DiffStatus::Bad;
let message = Some(format!(
@ -495,9 +496,14 @@ pub(crate) fn compare_property_list_of_list_of_list_of_ast_nodes<
for (e, r) in middle_value.zip(rust_optional) {
child_status.push(compare_ast_node(source, e, r.into())?);
}
if !child_status.is_empty() {
let diff_scope = artificial_diff_scope("optional value", child_status)?;
full_status.push(diff_scope);
}
}
// Compare mandatory value
let mut child_status: Vec<DiffEntry<'b, 's>> = Vec::with_capacity(rust_value.len());
let mandatory_value = mandatory_value.as_list()?;
if rust_value.len() != mandatory_value.len() {
let this_status = DiffStatus::Bad;
@ -513,11 +519,15 @@ pub(crate) fn compare_property_list_of_list_of_list_of_ast_nodes<
for (e, r) in mandatory_value.iter().zip(rust_value) {
child_status.push(compare_ast_node(source, e, r.into())?);
}
if !child_status.is_empty() {
let diff_scope = artificial_diff_scope("mandatory value", child_status)?;
full_status.push(diff_scope);
}
}
if child_status.is_empty() {
if full_status.is_empty() {
Ok(ComparePropertiesResult::NoChange)
} else {
let diff_scope = artificial_owned_diff_scope(emacs_field, child_status)?;
let diff_scope = artificial_owned_diff_scope(emacs_field, full_status)?;
Ok(ComparePropertiesResult::DiffEntry(diff_scope))
}
}