mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 11:50:54 +07:00
IJPL-326 make beforeApplicationLoaded as suspend
GitOrigin-RevId: 645cb7c678c41cd0f6f21f472a7e66fcbb9b8116
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2f42e486fc
commit
2efe22a776
@@ -16,5 +16,5 @@ interface ApplicationLoadListener {
|
||||
val EP_NAME: ExtensionPointName<ApplicationLoadListener> = ExtensionPointName("com.intellij.ApplicationLoadListener")
|
||||
}
|
||||
|
||||
fun beforeApplicationLoaded(application: Application, configPath: Path)
|
||||
suspend fun beforeApplicationLoaded(application: Application, configPath: Path)
|
||||
}
|
||||
|
||||
@@ -258,8 +258,8 @@ suspend fun initConfigurationStore(app: ApplicationImpl) {
|
||||
val configDir = PathManager.getConfigDir()
|
||||
|
||||
span("beforeApplicationLoaded") {
|
||||
ApplicationLoadListener.EP_NAME.forEachExtensionSafe { listener ->
|
||||
listener.beforeApplicationLoaded(app, configDir)
|
||||
for (extension in ApplicationLoadListener.EP_NAME.filterableLazySequence()) {
|
||||
extension.instance?.beforeApplicationLoaded(app, configDir)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,15 +7,12 @@ import com.intellij.openapi.components.Service
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.progress.ProcessCanceledException
|
||||
import com.intellij.util.concurrency.NonUrgentExecutor
|
||||
import com.jetbrains.rd.util.threading.coroutines.RdCoroutineScope
|
||||
import kotlinx.coroutines.*
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
class RdCoroutineHost(coroutineScope: CoroutineScope) : RdCoroutineScope() {
|
||||
companion object {
|
||||
private val logger = logger<RdCoroutineHost>()
|
||||
|
||||
val instance by lazy {
|
||||
val scope = ApplicationManager.getApplication().service<ScopeHolder>()
|
||||
RdCoroutineHost(scope.scope).apply {
|
||||
@@ -23,11 +20,11 @@ class RdCoroutineHost(coroutineScope: CoroutineScope) : RdCoroutineScope() {
|
||||
}
|
||||
}
|
||||
|
||||
fun init() { instance }
|
||||
fun init() {
|
||||
instance
|
||||
}
|
||||
|
||||
val applicationThreadPool get() = Dispatchers.IO
|
||||
val processIODispatcher = ProcessIOExecutorService.INSTANCE.asCoroutineDispatcher()
|
||||
val nonUrgentDispatcher = NonUrgentExecutor.getInstance().asCoroutineDispatcher()
|
||||
val processIODispatcher: ExecutorCoroutineDispatcher = ProcessIOExecutorService.INSTANCE.asCoroutineDispatcher()
|
||||
}
|
||||
|
||||
override val defaultContext: CoroutineContext = coroutineScope.coroutineContext
|
||||
@@ -56,15 +53,15 @@ class RdCoroutineHost(coroutineScope: CoroutineScope) : RdCoroutineScope() {
|
||||
@Deprecated("Dispatchers.EDT + ModalityState.any().asContextElement()", ReplaceWith("Dispatchers.EDT + ModalityState.any().asContextElement()", "kotlinx.coroutines.Dispatchers",
|
||||
"com.intellij.openapi.application.EDT", "com.intellij.openapi.application.ModalityState",
|
||||
"com.intellij.openapi.application.asContextElement"))
|
||||
val uiDispatcherAnyModality get() = Dispatchers.EDT + ModalityState.any().asContextElement()
|
||||
val uiDispatcherAnyModality: CoroutineContext
|
||||
get() = Dispatchers.EDT + ModalityState.any().asContextElement()
|
||||
|
||||
override fun onException(throwable: Throwable) {
|
||||
if (throwable !is CancellationException && throwable !is ProcessCanceledException) {
|
||||
logger.error("Unhandled coroutine throwable", throwable)
|
||||
logger<RdCoroutineHost>().error("Unhandled coroutine throwable", throwable)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Service(Service.Level.APP)
|
||||
private class ScopeHolder(val scope: CoroutineScope)
|
||||
private class ScopeHolder(@JvmField val scope: CoroutineScope)
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
@file:OptIn(ExperimentalCoroutinesApi::class)
|
||||
|
||||
package com.intellij.openapi.rd.util
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
@@ -17,12 +19,19 @@ import java.util.concurrent.CompletableFuture
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlin.coroutines.EmptyCoroutineContext
|
||||
|
||||
private val applicationThreadPool get() = RdCoroutineHost.applicationThreadPool
|
||||
private val processIODispatcher get() = RdCoroutineHost.processIODispatcher
|
||||
private val nonUrgentDispatcher get() = RdCoroutineHost.nonUrgentDispatcher
|
||||
private val uiDispatcher get() = RdCoroutineHost.instance.uiDispatcher
|
||||
private val uiDispatcherWithInlining get() = RdCoroutineHost.instance.uiDispatcherWithInlining
|
||||
private val uiDispatcherAnyModality get() = RdCoroutineHost.instance.uiDispatcherAnyModality
|
||||
private val applicationThreadPool: CoroutineDispatcher
|
||||
get() = Dispatchers.IO
|
||||
private val processIODispatcher: ExecutorCoroutineDispatcher
|
||||
get() = RdCoroutineHost.processIODispatcher
|
||||
|
||||
private val nonUrgentDispatcher: CoroutineDispatcher = Dispatchers.Default.limitedParallelism(2)
|
||||
|
||||
private val uiDispatcher: CoroutineContext
|
||||
get() = RdCoroutineHost.instance.uiDispatcher
|
||||
private val uiDispatcherWithInlining: CoroutineDispatcher
|
||||
get() = RdCoroutineHost.instance.uiDispatcherWithInlining
|
||||
private val uiDispatcherAnyModality: CoroutineContext
|
||||
get() = RdCoroutineHost.instance.uiDispatcherAnyModality
|
||||
|
||||
fun Lifetime.launchOnUi(
|
||||
context: CoroutineContext = EmptyCoroutineContext,
|
||||
|
||||
@@ -8,10 +8,7 @@ import com.intellij.ide.ApplicationLoadListener
|
||||
import com.intellij.openapi.application.Application
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.application.ex.ApplicationManagerEx
|
||||
import com.intellij.openapi.components.RoamingType
|
||||
import com.intellij.openapi.components.Service
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.components.stateStore
|
||||
import com.intellij.openapi.components.*
|
||||
import com.intellij.openapi.diagnostic.getOrLogException
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.options.SchemeManagerFactory
|
||||
@@ -20,7 +17,6 @@ import com.intellij.openapi.progress.runBlockingCancellable
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.project.ProjectCloseListener
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.util.childScope
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.FlowPreview
|
||||
import kotlinx.coroutines.channels.BufferOverflow
|
||||
@@ -105,7 +101,7 @@ class IcsManager @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun sync(syncType: SyncType, project: Project? = null, localRepositoryInitializer: (() -> Unit)? = null): Boolean {
|
||||
suspend fun sync(syncType: SyncType, localRepositoryInitializer: (() -> Unit)? = null): Boolean {
|
||||
return syncManager.sync(syncType, localRepositoryInitializer)
|
||||
}
|
||||
|
||||
@@ -241,25 +237,24 @@ class IcsManager @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
@Service
|
||||
internal class IcsManagerService {
|
||||
private class IcsManagerService(private val coroutineScope: CoroutineScope) {
|
||||
lateinit var icsManager: IcsManager
|
||||
|
||||
fun init(app: Application, configPath: Path) {
|
||||
val customPath = System.getProperty("ics.settingsRepository")
|
||||
val pluginSystemDir = if (customPath == null) configPath.resolve("settingsRepository") else Path.of(FileUtil.expandUserHome(customPath))
|
||||
@Suppress("DEPRECATION")
|
||||
val icsManager = IcsManager(pluginSystemDir, app.coroutineScope.childScope())
|
||||
val dir = if (customPath == null) configPath.resolve("settingsRepository") else Path.of(FileUtil.expandUserHome(customPath))
|
||||
val icsManager = IcsManager(dir = dir, coroutineScope = coroutineScope)
|
||||
this.icsManager = icsManager
|
||||
icsManager.beforeApplicationLoaded(app)
|
||||
}
|
||||
}
|
||||
|
||||
private class IcsApplicationLoadListener : ApplicationLoadListener {
|
||||
override fun beforeApplicationLoaded(application: Application, configPath: Path) {
|
||||
override suspend fun beforeApplicationLoaded(application: Application, configPath: Path) {
|
||||
if (application.isUnitTestMode) {
|
||||
return
|
||||
}
|
||||
|
||||
application.service<IcsManagerService>().init(application, configPath)
|
||||
application.serviceAsync<IcsManagerService>().init(application, configPath)
|
||||
}
|
||||
}
|
||||
@@ -75,10 +75,10 @@ fun doSync(icsManager: IcsManager, project: Project?, syncType: SyncType, url: S
|
||||
runBlockingModalWithRawProgressReporter(owner, icsMessage("task.sync.title")) {
|
||||
if (isRepositoryWillBeCreated && syncType != SyncType.OVERWRITE_LOCAL) {
|
||||
com.intellij.configurationStore.saveSettings(componentManager = ApplicationManager.getApplication(), forceSavingAllSettings = false)
|
||||
icsManager.sync(syncType = syncType, project = project) { copyLocalConfig() }
|
||||
icsManager.sync(syncType = syncType) { copyLocalConfig() }
|
||||
}
|
||||
else {
|
||||
icsManager.sync(syncType = syncType, project = project, localRepositoryInitializer = null)
|
||||
icsManager.sync(syncType = syncType, localRepositoryInitializer = null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -388,7 +388,7 @@ internal class SettingsRepositoryGitTest : SettingsRepositoryGitTestBase() {
|
||||
store.setPath(localConfigPath)
|
||||
store.storageManager.addStreamProvider(provider)
|
||||
|
||||
icsManager.sync(syncType, projectRule.project) { copyLocalConfig(store.storageManager) }
|
||||
icsManager.sync(syncType) { copyLocalConfig(store.storageManager) }
|
||||
|
||||
if (addLocalFiles) {
|
||||
assertThat(localConfigPath).isDirectory()
|
||||
|
||||
Reference in New Issue
Block a user