Skip to content

Commit

Permalink
Don't drop caches before finish/onError
Browse files Browse the repository at this point in the history
(cherry picked from commit 9b7fcd4)
  • Loading branch information
ting-yuan authored and KSP Auto Pick committed Sep 26, 2024
1 parent 88b5b99 commit 75e2082
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,15 @@ class KotlinSymbolProcessing(
provider.create(symbolProcessorEnvironment).also { deferredSymbols[it] = mutableListOf() }
}

fun dropCaches() {
KotlinGlobalModificationService.getInstance(project).publishGlobalSourceModuleStateModification()
KaSessionProvider.getInstance(project).clearCaches()
psiManager.dropResolveCaches()
psiManager.dropPsiCaches()

KSObjectCacheManager.clear()
}

var rounds = 0
// Run processors until either
// 1) there is an error
Expand Down Expand Up @@ -549,18 +558,12 @@ class KotlinSymbolProcessing(

val allKSFilesPointers = allDirtyKSFiles.filterIsInstance<Deferrable>().map { it.defer() }

// Drop caches
KotlinGlobalModificationService.getInstance(project).publishGlobalSourceModuleStateModification()
KaSessionProvider.getInstance(project).clearCaches()
psiManager.dropResolveCaches()
psiManager.dropPsiCaches()

KSObjectCacheManager.clear()

if (logger.hasError || codeGenerator.generatedFile.isEmpty()) {
break
}

dropCaches()

newKSFiles = prepareNewKSFiles(
kotlinCoreProjectEnvironment,
javaFileManager,
Expand Down Expand Up @@ -590,6 +593,7 @@ class KotlinSymbolProcessing(
)
}

dropCaches()
codeGenerator.closeFiles()
} finally {
Disposer.dispose(projectDisposable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.google.devtools.ksp.processing.Resolver
import com.google.devtools.ksp.processing.SymbolProcessor
import com.google.devtools.ksp.processing.SymbolProcessorEnvironment
import com.google.devtools.ksp.symbol.KSAnnotated
import com.google.devtools.ksp.symbol.KSFile
import com.google.devtools.ksp.validate

class MultipleroundProcessor : AbstractTestProcessor() {
val result = mutableListOf<String>()
Expand Down Expand Up @@ -46,10 +48,20 @@ class MultipleroundProcessor : AbstractTestProcessor() {
val allFiles = resolver.getAllFiles().map { it.fileName }
result.add(allFiles.map { if (it in newFiles) "+$it" else it }.sorted().joinToString())

filesFromLastRound = resolver.getAllFiles()
round++
return emptyList()
}

lateinit var filesFromLastRound: Sequence<KSFile>

override fun finish() {
val allFiles = filesFromLastRound.map { it.fileName }.joinToString(", ")
result.add("Finish: $allFiles")
assert(filesFromLastRound.all { it.validate() })
super.finish()
}

lateinit var env: SymbolProcessorEnvironment

override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor {
Expand Down
1 change: 1 addition & 0 deletions test-utils/testData/api/multipleround.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
// K : I0, I1, I2, I3, I4, I5
// J : I0, I1, I2, I3, I4, I5
// +I5.java, I0.kt, I1.java, I2.kt, I3.java, I4.kt, J.java, K.kt
// Finish: K.kt, J.java, I0.kt, I1.java, I2.kt, I3.java, I4.kt, I5.java
// END

// FILE: K.kt
Expand Down

0 comments on commit 75e2082

Please sign in to comment.