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 is an experiment to explore an alternative way to insert comments.
Currently there are two issues we need to solve with our commenting method.
between two constructs that's supposed to be on the same line)
to a different AST node after formatting. Both the way we format code
and the way we attach comments affect this, so just formatting the
code in a different way can cause issues with the comment placement.
I think, the underlying issue is that currently comment placement
happens automatically when we are printing a located element; and this
can make the formatted code syntactically incorrect, or introduce
idempotence issues.
I can think of a few solutions:
they play well with each other. However I think this might be an
uphill battle where changing either formatter or the commenting code
can cause new and more exciting issues.
those "trees that grow" extension points on the AST), and let the
printer print comments alongside with the source code. This approach
is probably the most flexible one; since it can both reproduce the
current behavior, and gives the printers ability to print comments
in a way they want. However, it is a tedious process to write custom
comment handling code to every AST element that can be commented,
and we must still make sure that the comments will be attached to
the same AST nodes on the second pass.
AST nodes, at least directly. The premise is that; in the end, users
do not comment an AST node; they comment a specific line in the source
code. So, we can place that comment in the corresponding line on the
formatted code without looking at AST at all. I think this approach
will be conceptually the simplest solution. The disadvantage is that,
not having any information about the AST might make things harder;
however I believe we can find workarounds for those cases.
In this branch, I am trying the third approach.
I create a "SourceMap" mapping the
SrcSpan
s in the input toSrcSpan
sin the output.
to <line>" according to their location on the input.
the output using the "SourceMap".
Text
, without anysyntactic information),
Currently I only implemented step 1, and am in the process of implementing
step 2 and 3.
This is a relatively big change, so if there is a simpler solution I am
happy to stop working on this branch; and maybe we can revisit the idea
if we keep having similar issues.