diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt index 31876b2f953..f283bcb6b36 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt @@ -165,10 +165,6 @@ class BasicCompletionSession( filter = filter.exclude(DescriptorKindExclude.TopLevelPackages) } - if (callTypeAndReceiver.shouldCompleteCallableExtensions()) { - filter = filter.exclude(TopLevelExtensionsExclude) // completed via indices - } - filter } 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 3784b99ef64..f8b000c2baf 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 @@ -116,7 +116,7 @@ abstract class CompletionSession( parameters.position.containingFile, parameters.offset, kotlinIdentifierPartPattern or singleCharPattern('@'), - kotlinIdentifierStartPattern) + kotlinIdentifierStartPattern)!! protected val prefixMatcher = CamelHumpMatcher(prefix) @@ -303,6 +303,14 @@ abstract class CompletionSession( nameExpression: KtSimpleNameExpression, runtimeReceiver: ExpressionReceiver? = null ): ReferenceVariants { + val completeExtensionsFromIndices = descriptorKindFilter.kindMask.and(DescriptorKindFilter.CALLABLES_MASK) != 0 + && callTypeAndReceiver !is CallTypeAndReceiver.IMPORT_DIRECTIVE + @Suppress("NAME_SHADOWING") + val descriptorKindFilter = if (completeExtensionsFromIndices) + descriptorKindFilter exclude TopLevelExtensionsExclude // handled via indices + else + descriptorKindFilter + fun getReferenceVariants(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection { return referenceVariantsHelper.getReferenceVariants( nameExpression, @@ -327,7 +335,7 @@ abstract class CompletionSession( } var notImportedExtensions: Collection = emptyList() - if (callTypeAndReceiver.shouldCompleteCallableExtensions()) { + if (completeExtensionsFromIndices) { val indicesHelper = indicesHelper(true) val nameFilter = if (additionalPropertyNameFilter != null) descriptorNameFilter or additionalPropertyNameFilter @@ -434,11 +442,6 @@ abstract class CompletionSession( } } - protected fun CallTypeAndReceiver<*, *>.shouldCompleteCallableExtensions(): Boolean { - return callType.descriptorKindFilter.kindMask.and(DescriptorKindFilter.CALLABLES_MASK) != 0 - && this !is CallTypeAndReceiver.IMPORT_DIRECTIVE - } - protected fun withCollectRequiredContextVariableTypes(action: (LookupElementFactory) -> Unit): Collection { val provider = CollectRequiredTypesContextVariablesProvider() val lookupElementFactory = createLookupElementFactory(provider) diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/SmartCompletionSession.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/SmartCompletionSession.kt index c0ae08b7b52..2f1cd1b59a4 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/SmartCompletionSession.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/SmartCompletionSession.kt @@ -47,8 +47,6 @@ class SmartCompletionSession( // we do not include SAM-constructors because they are handled separately and adding them requires iterating of java classes var filter = DescriptorKindFilter.VALUES exclude SamConstructorDescriptorKindExclude - filter = filter exclude TopLevelExtensionsExclude // handled via indices - if (smartCompletion?.expectedInfos?.filterFunctionExpected()?.isNotEmpty() ?: false) { // if function type is expected we need classes to obtain their constructors filter = filter.withKinds(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS_MASK)