From a0d2bd1d3a4ca7181ddfdb29e4d32e9eea982fee Mon Sep 17 00:00:00 2001 From: "Alexander.Kirsanov" Date: Sat, 20 May 2023 21:34:30 +0200 Subject: [PATCH] [rdct] Provide access to project-level sessions from an app-level one. Should save people from ad-hoc project guessing and dealing with the default project GitOrigin-RevId: 766f599d5a538f8b6a89571805dddc9bc51cdee5 --- .../intellij/openapi/client/ClientSession.kt | 19 ++++++++++++++++++- .../openapi/client/ClientSessionImpl.kt | 4 ++++ .../openapi/client/ClientSessionsManager.kt | 9 +++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/client/ClientSession.kt b/platform/platform-impl/src/com/intellij/openapi/client/ClientSession.kt index c726f28caa71..e075a47d8135 100644 --- a/platform/platform-impl/src/com/intellij/openapi/client/ClientSession.kt +++ b/platform/platform-impl/src/com/intellij/openapi/client/ClientSession.kt @@ -52,7 +52,15 @@ interface ClientSession : ComponentManager { */ @ApiStatus.Experimental @ApiStatus.Internal -interface ClientAppSession : ClientSession +interface ClientAppSession : ClientSession { + /** + * Clients may have access only to some of the projects. + * Currently, there's a limitation in Code With Me (CWM-2149) because of the complexity with permissions and calls. + * + * For remote-dev having several projects, or not having one open is natural same as in a local setup + */ + val projectSessions: List +} /** * Project level [ClientSession] @@ -60,6 +68,15 @@ interface ClientAppSession : ClientSession @ApiStatus.Experimental @ApiStatus.Internal interface ClientProjectSession : ClientSession { + /** + * Project this session belongs to. Unlike sessions there's only one project, + * independently of how many active users is operating with it. + */ val project: Project + + /** + * Some features live on app-level (e.g., UI, actions, popups) this allows to get from project-level to app-level. + * It's recommended to get session instead on manual [ClientId] manipulation + */ val appSession: ClientAppSession } diff --git a/platform/platform-impl/src/com/intellij/openapi/client/ClientSessionImpl.kt b/platform/platform-impl/src/com/intellij/openapi/client/ClientSessionImpl.kt index b9d376887ce6..56f20fc77065 100644 --- a/platform/platform-impl/src/com/intellij/openapi/client/ClientSessionImpl.kt +++ b/platform/platform-impl/src/com/intellij/openapi/client/ClientSessionImpl.kt @@ -13,6 +13,7 @@ import com.intellij.openapi.components.ServiceDescriptor import com.intellij.openapi.components.impl.stores.IComponentStore import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.project.Project +import com.intellij.openapi.project.ProjectManager import com.intellij.openapi.project.impl.ProjectImpl import com.intellij.serviceContainer.ComponentManagerImpl import com.intellij.serviceContainer.PrecomputedExtensionModel @@ -152,6 +153,9 @@ open class ClientAppSessionImpl( return pluginDescriptor.appContainerDescriptor } + override val projectSessions: List + get() = ProjectManager.getInstance().openProjects.mapNotNull { ClientSessionsManager.getProjectSession(it, this) } + init { @Suppress("LeakingThis") registerServiceInstance(ClientAppSession::class.java, this, fakeCorePluginDescriptor) diff --git a/platform/platform-impl/src/com/intellij/openapi/client/ClientSessionsManager.kt b/platform/platform-impl/src/com/intellij/openapi/client/ClientSessionsManager.kt index ade06a8d7c7e..4a45d41973f1 100644 --- a/platform/platform-impl/src/com/intellij/openapi/client/ClientSessionsManager.kt +++ b/platform/platform-impl/src/com/intellij/openapi/client/ClientSessionsManager.kt @@ -8,6 +8,7 @@ import com.intellij.openapi.application.impl.ApplicationImpl import com.intellij.openapi.components.service import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.project.Project +import com.intellij.openapi.project.ProjectManager import com.intellij.openapi.project.impl.ProjectImpl import com.intellij.openapi.util.Disposer import org.jetbrains.annotations.ApiStatus @@ -26,6 +27,14 @@ sealed class ClientSessionsManager { return getInstance(project).getSession(session.clientId) } + /** + * Clients may not have access to certain projects + * @return a list of project-level sessions available to a certain [ClientAppSession] + */ + fun getAllProjectSession(session: ClientAppSession): List { + return ProjectManager.getInstance().openProjects.mapNotNull { getProjectSession(it, session) } + } + /** * Returns a project-level session for a particular client. * @see ClientProjectSession