Intellij idea IntelliJ插件自动完成格式化

Intellij idea IntelliJ插件自动完成格式化,intellij-idea,autocomplete,formatting,intellij-plugin,Intellij Idea,Autocomplete,Formatting,Intellij Plugin,我将自动完成功能添加到IntelliJ插件中,如下所示: String completionString = "myFunction(err, data){if(err){}else{}}"; return LookupElementBuilder .create(completionString) .withBoldness(true) .withIcon(SailsJSIcons.SailsJS)

我将自动完成功能添加到IntelliJ插件中,如下所示:

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);

如何格式化我将在编辑器上使用的新方法?我不需要自定义格式,只需要IntelliJ的默认格式。您可以在查找元素中添加一个InsertHandler,并在其handleInsert方法中执行CodeStyleManager.ReformAtPsElement


然而,我完全不明白为什么你要通过一个完成贡献者来实现这一点。这看起来像一个活动模板,你的插件可以贡献活动模板,比定制完成要省力得多。实时模板会自动显示在完成列表中,并支持自动重新格式化。

您可以向查找元素添加插入句柄,并在其handleInsert方法中执行CodeStyleManager.ReformatPsElement


然而,我完全不明白为什么你要通过一个完成贡献者来实现这一点。这看起来像一个活动模板,你的插件可以贡献活动模板,比定制完成要省力得多。实时模板会自动显示在完成列表中,并支持自动重新格式化。

您是否有示例?也为活模板?如果live模板更易于使用,并且可以完成,我就接受它^^。我想自动生成一个nodeJS的基本函数结构,比如Model.myfunc->completion->Model.myfunctionparam1,{…};对于handleInsert下的CodeStyleManager.reformat,psiElement为null:哪个psiElement为null?您需要找到手动插入的元素。handleInsertInsertionContext,LookupElement item I just test item.getPsiElement但这是一个空的示例,具体说明了什么?若要从插件贡献实时模板,您需要实现DefaultLiveTemplatesProvider。您有示例吗?也为活模板?如果live模板更易于使用,并且可以完成,我就接受它^^。我想自动生成一个nodeJS的基本函数结构,比如Model.myfunc->completion->Model.myfunctionparam1,{…};对于handleInsert下的CodeStyleManager.reformat,psiElement为null:哪个psiElement为null?您需要找到手动插入的元素。handleInsertInsertionContext,LookupElement item I just test item.getPsiElement但这是一个空的示例,具体说明了什么?要从插件贡献实时模板,您需要实现DefaultLiveTemplatesProvider。