AzureMarker / intellij-lalrpop

Jetbrains plugin for the LALRPOP parser-generator
MIT License
16 stars 2 forks source link

A primitive formatter. #9

Closed dnbln closed 4 years ago

dnbln commented 4 years ago

There seems to be a weird bug where after every element it thinks there should be 2 blocks of indentation. For example, for this lalrpop file:

| <-  caret

// use statements
// everything else

Pressing enter if the caret is there would just work and creates and moves the caret to the beginning of the new line. While if the caret is here, in a file like this:

use crate::grammar::*;
grammar;
| <- caret here

// everything else

Pressing enter there would also move the caret 2 blocks forward(2 tabs / 8 spaces):

use crate::grammar::*;
grammar;

        | <- caret here

// everything else

Same thing happens within all kinds of blocks, like

grammar;

NonTerminal = { | <- caret here
}

Press enter.

grammar;

NonTerminal = {
....1...2...3
}

The caret should be at the position marked with 1, but intellij puts it at 3.

However, writing the alternative at the 3 position like:

grammar;
NonTerminal = {
            sy0 sy1 sy2 ...
}

And then formatting, will yield a file properly formatted, like this:

grammar;
NonTerminal = {
    sy0 sy1 sy2
}

And I can't seem to figure out why this happens.

Edit: After looking at some examples it seems I am building the blocks wrong. Will fix soon:tm:

AzureMarker commented 4 years ago

Did you give up on this? If you want help I can take a closer look.

dnbln commented 4 years ago

Rather than gave up I moved it to the formatter branch(maybe open another PR; I couldn't figure how to change the branch). The only thing I couldn't get right were the alignments, and I'd be happy with any help I can get on them.