Implemented KotlinResolveScopeEnlarger for modules
Before that we had dependency to iml file, which is incorrect
This commit is contained in:
@@ -16,7 +16,6 @@ import com.intellij.openapi.roots.impl.libraries.LibraryEx
|
||||
import com.intellij.openapi.roots.libraries.Library
|
||||
import com.intellij.openapi.util.ModificationTracker
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.ResolveScopeEnlarger
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.psi.util.CachedValueProvider
|
||||
import com.intellij.util.PathUtil
|
||||
@@ -170,7 +169,9 @@ data class ModuleProductionSourceInfo internal constructor(
|
||||
|
||||
override val stableName: Name = module.getStableName()
|
||||
|
||||
override fun contentScope(): GlobalSearchScope = enlargedSearchScope(ModuleProductionSourceScope(module), module.moduleFile)
|
||||
override fun contentScope(): GlobalSearchScope {
|
||||
return enlargedSearchScope(ModuleProductionSourceScope(module), module, isTestScope = false)
|
||||
}
|
||||
|
||||
override fun <T> createCachedValueProvider(f: () -> CachedValueProvider.Result<T>) = CachedValueProvider { f() }
|
||||
}
|
||||
@@ -186,7 +187,7 @@ data class ModuleTestSourceInfo internal constructor(override val module: Module
|
||||
|
||||
override val displayedName get() = module.name + " (test)"
|
||||
|
||||
override fun contentScope(): GlobalSearchScope = enlargedSearchScope(ModuleTestSourceScope(module), module.moduleFile)
|
||||
override fun contentScope(): GlobalSearchScope = enlargedSearchScope(ModuleTestSourceScope(module), module, isTestScope = true)
|
||||
|
||||
override fun modulesWhoseInternalsAreVisible() = module.cached(CachedValueProvider {
|
||||
val list = SmartList<ModuleInfo>()
|
||||
|
||||
@@ -5,10 +5,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.caches.resolve.util
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.openapi.extensions.ExtensionPointName
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.ResolveScopeEnlarger
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.psi.search.SearchScope
|
||||
import org.jetbrains.kotlin.idea.caches.project.ModuleSourceInfo
|
||||
import org.jetbrains.kotlin.idea.caches.project.ScriptModuleInfo
|
||||
import org.jetbrains.kotlin.idea.caches.project.SourceForBinaryModuleInfo
|
||||
@@ -39,15 +41,25 @@ fun getResolveScope(file: KtFile): GlobalSearchScope {
|
||||
}
|
||||
|
||||
fun enlargedSearchScope(searchScope: GlobalSearchScope, psiFile: PsiFile?): GlobalSearchScope {
|
||||
val virtualFile = psiFile?.originalFile?.virtualFile
|
||||
return enlargedSearchScope(searchScope, virtualFile)
|
||||
}
|
||||
|
||||
fun enlargedSearchScope(searchScope: GlobalSearchScope, moduleFile: VirtualFile?): GlobalSearchScope {
|
||||
if (moduleFile == null) return searchScope
|
||||
val vFile = psiFile?.originalFile?.virtualFile ?: return searchScope
|
||||
|
||||
return ResolveScopeEnlarger.EP_NAME.extensions.fold(searchScope) { scope, enlarger ->
|
||||
val extra = enlarger.getAdditionalResolveScope(moduleFile, scope.project)
|
||||
val extra = enlarger.getAdditionalResolveScope(vFile, scope.project)
|
||||
if (extra != null) scope.union(extra) else scope
|
||||
}
|
||||
}
|
||||
|
||||
fun enlargedSearchScope(searchScope: GlobalSearchScope, module: Module, isTestScope: Boolean): GlobalSearchScope {
|
||||
return KotlinResolveScopeEnlarger.EP_NAME.extensions.fold(searchScope) { scope, enlarger ->
|
||||
val extra = enlarger.getAdditionalResolveScope(module, isTestScope)
|
||||
if (extra != null) scope.union(extra) else scope
|
||||
}
|
||||
}
|
||||
|
||||
abstract class KotlinResolveScopeEnlarger {
|
||||
abstract fun getAdditionalResolveScope(module: Module, isTestScope: Boolean): SearchScope?
|
||||
|
||||
companion object {
|
||||
val EP_NAME = ExtensionPointName.create<KotlinResolveScopeEnlarger>("org.jetbrains.kotlin.resolveScopeEnlarger")
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,9 @@
|
||||
<extensionPoint qualifiedName="org.jetbrains.kotlin.syntheticScopeProviderExtension"
|
||||
interface="org.jetbrains.kotlin.synthetic.SyntheticScopeProviderExtension"
|
||||
area="IDEA_PROJECT"/>
|
||||
|
||||
<extensionPoint qualifiedName="org.jetbrains.kotlin.resolveScopeEnlarger"
|
||||
interface="org.jetbrains.kotlin.idea.caches.resolve.util.KotlinResolveScopeEnlarger"/>
|
||||
</extensionPoints>
|
||||
|
||||
<extensions defaultExtensionNs="org.jetbrains.kotlin">
|
||||
|
||||
@@ -46,6 +46,9 @@
|
||||
<extensionPoint qualifiedName="org.jetbrains.kotlin.syntheticScopeProviderExtension"
|
||||
interface="org.jetbrains.kotlin.synthetic.SyntheticScopeProviderExtension"
|
||||
area="IDEA_PROJECT"/>
|
||||
|
||||
<extensionPoint qualifiedName="org.jetbrains.kotlin.resolveScopeEnlarger"
|
||||
interface="org.jetbrains.kotlin.idea.caches.resolve.util.KotlinResolveScopeEnlarger"/>
|
||||
</extensionPoints>
|
||||
|
||||
<extensions defaultExtensionNs="org.jetbrains.kotlin">
|
||||
|
||||
@@ -46,6 +46,9 @@
|
||||
<extensionPoint qualifiedName="org.jetbrains.kotlin.syntheticScopeProviderExtension"
|
||||
interface="org.jetbrains.kotlin.synthetic.SyntheticScopeProviderExtension"
|
||||
area="IDEA_PROJECT"/>
|
||||
|
||||
<extensionPoint qualifiedName="org.jetbrains.kotlin.resolveScopeEnlarger"
|
||||
interface="org.jetbrains.kotlin.idea.caches.resolve.util.KotlinResolveScopeEnlarger"/>
|
||||
</extensionPoints>
|
||||
|
||||
<extensions defaultExtensionNs="org.jetbrains.kotlin">
|
||||
|
||||
Reference in New Issue
Block a user