Extensions
Extensions are the most common way for a plugin to extend the IntelliJ Platform's functionality in a way that is not as straightforward as adding an action to a menu or toolbar.
The following are some of the most common tasks accomplished using extensions:
The
com.intellij.toolWindow
extension point allows plugins to add tool windows (panels displayed at the sides of the IDE user interface);The
com.intellij.applicationConfigurable
andcom.intellij.projectConfigurable
extension points allow plugins to add pages to the Settings/Preferences dialog;Custom language plugins use many extension points to extend various language support features in the IDE.
There are more than 1000 extension points available in the platform and the bundled plugins, allowing customizing different parts of the IDE behavior.
Exploring Available Extensions
扩展点和监听器列表 lists all available extension points in IntelliJ Platform and from bundled plugins in IntelliJ IDEA. Additionally, dedicated Extension Point and Listener Lists specific to IDEs are available under Part VIII — Product Specific. Browse usages inside existing implementations of open-source IntelliJ Platform plugins via IntelliJ Platform Explorer.
Alternatively (or when using 3rd party extension points), all available extension points for the specified namespace (defaultExtensionNs
) can be listed using auto-completion inside the <extensions>
block in plugin.xml. Use in the lookup list to access more information about the extension point and implementation (if applicable). See 探索 IntelliJ Platform API for more information and strategies.
Declaring Extensions
Add an
<extensions>
element to your plugin.xml if it's not yet present there. Set thedefaultExtensionNs
attribute to one of the following values:com.intellij
, if your plugin extends the IntelliJ Platform core functionality.{ID of a plugin}
, if your plugin extends the functionality of another plugin (must configure Plugin Dependencies).
Add a new child element to the
<extensions>
element. The child element's name must match the name of the extension point you want the extension to access.Depending on the type of the extension point, do one of the following:
If the extension point was declared using the
interface
attribute, set theimplementation
attribute to the name of the class that implements the specified interface.If the extension point was declared using the
beanClass
attribute, set all properties annotated with the@Attribute
andTag
annotations in the specified bean class.
See the Declaring Extension Points section for details.
NB: When using Kotlin, use
class
and neverobject
for all implementations (more details).
To clarify this procedure, consider the following sample section of the plugin.xml file that defines two extensions designed to access the com.intellij.appStarter
and com.intellij.projectTemplatesFactory
extension points in the IntelliJ Platform, and one extension to access the another.plugin.myExtensionPoint
extension point in another plugin another.plugin
:
Extension Default Properties
The following properties are available always:
id
- unique ID. Consider prepending ID with the prefix related to the plugin name or ID to not clash with other plugins defining extensions with the same ID, e.g.,com.example.myplugin.myExtension
.order
- allows ordering all defined extensions usingfirst
,last
orbefore|after [id]
respectivelyos
- allows restricting an extension to given OS, e.g.,os="windows"
registers the extension on Windows only
If an extension instance needs to "opt out" in certain scenarios, it can throw ExtensionNotApplicableException
in its constructor.
Extension Properties Code Insight
Several tooling features are available to help configure bean class extension points in plugin.xml.
Properties annotated with @RequiredElement
are inserted automatically and validated (2019.3 and later). If the given property is allowed to have an explicit empty value, set allowEmpty
to true
(2020.3 and later).
Property names matching the following list will resolve to fully qualified class name:
implementation
className
serviceInterface
/serviceImplementation
ending with
Class
(case-sensitive)
A required parent type can be specified in the extension point declaration via nested <with>
:
Property name language
(or ending in *Language
, 2020.2+) resolves to all present Language
IDs.
Similarly, action
resolves to all registered <action>
IDs.
Specifying @org.jetbrains.annotations.Nls
validates a UI String
capitalization according to the text property Capitalization
enum value (2019.2 and later).
Attributes with Enum
type support code insight with lowerCamelCased notation (2020.1 and later).