-
-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Formatter fixes #1840
Formatter fixes #1840
Conversation
doSwitch is what finds the comments. If you skip doSwitch and call directly into the code that is specific to the given EObject, you will drop comments.
There is some black magic happening in the implementation of EList::add that removes EObjects from their containers when they are added to a new container. This works around that by just not adding the EObjects to a container.
This only applies when the comment is in the body of the code block. According to the grammar, the body does not start until some tokens appear -- that means non-whitespace, non-comment characters.
I think the only remaining problem is (5). I do not disagree with Christian on this, but it is not exactly a trivial change (it might take an afternoon to get it right). Therefore, this PR is awaiting a consensus on problem (5).
|
This may slow down the formatter. It also is not certain to work because isEqual could contain mistakes. However, it may substantially reduce the likelihood that the formatter silently produces wrong results. It is hard to be sure about this, however, because it is already rare for the formatter to produce wrong results.
438faf2
to
202d425
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for those fixes. They look good to me. I also tested this version of the formatter on the examples repo and it seems to fix the problems that I discovered previously.
I think we should also add tests based on the corner cases that I listed in #1832. We could add new integration tests, but probably it would be better to add specific formatter unit tests like the simple ones we already have in LffCliTest.java
This avoids inlining comments when the target syntactic element is multiple lines long. In such cases the comment instead gets its own line.
If a code block begins with a multiline comment, the multiline comment should still belong to the code block.
I'd like to draw attention to two significant changes other than the bugfixes:
The latter of these two changes is responsible for the big diff in our tests. The other bugfixes did not affect our tests because they only addressed corner cases that were found in the examples repo. |
I believe this is the CRLF/LF thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, modulo the .txt file that I commented on.
Great! Thanks a lot @petervdonovan! |
This fixes some of the problems in #1832.
at
clauses{=
=}
into the{=
=}
Point 4 might be merely a result from point 3, since the previous point results from destructive modification of the ECore model that might somehow violate the assumptions of the line breaker. Therefore, it might be solved; I'm not sure.
I am not sure about point (5). Fixing it would likely result in more special cases in the formatter. I would also like to point out that the current behavior is safe and semantics-preserving because comments that appear right after an opening
{=
do not seem to be included in the resultingCode
ECore object. Instead, I think they are treated as LF-level comments. As a result, a program with the following reaction compiles with the C target:whereas the following does not:
Note the usage of a
#
sign, which is not a valid C comment.formats to