[dynamic plugins] predicate fixed #IDEA-253844 fixed
[idea/community.git] / platform / service-container / overview.md
1 This document is a more like a draft, that will be finally moved to [IntelliJ Platform SDK](https://www.jetbrains.org/intellij/sdk/docs/welcome.html)
2
3 ## Service
4
5 Please see [Service](https://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_services.html).
6
7 To replace (mock) service in tests, use [ServiceContainerUtil](https://github.com/JetBrains/intellij-community/blob/master/platform/testFramework/src/com/intellij/testFramework/ServiceContainerUtil.kt).
8
9 ## Preloading Activity
10
11 An activity to be executed in background on startup (regardless is some project opened or not).
12
13 See [PreloadingActivity](https://github.com/JetBrains/intellij-community/blob/master/platform/platform-impl/src/com/intellij/openapi/application/PreloadingActivity.java).
14
15 To register:
16
17 ```xml
18 <extensions defaultExtensionNs="com.intellij">
19   <preloadingActivity implementation="com.example.CatPreloadingActivity"/>
20 </extensions>
21 ```
22
23 ## Startup Activity
24
25 An activity to be executed after project opening.
26
27 Executed after project is opened on a background thread with no visible progress indicator and regardless of the current indexing mode. [DumbAware] is respected currently, but it maybe changed soon. 
28
29 * Use [ProgressManager.run(Task.Backgroundable)] to execute work that needs to be visible to users. Including work that consumes CPU over a noticeable period. Using of `Application.executeOnPooledThread` is not needed if you use the `ProgressManager` API.
30 * Use [AppUiUtil.invokeLaterIfProjectAlive] to execute work that needs to be performed in the UI thread.
31 * Use [DumbService] to execute work that requires access to indices.
32
33 <!--
34     todo runWhenSmart is not good method, because it implies EDT thread, but should be executed in a background thread with read action instead
35 -->
36
37 See [StartupActivity]. Do not forget to implement `DumbAware` to indicate that activity can be performed not in EDT and during indexing.
38
39 There are two extension points:
40
41 * `postStartupActivity`
42 * `backgroundPostStartupActivity` Acts as `postStartupActivity` but executed not immediately after project opening, but with 5 seconds delay.
43
44 To register:
45
46 ```xml
47 <extensions defaultExtensionNs="com.intellij">
48   <postStartupActivity implementation="com.example.CatColoringStartupActivity"/>
49 </extensions>
50 ```
51
52 [DumbAware]: https://github.com/JetBrains/intellij-community/blob/master/platform/core-api/src/com/intellij/openapi/project/DumbAware.java
53 [ProgressManager.run(Task.Backgroundable)]: https://github.com/JetBrains/intellij-community/blob/747b08812b83e744d130e315a54cca6b41906f57/platform/core-api/src/com/intellij/openapi/progress/ProgressManager.java#L183
54 [StartupActivity]: https://github.com/JetBrains/intellij-community/blob/master/platform/core-api/src/com/intellij/openapi/startup/StartupActivity.java
55 [AppUiUtil.invokeLaterIfProjectAlive]: https://github.com/JetBrains/intellij-community/blob/747b08812b83e744d130e315a54cca6b41906f57/platform/platform-impl/src/com/intellij/ui/AppUIUtil.java#L204
56 [DumbService]: https://github.com/JetBrains/intellij-community/blob/master/platform/core-api/src/com/intellij/openapi/project/DumbService.java