Add CommonModuleResolveScopeEnlarger providing correct scope for commons
So #KT-22873 Fixed So #KT-22858 Fixed So #KT-22853 Fixed
This commit is contained in:
@@ -795,6 +795,8 @@
|
||||
|
||||
<lang.jvm.actions.jvmElementActionsFactory implementation="org.jetbrains.kotlin.idea.quickfix.crossLanguage.KotlinElementActionsFactory"/>
|
||||
|
||||
<resolveScopeEnlarger implementation="org.jetbrains.kotlin.idea.CommonModuleResolveScopeEnlarger"/>
|
||||
|
||||
<sdkType implementation="org.jetbrains.kotlin.idea.framework.KotlinSdkType"/>
|
||||
|
||||
<intentionAction>
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea
|
||||
|
||||
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.JdkOrderEntry
|
||||
import com.intellij.openapi.roots.ModuleRootManager
|
||||
import com.intellij.openapi.roots.ProjectFileIndex
|
||||
import com.intellij.openapi.roots.impl.LibraryScopeCache
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.ResolveScopeEnlarger
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.psi.search.SearchScope
|
||||
import org.jetbrains.kotlin.config.TargetPlatformKind
|
||||
import org.jetbrains.kotlin.idea.facet.findImplementingModules
|
||||
import org.jetbrains.kotlin.idea.project.targetPlatform
|
||||
|
||||
class CommonModuleResolveScopeEnlarger : ResolveScopeEnlarger() {
|
||||
override fun getAdditionalResolveScope(file: VirtualFile, project: Project): SearchScope? {
|
||||
val module = ProjectFileIndex.getInstance(project).getModuleForFile(file)
|
||||
if (module?.targetPlatform != TargetPlatformKind.Common) return null
|
||||
|
||||
val implementingModule = module.findImplementingModules(IdeModifiableModelsProviderImpl(project)).find {
|
||||
it.targetPlatform is TargetPlatformKind.Jvm
|
||||
} ?: return null
|
||||
|
||||
var result = GlobalSearchScope.EMPTY_SCOPE
|
||||
for (entry in ModuleRootManager.getInstance(implementingModule).orderEntries) {
|
||||
if (entry is JdkOrderEntry) {
|
||||
val scopeForSdk = LibraryScopeCache.getInstance(project).getScopeForSdk(entry)
|
||||
result = result.uniteWith(scopeForSdk)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
@@ -123,7 +123,7 @@ val mavenLibraryIdToPlatform: Map<String, TargetPlatformKind<*>> by lazy {
|
||||
.toMap()
|
||||
}
|
||||
|
||||
private fun Module.findImplementingModules(modelsProvider: IdeModifiableModelsProvider): List<Module> {
|
||||
internal fun Module.findImplementingModules(modelsProvider: IdeModifiableModelsProvider): List<Module> {
|
||||
return modelsProvider.modules.filter { module ->
|
||||
module.findImplementedModuleName(modelsProvider) == name
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user