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!

1

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.

0
Avatar
Permanently deleted user

I'm trying to add an ApplicationComponent which will register annotators when init component. But when I can't read settings in initComponent.

As Plugin components lifecycle said: the initComponent method is invoked before the loadState method. Any suggestion?

0

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?

1
Avatar
Permanently deleted user
0
Avatar
Permanently deleted user
0
Avatar
Permanently deleted user

Thanks.

0

请先登录再写评论。