[AA] KT-58257 Prepare KtResolveExtension API for active invalidation
- `KtResolveExtension`s need to participate in active invalidation, because LL FIR sessions depend on changes in resolve extension files. - The resolve extension will simply be able to use the `KotlinModificationSubscriptionService`, which is part of the Analysis API surface for **API implementors**, to publish modification events.
This commit is contained in:
committed by
Space Team
parent
0c94a3131c
commit
e3d803de8b
-2
@@ -6,7 +6,6 @@
|
||||
package org.jetbrains.kotlin.analysis.api.impl.base.test.cases.resolve.extensions
|
||||
|
||||
import com.intellij.mock.MockProject
|
||||
import com.intellij.openapi.util.ModificationTracker
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
@@ -47,7 +46,6 @@ class KtResolveExtensionForTest(
|
||||
private val shadowedScope: GlobalSearchScope,
|
||||
) : KtResolveExtension() {
|
||||
override fun getKtFiles(): List<KtResolveExtensionFile> = files
|
||||
override fun getModificationTracker(): ModificationTracker = ModificationTracker.NEVER_CHANGED
|
||||
override fun getContainedPackages(): Set<FqName> = packages
|
||||
override fun getShadowedScope(): GlobalSearchScope = shadowedScope
|
||||
}
|
||||
|
||||
+11
-14
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.resolve.extensions
|
||||
|
||||
import com.intellij.openapi.util.ModificationTracker
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
@@ -24,27 +23,25 @@ import org.jetbrains.kotlin.name.FqName
|
||||
*/
|
||||
public abstract class KtResolveExtension {
|
||||
/**
|
||||
* Get the list of files that should be generated for the module.
|
||||
* Get the list of files that should be generated for the module. Returned files should contain valid Kotlin code.
|
||||
*
|
||||
* The content of those files should remain valid until the tracker [getModificationTracker] is modified.
|
||||
* If the content of these files becomes invalid (e.g., because the source declarations they were based on changed), the
|
||||
* [KtResolveExtension] must publish an out-of-block modification event via the Analysis API message bus:
|
||||
* [org.jetbrains.kotlin.analysis.providers.topics.KotlinTopics.MODULE_OUT_OF_BLOCK_MODIFICATION].
|
||||
*
|
||||
* Returned files should contain a valid Kotlin code.
|
||||
* To react to changes in Kotlin sources, [KtResolveExtension] may subscribe to Analysis API topics:
|
||||
* [org.jetbrains.kotlin.analysis.providers.topics.KotlinTopics]. If the [KtResolveExtension] both subscribes to and
|
||||
* publishes modification events, care needs to be taken that no cycles are introduced. In general, the [KtResolveExtension] should
|
||||
* never publish an event for a module A in a listener for the same module A.
|
||||
*
|
||||
* An out-of-block modification event for the [KtResolveExtension]'s associated module does not need to be published in response to an
|
||||
* out-of-block modification event for the same module, because the original event suffices for invalidation.
|
||||
*
|
||||
* @see KtResolveExtensionFile
|
||||
* @see KtResolveExtension
|
||||
*/
|
||||
public abstract fun getKtFiles(): List<KtResolveExtensionFile>
|
||||
|
||||
/**
|
||||
* Returns a [ModificationTracker], which controls the validity lifecycle of the files provided by [getKtFiles].
|
||||
*
|
||||
* All files generated by [getKtFiles] should be valid if the [ModificationTracker] did not change.
|
||||
* If files become invalid (e.g., the in-source declarations they were based on changed) the [ModificationTracker] should be incremented.
|
||||
*
|
||||
* @see KtResolveExtension
|
||||
*/
|
||||
public abstract fun getModificationTracker(): ModificationTracker
|
||||
|
||||
/**
|
||||
* Returns the set of packages that are contained in the files provided by [getKtFiles].
|
||||
*
|
||||
|
||||
-4
@@ -6,7 +6,6 @@
|
||||
package org.jetbrains.kotlin.analysis.low.level.api.fir.resolve.extensions
|
||||
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.openapi.util.ModificationTracker
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisAllowanceManager
|
||||
@@ -37,7 +36,6 @@ import java.util.concurrent.ConcurrentHashMap
|
||||
* for the [org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProvider].
|
||||
*/
|
||||
abstract class LLFirResolveExtensionTool : FirSessionComponent {
|
||||
abstract val modificationTrackers: List<ModificationTracker>
|
||||
abstract val declarationProvider: LLFirResolveExtensionToolDeclarationProvider
|
||||
abstract val packageProvider: KotlinPackageProvider
|
||||
abstract val packageFilter: LLFirResolveExtensionToolPackageFilter
|
||||
@@ -59,8 +57,6 @@ internal class LLFirNonEmptyResolveExtensionTool(
|
||||
|
||||
override val packageFilter = LLFirResolveExtensionToolPackageFilter(extensions)
|
||||
|
||||
override val modificationTrackers by lazy { forbidAnalysis { extensions.map { it.getModificationTracker() } } }
|
||||
|
||||
override val declarationProvider: LLFirResolveExtensionToolDeclarationProvider =
|
||||
LLFirResolveExtensionToolDeclarationProvider(fileProvider, session.ktModule)
|
||||
|
||||
|
||||
-2
@@ -9,7 +9,6 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.ModificationTracker
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.SmartPointerManager
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.resolve.extensions.llResolveExtensionTool
|
||||
import org.jetbrains.kotlin.analysis.project.structure.*
|
||||
import org.jetbrains.kotlin.analysis.providers.KotlinModificationTrackerFactory
|
||||
import org.jetbrains.kotlin.analysis.providers.KtModuleStateTracker
|
||||
@@ -58,7 +57,6 @@ abstract class LLFirSession(
|
||||
add(ModuleStateModificationTracker(ktModule, validityTracker))
|
||||
addIfNotNull(outOfBlockTracker)
|
||||
add(dependencyTracker)
|
||||
llResolveExtensionTool?.modificationTrackers?.let(::addAll)
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user