From 0c74016ab75e4843c8dca2c33e14a4dba2366f49 Mon Sep 17 00:00:00 2001 From: Natalia Ukhorskaya Date: Mon, 1 Dec 2014 15:47:26 +0300 Subject: [PATCH] Remove duplicates in completion with runtime types --- .../plugin/completion/CompletionSession.kt | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/completion/CompletionSession.kt b/idea/src/org/jetbrains/jet/plugin/completion/CompletionSession.kt index e32a63d1d5c..3e0e69235d9 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/CompletionSession.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/CompletionSession.kt @@ -37,6 +37,8 @@ import org.jetbrains.jet.lang.resolve.scopes.DescriptorKindFilter import org.jetbrains.jet.lang.resolve.calls.smartcasts.SmartCastUtils import org.jetbrains.jet.lang.resolve.bindingContextUtil.getDataFlowInfo import org.jetbrains.jet.utils.addToStdlib.firstIsInstanceOrNull +import org.jetbrains.jet.plugin.refactoring.comparePossiblyOverridingDescriptors +import kotlin.properties.Delegates import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType class CompletionSessionConfiguration( @@ -121,8 +123,25 @@ abstract class CompletionSessionBase(protected val configuration: CompletionSess protected abstract fun doComplete() - protected fun getReferenceVariants(kindFilter: DescriptorKindFilter, shouldCastToRuntimeType: Boolean): Collection - = referenceVariantsHelper!!.getReferenceVariants(jetReference!!.expression, kindFilter, shouldCastToRuntimeType, prefixMatcher.asNameFilter()) + // set is used only for completion in code fragments + private var alreadyAddedDescriptors: Collection by Delegates.notNull() + + fun getReferenceVariants(kindFilter: DescriptorKindFilter, shouldCastToRuntimeType: Boolean): Collection { + val descriptors = referenceVariantsHelper!!.getReferenceVariants(jetReference!!.expression, kindFilter, shouldCastToRuntimeType, prefixMatcher.asNameFilter()) + if (!shouldCastToRuntimeType) { + if (position.getContainingFile() is JetCodeFragment) { + alreadyAddedDescriptors = descriptors + } + return descriptors + } + else { + return descriptors.filter { desc -> + !alreadyAddedDescriptors.any { + comparePossiblyOverridingDescriptors(it, desc) + } + } + } + } protected fun shouldRunTopLevelCompletion(): Boolean = configuration.completeNonImportedDeclarations && isNoQualifierContext()