Is there an easy way to suppress the closing brace when opening before a statement?
I've long since implemented a PairedBraceMatcher for my custom language plugin. In general it works great, but there's one thing it doesn't do that the Java editor does. Consider the following code:
for (Thing thing : bunchaThings)
doSomethingWith(thing);
In Java, when I place the caret at the end of the line containing the for loop and type "{", it doesn't close the brace. Instead I can quickly cursor down to below the statements I want enclosed in the block, type "}", and the now-enclosed block reformats.
In my language using a PairedBraceMatcher, the closing brace is inserted immediately, so I have to backspace to delete it before moving down to place the real closing brace. Not a huge thing, but just one more key I have to type, and because Java acts differently, I sometimes forget to and have to go back up to fix things.
I've implemented isPairedBracesAllowedBeforeType() and it works great for parens and such, but because it only has one element of lookahead, and because that element is almost always whitespace, it doesn't solve the problem described above.
I looked into how Java is doing this and it gets pretty convoluted pretty quickly. Before I dive into replicating that logic, I'm hoping that this is a much simpler problem to solve and I'm just not seeing the obvious solution. It seems like a variation on isPairedBracesAllowedBeforeType() that allows me to look further ahead in the element context would do it, but I haven't seen anything like that.
Thanks in advance for any insights!
Please sign in to leave a comment.
I guess, the logic was hard to implement purely in terms of lexer tokens, so it was done in terms of PSI structure (in JavaTypedHandler). I doubt, there's a simpler solution here.
Thanks, Dmitry. I'll keep looking and post anything I find here.