-
Notifications
You must be signed in to change notification settings - Fork 2
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
Unable to configure line length #53
Comments
Try adding this to your .editorconfig:
Note that kdoc-formatter has two separate concepts:
When you have deeply nested code, this distinction doesn't matter; the comments will break at the maximum line length. But for really wide code lines, the comments will not use the full line width. This is intentional, because for readability, you don't want really long lines -- those are harder to read (it's why books are typically in portrait orientation, not landscape). And for comments, readability is the primary concern, whereas for code, structure is the main concern. I recently (in 1.5.1) changed the default from matching the line width to being 72. This is typically the default for markdown files, as well as git commit messages. Kdoc formatter will also initialize this value from the line-width configured for markdown files (hence the above [*.md] rule). Maybe this is a bit controversial, though I do think it makes for much nicer comments. At a minimum I should make sure it's easy to configure this for non-.editorconfig projects in IntelliJ. |
Thank you for the reply @tnorbye. I tried making your suggested change, but it's still not working (still defaulting to 72). I even tried changing the file mask to In my project root, I have a file named
FWIW, I'm only trying to auto-format class-level and function-level KDoc. I'm not trying to format standalone markdown files (but I could see that being valuable as well). I don't have a strong preference on the default behavior, as long as it's configurable, but I will add my $0.02: ~72 is a very practical width for commit messages, but I think the vast majority of codebases will consider it too short for function-level documentation. Something closer to ~100 seems more conventional/modern for that. I actually wouldn't mind being able to declare separate line widths for class-level documentation and function-level documentation. Personally, I prefer around 100 and 80 for those, respectively. |
I've attempted to fix this, in IDE plugin version 1.5.2. I haven't submitted it to JetBrains yet; can you try installing it to see if it works for you? With this there's a new setting at the bottom of the KDoc Formatting Options panel. You can find the plugin zip to install (go to the Plugins settings page, click on the settings icon and then install plugin from disk). You can find the plugin zip on the 1.5.2 release page: https://github.com/tnorbye/kdoc-formatter/releases/tag/v1.5.2 |
I uploaded 1.5.2 to the plugin center and it's been approved and is public now. |
Thanks @tnorbye for this quick fix! Just tested 1.5.2 and it works for my use case. Here's some feedback from testing it:
Thanks again! |
Misc code cleanup (such as a new FormattingTask object which passes around state for the formatting job, such that it no longer has to have the hacky parameter order list in the options class etc). Plus 1.5.5 work: - Fixed the following bugs: - #53: The collapse-single-line setting does not work in the IDE - #69: Paragraph + list (stability), variation 2 - #70: Multi-line @link isn't converted if there's a # - #71: Make plugin dynamic - #72: @param with brackets is not supported - A bug where `<p>` paragraphs following a blank line would be deleted (without leaving a blank paragraph separator) - Changed heuristics around optimal or greedy line breaking in list items and for KDoc tag and TODO-item paragraph formatting. - The .editorconfig support is improved. It will now pick up the nearest applicable .editorconfig settings for a file, but any options explicitly set from the command line will override the .editor config. - Also, the "collapse documents that fit on a single line" option, instead of just defaulting to true, will now use the default specified for the equivalent setting for Java (if set), ensuring a more consistent codebase. (You can also set it for Kotlin using `ij_kotlin_doc_do_not_wrap_if_one_line`, though that option isn't supported in the IDE or by the Kotlin plugin currently.) - Preliminary support for formatting line comments and block comments (enabled via new flags, `--include-line-comments` and `--include-block-comments`.) - Misc IDE plugin improvements - `<pre>` tags are converted into KDoc preformatted blocks
Thanks for the note about the "collapse short comments" thing not working -- that was an embarassing copy paste error. It's been fixed in 1.5.5, just released. Also in 1.5.3 or 4 I added a new IDE setting which lets you manually configure override line lengths (and comment widths) in the IDE plugin which will override whatever the inferred .editorconfig settings are, which I think gives you what you need -- see the last two text fields here: https://github.com/tnorbye/kdoc-formatter/blob/main/screenshot-settings.png (I've also done some preliminary work on block and line comments. From the command line you can format whole files with it; from the IDE only interactively the comment under the caret using the dedicated format kdoc action.) If there are other bugs or remaining things I missed here, please file new separate issues. Thanks again. |
Thanks @tnorbye! Love the built-in line width option. FWIW, I'm still a little confused on "line width" vs "comment width". I thought the plugin only formats KDoc (comments)? Or is it supposed to refer to Regardless, I'm happy with the current behavior, where the below configuration will correctly only auto-format KDoc to 100 width: |
@tnorbye It looks like something broke between version 1.5.4 and 1.5.5 where the above config is no longer working. In 1.5.4 this would correctly format to 100 width. Now it's formatting to 72 again. |
Ugh, I see it. Embarrassing. I really should try to write a UI test for this; the formatting machinery is well covered with unit tests but not the plugin UI code. #74 |
This is available in 1.5.6 now. I've uploaded it to plugins.jetbrains.com; approvals usually take around a day but you can install it manually from https://github.com/tnorbye/kdoc-formatter/releases/tag/v1.5.6 |
First of all, thanks for the great plugin! This is a huge time saver compared to manually formatting KDoc.
However, I am unable to successfully configure the line length when using the IntelliJ plugin. I have the following
.editorconfig
file in the root of my project:With this setting under "Code Style" enabled:
But whenever I format, it uses the default line length of 72, which is too short for my preferences.
Version: 1.5.1
Thanks!
The text was updated successfully, but these errors were encountered: