mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
extract PsiVFSModuleRootListener to toplevel
GitOrigin-RevId: ed324d0501686ff0e998107ce71d36ecf63b8c38
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d43ac97ddb
commit
170895dc20
@@ -504,61 +504,6 @@ class PsiVFSListener internal constructor(private val project: Project) {
|
||||
)
|
||||
}
|
||||
|
||||
internal class MyModuleRootListener(private val listenerProject: Project) : ModuleRootListener {
|
||||
// accessed from within write action only
|
||||
private var depthCounter = 0
|
||||
|
||||
override fun beforeRootsChange(event: ModuleRootEvent) {
|
||||
LOG.trace { "beforeRootsChanged call" }
|
||||
if (event.isCausedByFileTypesChange) {
|
||||
return
|
||||
}
|
||||
|
||||
LOG.trace { "Event is not caused by file types change" }
|
||||
ApplicationManager.getApplication().runWriteAction(ExternalChangeAction {
|
||||
depthCounter++
|
||||
LOG.trace { "depthCounter increased $depthCounter" }
|
||||
if (depthCounter > 1) {
|
||||
return@ExternalChangeAction
|
||||
}
|
||||
|
||||
val psiManager = PsiManager.getInstance(listenerProject) as PsiManagerImpl
|
||||
val treeEvent = PsiTreeChangeEventImpl(psiManager)
|
||||
treeEvent.propertyName = PsiTreeChangeEvent.PROP_ROOTS
|
||||
psiManager.beforePropertyChange(treeEvent)
|
||||
})
|
||||
}
|
||||
|
||||
override fun rootsChanged(event: ModuleRootEvent) {
|
||||
LOG.trace { "rootsChanged call" }
|
||||
val psiManager = PsiManager.getInstance(listenerProject) as PsiManagerImpl
|
||||
val fileManager = psiManager.fileManager as FileManagerImpl
|
||||
fileManager.dispatchPendingEvents()
|
||||
|
||||
if (event.isCausedByFileTypesChange) {
|
||||
return
|
||||
}
|
||||
|
||||
LOG.trace { "Event is not caused by file types change" }
|
||||
ApplicationManager.getApplication().runWriteAction(
|
||||
ExternalChangeAction {
|
||||
depthCounter--
|
||||
LOG.trace { "depthCounter decreased $depthCounter" }
|
||||
assert(depthCounter >= 0) { "unbalanced `beforeRootsChange`/`rootsChanged`: $depthCounter" }
|
||||
if (depthCounter > 0) {
|
||||
return@ExternalChangeAction
|
||||
}
|
||||
|
||||
DebugUtil.performPsiModification<RuntimeException>(null) { fileManager.possiblyInvalidatePhysicalPsi() }
|
||||
|
||||
val treeEvent = PsiTreeChangeEventImpl(psiManager)
|
||||
treeEvent.propertyName = PsiTreeChangeEvent.PROP_ROOTS
|
||||
psiManager.propertyChanged(treeEvent)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun handleVfsChangeWithoutPsi(vFile: VirtualFile) {
|
||||
if (!reportedUnloadedPsiChange && isInRootModel(vFile)) {
|
||||
fileManager.firePropertyChangedForUnloadedPsi()
|
||||
@@ -630,6 +575,61 @@ class PsiVFSListener internal constructor(private val project: Project) {
|
||||
}
|
||||
}
|
||||
|
||||
internal class PsiVFSModuleRootListener(private val listenerProject: Project) : ModuleRootListener {
|
||||
// accessed from within write action only
|
||||
private var depthCounter = 0
|
||||
|
||||
override fun beforeRootsChange(event: ModuleRootEvent) {
|
||||
LOG.trace { "beforeRootsChanged call" }
|
||||
if (event.isCausedByFileTypesChange) {
|
||||
return
|
||||
}
|
||||
|
||||
LOG.trace { "Event is not caused by file types change" }
|
||||
ApplicationManager.getApplication().runWriteAction(ExternalChangeAction {
|
||||
depthCounter++
|
||||
LOG.trace { "depthCounter increased $depthCounter" }
|
||||
if (depthCounter > 1) {
|
||||
return@ExternalChangeAction
|
||||
}
|
||||
|
||||
val psiManager = PsiManager.getInstance(listenerProject) as PsiManagerImpl
|
||||
val treeEvent = PsiTreeChangeEventImpl(psiManager)
|
||||
treeEvent.propertyName = PsiTreeChangeEvent.PROP_ROOTS
|
||||
psiManager.beforePropertyChange(treeEvent)
|
||||
})
|
||||
}
|
||||
|
||||
override fun rootsChanged(event: ModuleRootEvent) {
|
||||
LOG.trace { "rootsChanged call" }
|
||||
val psiManager = PsiManager.getInstance(listenerProject) as PsiManagerImpl
|
||||
val fileManager = psiManager.fileManager as FileManagerImpl
|
||||
fileManager.dispatchPendingEvents()
|
||||
|
||||
if (event.isCausedByFileTypesChange) {
|
||||
return
|
||||
}
|
||||
|
||||
LOG.trace { "Event is not caused by file types change" }
|
||||
ApplicationManager.getApplication().runWriteAction(
|
||||
ExternalChangeAction {
|
||||
depthCounter--
|
||||
LOG.trace { "depthCounter decreased $depthCounter" }
|
||||
assert(depthCounter >= 0) { "unbalanced `beforeRootsChange`/`rootsChanged`: $depthCounter" }
|
||||
if (depthCounter > 0) {
|
||||
return@ExternalChangeAction
|
||||
}
|
||||
|
||||
DebugUtil.performPsiModification<RuntimeException>(null) { fileManager.possiblyInvalidatePhysicalPsi() }
|
||||
|
||||
val treeEvent = PsiTreeChangeEventImpl(psiManager)
|
||||
treeEvent.propertyName = PsiTreeChangeEvent.PROP_ROOTS
|
||||
psiManager.propertyChanged(treeEvent)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private class MyFileDocumentManagerListener(private val project: Project) : FileDocumentManagerListener {
|
||||
private val fileManager = PsiManagerEx.getInstanceEx(project).fileManager as FileManagerImpl
|
||||
|
||||
|
||||
@@ -1797,7 +1797,7 @@
|
||||
topic="com.intellij.codeInsight.lookup.LookupManagerListener"/>
|
||||
<listener class="com.intellij.lang.documentation.ide.impl.DocumentationAutoPopupListener"
|
||||
topic="com.intellij.codeInsight.lookup.LookupManagerListener"/>
|
||||
<listener class="com.intellij.psi.impl.file.impl.PsiVFSListener$MyModuleRootListener"
|
||||
<listener class="com.intellij.psi.impl.file.impl.PsiVFSModuleRootListener"
|
||||
topic="com.intellij.openapi.roots.ModuleRootListener"/>
|
||||
<listener class="com.intellij.workspaceModel.ide.impl.legacyBridge.facet.FacetEntityChangeListener$WorkspaceModelListener"
|
||||
topic="com.intellij.platform.backend.workspace.WorkspaceModelChangeListener"/>
|
||||
|
||||
Reference in New Issue
Block a user