@@ -20,14 +20,18 @@ import com.intellij.navigation.ChooseByNameContributor
20
20
import com.intellij.navigation.GotoClassContributor
21
21
import com.intellij.navigation.NavigationItem
22
22
import com.intellij.openapi.project.Project
23
+ import com.intellij.openapi.vfs.VirtualFile
24
+ import com.intellij.psi.search.DelegatingGlobalSearchScope
23
25
import com.intellij.psi.search.GlobalSearchScope
24
26
import com.intellij.psi.stubs.StubIndex
27
+ import org.jetbrains.kotlin.idea.decompiler.builtIns.KotlinBuiltInClassFileType
25
28
import org.jetbrains.kotlin.idea.stubindex.KotlinClassShortNameIndex
26
29
import org.jetbrains.kotlin.idea.stubindex.KotlinFunctionShortNameIndex
27
30
import org.jetbrains.kotlin.idea.stubindex.KotlinPropertyShortNameIndex
28
31
import org.jetbrains.kotlin.idea.stubindex.KotlinSourceFilterScope
29
32
import org.jetbrains.kotlin.psi.KtEnumEntry
30
33
import org.jetbrains.kotlin.psi.KtNamedDeclaration
34
+ import java.util.*
31
35
32
36
class KotlinGotoClassContributor : GotoClassContributor {
33
37
override fun getQualifiedName (item : NavigationItem ): String? {
@@ -51,10 +55,18 @@ class KotlinGotoClassContributor : GotoClassContributor {
51
55
}
52
56
}
53
57
54
-
58
+ /*
59
+ * Logic in IDEA that adds classes to "go to symbol" popup result goes around GotoClassContributor.
60
+ * For Kotlin classes it works using light class generation.
61
+ * We have to process Kotlin builtIn classes separately since no light classes are built for them.
62
+ * */
55
63
class KotlinGotoSymbolContributor : ChooseByNameContributor {
56
64
override fun getNames (project : Project , includeNonProjectItems : Boolean ): Array <String > {
57
- return listOf (KotlinFunctionShortNameIndex .getInstance(), KotlinPropertyShortNameIndex .getInstance()).flatMap {
65
+ return listOf (
66
+ KotlinFunctionShortNameIndex .getInstance(),
67
+ KotlinPropertyShortNameIndex .getInstance(),
68
+ KotlinClassShortNameIndex .getInstance()
69
+ ).flatMap {
58
70
StubIndex .getInstance().getAllKeys(it.key, project)
59
71
}.toTypedArray()
60
72
}
@@ -63,9 +75,17 @@ class KotlinGotoSymbolContributor : ChooseByNameContributor {
63
75
val baseScope = if (includeNonProjectItems) GlobalSearchScope .allScope(project) else GlobalSearchScope .projectScope(project)
64
76
val noLibrarySourceScope = KotlinSourceFilterScope .sourceAndClassFiles(baseScope, project)
65
77
66
- val functions = KotlinFunctionShortNameIndex .getInstance().get(name, project, noLibrarySourceScope)
67
- val properties = KotlinPropertyShortNameIndex .getInstance().get(name, project, noLibrarySourceScope)
78
+ val result = ArrayList <NavigationItem >()
79
+ result + = KotlinFunctionShortNameIndex .getInstance().get(name, project, noLibrarySourceScope)
80
+ result + = KotlinPropertyShortNameIndex .getInstance().get(name, project, noLibrarySourceScope)
81
+ result + = KotlinClassShortNameIndex .getInstance().get(name, project, BuiltInClassesScope (noLibrarySourceScope))
82
+
83
+ return result.toTypedArray()
84
+ }
85
+ }
68
86
69
- return functions.plus<NavigationItem >(properties).filterNotNull().toTypedArray()
87
+ private class BuiltInClassesScope (baseScope : GlobalSearchScope ) : DelegatingGlobalSearchScope(baseScope) {
88
+ override fun contains (file : VirtualFile ): Boolean {
89
+ return file.fileType == KotlinBuiltInClassFileType && file in myBaseScope
70
90
}
71
91
}
0 commit comments