How to implement auto format code on type?


I like it when I wrote java code Intellij IDEA provide some auto reformat, for example after I type colon in a swich-case statement, idea will reformat the line with correct indent:

I want to implement a similar feature in my custom language plugin, which interface should I use? Any help/pointers are gratefully received :)

Comment actions Permalink


Comment actions Permalink

Yann Cebron, Thanks! 

Further question:  I see that LineIndentProvider only adjusts the indent of the line, but not whitespaces. If I want to reformat the line with both indent and whitespaces, what interface should I use?

For example, I want to reformat this right after I type enter at the end of this line:

if        a: print(a)

what I expect this line to be reformatted to: (remove redundant whitespaces, add a line break with correct indent)

if a:

Please take another look, thanks!

Comment actions Permalink

Xiarui, use the com.intellij.codeInsight.actions.ReformatCodeProcessor action.


Please sign in to leave a comment.