API to get ProjectManager in coroutines:

`ProjectManager.getInstance` is blocking, hence can't be used in `suspend` context.

1. Annotation added to `ProjectManagerEx` not to miss this fact.
2. New method added to be called from `suspend`


(cherry picked from commit adbf699fc2adbadf1f07d1a79e43687471984a68)

IJ-MR-144580

GitOrigin-RevId: 9362e7e0907c3e198e14a6096440bd01e197b00e
This commit is contained in:
Ilya.Kazakevich
2024-09-11 13:07:16 +02:00
committed by intellij-monorepo-bot
parent 61aa06db74
commit bdf4e757a0
3 changed files with 9 additions and 2 deletions

View File

@@ -925,6 +925,7 @@ a:com.intellij.openapi.project.ex.ProjectManagerEx
f:com.intellij.openapi.project.ex.ProjectManagerEx$Companion
- f:getIS_CHILD_PROCESS():Z
- f:getInstanceEx():com.intellij.openapi.project.ex.ProjectManagerEx
- f:getInstanceExAsync(kotlin.coroutines.Continuation):java.lang.Object
- f:getInstanceExIfCreated():com.intellij.openapi.project.ex.ProjectManagerEx
- *f:isChildProcessPath(java.nio.file.Path):Z
e:com.intellij.openapi.project.ex.ProjectManagerEx$PerProjectState

View File

@@ -2,10 +2,12 @@
package com.intellij.openapi.project.ex
import com.intellij.ide.impl.OpenProjectTask
import com.intellij.openapi.application.PathManager
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.serviceAsync
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ProjectManager
import com.intellij.openapi.util.SystemInfoRt
import com.intellij.util.concurrency.annotations.RequiresBlockingContext
import org.jetbrains.annotations.ApiStatus.Experimental
import org.jetbrains.annotations.ApiStatus.Internal
import org.jetbrains.annotations.TestOnly
@@ -39,8 +41,11 @@ abstract class ProjectManagerEx : ProjectManager() {
const val PER_PROJECT_SUFFIX: String = "INTERNAL_perProject"
@JvmStatic
@RequiresBlockingContext
fun getInstanceEx(): ProjectManagerEx = getInstance() as ProjectManagerEx
suspend fun getInstanceExAsync(): ProjectManagerEx = ApplicationManager.getApplication().serviceAsync()
@JvmStatic
fun getInstanceExIfCreated(): ProjectManagerEx? = getInstanceIfCreated() as ProjectManagerEx?

View File

@@ -21,7 +21,8 @@ public abstract class ProjectManager {
public static final Topic<ProjectManagerListener> TOPIC = new Topic<>(ProjectManagerListener.class, Topic.BroadcastDirection.TO_DIRECT_CHILDREN, true);
/**
* @return {@code ProjectManager} instance
* @return {@code ProjectManager} instance.
* For coroutines, see <pre>ProjectManagerEx</pre>
*/
@RequiresBlockingContext
public static ProjectManager getInstance() {