How to auto start(initialize) plugin on project loaded?
Answered
Hi, I'm new to Java and plugin development!
I tried to make simple plugin with https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started.html
But the tutorial is with doing some action (like keyboard action).
In plugin.xml, (<action class="{ACTION CLASS}">) 'ACTION CLASS' is initialized after some keyboard action. but I want to make not like this, just initialize on project loaded
To make syntax highlighter and bubble tooltip on mouse hover, how can I register actions in plugin.xml file?
Please sign in to leave a comment.
If you need to execute some code when Project is opened, you can use `com.intellij.openapi.startup.StartupActivity`:
Or you can register `com.intellij.openapi.components.ProjectComponent` to create an instance of your class for each Project:
See https://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_components.html
Likely, implementing a syntax highlighter via action in plugin.xml is a wrong approach.
See https://www.jetbrains.org/intellij/sdk/docs/tutorials/custom_language_support_tutorial.html and https://www.jetbrains.org/intellij/sdk/docs/reference_guide/custom_language_support.html
@Aleksey Pivovarov
Thanks! Really helpful.
and..one more question, using 'StartupActivity' is not support for each project?
Thanks
Only one instance of `StartupActivity` will be created created, but `void runActivity(Project project);` method will be called for each project.
I am getting this error
```
java.lang.Throwable: Only bundled plugin can define com.intellij.startupActivity: PluginDescriptor(name=JHelper, id=name.admitriev.jhelper, descriptorPath=plugin.xml, path=~/workspace/github/JHelper/build/idea-sandbox/plugins/JHelper, version=0.23, package=null)
```
You're using wrong EP - it should be "postStartupActivity", not "startupActivity".