Explicitly state that PluginDeclarationProviderFactory is source-only
Before this change `filesScope` was effectively empty in cases when
module info is a library, thus looking
into PackageIndexUtil.packageExists(name, indexedFilesScope, project)
was kind of redundant since it always returns false for empty scopes
The initial motivation was run by 1716720604
that made PackageIndexUtil::packageExists calls much more frequent
This commit is contained in:
@@ -221,9 +221,6 @@ class LibraryInfo(val project: Project, val library: Library) : IdeaModuleInfo,
|
||||
|
||||
override fun contentScope(): GlobalSearchScope = LibraryWithoutSourceScope(project, library)
|
||||
|
||||
override val isLibrary: Boolean
|
||||
get() = true
|
||||
|
||||
override fun dependencies(): List<IdeaModuleInfo> {
|
||||
val result = LinkedHashSet<IdeaModuleInfo>()
|
||||
result.add(this)
|
||||
@@ -261,9 +258,6 @@ data class LibrarySourceInfo(val project: Project, val library: Library) : IdeaM
|
||||
|
||||
override fun sourceScope(): GlobalSearchScope = KotlinSourceFilterScope.librarySources(LibrarySourceScope(project, library), project)
|
||||
|
||||
override val isLibrary: Boolean
|
||||
get() = true
|
||||
|
||||
override fun modulesWhoseInternalsAreVisible(): Collection<ModuleInfo> {
|
||||
return listOf(LibraryInfo(project, library))
|
||||
}
|
||||
@@ -366,4 +360,4 @@ interface SourceForBinaryModuleInfo : IdeaModuleInfo {
|
||||
|
||||
override val moduleOrigin: ModuleOrigin
|
||||
get() = ModuleOrigin.OTHER
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.idea.stubindex
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.ProjectRootManager
|
||||
import com.intellij.openapi.util.Ref
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.search.DelegatingGlobalSearchScope
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
@@ -86,9 +85,6 @@ class KotlinSourceFilterScope private constructor(
|
||||
@JvmStatic
|
||||
fun projectSourceAndClassFiles(delegate: GlobalSearchScope, project: Project) = create(delegate, true, false, true, false, project)
|
||||
|
||||
@JvmStatic
|
||||
fun sources(delegate: GlobalSearchScope, project: Project) = create(delegate, true, false, false, true, project)
|
||||
|
||||
@JvmStatic
|
||||
fun projectSources(delegate: GlobalSearchScope, project: Project) = create(delegate, true, false, false, false, project)
|
||||
|
||||
|
||||
+3
-4
@@ -61,10 +61,9 @@ class PluginDeclarationProviderFactory(
|
||||
fileBasedDeclarationProviderFactory.packageExists(fqName) || stubBasedPackageExists(fqName)
|
||||
|
||||
private fun stubBasedPackageExists(name: FqName): Boolean {
|
||||
return if (moduleInfo is ModuleSourceInfo)
|
||||
project.service<PerModulePackageCacheService>().packageExists(name, moduleInfo)
|
||||
else
|
||||
PackageIndexUtil.packageExists(name, indexedFilesScope, project)
|
||||
// We're only looking for source-based declarations
|
||||
val moduleSourceInfo = moduleInfo as? ModuleSourceInfo ?: return false
|
||||
return project.service<PerModulePackageCacheService>().packageExists(name, moduleSourceInfo)
|
||||
}
|
||||
|
||||
private fun getStubBasedPackageMemberDeclarationProvider(name: FqName): PackageMemberDeclarationProvider? {
|
||||
|
||||
+22
-7
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.stubindex.resolve
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.kotlin.analyzer.ModuleInfo
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.ModuleSourceInfo
|
||||
import org.jetbrains.kotlin.idea.stubindex.KotlinSourceFilterScope
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
|
||||
@@ -28,11 +29,25 @@ import org.jetbrains.kotlin.storage.StorageManager
|
||||
class PluginDeclarationProviderFactoryService : DeclarationProviderFactoryService() {
|
||||
|
||||
override fun create(
|
||||
project: Project,
|
||||
storageManager: StorageManager,
|
||||
syntheticFiles: Collection<KtFile>,
|
||||
filesScope: GlobalSearchScope,
|
||||
moduleInfo: ModuleInfo
|
||||
): DeclarationProviderFactory =
|
||||
PluginDeclarationProviderFactory(project, KotlinSourceFilterScope.sources(filesScope, project), storageManager, syntheticFiles, moduleInfo)
|
||||
project: Project,
|
||||
storageManager: StorageManager,
|
||||
syntheticFiles: Collection<KtFile>,
|
||||
filesScope: GlobalSearchScope,
|
||||
moduleInfo: ModuleInfo
|
||||
): DeclarationProviderFactory {
|
||||
if (syntheticFiles.isEmpty() && moduleInfo !is ModuleSourceInfo) {
|
||||
// No actual source declarations for libraries
|
||||
// Even in case of libraries sources they should be obtained through the classpath with subsequent decompiling
|
||||
// Anyway, we'll filter them out with `KotlinSourceFilterScope.sources` call below
|
||||
return DeclarationProviderFactory.EMPTY
|
||||
}
|
||||
|
||||
return PluginDeclarationProviderFactory(
|
||||
project,
|
||||
KotlinSourceFilterScope.projectSources(filesScope, project),
|
||||
storageManager,
|
||||
syntheticFiles,
|
||||
moduleInfo
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user