eclipse-archived / ceylon.formatter

A formatter for the Ceylon programming language, written in Ceylon.
Apache License 2.0
14 stars 11 forks source link

Line break intersection goes over comments #56

Closed lucaswerkmeister closed 10 years ago

lucaswerkmeister commented 10 years ago

The formatter turns

switch (...)
case (...) {
} // comment
case (...) {
}

into

switch (...)
case (...) {
}
// comment
case (...) {
}

because the case token declares that it must have a line break before it, and the FormattingWriter applies that between the } and the // comment as well.

lucaswerkmeister commented 10 years ago
        /*
         handle the part before this token:
         fast-forward, intersect allowed line breaks, write out line breaks
         */
        intersectAllowedLineBreaks(lineBreaksBefore, false);
        fastForward((AntlrToken? current) { ...
            });
        for (i in 0:lineBreakAmount(givenLineBreaks)) {
            tokenQueue.add(LineBreak());
        }

I like how I managed to write the correct order in the comment and then implemented the wrong order :D