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

Tango comments <-> rustfmt interaction #9

Closed
skade opened this issue Sep 28, 2016 · 7 comments
Closed

Tango comments <-> rustfmt interaction #9

skade opened this issue Sep 28, 2016 · 7 comments
Labels

Comments

@skade
Copy link

skade commented Sep 28, 2016

cargo fmt works quite well with tango because of the bidirectional source mapping, except for one aspect: comments.

There's two issues:

rustfmt will destroy tango comments:

//@

will become

// @

It will also destroy these blocks when fixing overlong comment lines:

//@ This is a very long line that breaks < here

will become

// @ This is a very long line that breaks
// < here

Breaking the source mapping.

A desired outcome would be that cargo build && cargo fmt && cargo build yields a clean tango file.

@pnkfelix
Copy link
Owner

I have been thinking more about this since you told me about it on twitter.

I could extend tango to allow whitespace between the // and the @ when it is looking for its special symbol sequence during rust->md conversion, as a hack to deal with the first problem.

The fact that rustfmt will introduce line breaks into long comment lines seems unfortunate. I guess I could change tango so that it will break such lines itself during the md->rust trip, and then reassemble them into a single line during the rust->md trip (by making the follow-on lines have a marker like //@\ or something)

I am not terribly thrilled with the idea of introducing either change by default, but since the design of tango is that it is invoked as a library function, not a command line executable, it seems like I could just make these choices user-selectable. E.g. put them into options and then perhaps also offer modes like "Max RustFmt Compatibilty" vs "Preserve-Line-Structure".

@pnkfelix
Copy link
Owner

(If you ask me, though, I think rustfmt should be smarter when it is injecting line breaks. If a series of comments has a wall of trailing characters after each //, like this:

    //^ Starting line
    //| Here is one line
    //| and another
    //| and another but this one is really long
    //| and a final one

then I think it would be more reasonable for rustfmt to infer, based on looking at the comment lines immediately above and below, that the author intends for each line to start with //|. (Its not perfect, since it would fail to do the right thing on the first or second line in the example above. But it would be better than what it is doing today.)

@skade
Copy link
Author

skade commented Sep 28, 2016

Considering that rustfmt rewrites the source completely and stores the orginal comment header, this seems like a feasible option.

https://github.com/rust-lang-nursery/rustfmt/blob/master/src/comment.rs#L23-L56

@skade
Copy link
Author

skade commented Sep 28, 2016

Feel free to weigh in here: rust-lang/rustfmt#1179

@pnkfelix
Copy link
Owner

pnkfelix commented Jun 7, 2017

Hey @skade is this still an issue, or has rustfmt been revised to not redo line-breaking now? I think that is a reasonable inference from rust-lang/style-team#17, but I am not sure.

@Screwtapello
Copy link
Contributor

I can confirm that rustfmt no longer messes with the content of comments. It warns about comments that exceed its configured maximum width, but does not re-flow them or break Tango's markers in any way.

@pnkfelix
Copy link
Owner

pnkfelix commented May 2, 2018

Closing as no longer a significant bug

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

No branches or pull requests

3 participants