3.0 KiB
title |
---|
Plugin Components |
Warning
When writing new plugins, creating components should be avoided. Any existing components should be migrated to services, extensions, or listeners (see below).
Plugin components are a legacy feature supported for compatibility with plugins created for older versions of the IntelliJ Platform. Plugins using components do not support dynamic loading (the ability to install, update, and uninstall plugins without restarting the IDE).
Plugin components are defined in the <application-components>
, <project-components>
, and <module-components>
sections in a Plugin Configuration File.
Migration
To migrate existing code from components to more modern APIs, please see the following guidelines.
Manage State
To manage some state or logic that is only needed when the user performs a specific operation, use a Service.
Persisting State
To store the state of your plugin at the application or project level, use a Service, and implement the PersistentStateComponent
interface. See Persisting State of Components for details.
Subscribing to Events
To subscribe to events, use a listener or create an extension for a dedicated extension point (for example, com.intellij.editorFactoryListener
) if one exists for the event to subscribe to.
Application Startup
Executing code on application startup should be avoided whenever possible because it slows down startup. Plugin code should only be executed when projects are opened (see Project Open) or when the user invokes an action of a plugin. If this cannot be avoided, add a listener subscribing to the AppLifecycleListener topic.
Project Open
To execute code when a project is being opened, use one of these two extensions:
- StartupActivity registered via
com.intellij.postStartupActivity
for immediate execution - StartupActivity.Background registered via
com.intellij.backgroundPostStartupActivity
for execution with 5 seconds delay (2019.3 or later)
Application/Project Close
To execute code on project closing or application shutdown, implement the Disposable
interface in a Service and place the code in the dispose()
method. Alternatively, use Disposer.register()
passing a Project
or Application
service instance as the parent
argument (see Choosing a Disposable Parent).