Open sageserpent-open opened 8 months ago
Edit anchoring refers to a potential implementation technique where a section that is not matched but is surrounded by two sections that are matched and which move in tandem is treated as if it moved with the surrounding sections; it is anchored to them.
This also applies when an unmatched section at the beginning or end of a file is adjacent at the other end with a moved section.
For this to make sense, we have to have two unmatched sections that are anchored to a section or pair of surrounding sections belonging to the same match(es), and the unmatched sections need to be equivalent using the fallback comparison for sections based on content. This is analogous to the use of fallback comparison by the LCS algorithm which can declare unmatched sections as forming a last-minute match as it aligns sections to build the LCS, only here we build last-minute moves.
Once we have the last-minute move, we can apply edit or delete propagation and that should lead to the desired outcome.
Of course, this is just an implementation sketch. Any other technique that leads to the stranded edit being propagated as just as good.
This isn't part of this ticket, but another use of anchoring is to carry an inserted new section along with one or two adjacent moving sections. Regardless of how big a new section is, it can't be matched by virtue of being new, so is currently left stranded as well.
Food for thought...
(Ticket #30 covers this).
The test
CodeMotionAnalysisExtension.codeMotion
has an example base input file and left input file that both contain the following segment:Note the comment (which does not refer to the following
true
, rather to the edit of text on the right input file to:This comment is required to make the test pass - without it, the initialiser doesn't match across the base and left, as it is just one token long; this match is needed because the overall segment moves on the left, and for edit propagation to work there has to be a detected move which in turn results from the match. Instead, the edit is left stranded at the source of the move and contributes to a merge conflict there.
The job here is to provide the same functionality but without depending on the edited section being long enough to be matched.