Formatter - comment settings based on position
Hello again, I'm looking for help with blank lines formatter settings of comments. I'll try to simplify as possible.
I've set up a formatter that has 1 blank line between variables and 2 blank lines above function declaration, so it does works fine, but problem is, when I add comments into it.

.after(VARIABLE).blankLines(1)
.before(METHOD).blankLines(2)
will give me correct formatting, but when adding comments, I want to stick it with the block below, so to stop pushing variable/function from comments above I'd like to set some overriding rule like:
.after(COMMENT).blankLines(0)
But even then it'd create an issue that between variable and function there would be only 1 line as the rule 2 lines above function would be overriden.
Is there a way for something like including comment block into the block below - or any other correct approach to this?

I was also thinking about adding comment into bnf grammar but than I'd have to drop the standard PsiComment elementand instead introduced a new language specific one? Which I'm not sure if it would break things like commenting line and such and just seems wrong to do it this way.
Thank you and have a nice day.
请先登录再写评论。
Hi,
I suggest handling these cases in
Block.getSpacing()by ignoring comment elements. If one of the blocks is a comment, take its non-comment sibling and returnSpacingBuilder.getSpacing(parent, block1, nonCommentBlock2)fromBlock.getSpacing().Thank you, that was actually quite an easy solution I've missed.