-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adjust indentation when migrating edits or insertions. #41
Comments
This should follow #9. |
Something simple... The base file:
Let's apply a global indentation change on the left:
Let's muck around with the indentation on the right:
So no code motion, and all changes are just on indentation. I want to see this as a merge:
So the global indentation change on the left applies a a global correction, but the line-by-line indentation changes are also taken into account. |
What should happen if the right makes significant changes that also include line-by-line indentation changes? Say we have on the right:
Obviously, I want to see this as a merge:
Again, the global indentation change on the left applies a global correction. |
Suppose we add code motion into the mix, first with just whitespace changes... On the left, let's move a block in addition to a global indentation change:
My intuition leads me to this desired merge:
The line-by-line indentation changes are applied at the move destination. |
Finally, let's mix code motion with significant changes that also include line-by-line indentation changes... The base file:
On the left:
On the right:
I think I want to see this:
|
Let's go with these four examples and write tests for them. As long as they pass, I don't care what else happens regarding indentation for now, well as long as the changes other than indentation are correctly merged (including whitespace). Note the subtletly there - the idea is to merge indentation changes, but whitespace changes within the main body of a line of text are merged as usual. If a line is indented differently on the left and right and also has whitespace-only changes within the main body of the line on either side, then once the indentation is sorted out, the existing rules for selecting whitespace changes from either side will come into play. |
TODO: what about insertions? Let's defer these until the test examples above pass... |
TODO: suppose a migrated edit or insertion has ragged boundaries that are somewhere within non-indentation text at either the source or destination of a move? That is expected to include situations where the section has one or more linebreaks within it, but the boundaries are nonetheless ragged. |
An outline of how this might be achieved...
|
NOTE: have to watch out for when a decrease in indentation of the leading line would cause further lines in the section to exceed the available margin. Would it be better to compute the maximum common indentation of a section and base the indentation deltas off that, rather than between the successor's initial line and the predecessor's final line? |
Let's try the first example, doing a thought-experiment using the maximum common indentation delta... The base file:
Let's apply a global indentation change on the left:
Let's muck around with the indentation on the right:
Merging the deltas: Section A, delta of 8 spaces (from the left). So that would yield...
Looks good so far. |
Let's try the second example, doing a thought-experiment using the maximum common indentation delta... Say we have on the right:
Merging the deltas: Section A, delta of 8 spaces (from the left). So that would yield...
Again, looks good. |
The third example, using the maximum common indentation delta... The base file:
On the left, let's move a block in addition to a global indentation change:
Let's muck around with the indentation on the right:
Merging the deltas: Section A, delta of 8 spaces (from the left). So that would yield...
This is slightly different from the third example as presented, but makes sense in its own right. Perhaps section D's delta should be calculated wrt the nearest predecessor section that didn't move - namely section C? So that would give 0 on the base, 0 on the left and 0 and right. Merging the deltas: Section A, delta of 8 spaces (from the left). So that would yield...
Which is precisely the original example. |
It looks like merging the delta of the maximum common indentation for each section could work well, but we have to apply this after discovering the moves, skipping over sections that have moved out or in, including migrated ones. Move destinations simply apply their original delta regardless of what is going on in the source of the move or its edit. No idea what to do about insertions yet, though... |
Should insertions use the delta with their preceding (or failing that, succeeding) anchor? |
Added |
This is to support Python, F#, Scala 3 etc where indentation is important.
We want migrated code to compile correctly in its new home, so it should indent consistently with the surrounding code.
This may come for free when migrating edits - need a test case to check this.
Insertions need to have their relative indentation wrt their anchors determined, so that they can be aligned with the anchors' destinations.
The text was updated successfully, but these errors were encountered: