syntax icon indicating copy to clipboard operation
syntax copied to clipboard

Smart linebreak printer for pipe chains

Open amiralies opened this issue 4 years ago • 2 comments

They are currently being formatted based on line width. it would be good to allow user decide whether to break line on pipes or not.

for example this code gets formatted to a single line with default line width

let bazz = foo.bars->OptionEx.arrayValues->Map.String.fromArray

I found this more readable

let bazz =
  foo.bars
  ->OptionEx.arrayValue
  ->Map.String.fromArray

amiralies avatar Feb 04 '21 20:02 amiralies

Yes, that’s something I’ve also been thinking about. As the line width gets longer, the width algorithm becomes less and less “nice”. There’s definitely an opportunity for improvement here.

IwanKaramazow avatar Feb 06 '21 16:02 IwanKaramazow

There's a balance to be had, because for some pipes (e.g. if the above used local functions and was foo.bars->arrayValues->fromArray I'd rather it stay on one line. Perhaps trigger wrap based on the number of pipes (e.g. 3) rather than line width?

TheSpyder avatar Aug 31 '21 23:08 TheSpyder

The rescript-lang/syntax repo is obsolete and will be archived soon. If this issue is still relevant, please reopen in the compiler repo (https://github.com/rescript-lang/rescript-compiler) or comment here to ask for it to be moved. Thank you for your contributions.

stale[bot] avatar May 28 '23 15:05 stale[bot]