From 1c5a987807fcfc7556c879d59c5796a113fbd883 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Sat, 16 Mar 2024 00:08:01 +0100 Subject: [PATCH] open editor as soon as workspace index is ready to use GitOrigin-RevId: 29461d3dd47b1efa345876a12b1988c2f8d92e41 --- .../ProjectRunConfigurationInitializer.kt | 2 +- .../module/ModuleBridgeLoaderService.kt | 5 +++- .../lightEdit/project/LightEditProjectImpl.kt | 4 +-- .../project/impl/ProjectFrameAllocator.kt | 3 +-- .../project/impl/ProjectManagerImpl.kt | 27 ++++++++++--------- .../openapi/wm/impl/ProjectFrameHelper.kt | 5 ++-- .../src/META-INF/LangExtensions.xml | 1 + 7 files changed, 27 insertions(+), 20 deletions(-) diff --git a/platform/execution-impl/src/com/intellij/execution/impl/ProjectRunConfigurationInitializer.kt b/platform/execution-impl/src/com/intellij/execution/impl/ProjectRunConfigurationInitializer.kt index 15c483dc8055..fefa4d3ff60f 100644 --- a/platform/execution-impl/src/com/intellij/execution/impl/ProjectRunConfigurationInitializer.kt +++ b/platform/execution-impl/src/com/intellij/execution/impl/ProjectRunConfigurationInitializer.kt @@ -13,7 +13,7 @@ import com.intellij.openapi.project.impl.ProjectServiceContainerInitializedListe import kotlinx.coroutines.launch private class ProjectRunConfigurationInitializer : ProjectServiceContainerInitializedListener { - override suspend fun execute(project: Project) { + override suspend fun execute(project: Project, workspaceIndexReady: () -> Unit) { val coroutineTracer = CoroutineTracerShim.coroutineTracer @Suppress("UsagesOfObsoleteApi") (project as ComponentManagerEx).getCoroutineScope().launch(coroutineTracer.rootTrace()) { diff --git a/platform/lang-impl/src/com/intellij/workspaceModel/ide/impl/legacyBridge/module/ModuleBridgeLoaderService.kt b/platform/lang-impl/src/com/intellij/workspaceModel/ide/impl/legacyBridge/module/ModuleBridgeLoaderService.kt index 1c7309f72459..f8e8798c6ea0 100644 --- a/platform/lang-impl/src/com/intellij/workspaceModel/ide/impl/legacyBridge/module/ModuleBridgeLoaderService.kt +++ b/platform/lang-impl/src/com/intellij/workspaceModel/ide/impl/legacyBridge/module/ModuleBridgeLoaderService.kt @@ -53,7 +53,7 @@ private fun setupOpenTelemetryReporting(meter: Meter) { } private class ModuleBridgeLoaderService : ProjectServiceContainerInitializedListener { - override suspend fun execute(project: Project) { + override suspend fun execute(project: Project, workspaceIndexReady: () -> Unit) { coroutineScope { val projectModelSynchronizer = project.serviceAsync() val workspaceModel = project.serviceAsync() as WorkspaceModelImpl @@ -118,6 +118,9 @@ private class ModuleBridgeLoaderService : ProjectServiceContainerInitializedList WorkspaceModelCacheImpl.invalidateCaches() throw RuntimeException(e) } + finally { + workspaceIndexReady() + } } moduleLoadingTimeMs.addElapsedTime(start) diff --git a/platform/platform-impl/src/com/intellij/ide/lightEdit/project/LightEditProjectImpl.kt b/platform/platform-impl/src/com/intellij/ide/lightEdit/project/LightEditProjectImpl.kt index 77d65a60a948..1b531b3327cf 100644 --- a/platform/platform-impl/src/com/intellij/ide/lightEdit/project/LightEditProjectImpl.kt +++ b/platform/platform-impl/src/com/intellij/ide/lightEdit/project/LightEditProjectImpl.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.ide.lightEdit.project import com.intellij.ide.impl.runUnderModalProgressIfIsEdt @@ -39,7 +39,7 @@ internal class LightEditProjectImpl private constructor(projectPath: Path) : this@LightEditProjectImpl.createComponentsNonBlocking() } projectInitListeners { - it.execute(this@LightEditProjectImpl) + it.execute(this@LightEditProjectImpl, workspaceIndexReady = {}) } } } diff --git a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectFrameAllocator.kt b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectFrameAllocator.kt index d5b5f5f4c240..bb5dde0bfe21 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectFrameAllocator.kt +++ b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectFrameAllocator.kt @@ -133,7 +133,6 @@ private class FrameAllocatorProjectInitObserver( } launch { - rawProjectDeferred.join() span("project frame assigning") { frameHelper.setProject(project) } @@ -174,13 +173,13 @@ internal class ProjectUiFrameAllocator(@JvmField val options: OpenProjectTask, val projectInitObserver = FrameAllocatorProjectInitObserver(coroutineScope = loadingScope, deferredProjectFrameHelper = deferredProjectFrameHelper) - val rawProjectDeferred = projectInitObserver.rawProjectDeferred async(CoroutineName("project frame creating")) { createFrameManager(loadingScope = loadingScope, deferredProjectFrameHelper = deferredProjectFrameHelper) } val startOfWaitingForReadyFrame = AtomicLong(-1) + val rawProjectDeferred = projectInitObserver.rawProjectDeferred val reopeningEditorJob = outOfLoadingScope.launch { val project = rawProjectDeferred.await() span("restoreEditors") { diff --git a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.kt b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.kt index 2bc1cccda411..43501a4f3b84 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.kt +++ b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.kt @@ -681,7 +681,7 @@ open class ProjectManagerImpl : ProjectManagerEx(), Disposable { try { try { // cancel async preloading of services as soon as possible - (project as ComponentManagerEx).getCoroutineScope().coroutineContext.job.cancelAndJoin() + (project as ProjectImpl).getCoroutineScope().coroutineContext.job.cancelAndJoin() } catch (secondException: Throwable) { e.addSuppressed(secondException) @@ -1226,15 +1226,19 @@ private suspend fun initProject(file: Path, val isTrusted = async { !isTrustCheckNeeded || checkOldTrustedStateAndMigrate(project, file) } val beforeComponentCreation = projectInitObserver?.beforeInitRawProject(project) + val workspaceIndexReady = CompletableDeferred() + launch { + workspaceIndexReady.join() + projectInitObserver?.rawProjectDeferred?.complete(project) + if (preloadServices) { + schedulePreloadServices(project) + } + } projectInitListeners { - it.execute(project) + it.execute(project = project, workspaceIndexReady = { workspaceIndexReady.complete(Unit) }) } - projectInitObserver?.rawProjectDeferred?.complete(project) - - if (preloadServices) { - schedulePreloadServices(project) - } + workspaceIndexReady.complete(Unit) launch { beforeComponentCreation?.join() @@ -1263,8 +1267,7 @@ private suspend fun initProject(file: Path, } internal suspend inline fun projectInitListeners(crossinline executor: suspend (ProjectServiceContainerInitializedListener) -> Unit) { - val extensionArea = ApplicationManager.getApplication().extensionArea as ExtensionsAreaImpl - val ep = extensionArea + val ep = (ApplicationManager.getApplication().extensionArea as ExtensionsAreaImpl) .getExtensionPoint("com.intellij.projectServiceContainerInitializedListener") for (adapter in ep.sortedAdapters) { val pluginDescriptor = adapter.pluginDescriptor @@ -1272,7 +1275,7 @@ internal suspend inline fun projectInitListeners(crossinline executor: suspend ( !(pluginDescriptor.pluginId.idString == "com.jetbrains.codeWithMe" && adapter.assignableToClassName == "com.jetbrains.rdserver.unattendedHost.UnattendedHostManager\$ProjectAttachActivity") && !(pluginDescriptor.pluginId.idString == "intellij.rider.plugins.cwm" - && adapter.assignableToClassName == "com.jetbrains.rdserver.unattendedHost.UnattendedHostManager\$ProjectAttachActivity")) { + && adapter.assignableToClassName == "com.jetbrains.rdserver.unattendedHost.UnattendedHostManager\$ProjectAttachActivity")) { LOG.error(PluginException("Plugin $pluginDescriptor is not approved to add ${ep.name}", pluginDescriptor.pluginId)) continue } @@ -1287,7 +1290,7 @@ private suspend fun confirmOpenNewProject(options: OpenProjectTask): Int { return GeneralSettings.OPEN_PROJECT_NEW_WINDOW } - var mode = GeneralSettings.getInstance().confirmOpenNewProject + var mode = serviceAsync().confirmOpenNewProject if (mode == GeneralSettings.OPEN_PROJECT_ASK) { val ideUICustomization = serviceAsync() val message = if (options.projectName == null) { @@ -1345,7 +1348,7 @@ interface ProjectServiceContainerInitializedListener { /** * Invoked after container configured. */ - suspend fun execute(project: Project) + suspend fun execute(project: Project, workspaceIndexReady: () -> Unit) } @TestOnly diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ProjectFrameHelper.kt b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ProjectFrameHelper.kt index 63080c63a475..ea04b09b1bd9 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ProjectFrameHelper.kt +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ProjectFrameHelper.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.wm.impl import com.intellij.ide.RecentProjectsManager @@ -12,6 +12,7 @@ import com.intellij.openapi.application.ApplicationNamesInfo import com.intellij.openapi.application.EDT import com.intellij.openapi.application.ModalityState import com.intellij.openapi.application.impl.LaterInvocator +import com.intellij.openapi.components.serviceAsync import com.intellij.openapi.components.serviceIfCreated import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.diagnostic.debug @@ -308,7 +309,7 @@ open class ProjectFrameHelper internal constructor( internal suspend fun setProject(project: Project) { rootPane.setProject(project) activationTimestamp?.let { - RecentProjectsManager.getInstance().setActivationTimestamp(project, it) + serviceAsync().setActivationTimestamp(project, it) } } diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index dcc5c081e8fd..b111b1d6b83c 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -10,6 +10,7 @@ overrides="true"/>