mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
[workspace model] Groovy migrate to async events
GitOrigin-RevId: d7f9f4e2f30725b1339de7cfa5d2f673b7676d51
This commit is contained in:
committed by
intellij-monorepo-bot
parent
532a38b0b0
commit
9491bab98a
@@ -0,0 +1,30 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.plugins.groovy.dgm
|
||||
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.util.asSafely
|
||||
import com.intellij.workspaceModel.ide.WorkspaceModel
|
||||
import com.intellij.workspaceModel.ide.impl.legacyBridge.module.ModuleManagerBridgeImpl.Companion.moduleMap
|
||||
import com.intellij.workspaceModel.storage.bridgeEntities.ModuleEntity
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import org.jetbrains.plugins.groovy.transformations.macro.GroovyMacroRegistryService
|
||||
|
||||
class GroovyAsyncMacroModuleListener(private val project: Project, private val cs: CoroutineScope) {
|
||||
internal fun subscribe() {
|
||||
cs.launch {
|
||||
WorkspaceModel.getInstance(project).changesEventFlow.collect { event ->
|
||||
val moduleChanges = event.getChanges(ModuleEntity::class.java)
|
||||
if (moduleChanges.none()) {
|
||||
return@collect
|
||||
}
|
||||
for (moduleEntity in moduleChanges) {
|
||||
val entityToFlush = moduleEntity.oldEntity ?: continue
|
||||
val bridge = event.storageBefore.moduleMap.getDataByEntity(entityToFlush) ?: continue
|
||||
project.service<GroovyMacroRegistryService>().asSafely<GroovyMacroRegistryServiceImpl>()?.refreshModule(bridge)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.plugins.groovy.dgm
|
||||
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.util.asSafely
|
||||
import com.intellij.workspaceModel.ide.WorkspaceModelChangeListener
|
||||
import com.intellij.workspaceModel.ide.impl.legacyBridge.module.ModuleManagerBridgeImpl.Companion.moduleMap
|
||||
import com.intellij.workspaceModel.storage.EntityChange
|
||||
import com.intellij.workspaceModel.storage.VersionedStorageChange
|
||||
import com.intellij.workspaceModel.storage.bridgeEntities.ModuleEntity
|
||||
import org.jetbrains.plugins.groovy.transformations.macro.GroovyMacroRegistryService
|
||||
|
||||
class GroovyMacroModuleListener : WorkspaceModelChangeListener {
|
||||
|
||||
override fun changed(event: VersionedStorageChange) {
|
||||
val moduleChanges = event.getChanges(ModuleEntity::class.java)
|
||||
if (moduleChanges.none()) {
|
||||
return
|
||||
}
|
||||
for (moduleEntity in moduleChanges) {
|
||||
val entityToFlush = moduleEntity.oldEntity ?: continue
|
||||
val bridge = event.storageBefore.moduleMap.getDataByEntity(entityToFlush) ?: continue
|
||||
bridge.project.service<GroovyMacroRegistryService>().asSafely<GroovyMacroRegistryServiceImpl>()?.refreshModule(bridge)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.psi.util.*
|
||||
import com.intellij.util.asSafely
|
||||
import com.intellij.util.containers.addIfNotNull
|
||||
import com.intellij.workspaceModel.ide.WorkspaceModelTopics
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall
|
||||
@@ -24,12 +24,12 @@ import org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames
|
||||
import org.jetbrains.plugins.groovy.transformations.macro.GroovyMacroRegistryService
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
class GroovyMacroRegistryServiceImpl(val project: Project) : GroovyMacroRegistryService, Disposable {
|
||||
class GroovyMacroRegistryServiceImpl(val project: Project, val cs: CoroutineScope) : GroovyMacroRegistryService, Disposable {
|
||||
|
||||
private val availableModules: MutableMap<Module, CachedValue<Set<SmartPsiElementPointer<PsiMethod>>>> = ConcurrentHashMap()
|
||||
|
||||
init {
|
||||
project.messageBus.connect().subscribe(WorkspaceModelTopics.CHANGED, GroovyMacroModuleListener())
|
||||
GroovyAsyncMacroModuleListener(project, cs).subscribe()
|
||||
}
|
||||
|
||||
override fun resolveAsMacro(call: GrMethodCall): PsiMethod? {
|
||||
|
||||
Reference in New Issue
Block a user