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?

1
5 comments

If you need to execute some code when Project is opened, you can use `com.intellij.openapi.startup.StartupActivity`:

<extensions defaultExtensionNs="com.intellij">
<postStartupActivity implementation="com.MyStartupActivity"/>
</extensions>

Or you can register `com.intellij.openapi.components.ProjectComponent` to create an instance of your class for each Project:

<project-components>
<component>
<implementation-class>com.MyComponent</implementation-class>
</component>
</project-components>

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

1
Avatar
Permanently deleted user

@Aleksey Pivovarov

Thanks! Really helpful.

and..one more question, using 'StartupActivity' is not support for each project?

Thanks

0

Only one instance of `StartupActivity` will be created created, but `void runActivity(Project project);` method will be called for each project.

0
Avatar
Permanently deleted user

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)

```

0

You're using wrong EP - it should be "postStartupActivity", not "startupActivity".

2

Please sign in to leave a comment.