Diff: Confusing result for binary operators
Closed this issue · 1 comments
Semantic diffs let the children of branches "slide", which makes sense for some data structures. For instance, here the 2 is being deleted from the list, then added back at the head of the list, "pushing" the 1 into the second position. This is a natural way to think about the modification when the children are comma-separated.
For binary operators, this can lead to a confusing diff. Here, the 2 is being deleted and the diff shows the 1 still to the left of the >. When we add a 2 as the first child of >, it "slides" the 1 to the right of the binary operation. This is confusing and harder to follow.
Optimally, I believe this diff should show both the 1 and 2 being deleted on both sides of the >, and then 2 and 1 being added back on both sides. I haven't thought it fully through yet, but I think this may end up somewhat tricky.
When we encounter a branch like 2 > 1
or foo(2, 1),
traversing the zipper always proceeds in the order call -> args, so you’d get >/foo, then 2, then 1.
What if we modified traversal so that nodes were presented in the syntactic order? I think this could be done by changing children
in the zipper implementation to return [left, call, right]
if the call is a binary op, instead of always returning [call | args]
.
Edit: Not that simple since 2 > 1
parses to {:>, [], [{:int, [], 2}, {:int, [], 1}]}
, so we don't actually treat the >
separately from the call.