From ce05434a0c7e9da229647084fd296c1e928bdfdd Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Wed, 30 Sep 2015 17:53:20 +0300 Subject: [PATCH] Fixed extension functions being grayed in import statement completion #KT-5627 Fixed --- .../kotlin/idea/completion/CompletionSession.kt | 14 +++++++++----- .../kotlin/idea/completion/LookupElementFactory.kt | 3 ++- .../multifile/InImport/InImport.dependency.kt | 7 +++++++ .../testData/basic/multifile/InImport/InImport.kt | 8 ++++++++ .../MultiFileJvmBasicCompletionTestGenerated.java | 6 ++++++ 5 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 idea/idea-completion/testData/basic/multifile/InImport/InImport.dependency.kt create mode 100644 idea/idea-completion/testData/basic/multifile/InImport/InImport.kt diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionSession.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionSession.kt index d4aecf31e89..431c8629e6f 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionSession.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionSession.kt @@ -314,9 +314,9 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC insertHandlerProvider, contextVariablesProvider) } - private fun detectCallTypeAndReceiverTypes(): Pair, Collection> { + private fun detectCallTypeAndReceiverTypes(): Pair, Collection?> { if (nameExpression == null) { - return CallType.DEFAULT to emptyList() + return CallType.DEFAULT to null } val callTypeAndReceiver = CallTypeAndReceiver.detect(nameExpression) @@ -338,9 +338,13 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC is CallTypeAndReceiver.SAFE -> receiverExpression = callTypeAndReceiver.receiver is CallTypeAndReceiver.INFIX -> receiverExpression = callTypeAndReceiver.receiver is CallTypeAndReceiver.UNARY -> receiverExpression = callTypeAndReceiver.receiver - is CallTypeAndReceiver.IMPORT_DIRECTIVE -> receiverExpression = callTypeAndReceiver.receiver - is CallTypeAndReceiver.PACKAGE_DIRECTIVE -> receiverExpression = callTypeAndReceiver.receiver - is CallTypeAndReceiver.TYPE -> receiverExpression = callTypeAndReceiver.receiver + + is CallTypeAndReceiver.IMPORT_DIRECTIVE, + is CallTypeAndReceiver.PACKAGE_DIRECTIVE, + is CallTypeAndReceiver.TYPE -> + // we don't need to highlight immediate members in these cases + return callTypeAndReceiver.callType to null + else -> throw RuntimeException() //TODO: see KT-9394 } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementFactory.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementFactory.kt index 638edfc1072..824dc9ec452 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementFactory.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementFactory.kt @@ -44,7 +44,7 @@ import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf class LookupElementFactory( private val resolutionFacade: ResolutionFacade, - private val receiverTypes: Collection, + private val receiverTypes: Collection?, private val callType: CallType<*>, private val isInStringTemplateAfterDollar: Boolean, public val insertHandlerProvider: InsertHandlerProvider, @@ -235,6 +235,7 @@ class LookupElementFactory( } private fun callableWeight(descriptor: DeclarationDescriptor): CallableWeight? { + if (receiverTypes == null) return null if (descriptor !is CallableDescriptor) return null val overridden = descriptor.overriddenDescriptors diff --git a/idea/idea-completion/testData/basic/multifile/InImport/InImport.dependency.kt b/idea/idea-completion/testData/basic/multifile/InImport/InImport.dependency.kt new file mode 100644 index 00000000000..9c493558d44 --- /dev/null +++ b/idea/idea-completion/testData/basic/multifile/InImport/InImport.dependency.kt @@ -0,0 +1,7 @@ +package second + +fun String.extensionFun(){} +val Int.extensionVal: Int get() = 1 + +fun topLevelFun(p: (String, Int) -> Unit){} +val topLevelVal: Int = 1 diff --git a/idea/idea-completion/testData/basic/multifile/InImport/InImport.kt b/idea/idea-completion/testData/basic/multifile/InImport/InImport.kt new file mode 100644 index 00000000000..97bf17fd056 --- /dev/null +++ b/idea/idea-completion/testData/basic/multifile/InImport/InImport.kt @@ -0,0 +1,8 @@ +package first + +import second. + +// EXIST: { itemText: "extensionFun", tailText: "() for String in second", attributes: "" } +// EXIST: { itemText: "extensionVal", tailText: " for Int in second", attributes: "" } +// EXIST: { itemText: "topLevelFun", tailText: "(p: (String, Int) -> Unit) (second)", attributes: "" } +// EXIST: { itemText: "topLevelVal", tailText: " (second)", attributes: "" } diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/MultiFileJvmBasicCompletionTestGenerated.java b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/MultiFileJvmBasicCompletionTestGenerated.java index 5a3ff4c4b33..8edf7ccac04 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/MultiFileJvmBasicCompletionTestGenerated.java +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/MultiFileJvmBasicCompletionTestGenerated.java @@ -131,6 +131,12 @@ public class MultiFileJvmBasicCompletionTestGenerated extends AbstractMultiFileJ doTest(fileName); } + @TestMetadata("InImport") + public void testInImport() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/multifile/InImport/"); + doTest(fileName); + } + @TestMetadata("InImportedFunctionLiteralParameter") public void testInImportedFunctionLiteralParameter() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/multifile/InImportedFunctionLiteralParameter/");