Repository navigation
syntax: fix nested heredoc indentation - #1409
Merged
Merged
Conversation
Implement a Write method for extraIndenter that ensures a nested heredoc does not bypass (by directly calling the bufio.Writer) the indentation accounting of the outer extraIndenter. Fixes #1403
Lines coming from a nested extraIndenter are wrapped in tabwriter.Escape, so they appear to have no indentation and take the under-indent branch. Pinning them to the first line's source indentation only worked when it matched baseIndent, as with two levels of nesting; use baseIndent, where the first line is actually printed.
Owner
|
Thanks, the fix LGTM - I just found that at deeper levels we were still buggy due to another oversight. I've fixed that in a commit I've pushed on top of yours here, as both felt like they were closely related. |
Contributor
Author
|
Thank you! I should have tested for n :) |
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.
Continuing the explanation from #1403 (comment):
The
Writemethod is only really used when writing the content of a heredoc. In the normal case, one level of heredoc, this is fine. Everything in it will useWriteBytewhich handles the heredoc indentation.Where it went wrong is with an inner heredoc. In that situation the inner
extraIndenterwrites only the tabs to the buffer of the outer heredoc, while writing the trimmed content directly to the outerWrite(which is abufio.WriterI think). This results in the content of the inner heredoc having no tabs, which accumulate in the buffer and are output with the ending marker.This fix defines a
Writemethod forextraIndenterthat forwards the writes to theWriteByte(likeWriteString) so that all writes are via the same path, as intended, and inner heredocs do not bypass it anymore.Fixes #1403