KT-29926: Get rid of filterFunctionExpected
- `filterFunctionExpected` does not provide meaningful concept, and will be a problem in the next steps on this issue. - Refactor `SmartCompletionSession::descriptorKindFilter` to more precisely tell why we include references to constructors if we are completion functions
This commit is contained in:
committed by
Roman Golyshev
parent
e2b91cfec7
commit
84b9044187
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.completion.smart
|
||||
import com.intellij.codeInsight.lookup.LookupElement
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import org.jetbrains.kotlin.builtins.isFunctionType
|
||||
import org.jetbrains.kotlin.idea.completion.LambdaSignatureTemplates
|
||||
import org.jetbrains.kotlin.idea.completion.suppressAutoInsertion
|
||||
import org.jetbrains.kotlin.idea.core.ExpectedInfo
|
||||
@@ -35,7 +36,7 @@ object LambdaItems {
|
||||
}
|
||||
|
||||
fun addToCollection(collection: MutableCollection<LookupElement>, expectedInfos: Collection<ExpectedInfo>) {
|
||||
val functionExpectedInfos = expectedInfos.filterFunctionExpected()
|
||||
val functionExpectedInfos = expectedInfos.filter { it.fuzzyType?.type?.isFunctionType == true }
|
||||
if (functionExpectedInfos.isEmpty()) return
|
||||
|
||||
val functionTypes = functionExpectedInfos
|
||||
|
||||
+10
-5
@@ -21,12 +21,14 @@ import com.intellij.codeInsight.completion.CompletionResultSet
|
||||
import com.intellij.codeInsight.completion.CompletionSorter
|
||||
import com.intellij.codeInsight.lookup.LookupElement
|
||||
import com.intellij.psi.impl.source.tree.LeafPsiElement
|
||||
import org.jetbrains.kotlin.builtins.isFunctionType
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.idea.completion.*
|
||||
import org.jetbrains.kotlin.idea.core.ExpectedInfo
|
||||
import org.jetbrains.kotlin.idea.core.ExpectedInfos
|
||||
import org.jetbrains.kotlin.idea.core.completion.DeclarationLookupObject
|
||||
import org.jetbrains.kotlin.idea.core.fuzzyType
|
||||
import org.jetbrains.kotlin.idea.util.CallTypeAndReceiver
|
||||
import org.jetbrains.kotlin.load.java.sam.SamConstructorDescriptorKindExclude
|
||||
import org.jetbrains.kotlin.psi.LambdaArgument
|
||||
@@ -45,14 +47,17 @@ class SmartCompletionSession(
|
||||
|
||||
override val descriptorKindFilter: DescriptorKindFilter by lazy {
|
||||
// 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
|
||||
val filter = DescriptorKindFilter.VALUES exclude SamConstructorDescriptorKindExclude
|
||||
|
||||
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)
|
||||
val referenceToConstructorIsApplicable = smartCompletion?.expectedInfos.orEmpty().any {
|
||||
it.fuzzyType?.type?.isFunctionType == true
|
||||
}
|
||||
|
||||
filter
|
||||
if (referenceToConstructorIsApplicable) {
|
||||
filter.withKinds(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS_MASK)
|
||||
} else {
|
||||
filter
|
||||
}
|
||||
}
|
||||
|
||||
private val smartCompletion by lazy(LazyThreadSafetyMode.NONE) {
|
||||
|
||||
@@ -335,8 +335,5 @@ fun DeclarationDescriptor.fuzzyTypesForSmartCompletion(
|
||||
}
|
||||
}
|
||||
|
||||
fun Collection<ExpectedInfo>.filterFunctionExpected()
|
||||
= filter { it.fuzzyType != null && it.fuzzyType!!.type.isFunctionType }
|
||||
|
||||
fun Collection<ExpectedInfo>.filterCallableExpected()
|
||||
= filter { it.fuzzyType != null && ReflectionTypes.isCallableType(it.fuzzyType!!.type) }
|
||||
|
||||
Reference in New Issue
Block a user