plugins/kotlin/compiler-reference-index/README.md
Compiler reference index service – is a service that allows to reduce the search scope of a declaration usages for compiled projects.
Basis: a large codebase with many declarations and usages with common names like getInstance
Action: find usages of some getInstance declaration
Problem: a lot of false positive candidate files caused by text search
Solution: extract usage information from the compiler to reduce the search scope
Compile project before searching.
We have Show Compiler Index Status internal action to check the difference between Use Scope and Code Usage Scope.
Q: How to use it?
A: Put the caret at the declaration and call the action
PsiSearchHelper#getCodeUsageScope
KotlinScopeOptimizer and JavaCompilerReferencesCodeUsageScopeOptimizer under the hoodIncrementalJvmCacheJavaBackwardReferenceRegistrarKotlinCompilerReferenceIndexStorageBackwardReferenceReaderKotlinCompilerReferenceIndexBuilderJavaBackwardReferenceIndexBuilderDirtyScopeHolder by KotlinCompilerReferenceIndexServiceDirtyScopeHolder by CompilerReferenceServiceImplCompilerReferenceServiceImpl and KotlinCompilerReferenceIndexService on the project startup
BuildManagerListener to handle the start and the end of a buildPortableCachesLoadListener to drop the index to avoid JPS cache corruptionCompilerManager#isUpToDate check by IsUpToDateCheckStartupActivity as backgroundPostStartupActivity
activeBuildCountactiveBuildCountactiveBuildCount == 0 then open the index storageThe dirty scope operates with modules. All modules are dirty be default (except for up to date case).
We should track changed files to provide the correct search scope. A change in the file causes the current and all dependent modules to be marked as "dirty".
The scope also contains modules excluded from compilation.
The result search scope should contain files from:
CompilerReferenceService and KotlinCompilerReferenceIndexService into one service