mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-30 18:27:49 +08:00
plugin_services.md: note related new inspections
This commit is contained in:
parent
9e28fcc5d1
commit
82f87d539b
@ -1,7 +1,7 @@
|
||||
<!-- Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -->
|
||||
|
||||
# Services
|
||||
|
||||
<!-- Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -->
|
||||
|
||||
<link-summary>Registering and using on-demand services to encapsulate plugin functionality.</link-summary>
|
||||
|
||||
A _service_ is a plugin component loaded on demand when your plugin calls the `getService()` method of corresponding [`ComponentManager`](%gh-ic%/platform/extensions/src/com/intellij/openapi/components/ComponentManager.java) instance (see [Types](#types)).
|
||||
@ -43,13 +43,18 @@ Instead, annotate service class with [`@Service`](%gh-ic%/platform/core-api/src/
|
||||
Project-level services must specify `@Service(Service.Level.PROJECT)`.
|
||||
The service instance will be created in scope according to the caller (see [Retrieving a Service](#retrieving-a-service)).
|
||||
|
||||
Restrictions:
|
||||
### Light Service Restrictions
|
||||
|
||||
* None of these attributes is required: `os`, `client`, `overrides`, `id`, `preload`.
|
||||
* Service class must be `final`.
|
||||
* Constructor injection of dependency services is not supported.
|
||||
* [Constructor injection](#constructor) of dependency services is not supported.
|
||||
* If application-level service is a [PersistentStateComponent](persisting_state_of_components.md), roaming must be disabled (`roamingType = RoamingType.DISABLED`).
|
||||
|
||||
Use these inspections to verify these and highlight services that can be converted (2023.3):
|
||||
- <control>Plugin DevKit | Code | Light service must be final</control>
|
||||
- <control>Plugin DevKit | Code | Mismatch between light service level and its constructor</control>
|
||||
- <control>Plugin DevKit | Code | A service can be converted to a light one</control> and corresponding <control>Plugin DevKit | Plugin descriptor | A service can be converted to a light one</control> for <path>plugin.xml</path>
|
||||
|
||||
### Examples
|
||||
|
||||
|
||||
@ -128,6 +133,7 @@ To register a non-[Light Service](#light-services), distinct extension points ar
|
||||
|
||||
To expose service API, create separate class for `serviceInterface` and extend it in corresponding class registered in `serviceImplementation`.
|
||||
If `serviceInterface` isn't specified, it's supposed to have the same value as `serviceImplementation`.
|
||||
Use inspection <control>Plugin DevKit | Plugin descriptor | Plugin.xml extension registration</control> to highlight redundant `serviceInterface` declarations.
|
||||
|
||||
To provide custom implementation for test/headless environment, specify `testServiceImplementation`/`headlessImplementation` additionally.
|
||||
|
||||
@ -260,6 +266,10 @@ Registration in <path>plugin.xml</path>:
|
||||
> Instead, **always** obtain these service instances directly and **only** at the location where they're needed.
|
||||
> Failing to do so can lead to unexpected exceptions and severe consequences for your plugin's functionality.
|
||||
>
|
||||
> Such problems are highlighted via inspections (2023.3):
|
||||
> - <control>Plugin DevKit | Code | Application service assigned to a static final field or immutable property</control>
|
||||
> - <control>Plugin DevKit | Code | Incorrect or simplifiable retrieving service</control>
|
||||
>
|
||||
{style="warning"}
|
||||
|
||||
Getting a service doesn't need a read action and can be performed from any thread.
|
||||
|
Loading…
x
Reference in New Issue
Block a user