Skip to content
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

Reformat Column Comments #117

Open
Z2Flow opened this issue May 25, 2024 · 8 comments
Open

Reformat Column Comments #117

Z2Flow opened this issue May 25, 2024 · 8 comments

Comments

@Z2Flow
Copy link

Z2Flow commented May 25, 2024

This stems from reverse-engineering a PostgreSQL database…
Add the ability to move column comments to the next line, and indented 'n' spaces.
Also soft-wrap to column 'm' (default 80), and interpret newline characters (\n).

Currently columns with long comments cause the page width to extend to the end of the comment making it difficult to access the datatype as it overflows the window.

E.g. current formatting:

# assembly_failures(The list of causes of failure for an assembly.\n This is a template field copied to the Test when it is created.\n This array creates a list of checkboxes in the form. :jsonb

Proposed formatting:

#  assembly_failures                                       :jsonb
#       The list of causes of failure for an assembly.
#       This is a template field copied to the Test when it is created.
#       This array creates a list of checkboxes in the form.

Version

  • annotaterb version: 4.8.0
  • rails version: 7.1.3
  • ruby version: 3.3.0
@drwl
Copy link
Owner

drwl commented May 28, 2024

@Z2Flow thanks for submitting a detailed issue. I think the request makes sense. I'll have some time to take a look at this on my Friday.

@drwl
Copy link
Owner

drwl commented Jun 2, 2024

@Z2Flow Sorry for the delay, I had a time to take a look. Adding support for multi-line column comments should be okay, did you have an example migration you could share where you add new lines?

Regarding word wrapping, I would want to flush it out a bit because of the impact of supporting max line width would affect a lot of the code. I did a quick digging as well since I haven't touched anything that does word wrapping and came across this gem [1] and apparently there are different word wrap / soft wrap modes.

[1] https://github.com/pazdera/word_wrap

@Z2Flow
Copy link
Author

Z2Flow commented Jun 3, 2024 via email

@Z2Flow
Copy link
Author

Z2Flow commented Jun 5, 2024 via email

@drwl
Copy link
Owner

drwl commented Jun 21, 2024

@Z2Flow apologies for the delay, I have some time now so I'm back to working on multi-line comments.

Can you check for me how \n (line breaks) are stored for you? I'm finding if I have a migration that adds multi-line comments like this:

class AddFooToTestDefaults < ActiveRecord::Migration[7.0]
  def change
    add_column :test_defaults, :foo, :boolean, default: false, comment: 'The list of causes of failure for an assembly.\n      This is a template field copied to the Test when it is created.\n      This array creates a list of checkboxes in the form.'
  end
end

then in the schema and (I think in Postgres as well) it gets escaped. Can you confirm?

Snippet from my schema.rb:

t.boolean "foo", default: false, comment: "The list of causes of failure for an assembly.\\n      This is a template field copied to the Test when it is created.\\n      This array creates a list of checkboxes in the form."

@Z2Flow
Copy link
Author

Z2Flow commented Jun 24, 2024 via email

@drwl
Copy link
Owner

drwl commented Jun 28, 2024

As an update, I did take a look at this yesterday. The changes required were more extensive than I originally thought, so for the time being I'm not going to work on this and instead focus on some refactors to make this change easier in the future. If you do want to add this change though, I would be more than happy to review any PRs.

Changes required would be:

  • Adding new config/parser option
  • ModelWrapper#max_schema_info_width adding support for getting the width if there are column comments and split by new lines
  • ColumnAnnotation::AnnotationBuilder#build support making the new lines comments using the correct formatter (default, markdown, rdoc, etc)

Potential changes:

  • AnnotationDiffGenerator may need to be changed

@Z2Flow
Copy link
Author

Z2Flow commented Jun 29, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants