It is possible to dynamically add or remove annotator section in extensions ?
I created a plugin which support some languages, now I want to add some functionality so that user could turn on or turn off this functionality for some languages.
My plugin.xml like :
<extensions defaultExtensionNs="com.intellij">
<!-- Add your extensions here -->
<annotator language="Clojure" implementationClass="com.github.izhangzhihao.rainbow.brackets.RainbowBrackets"/>
<annotator language="JAVA" implementationClass="com.github.izhangzhihao.rainbow.brackets.RainbowBrackets"/>
<annotator language="kotlin" implementationClass="com.github.izhangzhihao.rainbow.brackets.RainbowBrackets"/>
<annotator language="Python" implementationClass="com.github.izhangzhihao.rainbow.brackets.RainbowBrackets"/>
<annotator language="Haskell" implementationClass="com.github.izhangzhihao.rainbow.brackets.RainbowBrackets"/>
<annotator language="Agda" implementationClass="com.github.izhangzhihao.rainbow.brackets.RainbowBrackets"/>
<annotator language="Rust" implementationClass="com.github.izhangzhihao.rainbow.brackets.RainbowBrackets"/>
</extensions>
As you seen. So, it is possible to dynamically add or remove `annotator`s in `extensions` sections? Thanks!
请先登录再写评论。
You can dynamically load an extension via Extensions.getRootArea().registerExtension(). However it may be simpler to just check if the option is enabled in 'annotate' method and do nothing if the functionality is disabled.
I'm trying to add an
ApplicationComponentwhich will register annotators when init component. But when I can't read settings ininitComponent.As Plugin components lifecycle said: the initComponent method is invoked before the loadState method. Any suggestion?
You can add/remove extension directly in 'loadState' method. But note that it's not recommended to create ApplicationComponent in plugins, see its javadoc for details. Why not just return from 'annotate' method if the functionality is disabled?
Thanks.