diff --git a/plugins/stats-collector/src/com/intellij/completion/ml/MLCompletionWeigher.kt b/plugins/stats-collector/src/com/intellij/completion/ml/MLCompletionWeigher.kt index e494594a277a..2d69165b8623 100644 --- a/plugins/stats-collector/src/com/intellij/completion/ml/MLCompletionWeigher.kt +++ b/plugins/stats-collector/src/com/intellij/completion/ml/MLCompletionWeigher.kt @@ -13,7 +13,6 @@ class MLCompletionWeigher : CompletionWeigher() { override fun weigh(element: LookupElement, location: CompletionLocation): Comparable? { val storage = (LookupManager.getActiveLookup(location.completionParameters.editor) as? LookupImpl) ?.let { LookupStorage.get(it) } ?: return DummyComparable.EMPTY - if (!storage.shouldComputeFeatures()) return DummyComparable.EMPTY val result = mutableMapOf() val contextFeatures = storage.contextProvidersResult() for (provider in ElementFeatureProvider.forLanguage(storage.language)) { diff --git a/plugins/stats-collector/src/com/intellij/completion/sorting/RankingSupport.kt b/plugins/stats-collector/src/com/intellij/completion/sorting/RankingSupport.kt index 07cf01738b77..312b11ec1a41 100644 --- a/plugins/stats-collector/src/com/intellij/completion/sorting/RankingSupport.kt +++ b/plugins/stats-collector/src/com/intellij/completion/sorting/RankingSupport.kt @@ -14,7 +14,6 @@ import com.intellij.stats.experiment.WebServiceStatus object RankingSupport { private val EP_NAME: ExtensionPointName = ExtensionPointName("com.intellij.completion.ml.model") private val LOG = logger() - var enabledInTests: Boolean = false fun getRankingModel(language: Language): RankingModelWrapper? { val provider = findProviderForLanguage(language) @@ -48,7 +47,7 @@ object RankingSupport { private fun shouldSortByML(provider: RankingModelProvider): Boolean { val application = ApplicationManager.getApplication() val webServiceStatus = WebServiceStatus.getInstance() - if (application.isUnitTestMode) return enabledInTests + if (application.isUnitTestMode) return false val settings = CompletionMLRankingSettings.getInstance() if (application.isEAP && webServiceStatus.isExperimentOnCurrentIDE() && settings.isCompletionLogsSendAllowed) { // AB experiment diff --git a/plugins/stats-collector/src/com/intellij/stats/completion/ContextFeaturesContributor.kt b/plugins/stats-collector/src/com/intellij/stats/completion/ContextFeaturesContributor.kt index b1b791fd0e2c..0c6c35817bd7 100644 --- a/plugins/stats-collector/src/com/intellij/stats/completion/ContextFeaturesContributor.kt +++ b/plugins/stats-collector/src/com/intellij/stats/completion/ContextFeaturesContributor.kt @@ -20,7 +20,7 @@ class ContextFeaturesContributor : CompletionContributor() { val lookup = LookupManager.getActiveLookup(parameters.editor) as? LookupImpl if (lookup != null) { val storage = MutableLookupStorage.get(lookup) - if (storage != null && storage.shouldComputeFeatures() && !storage.isContextFactorsInitialized()) { + if (storage != null && !storage.isContextFactorsInitialized()) { calculateContextFactors(lookup, parameters, storage) } } diff --git a/plugins/stats-collector/test/com/intellij/stats/completion/MLFeaturesComputingTest.kt b/plugins/stats-collector/test/com/intellij/stats/completion/MLFeaturesComputingTest.kt deleted file mode 100644 index 2b588911cd83..000000000000 --- a/plugins/stats-collector/test/com/intellij/stats/completion/MLFeaturesComputingTest.kt +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -package com.intellij.stats.completion - -import com.intellij.codeInsight.completion.CompletionLocation -import com.intellij.codeInsight.completion.ml.* -import com.intellij.codeInsight.lookup.Lookup -import com.intellij.codeInsight.lookup.LookupElement -import com.intellij.completion.sorting.RankingSupport -import com.intellij.lang.java.JavaLanguage -import com.intellij.openapi.Disposable -import com.intellij.openapi.extensions.Extensions -import com.intellij.openapi.util.Disposer -import junit.framework.TestCase - -class MLFeaturesComputingTest : CompletionLoggingTestBase() { - fun `test features should be calculated if logging enabled`() = doTest(true, false, true) - - fun `test features should be calculated if ranking enabled`() = doTest(false, true, true) - - fun `test features should be calculated if ranking and logging enabled`() = doTest(true, true, true) - - fun `test features should not be calculated if ranking and logging disabled`() = doTest(false, false, false) - - private fun doTest(enableLogging: Boolean, enableRanking: Boolean, shouldCompute: Boolean) { - val contextFeatureProvider = TestContextFeatureProvider() - ContextFeatureProvider.EP_NAME.addExplicitExtension(JavaLanguage.INSTANCE, contextFeatureProvider, testRootDisposable) - val elementFeatureProvider = TestElementFeatureProvider() - ElementFeatureProvider.EP_NAME.addExplicitExtension(JavaLanguage.INSTANCE, elementFeatureProvider, testRootDisposable) - - setLoggingEnabled(enableLogging) - setRankingEnabled(enableRanking) - - myFixture.completeBasic() - myFixture.type("r") - myFixture.finishLookup(Lookup.NORMAL_SELECT_CHAR) - - TestCase.assertEquals(shouldCompute, contextFeatureProvider.invocationCount != 0) - if (shouldCompute) { - TestCase.assertEquals("Context features should be calculated exactly once", 1, contextFeatureProvider.invocationCount) - } - TestCase.assertEquals(shouldCompute, elementFeatureProvider.invocationCount != 0) - } - - private fun setLoggingEnabled(value: Boolean) { - if (!value) { - Extensions.getRootArea().getExtensionPoint(CompletionTrackerDisabler.EpName).registerExtension(object : CompletionTrackerDisabler { - override fun isDisabled(): Boolean = true - }, testRootDisposable) - } - } - - private fun setRankingEnabled(value: Boolean) { - val valueBefore = RankingSupport.enabledInTests - Disposer.register(testRootDisposable, Disposable { RankingSupport.enabledInTests = valueBefore }) - RankingSupport.enabledInTests = value - } - - private class TestContextFeatureProvider : ContextFeatureProvider { - @Volatile - var invocationCount = 0 - - override fun getName(): String = "test" - - override fun calculateFeatures(environment: CompletionEnvironment): Map { - invocationCount += 1 - return emptyMap() - } - } - - private class TestElementFeatureProvider() : ElementFeatureProvider { - override fun getName(): String = "test" - - @Volatile - var invocationCount = 0 - - override fun calculateFeatures(element: LookupElement, - location: CompletionLocation, - contextFeatures: ContextFeatures): Map { - invocationCount += 1 - return emptyMap() - } - } -}