How to implement auto format code on type?
Answered
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 :)
Please sign in to leave a comment.
com.intellij.psi.codeStyle.lineIndent.LineIndentProvider
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:
what I expect this line to be reformatted to: (remove redundant whitespaces, add a line break with correct indent)
Please take another look, thanks!
Xiarui, use the com.intellij.codeInsight.actions.ReformatCodeProcessor action.