diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/findDecompiledDeclaration.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/findDecompiledDeclaration.kt index afa0f25ac44..52d8cfbea2f 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/findDecompiledDeclaration.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/findDecompiledDeclaration.kt @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.builtins.DefaultBuiltIns import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.idea.decompiler.KtDecompiledFile import org.jetbrains.kotlin.idea.decompiler.textBuilder.DecompiledTextIndexer +import org.jetbrains.kotlin.idea.script.KotlinScriptConfigurationManager import org.jetbrains.kotlin.idea.stubindex.KotlinFullClassNameIndex import org.jetbrains.kotlin.idea.stubindex.KotlinSourceFilterScope import org.jetbrains.kotlin.idea.stubindex.KotlinTopLevelFunctionFqnNameIndex @@ -76,11 +77,16 @@ private fun findCandidateDeclarationsInIndex( project: Project, referencedDescriptor: DeclarationDescriptor ): Collection { - val scope = KotlinSourceFilterScope.libraryClassFiles(GlobalSearchScope.allScope(project), project) + val scope = GlobalSearchScope.union( + arrayOf( + KotlinSourceFilterScope.libraryClassFiles(GlobalSearchScope.allScope(project), project), + // NOTE: using this scope here and getNoScopeWrap below is hopefully temporary and will be removed after refactoring + // of searching logic + KotlinScriptConfigurationManager.getInstance(project).getAllScriptsClasspathScope())) val containingClass = DescriptorUtils.getParentOfType(referencedDescriptor, ClassDescriptor::class.java, false) if (containingClass != null) { - return KotlinFullClassNameIndex.getInstance().get(containingClass.fqNameSafe.asString(), project, scope) + return KotlinFullClassNameIndex.getInstance().getNoScopeWrap(containingClass.fqNameSafe.asString(), project, scope) } val topLevelDeclaration = DescriptorUtils.getParentOfType(referencedDescriptor, PropertyDescriptor::class.java, false) @@ -92,10 +98,16 @@ private fun findCandidateDeclarationsInIndex( val fqName = topLevelDeclaration.fqNameSafe.asString() when (topLevelDeclaration) { is FunctionDescriptor -> { - return KotlinTopLevelFunctionFqnNameIndex.getInstance().get(fqName, project, scope) + return if (scriptsScope != null) + KotlinTopLevelFunctionFqnNameIndex.getInstance().getNoScopeWrap(fqName, project, scope) + else + KotlinTopLevelFunctionFqnNameIndex.getInstance().get(fqName, project, scope) } is PropertyDescriptor -> { - return KotlinTopLevelPropertyFqnNameIndex.getInstance().get(fqName, project, scope) + return if (scriptsScope != null) + KotlinTopLevelPropertyFqnNameIndex.getInstance().getNoScopeWrap(fqName, project, scope) + else + KotlinTopLevelPropertyFqnNameIndex.getInstance().get(fqName, project, scope) } else -> error("Referenced non local declaration that is not inside top level function, property of class:\n $referencedDescriptor") } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinFullClassNameIndex.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinFullClassNameIndex.java index 8e1c0b2888b..38dc94cb673 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinFullClassNameIndex.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinFullClassNameIndex.java @@ -50,4 +50,10 @@ public class KotlinFullClassNameIndex extends StringStubIndexExtension get(@NotNull String fqName, @NotNull Project project, @NotNull GlobalSearchScope scope) { return StubIndex.getElements(KEY, fqName, project, KotlinSourceFilterScope.sourcesAndLibraries(scope, project), KtClassOrObject.class); } + + // temporary hack, see comments in findCandidateDeclarationsInIndex (findDecompiledDeclaration.kt) + @NotNull + public Collection getNoScopeWrap(@NotNull String fqName, @NotNull Project project, @NotNull GlobalSearchScope scope) { + return StubIndex.getElements(KEY, fqName, project, scope, KtClassOrObject.class); + } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinTopLevelFunctionFqnNameIndex.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinTopLevelFunctionFqnNameIndex.java index 688c7b1edcb..782658ba425 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinTopLevelFunctionFqnNameIndex.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinTopLevelFunctionFqnNameIndex.java @@ -52,4 +52,10 @@ public class KotlinTopLevelFunctionFqnNameIndex extends StringStubIndexExtension public Collection get(@NotNull String s, @NotNull Project project, @NotNull GlobalSearchScope scope) { return StubIndex.getElements(KEY, s, project, KotlinSourceFilterScope.sourcesAndLibraries(scope, project), KtNamedFunction.class); } + + // temporary hack, see comments in findCandidateDeclarationsInIndex (findDecompiledDeclaration.kt) + @NotNull + public Collection getNoScopeWrap(@NotNull String s, @NotNull Project project, @NotNull GlobalSearchScope scope) { + return StubIndex.getElements(KEY, s, project, scope, KtNamedFunction.class); + } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinTopLevelPropertyFqnNameIndex.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinTopLevelPropertyFqnNameIndex.java index d081eb7b8cd..b89df1069cf 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinTopLevelPropertyFqnNameIndex.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinTopLevelPropertyFqnNameIndex.java @@ -49,4 +49,10 @@ public class KotlinTopLevelPropertyFqnNameIndex extends StringStubIndexExtension public Collection get(@NotNull String s, @NotNull Project project, @NotNull GlobalSearchScope scope) { return StubIndex.getElements(KEY, s, project, KotlinSourceFilterScope.sourcesAndLibraries(scope, project), KtProperty.class); } + + // temporary hack, see comments in findCandidateDeclarationsInIndex (findDecompiledDeclaration.kt) + @NotNull + public Collection getNoScopeWrap(@NotNull String s, @NotNull Project project, @NotNull GlobalSearchScope scope) { + return StubIndex.getElements(KEY, s, project, scope, KtProperty.class); + } }