IntelliJ plugin autocomplete formatting

Refresh

February 2019

Views

173 time

1

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

String completionString = "myFunction(err, data){if(err){}else{}}";
return LookupElementBuilder
                .create(completionString)
                .withBoldness(true)
                .withIcon(SailsJSIcons.SailsJS)
                .withPresentableText("myFunction()")
                .withCaseSensitivity(true)
                .withTypeText(type)
                .withTailText(" (" + item + ")", true)
                .withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE);

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

4

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.