Show kotlin builtIn classes in "go to symbol"
#KT-10474 Fixed
This commit is contained in:
@@ -20,14 +20,18 @@ import com.intellij.navigation.ChooseByNameContributor
|
|||||||
import com.intellij.navigation.GotoClassContributor
|
import com.intellij.navigation.GotoClassContributor
|
||||||
import com.intellij.navigation.NavigationItem
|
import com.intellij.navigation.NavigationItem
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
|
import com.intellij.psi.search.DelegatingGlobalSearchScope
|
||||||
import com.intellij.psi.search.GlobalSearchScope
|
import com.intellij.psi.search.GlobalSearchScope
|
||||||
import com.intellij.psi.stubs.StubIndex
|
import com.intellij.psi.stubs.StubIndex
|
||||||
|
import org.jetbrains.kotlin.idea.decompiler.builtIns.KotlinBuiltInClassFileType
|
||||||
import org.jetbrains.kotlin.idea.stubindex.KotlinClassShortNameIndex
|
import org.jetbrains.kotlin.idea.stubindex.KotlinClassShortNameIndex
|
||||||
import org.jetbrains.kotlin.idea.stubindex.KotlinFunctionShortNameIndex
|
import org.jetbrains.kotlin.idea.stubindex.KotlinFunctionShortNameIndex
|
||||||
import org.jetbrains.kotlin.idea.stubindex.KotlinPropertyShortNameIndex
|
import org.jetbrains.kotlin.idea.stubindex.KotlinPropertyShortNameIndex
|
||||||
import org.jetbrains.kotlin.idea.stubindex.KotlinSourceFilterScope
|
import org.jetbrains.kotlin.idea.stubindex.KotlinSourceFilterScope
|
||||||
import org.jetbrains.kotlin.psi.KtEnumEntry
|
import org.jetbrains.kotlin.psi.KtEnumEntry
|
||||||
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
class KotlinGotoClassContributor : GotoClassContributor {
|
class KotlinGotoClassContributor : GotoClassContributor {
|
||||||
override fun getQualifiedName(item: NavigationItem): String? {
|
override fun getQualifiedName(item: NavigationItem): String? {
|
||||||
@@ -51,10 +55,18 @@ class KotlinGotoClassContributor : GotoClassContributor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Logic in IDEA that adds classes to "go to symbol" popup result goes around GotoClassContributor.
|
||||||
|
* For Kotlin classes it works using light class generation.
|
||||||
|
* We have to process Kotlin builtIn classes separately since no light classes are built for them.
|
||||||
|
* */
|
||||||
class KotlinGotoSymbolContributor : ChooseByNameContributor {
|
class KotlinGotoSymbolContributor : ChooseByNameContributor {
|
||||||
override fun getNames(project: Project, includeNonProjectItems: Boolean): Array<String> {
|
override fun getNames(project: Project, includeNonProjectItems: Boolean): Array<String> {
|
||||||
return listOf(KotlinFunctionShortNameIndex.getInstance(), KotlinPropertyShortNameIndex.getInstance()).flatMap {
|
return listOf(
|
||||||
|
KotlinFunctionShortNameIndex.getInstance(),
|
||||||
|
KotlinPropertyShortNameIndex.getInstance(),
|
||||||
|
KotlinClassShortNameIndex.getInstance()
|
||||||
|
).flatMap {
|
||||||
StubIndex.getInstance().getAllKeys(it.key, project)
|
StubIndex.getInstance().getAllKeys(it.key, project)
|
||||||
}.toTypedArray()
|
}.toTypedArray()
|
||||||
}
|
}
|
||||||
@@ -63,9 +75,17 @@ class KotlinGotoSymbolContributor : ChooseByNameContributor {
|
|||||||
val baseScope = if (includeNonProjectItems) GlobalSearchScope.allScope(project) else GlobalSearchScope.projectScope(project)
|
val baseScope = if (includeNonProjectItems) GlobalSearchScope.allScope(project) else GlobalSearchScope.projectScope(project)
|
||||||
val noLibrarySourceScope = KotlinSourceFilterScope.sourceAndClassFiles(baseScope, project)
|
val noLibrarySourceScope = KotlinSourceFilterScope.sourceAndClassFiles(baseScope, project)
|
||||||
|
|
||||||
val functions = KotlinFunctionShortNameIndex.getInstance().get(name, project, noLibrarySourceScope)
|
val result = ArrayList<NavigationItem>()
|
||||||
val properties = KotlinPropertyShortNameIndex.getInstance().get(name, project, noLibrarySourceScope)
|
result += KotlinFunctionShortNameIndex.getInstance().get(name, project, noLibrarySourceScope)
|
||||||
|
result += KotlinPropertyShortNameIndex.getInstance().get(name, project, noLibrarySourceScope)
|
||||||
|
result += KotlinClassShortNameIndex.getInstance().get(name, project, BuiltInClassesScope(noLibrarySourceScope))
|
||||||
|
|
||||||
return functions.plus<NavigationItem>(properties).filterNotNull().toTypedArray()
|
return result.toTypedArray()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class BuiltInClassesScope(baseScope: GlobalSearchScope) : DelegatingGlobalSearchScope(baseScope) {
|
||||||
|
override fun contains(file: VirtualFile): Boolean {
|
||||||
|
return file.fileType == KotlinBuiltInClassFileType && file in myBaseScope
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// RUNTIME_WITH_SOURCES
|
||||||
|
// CHECK_BOX
|
||||||
|
// SEARCH_TEXT: Int
|
||||||
|
// ALLOW_MORE_RESULTS
|
||||||
|
// REF: (kotlin).Int
|
||||||
@@ -112,6 +112,12 @@ public class KotlinGotoTestGenerated extends AbstractKotlinGotoTest {
|
|||||||
doSymbolTest(fileName);
|
doSymbolTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("builtInInt.kt")
|
||||||
|
public void testBuiltInInt() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/navigation/gotoSymbol/builtInInt.kt");
|
||||||
|
doSymbolTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("functions.kt")
|
@TestMetadata("functions.kt")
|
||||||
public void testFunctions() throws Exception {
|
public void testFunctions() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/navigation/gotoSymbol/functions.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/navigation/gotoSymbol/functions.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user