-
Notifications
You must be signed in to change notification settings - Fork 925
[unstable option] wrap_comments #3347
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
What is left to stabilize this? |
There is now a documented process describing stabilisation so we'd have to go through the conditions set there. |
Is there a link to the stabilization process? I can't find it from the README. I'd like to see us go through this process for the |
The process for stabilizing options is defined in https://github.com/rust-lang/rustfmt/blob/master/Processes.md @scampi & @topecongiro - correct me if I'm wrong but my understanding is that the current focus is on rustfmt 2.0, and that stabilization of some of these currently-unstable config options won't come til after the 2.0 release (based on https://github.com/rust-lang/rustfmt/projects/2) |
FWIW while I'd like to see this stabilized, this option can also break markdown. Last time I tried, a large markdown table I had was wrapped, which meant it was no longer valid markdown. |
Is there a way of saying "Do not wrap this comment"? We have a similar problem with long maths formulae. It's not a blocker, it just takes a bit of effort to fix up the formulae afterwards, however it would be nice if we could make exceptions for some blocks of text. I suppose the markdown could be checked programatically before and after each conversion and the formatting could be skipped if the markdown is broken. That won't catch the formulae but it might help in your case @jhpratt . Maybe there is a nice markdown formatter out there in the wild that understands when it is looking at a table. |
Any updates on this? |
@daniel5151 Updates are posted as they come in. What you see in this thread is the current status. |
Would it be plausible to split this into |
Could you elaborate a bit on the motivation? Is it just about wanting |
I actually don't care about normal comments much, I want to be able to have rustfmt wrap my doc comments. My thought was that normal comments aren't required to be markdown, so it would make sense to split the implementation. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
These options are unstable and depend on the following PR's: rust-lang/rustfmt#3347 rust-lang/rustfmt#3349
Aims to close #1594. These options are unstable and depend on the following PR's: [wrap_comments](https://rust-lang.github.io/rustfmt/?version=v1.4.36&search=#wrap_comments): rust-lang/rustfmt#3347 [comment_width](https://rust-lang.github.io/rustfmt/?version=v1.4.36&search=#comment_width): rust-lang/rustfmt#3349 [normalize_comments](https://rust-lang.github.io/rustfmt/?version=v1.4.36&search=#normalize_comments): rust-lang/rustfmt#3350 @alice-i-cecile do you think this will solve the issue? When enabled, running the formatter locally should take the configurations into account to format comments. `--check` runs should also be considering them. This should be testable on the `nightly` toolchain. ~I didn't delve into normalizing `//` vs `/* */` though, should I take a look into that too? [normalize_comments](https://rust-lang.github.io/rustfmt/?version=v1.4.36&search=#normalize_comments) seems to be the solution for that but it's also unstable (tracking issue: rust-lang/rustfmt#3350). I can also add this configuration (commented out, of course) if it's desirable.~ Added `normalize_comments` option.
The current implementation of this feature doesn't reflow short comments back into the lines above. Is this something that could be implemented? |
This feature does not remove a leading blank comment line but it removes trailing blank lines.
becomes
It's rather common to have an empty comment line before the associated section of code. It feels like this should at least be configurable. |
Just brainstorming here... there's an actively maintained library Basically it seems like rustdoc needs some markdown-aware comment formatting, and it doesn't make sense to reinvent the wheel Edit: more discussion on this at #5782 |
I would prefer a |
It would be good to be able to turn this off for specific comments or files. My use case for this is things like For example I have this comment that is used (with pub(crate) enum Transform {
// Other options here, elided for brevity...
/// Get the value for a key from the system keyring. Useful for passwords
/// etc that you do not want in your dotfiles repo.
///
/// Arguments:
/// * service="service-name" (service name to find entry in the keyring)
/// * user="user-name" (username to find entry in the keyring)
///
/// On Linux you can add an entry to the keyring using:
/// secret-tool store --label="Descriptive name" service "service-name" username "user-name"
#[strum(serialize = "keyring")]
Keyring,
} Rustfmt with |
@VorpalBlade would using |
+1 for this. I just came here this. I've been using wrap_comments daily now and it's been really good. I've been happy just typing and all the wrapping gets taken care off automatically until today when I had long lines of code with calls to the error tracing macro that I commented out temporarily and now tried to uncomment to find that all my macros got line wrapped. I have no idea how this could be addressed but this is IMO a surprising problem. Obvious after you think about it but not acceptable on stable rust IMO. New users coming in would do as they normally do comment out code and be surprised when they try to uncomment it. |
I have a proposal for an alternate solution to Personally, whenever I have a comment that I want to persist in the code, I use I'm not sure how many people use the same scheme as me, maybe y'all should 👍 if this option would work for y'all, and 👎 if you use comments differently such that it wouldn't? EDIT: Wow, I didn't think I'd be that weird |
To workaround this I generally just don't comment out blocks of code at all, but use normal blocks and cfg those out. fn foo() {
// <some code here>
} to fn foo() {
#[cfg(no)]
{
// <some code here, correctly formatted and IDE highlighted, and collapsible as a single region,
// now slightly rightward>
}
} at item level, I use an inline module instead of expression blocks. |
that works and i used to to it, but some part of rust screams at unknown configs by default these days. |
Yeah that is annoying, project boilerplate both new and existing but newly updated now includes adding it to check-cfg. At least once |
Those are great work a rounds but I'm saying that for people new to rust that is not exactly approachable. I'm not the only person that highlights a some lines of code the Ctrl + / in my IDE. It's a surprising thing to have that then get broken by the formatter so that it cannot just be uncommented |
TL;DR: do any of the above ideas need to block stabilization of this as it is now? I don't think this issue is about making comment wrapping on by default, correct? It’s just about stabilizing the option. Does (should?) an option to limit comment wrapping to doc comments, or I suppose there could be some bike-shedding around how to configure those other options, but it seems like simply stabilizing the current functionality wouldn't really get in the way of developing those other options in the future. |
Tracking issue for unstable option: wrap_comments
The text was updated successfully, but these errors were encountered: