Add PreserveCommentIndents to provide ability to preserve comments with odd indentation #749
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 PR solves: #747 (and is a follow up to #734)
It allows for the parser (and AST nodes) to pre configured to preserve the level of indentation that comments are found to be at. This helps to cover some additional use-cases that cannot be supported currently like the one I reported initially here: #713 (comment)
This is accomplished by adding a new mode that is used along side with ParseComments mode. Notably if the new mode is used alone it currently will not work.
I opted for a new mode because based on the report from #713 and fix in #734 it seems some users/use-cases desire comments Parsed but not preserved at same indent. It seems this functions as a minimal beautification step in that case.
Future Consideration
This does not cover, nor seek to attempt covering, other comment related indent concerns. For instance in-line comments may have odd spacing following the value that the comment is after. So something like:
While it could be possible to preserve this spacing in some cases - i.e. to ensure the
#
outputs in the same column as it is found. This would be a risk as, in cases where the value length changes (grows) a collision could occur. So because that solution is quite a different issue than indent levels this has been intentionally excluded from this fix.Before submitting your PR, please confirm the following.