[Analysis API] Rework in-block modifications for dandling file modules

Before the change, all code fragment sessions were invalidated on any
PSI change. It was a simple solution, though not very effective.
Fragments were invalidated not only on a physical module change, but
also on change in another, unrelated code fragment.

As code fragment sessions were reworked to support also ordinary '.kt'
files, the old logic started to have even less sense, because ordinary
dangling files do not have a context element (they only have a context
module).

Currently, code fragment sessions are invalidated on any change in a
physical (non-dangling) module, and are also invalidated on any change
in their contextual dangling module, if any. With some work, this can be
improved further, so code fragments will be invalidated only on changes
in modules they depend on.

Relevant tests can be found in the IntelliJ project
(DanglingFileModuleInvalidationTest).
This commit is contained in:
Yan Zhulanow
2023-11-09 22:31:42 +09:00
committed by Space Team
parent 432884fe84
commit 7944602066
5 changed files with 77 additions and 24 deletions
@@ -0,0 +1,19 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.analysis.providers.topics
import org.jetbrains.kotlin.analysis.project.structure.KtModule
public fun interface KotlinCodeFragmentContextModificationListener {
/**
* [onModification] is invoked in a write action before or after a context change for code fragments depending on the [module].
*
* All code fragments depending on [module], both directly or transitively, should be considered modified when this event is received.
*
* @see KotlinTopics
*/
public fun onModification(module: KtModule)
}
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.analysis.providers.analysisMessageBus
* - [KotlinGlobalModuleStateModificationListener]
* - [KotlinGlobalSourceModuleStateModificationListener]
* - [KotlinGlobalSourceOutOfBlockModificationListener]
* - [KotlinCodeFragmentContextModificationListener]
*
* Care needs to be taken with the lack of interplay between different types of topics: Publishing a global modification event, for example,
* does not imply the corresponding module-level event. Similarly, publishing a module state modification event does not imply out-of-block
@@ -60,4 +61,7 @@ public object KotlinTopics {
public val GLOBAL_SOURCE_OUT_OF_BLOCK_MODIFICATION: Topic<KotlinGlobalSourceOutOfBlockModificationListener> =
Topic(KotlinGlobalSourceOutOfBlockModificationListener::class.java, Topic.BroadcastDirection.TO_CHILDREN, true)
public val CODE_FRAGMENT_CONTEXT_MODIFICATION: Topic<KotlinCodeFragmentContextModificationListener> =
Topic(KotlinCodeFragmentContextModificationListener::class.java, Topic.BroadcastDirection.TO_CHILDREN, true)
}