eclipse-archived / ceylon.formatter

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

No newlines between toplevel declarations #84

Closed lucaswerkmeister closed 9 years ago

lucaswerkmeister commented 9 years ago

In absence of a token stream, toplevel declarations are formatted without any line breaks between them, like this:

"The run function."
shared void run() {
    sysout.println("Hello, World!");
    return;
} shared class MyBoolean(shared actual String string) of myTrue | myFalse extends Object() satisfies MyObject {
    /* ... */
} class B() => MyBoolean(); interface Strings => {String*}; alias Primitive => Integer|Float|Boolean|Character?; function genericLoop<in TParam1 = String->Integer,out TParam2 = Anything()>(dynamic param = [])
        given TParam1 of Integer | Float
        given TParam2 satisfies [Anything, Anything=] & <Outer.Inner>[] => genericLoop<TParam1,TParam2>();

(from ceylon.ast’s completeCompilationUnit).

lucaswerkmeister commented 9 years ago

Hm, perhaps the current line break model isn’t expressive enough… if the original line breaks are available, we do want to permit 0..3 line breaks between bodies / statements (trailing comments), but we can currently only influence what happens without tokens by changing the order of that range (first element is picked), and while 0 is not enough, 3 is too much :/

EDIT: The same goes for statements. Range 0..2, but a blank line between all statements is too much as well.

lucaswerkmeister commented 9 years ago

One hacky fix would be to use

lineBreaksAfter = tokens exists then 0..3 else 1..0;

for the line breaks

I don’t like how this undermines the abstraction from FormattingWriter, but since it’s restricted only two functions (visitBody, writeSemicolon), I could probably live with it.

lucaswerkmeister commented 9 years ago

Done, good enough for 1.1.0 at least.