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

rustfmt::vertical - pad tables so that elements line up vertically? #4710

Open
gilescope opened this issue Feb 20, 2021 · 1 comment
Open

Comments

@gilescope
Copy link

#[rustfmt::skip] is used whenever we want rustfmt to not mess up the formatting.
But quite a few times I see this it is for tables / vecs in vecs where we are after padding so that things line up vertically so that the line by line differences are minimised and we can clearly see the differences.
Tabs help but maintaing tables manually is time consuming.

I think an opt in hint to format the item giving preference to vertical similarity would be really cool. I appreciate it's probably hard to do in general but I am sure there are some 80/20 cases that could give us most of the benefit.

Or is there already such a thing and I just didn't know about it?

@calebcartwright
Copy link
Member

The only thing available today is the indent_style config option that can be changed to Visual and emit something like this:

fn main() {
    let lorem = vec!["ipsum",
                     "dolor",
                     "sit",
                     "amet",
                     "consectetur",
                     "adipiscing",
                     "elit"];
}

However, note that indent_style gets applied consistently, not just to one or two macros. Beyond that there's not anything else that comes to mind, nor really much more we can do. Many times in these cases folks want to have (from a rustfmt/AST POV) an arbitrary number of elements per row sometimes with their own internal padding (somewhat like multiple central aligned columns within) and I just don't see it being feasible for rustfmt to attempt to do something like that.

Would certainly be happy to review a PR if someone proves me wrong and comes up with a relatively clean implementation, but I don't see the rustfmt team ever getting around to working on this ourselves.

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

No branches or pull requests

2 participants