fix(code-action): preserve non-matching bindings in bulk Pack All#845
Open
inclyc wants to merge 1 commit into
Open
fix(code-action): preserve non-matching bindings in bulk Pack All#845inclyc wants to merge 1 commit into
inclyc wants to merge 1 commit into
Conversation
The bulk "Pack all 'X' bindings to nested set" and "Recursively pack all
..." actions computed a single contiguous range from the leftmost to the
rightmost matching sibling and replaced it with the packed text. When
matching siblings were non-contiguous, that range engulfed intermediate
non-matching bindings, which the replacement silently dropped.
For example, `{ a.x = 1; b.y = 2; a.z = 3; }` produced
`{ a = { x = 1; z = 3; }; }` instead of preserving `b.y = 2;`.
Emit a multi-edit WorkspaceEdit instead: replace the first matching
binding with the packed text, then delete each subsequent matching
binding in place. Intermediate non-matching bindings are left untouched.
Tighten the existing non-contiguous and shallow-bulk lit tests to
verify the two-edit shape, and add a regression test that mirrors the
original bug report.
|
Could we make it so it doesn't leave empty lines? {
a.x = 1;
b = 2;
a.y = {
d = 3;
};
c = 4;
}using code actions gives: {
a = { x = 1; y = {
d = 3;
}; };
b = 2;
c = 4;
}but I think it would be better to produce: {
a = { x = 1; y = {
d = 3;
}; };
b = 2;
c = 4;
}It shouldn't remove empty lines that were already present, so e.g. {
a.x = 1;
a.y = 3;
}should be transformed to: {
a = { x = 1; y = 3; };
}Implementation wise I think, the deletion should extend to the beginning and to the end of the line (including end of the line), as long as it's only whitespace.Z I'm asking for this, because nixfmt won't remove single empty lines, as it leaves empty lines on purpose. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bulk "Pack all 'X' bindings to nested set" and "Recursively pack all ..." actions computed a single contiguous range from the leftmost to the rightmost matching sibling and replaced it with the packed text. When matching siblings were non-contiguous, that range engulfed intermediate non-matching bindings, which the replacement silently dropped.
For example,
{ a.x = 1; b.y = 2; a.z = 3; }produced{ a = { x = 1; z = 3; }; }instead of preservingb.y = 2;.Emit a multi-edit WorkspaceEdit instead: replace the first matching binding with the packed text, then delete each subsequent matching binding in place. Intermediate non-matching bindings are left untouched.
Tighten the existing non-contiguous and shallow-bulk lit tests to verify the two-edit shape, and add a regression test that mirrors the original bug report.
Fixes: #837