Fix wrong indenting with hard tabs in binop pairs#6883
Open
matthewhughes934 wants to merge 3 commits into
Open
Fix wrong indenting with hard tabs in binop pairs#6883matthewhughes934 wants to merge 3 commits into
matthewhughes934 wants to merge 3 commits into
Conversation
And pass only the required attribute, similarly to `wrap_str`
This is required so that `last_line_width` knows the width of the prefix and where the rest of the string starts. Rename the function appropriately and replace a call to `str::chars` with `str::char_indices` to make it more explicit we want an index here (though the two are equivalent in this case, since we only loop over single byte characters)
So that the line width is calculated as the rendered width of any
trailing space plus the unicode width of the rest of the string.
That is, for example, so that the line:
\s\s\s\ssome_func();
Would have the same length as
\tsome_func();
Assuming `tab_spaces=4`.
This fixes a issue where the formatting a collection of binary
operations would depend on whether hard of soft tabs were used.
Specifically in the change to the call of `last_line_width` at line 135
of `src/pairs.rs`: the inconsistency above meant under some conditions
when using hard tabs we could satisfy the condition on that line and
drop into the block to snuggle the lines together, where with soft tabs
a different width would be computed and we'd avoid snuggling them. A
test has been added covering this case.
c8fd0cf to
2595630
Compare
Contributor
Author
|
two notes/questions:
|
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.
This changeset is split up into 3 patches. The first two are some small
changes (in
src/utils.rs) to help make the third commit, the bulk ofthis changeset, a bit simpler. The third commit introduces an additional
argument to a util function, and so requires updating all its callsites.
All changes outside of
src/utils.rsshould just be updating thesecallsites (with the exception of an added test). The commits:
Avoid passing entire config to
get_prefix_space_widthAnd pass only the required attribute, similarly to
wrap_strRewrite
get_prefix_space_widthto also give the prefix endThis is required so that
last_line_widthknows the width of the prefixand where the rest of the string starts.
Rename the function appropriately and replace a call to
str::charswith
str::char_indicesto make it more explicit we want an index here(though the two are equivalent in this case, since we only loop over
single byte characters)
Teach
last_line_widthaboutconfig.tab_spacesSo that the line width is calculated as the rendered width of any
trailing space plus the unicode width of the rest of the string.
That is, for example, so that the line:
Would have the same length as
Assuming
tab_spaces=4.This fixes a issue where the formatting a collection of binary
operations would depend on whether hard of soft tabs were used.
Specifically in the change to the call of
last_line_widthat line 135of
src/pairs.rs: the inconsistency above meant under some conditionswhen using hard tabs we could satisfy the condition on that line and
drop into the block to snuggle the lines together, where with soft tabs
a different width would be computed and we'd avoid snuggling them. A
test has been added covering this case.