Skip to content

Commit 4dd3f30

Browse files
committed
Build stubs for local functions; show them in Goto Symbol
#KT-14161 Fixed
1 parent f72dd75 commit 4dd3f30

File tree

8 files changed

+42
-16
lines changed

8 files changed

+42
-16
lines changed

compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ object KotlinStubVersions {
2323
// Though only kotlin declarations (no code in the bodies) are stubbed, please do increase this version
2424
// if you are not 100% sure it can be avoided.
2525
// Increasing this version will lead to reindexing of all kotlin source files on the first IDE startup with the new version.
26-
const val SOURCE_STUB_VERSION = 122
26+
const val SOURCE_STUB_VERSION = 123
2727

2828
// Binary stub version should be increased if stub format (org.jetbrains.kotlin.psi.stubs.impl) is changed
2929
// or changes are made to the core stub building code (org.jetbrains.kotlin.idea.decompiler.stubBuilder).
3030
// Increasing this version will lead to reindexing of all binary files that are potentially kotlin binaries (including all class files).
31-
private const val BINARY_STUB_VERSION = 59
31+
private const val BINARY_STUB_VERSION = 60
3232

3333
// Classfile stub version should be increased if changes are made to classfile stub building subsystem (org.jetbrains.kotlin.idea.decompiler.classFile)
3434
// Increasing this version will lead to reindexing of all classfiles.

compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/KtStubElementType.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,9 @@ public String getExternalId() {
8787
@Override
8888
public boolean shouldCreateStub(ASTNode node) {
8989
PsiElement psi = node.getPsi();
90-
if (psi instanceof KtClassOrObject) {
90+
if (psi instanceof KtClassOrObject || psi instanceof KtFunction) {
9191
return true;
9292
}
93-
if (psi instanceof KtFunction) {
94-
return !((KtFunction) psi).isLocal();
95-
}
9693
if (psi instanceof KtProperty) {
9794
return !((KtProperty) psi).isLocal();
9895
}

idea/src/org/jetbrains/kotlin/idea/presentation/DeclarationPresenters.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import com.intellij.openapi.util.Iconable
2525
import org.jetbrains.kotlin.idea.KotlinIconProvider
2626
import org.jetbrains.kotlin.lexer.KtTokens
2727
import org.jetbrains.kotlin.psi.*
28+
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
2829

2930
open class KotlinDefaultNamedDeclarationPresentation(private val declaration: KtNamedDeclaration) : ColoredItemPresentation {
3031

@@ -38,6 +39,10 @@ open class KotlinDefaultNamedDeclarationPresentation(private val declaration: Kt
3839
override fun getPresentableText() = declaration.name
3940

4041
override fun getLocationString(): String? {
42+
if (declaration is KtFunction && declaration.isLocal) {
43+
val containingDeclaration = declaration.getStrictParentOfType<KtDeclaration>() ?: return null
44+
return "(in ${containingDeclaration.name})"
45+
}
4146
val name = declaration.fqName ?: return null
4247
val qualifiedContainer = name.parent().toString()
4348
val parent = declaration.parent
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fun main(args: Array<String>) {
2+
fun myFoo() {
3+
4+
}
5+
}
6+
7+
// SEARCH_TEXT: myFoo
8+
// REF: (in main).myFoo()

idea/testData/resolve/referenceInLib/toLocalFun.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ val tl = <caret>topLevel()
55
// CONTEXT: return <ref-caret>local()
66
// WITH_LIBRARY: /resolve/referenceInLib/inLibrarySource
77

8-
// REF: local()
8+
// REF: (in inlibrary.test.topLevel).local()

idea/testData/stubs/AnnotationOnLocalFunction.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,11 @@ PsiJetFileStubImpl[package=]
33
IMPORT_LIST
44
FUN[fqName=foo, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=true, name=foo]
55
VALUE_PARAMETER_LIST
6+
FUN[fqName=null, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, name=innerFoo]
7+
MODIFIER_LIST[]
8+
ANNOTATION_ENTRY[hasValueArguments=false, shortName=Deprecated]
9+
CONSTRUCTOR_CALLEE
10+
TYPE_REFERENCE
11+
USER_TYPE
12+
REFERENCE_EXPRESSION[referencedName=Deprecated]
13+
VALUE_PARAMETER_LIST

idea/testData/stubs/LocalClassInLocalFunction.expected

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ PsiJetFileStubImpl[package=]
55
CLASS[fqName=T, isEnumEntry=false, isInterface=true, isLocal=false, isTopLevel=true, name=T, superNames=[]]
66
FUN[fqName=foo, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=true, name=foo]
77
VALUE_PARAMETER_LIST
8-
CLASS[fqName=null, isEnumEntry=false, isInterface=false, isLocal=true, isTopLevel=false, name=Test, superNames=[A, T]]
9-
SUPER_TYPE_LIST
10-
SUPER_TYPE_CALL_ENTRY
11-
CONSTRUCTOR_CALLEE
8+
FUN[fqName=null, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, name=bar]
9+
VALUE_PARAMETER_LIST
10+
CLASS[fqName=null, isEnumEntry=false, isInterface=false, isLocal=true, isTopLevel=false, name=Test, superNames=[A, T]]
11+
SUPER_TYPE_LIST
12+
SUPER_TYPE_CALL_ENTRY
13+
CONSTRUCTOR_CALLEE
14+
TYPE_REFERENCE
15+
USER_TYPE
16+
REFERENCE_EXPRESSION[referencedName=A]
17+
SUPER_TYPE_ENTRY
1218
TYPE_REFERENCE
1319
USER_TYPE
14-
REFERENCE_EXPRESSION[referencedName=A]
15-
SUPER_TYPE_ENTRY
16-
TYPE_REFERENCE
17-
USER_TYPE
18-
REFERENCE_EXPRESSION[referencedName=T]
20+
REFERENCE_EXPRESSION[referencedName=T]

idea/tests/org/jetbrains/kotlin/idea/navigation/KotlinGotoTestGenerated.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ public void testJavaMethods() throws Exception {
143143
doSymbolTest(fileName);
144144
}
145145

146+
@TestMetadata("localFunction.kt")
147+
public void testLocalFunction() throws Exception {
148+
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/navigation/gotoSymbol/localFunction.kt");
149+
doSymbolTest(fileName);
150+
}
151+
146152
@TestMetadata("privateTopLevelDeclarations.kt")
147153
public void testPrivateTopLevelDeclarations() throws Exception {
148154
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/navigation/gotoSymbol/privateTopLevelDeclarations.kt");

0 commit comments

Comments
 (0)