Rustfmt: [unstable option] file_lines

Created on 13 Feb 2019  路  7Comments  路  Source: rust-lang/rustfmt

Tracking issue for file_lines

stabilisation-request unstable option

Most helpful comment

3442 is a blocker for us to be able to use --file-lines at all - it produces inconsistent and bimodal results.

There's also another bug I haven't narrowed down yet where rustfmt seems to (sometimes) infinitely indent the internals of macro definitions, which could also be --file-lines related.

All 7 comments

Will this option be stabilized anytime soon? We use it for quite some time in RLS for the Range Formatting and it seems to work without any problems.

One thing that sometimes happens IIRC is that it can "grab" remaining parts of the selected expression/AST node outside of the specified range by 1 or 2 lines but it always seemed like it did a reasonable thing, e.g. it was hard to imagine how you could only partially format the specified range.

RLS also uses feature gating for this, so if it were made stable we could offer it to our users out of box, without them having to opt-in into unstable features. cc @nrc

One thing that sometimes happens IIRC is that it can "grab" remaining parts of the selected expression/AST node outside of the specified range by 1 or 2 lines but it always seemed like it did a reasonable thing, e.g. it was hard to imagine how you could only partially format the specified range.

@Xanewok Sounds like that is by design, see https://github.com/rust-lang/rustfmt/issues/1514#issuecomment-301342264 and https://github.com/rust-lang/rustfmt/issues/1514#issuecomment-400959602.

I have combed through the issues mentioning or related to file-lines in order to get a better idea of the current state of that option. Here is an overview and my take on them:

Overall, I would say 2 issues are needed to complete stabilisation. @topecongiro ?

3442 is a blocker for us to be able to use --file-lines at all - it produces inconsistent and bimodal results.

There's also another bug I haven't narrowed down yet where rustfmt seems to (sometimes) infinitely indent the internals of macro definitions, which could also be --file-lines related.

Looks like #3442 is fixed now. It is by design that file lines 'rounds up'. We need to round up to the nearest AST node in the best case and we are currently very conservative (I think round up to the nearest item, or maybe even module). So while we could do better, I don't think we need to block stabilisation (although we would need to think about what exactly stability means then). Note that the LSP spec permits rounding up.

@scampi is there any issue left that's specifically related to file_lines which blocks this stabilization?

@Xanewok I believe #1873 is the outstanding issue

Was this page helpful?
0 / 5 - 0 ratings