IntelliJ plugin autocomplete formatting


February 2019


175 time


I add an autocomplete fonctionnality to my IntelliJ plugin like this :

String completionString = "myFunction(err, data){if(err){}else{}}";
return LookupElementBuilder
                .withTailText(" (" + item + ")", true)

How can I format the new method I will put on editor ? I don't want a custom formatting, just want the default formatting of IntelliJ

1 answers


You can add an InsertHandler to your LookupElement and perform CodeStyleManager.reformat(psiElement) in its handleInsert method.

However, I don't see why you're making this available through a completion contributor at all. This looks like a live template, and your plugin can contribute live templates with far less effort than custom completion. Live templates are automatically shown in completion lists and support automatic reformatting.