eclipse-archived / ceylon.formatter

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

Consistency with IDE intentation #31

Open lucaswerkmeister opened 10 years ago

lucaswerkmeister commented 10 years ago

At the moment, the formatter is inconsistent in some points with the IDE’s indentation – for example, the IDE gives extends and satisfies a preIndent of 2, the formatter only 1 – and in other places, it’s consistent, but I dislike the behavior – for example, both currently give then and else a preIndent of 0, but I think it should be 1.

@gavinking In general, how much of the IDE indentation strategy should I consider “intentional”? For example, I’m pretty sure that the missing indentation of chained comprehensions is just “forgot to implement that” or a bug and not intentional.

Code examples to illustrate my points above:

// IDE
class Thing
        extends This()
        satisfies That {}
// formatter
class Thing
    extends This()
    satisfies That {}
// both are probably okay

// IDE, formatter
value v = condition
then value1
else value2;
// should be
value v = condition
    then value1
    else value2;

// IDE
value v = {
    for (c1 in "hello")
    for (c2 in "bye")
    c1->c2
};
// formatter
value v = {
    for (c1 in "hello")
        for (c2 in "bye")
            c1->c2
};
gavinking commented 10 years ago

the IDE gives extends and satisfies a preIndent of 2

I much prefer that, though perhaps it should be configgable.

both currently give then and else a preIndent of 0, but I think it should be 1.

The issue is that I'm very limited in what I can do in the autoeditstrategy because i'm working at the character and token level. So I can't distinguish the else operator from the else block of an if statement. I would much prefer if both were indented to the second level like other operators, but that's something I would need an AST for.

lucaswerkmeister commented 10 years ago

I much prefer that

alright, then I’ll make it configurable with a default value of 2.

The issue is that I'm very limited in what I can do in the autoeditstrategy because i'm working at the character and token level.

Maybe the formatter could add indentation information to the tokens during formatting, and the IDE would use that instead?

gavinking commented 10 years ago

I don't see how that would work. The IDE throws away tokens every time you type something.

lucaswerkmeister commented 10 years ago

Oh… well at least I understand now why it slows down so much when editing FormattingVisitor.ceylon :D (~1600 LOC, lexer + parser takes ~150ms)

lucaswerkmeister commented 10 years ago

Actually… I just noticed that what I said about the comprehensions isn’t true. Currently, both the IDE and the formatter output this:

value v = {
    for (i1 in 1..100)
    for (i2 in 1..100)
    if (i1 < i2)
    i1 -> i2
};

However, I really think it should be indented like this:

value v = {
    for (i1 in 1..100)
        for (i2 in 1..100)
            if (i1 < i2)
                i1 -> i2
};

@gavinking what do you think? Is the IDE’s indentation of this intentional?

gavinking commented 10 years ago

@lucaswerkmeister I prefer your suggestion. IIRC, it would be very difficult to implement it in the AutoEditStrategy. I can't consider either a closing paren or for as triggering a "continuation", unfortunately.

lucaswerkmeister commented 10 years ago

Yeah, I currently have the same problem that I can't tie the indentation to any specific token, but I think it shouldn't be too difficult for me to adapt the formatter's architecture.

----- Ursprüngliche Nachricht ----- Von: "Gavin King" notifications@github.com Gesendet: ‎14.‎03.‎2014 12:49 An: "lucaswerkmeister/ceylon.formatter" ceylon.formatter@noreply.github.com Cc: "Lucas Werkmeister" mail@lucaswerkmeister.de Betreff: Re: [ceylon.formatter] Consistency with IDE intentation (#31)

@lucaswerkmeister I prefer your suggestion. IIRC, it would be very difficult to implement with in the AutoEditStrategy. I can't consider either a closing paren or for as triggering a "continuation", unfortunately. — Reply to this email directly or view it on GitHub.

lucaswerkmeister commented 10 years ago

Another example where the formatter is inconsistent with the IDE is #26. @gavinking any thoughts on that?