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
Comments get lost when generating annotations #951
Comments
running into this as well |
It works to add a blank line above the comment before annotating, but you need to find them first (I spotted it accidentally when reviewing a PR). |
Yes but obviously nobody remembers to do that on a large team :)
…On Jul 29, 2022, 8:30 AM -0400, alexeyr-ci1 ***@***.***>, wrote:
It works to add a blank line above the comment before annotating, but you need to find them first (I spotted it accidentally when reviewing a PR).
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Sorry, it's actually worse than I thought. It looked like it worked only because the comment wasn't getting regenerated. If I use |
Is there a workaround for this? |
Hey folks, I believe I was able to solve this bug in my gem drwl/annotaterb#72 |
This PR attempts to fix a long standing bug that was carried over from the original gem. Comments near an annotation would get removed when adding or updating annotations. ctran/annotate_models#951, https://github.com/ctran/annotate_models/#warning **Context** Prior to this change, the AnnotateRb and the old gem Annotate would annotate model files in 1 of 2 ways: 1. The "update" method, existing annotations would be found using a regex and then new annotations would be changed in place. If a human made comment was added after the annotation block **without** a new line, it would get removed during the update process. 2. The "overwrite" method, which would happen when annotations did not exist OR if the `:force` option was set to true. A regex would be used to find annotation, remove it from the file, and then add annotations again to the file depending on options such as `:position`. Relying on regexes to identify annotations in a file made it hard to reason about and hard to change, so most of them were removed and replaced with a custom Ruby file parser using Ripper [1], which makes working with Ruby files deterministic. This PR makes the following behavioral changes: - When updating annotations (i.e. annotations exist && `force: false`), it only updates the annotations and should no longer delete any human comments that are before or after an annotation block - When generating (no annotations exist in the file) or re-generating annotations (`force: true`), it removes the annotation block and surrounding whitespace, if it exists, and then depending on the `position` option, will add annotations before the class declaration or after the class declaration. In the case of re-generating annotations, any surrounding whitespace will be preserved assuming annotations are being written to the same position. [1] A great write up on Ripper: https://kddnewton.com/2022/02/14/formatting-ruby-part-1.html
I wasn't aware of the fork. I'll definitely check it out. Thanks! |
When there are already comments above a class definition, AnnotateModels deletes them when regenerating annotations.
Here's a short video showing the issue: https://cln.sh/Iw7NsPk7yEfmkyPWtIim
Version
The text was updated successfully, but these errors were encountered: