Provide correct resolve scope to binaries in script dependencies

#KT-16760 Fixed
This commit is contained in:
Pavel V. Talanov
2017-08-21 16:38:29 +03:00
parent a120130069
commit 4ada692421
2 changed files with 41 additions and 0 deletions
@@ -0,0 +1,40 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.idea.core.script.dependencies
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.ResolveScopeProvider
import com.intellij.psi.search.GlobalSearchScope
import org.jetbrains.kotlin.idea.caches.resolve.ScriptDependenciesModuleInfo
import org.jetbrains.kotlin.idea.caches.resolve.ScriptDependenciesSourceModuleInfo
import org.jetbrains.kotlin.idea.caches.resolve.getModuleInfoByVirtualFile
class ScriptDependenciesResolveScopeProvider : ResolveScopeProvider() {
override fun getResolveScope(file: VirtualFile, project: Project): GlobalSearchScope? {
val moduleInfo = getModuleInfoByVirtualFile(project, file) ?: return null
val scriptDependenciesModuleInfo = (moduleInfo as? ScriptDependenciesModuleInfo)
?: (moduleInfo as? ScriptDependenciesSourceModuleInfo)?.binariesModuleInfo
?: return null
return GlobalSearchScope.union(
arrayOf(
GlobalSearchScope.fileScope(project, file),
*scriptDependenciesModuleInfo.dependencies().map { it.contentScope() }.toTypedArray()
)
)
}
}
+1
View File
@@ -2576,6 +2576,7 @@
<indexedRootsProvider implementation="org.jetbrains.kotlin.idea.core.script.dependencies.KotlinScriptDependenciesIndexableSetContributor"/>
<psi.clsCustomNavigationPolicy implementation="org.jetbrains.kotlin.idea.core.script.dependencies.ScriptDependencySourceNavigationPolicyForJavaClasses"/>
<resolveScopeProvider implementation="org.jetbrains.kotlin.idea.core.script.dependencies.KotlinScriptResolveScopeProvider"/>
<resolveScopeProvider implementation="org.jetbrains.kotlin.idea.core.script.dependencies.ScriptDependenciesResolveScopeProvider"/>
<projectOpenProcessor implementation="org.jetbrains.kotlin.gradle.GradleKotlinDSLProjectOpenProcessor"/>
<projectImportProvider implementation="org.jetbrains.kotlin.gradle.GradleKotlinDSLProjectImportProvider"/>