fix: Don't swallow trailing whitespace of merged nodes #59
No reviewers
Labels
No labels
Compat/Breaking
Kind
Bad merge
Kind
Bug
Kind
Documentation
Kind
Enhancement
Kind
Feature
Kind
New language
Kind
Security
Kind
Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: mergiraf/mergiraf#59
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "wetneb/mergiraf:58-trailing-whitespace"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes #58.
This is something I also encountered when working on Kotlin support (#56), but since the problem is also present in TOML I think it's worth backporting.
Opening the PR with the failing test case first to demonstrate the failure.
Cc @funkeleinhorn @ugur-a
@ -513,0 +532,4 @@
}
(_, Some(node), _) | (_, _, Some(node)) | (Some(node), _, _) => {
node.trailing_whitespace()
}
This is a bit of a complicated logic: the three versions of a given node (base, left, right) can have different trailing whitespaces, and this heuristic attempts to pick the most sensible one:
Happy to make adjustments if you can think of a better idea…
This looks kind of similar to
let (preceding_whitespace, indentation_shift) = match whitespaces {
[Some(whitespace_left), Some(whitespace_right), Some(whitespace_base)] => {
if whitespace_base == whitespace_left {
whitespace_right
} else {
whitespace_left
}
}
[Some(w), _, _] | [_, Some(w), _] | [_, _, Some(w)] => w,
_ => representatives
.iter()
.find_map(|repr| {
let indentation_shift =
repr.node.indentation_shift().unwrap_or("").to_owned();
let ancestor_newlines =
format!("\n{}", repr.node.ancestor_indentation().unwrap_or(""));
let new_newlines = format!("\n{indentation}");
if let Some(preceding_whitespace) = repr.node.preceding_whitespace() {
let new_whitespace =
preceding_whitespace.replace(&ancestor_newlines, &new_newlines);
Some((new_whitespace, indentation_shift))
} else {
None
}
})
.unwrap_or_default(),
};
now that #62 is merged, so I'd say the logic is actually okay and also consistent. So LGTM!
Yes, I also noticed that your new version makes it easier to specify the priority of revisions if necessary, which can be useful.