Formatter and Indentation




I know here are some answers already regarding this question, but unfortunately the answers are way too old or did not resolve the problem.

So here we go.


I have a simple Lua Grammar and all i want to get every Child Block indented by 1 tab. As you can see, as far as the parent is not the File itself, i want to get a normal Indent. The "return parent.getIndent();" was already a Indent.getNoneIndent() and null, always with the same result: nothing...


My FormattingBlock where the indentation is built, inherited from AbstractBlock:

spacing rules:

PsiTree (CoronaBlockImpl(BLOCK) starting from the second layer should be indented):

and now the result i get from the indentation:


so can someone please explain to me, why this stuff is not indented as expected? As far as I have read through forums, Documentations and internets this should be correct?


getSpacing should work (indent text by specified # of spaces) if Indent is not used.

let's try this:

  1. use null everywhere Indent is currently used
  2. check if getSpacing is called for every block. Every symbol should be in its own Block. getSpacing should be called with CRLF, first symbol 
  3. for testing: specify arbitrary space size (say, 8 so it is clear: is it used or not)

just remembered something: for this to work, CRLF should be in a block, too. Need to include it somehow.


nope, it does not. Tested it yet again and is not working. It does move nothing but new lines... horizontally there is nothing happening

edit: sry, didn't see your edit in time, will test that now


really, the CRLF have to be their own block? I read somewhere here in one post that they just have to be excluded from the blocks. Right now every little thing, except whitespaces (which are tabs, new lines and whitespaces itself) are in their own blocks. The whitespaces are excluded. 

I also read somewhere, that whitespaces should ne be in multiple tokens... For example for every tab and new line a single whitespace entry...


well this is not a recommended approach to formatting.

it works though. Sometimes indenting logic does not fit the built-in cases. Then there is no choice but to use spaces.

let's give newlines (CRLF) their own blocks and see what happens.

Indent is still there if you decide to make it work.


well, i would prefer to get Indent to work, but until i have no idea how, i stick with the good ol' "whatever"-way :D


Problem with that approch is, that, like I tried to say, every new line and whitespace stuff is combined in one Element. So to get this solution to work, I have to change Lexer and probably adjust Parser and so on. And that seems to be a bit too much work for "just a try". You know what I am trying to say?


I understand. It is a lot of time and work, yes. If there is not enough time, maybe it's best to focus on another part of plugin and leave formatting for later.

Formatting is very tricky.

Just to clarify: getSpacing can be used to indent "with pixel precision" ;)

"try" here means: see if you can (~ there is enough time to) make it work. Not "let's see if it works or not".

and again: it takes a lot of time and effort.


Please sign in to leave a comment.