Open lukedegruchy opened 9 years ago
Alright, this requires at least #18 (alignment) and #11 (line breaks after every argument, even though not all of them are necessary to make it fit). Eventually, I hope to move ceylon.formatter
to something more powerful than it is today, similar to dartfmt (I think this feature requires what they call constraints), but that’ll take a while.
Also, a commentary on code style: I much prefer this style:
void functionWithReallyLongParamList(one, two, three, four, five, six, seven) {
"This is documentation.
It takes up lots of space, so it’s better to put it in the body,
rather than flood the parameter list with TMI."
String one;
"This is also documentation."
String two;
"Look at all this
documentation!"
String three;
"Much document.
Very clear.
Such readable.
Wow."
String four;
// …
}
@lucaswerkmeister yeah, definitely.
I keep forgetting you can do that trick with functions as well as classes.
I think my suggestion actually is more applicable to the expression function syntax, where it's not possible to declare variables outside of the param list.
Boolean functionWithReallyLongParamList(String one,
String two,
String three,
String four,
String five,
String six,
String seven)
=> ....
@lukedegruchy also, function headers for formal
or native
functions.
Also, https://github.com/ceylon/ceylon.formatter/issues/117#issuecomment-141699968 is rubbish. If I change FormattingVisitor
to enforce a line break after every comma, you get this:
void functionWithReallyLongParamList(String one,
String two,
String three,
String four,
String five,
String six,
String seven) {}
I don’t see why alignment would be needed here, this is just standard indentation of the opening parenthesis.
Remaining questions:
(
and the String one
?I guess what I'm asking for is the Ceylon equivalent of the following Eclipse Java formatter settings. Whether or not these are feasible given the technical concerns raised by @lucaswerkmeister in the comment immediately preceding this one is another question.
Preferences > Java > Code Style > Formatter >
Indentation > Tab Policy: Spaces only
Line Wrapping > Line Wrapping Policy: Indent all, except first element if not necessary Indentation Policy: Indent on column
What's odd is that it doesn't work at all as intended in the preview if the tab policy is the default, which is tabs only.
This is obviously not intended for 1.2 and is a feature request.
My personal preference is to take a really long parameter list, for example:
And format it this way:
I realize most Ceylon developers won't necessarily prefer that style but I think it should be an available option.