sway icon indicating copy to clipboard operation
sway copied to clipboard

Chained methods & fields that should be multiline need logic to handle vertical formatting

Open eureka-cpu opened this issue 3 years ago • 6 comments

fuelcoin.really_long_field.other_really_long_field.foo().bar().baz().quux();

should be:

fuelcoin
    .really_long_field
    .other_really_long_field
    .foo()
    .bar()
    .baz()
    .quux();

To elaborate further, this applies only to swayfmt. Logic needs to be added to handle the formatting of Sway code so that chained methods & fields that exceed a certain length (IIRC it's 60 but we are using the rustfmt standard which you can find here) are formatted as multiline chains.

rustfmt has a file dedicated to handling formatting of chains, here.

eureka-cpu avatar Nov 30 '22 06:11 eureka-cpu

hey @eureka-cpu, is the issue still open, i'd like to try to solve this issue :))

AliJafriETH avatar Dec 25 '22 20:12 AliJafriETH

hey @eureka-cpu, is the issue still open, i'd like to try to solve this issue :))

Please, feel free!

eureka-cpu avatar Dec 27 '22 00:12 eureka-cpu

Take a look at how we handle import statements for some general direction

eureka-cpu avatar Dec 27 '22 00:12 eureka-cpu

Hey @eureka-cpu, sorry for such a late response but i'm not able to find the issue? Could you please help me out?

AliJafriETH avatar Jan 01 '23 20:01 AliJafriETH

Hi @AliJafriETH, I would start by adding a few tests to swayfmt/src/formatter/mod.rs. Then check swayfmt/src/utils/language/expr/mod.rs, you should find everything you need there. Hopefully this clarifies where, but if you still need help feel free to reach out.

eureka-cpu avatar Jan 01 '23 21:01 eureka-cpu

Hey @eureka-cpu, thank you so much for the help, I'll update you with the progress :))

Thanks 💯

AliJafriETH avatar Jan 01 '23 22:01 AliJafriETH