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
Refactor handling of comments #2371
Conversation
Define and centralize how comments are interpreted. The new function is also used by normalization, which had inconsistent rules before.
A few regressions
This fixes two instances of unstable formatting but might be a regression when `wrap-comments=false`.
This reverts commit 70e5752b06fdef97e3c729d3bbfed14888ece62a.
The indentation of doc comments is significative for verbatim blocks. The decision of parsing a regular comment as doc must be done before decoding a comment. Regressions are due to test cases previously crashing finally being run.
This reverts commit f5cce1a. No longer the case.
This break was removed in previous commits
Allow indented lines with no asterisks and trailing newline in asterisk prefixed comments. A trailing newline results in the star of the closing token to be aligned with the asterisks.
The changes caused by this PR are reasonable to me: the original placement of |
Closes #2468 |
I had another quick look at this, do I understand correctly that in the current state of this PR there are still a number of regressions where lines are now wrapped before they reach the margin, and a number of regressions where the margin is now exceeded? The plan is to resolve these before merging this, right? |
I'm still investigating this issue but I'm now considering merging without it fixed. The issue seems rare and I'm clueless on how to fix it. |
Remove the forced line break before a multi-line comment. The asymmetry of this forced line break allowed comments to be move back and forth between being attached to after `f` or before `a`. This adds regressions.
Consecutive comments with no empty line in between are not formatted.
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.
LGTM, thanks!
Splitting the decoding/formatting makes the code easier to maintain indeed.
The only changes on the tests are improvements, so let's merge this one :)
The unexplained break regression is fixed and the new cases where the margin is exceeded is due to asterisk prefixed comments that do not wrap. This is ready to be merged! |
This rewrite part of the code that parses and formats comments to remove repeated or inconsistent code.
One function interprets comments:
Cmt.decode
. It returns a richer type that allow to implement formatting as it was before.The normalization is changed to use that, no more
is_docstring
and normalization of indentation is now consistent. This fixes normalization problem for comments parsed as doc and cinaps comments.