mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Revert "[stats-collector] Do not compute ML features if ranking and logging are disabled"
This reverts commit b48bf0de (due to broken PhpMLCompletionFeaturesTest) GitOrigin-RevId: 537c79a57db1318771f789cc3c278af333ae97a7
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7dfc47bfba
commit
43b9a18d15
@@ -13,7 +13,6 @@ class MLCompletionWeigher : CompletionWeigher() {
|
||||
override fun weigh(element: LookupElement, location: CompletionLocation): Comparable<Nothing>? {
|
||||
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<String, Any>()
|
||||
val contextFeatures = storage.contextProvidersResult()
|
||||
for (provider in ElementFeatureProvider.forLanguage(storage.language)) {
|
||||
|
||||
@@ -14,7 +14,6 @@ import com.intellij.stats.experiment.WebServiceStatus
|
||||
object RankingSupport {
|
||||
private val EP_NAME: ExtensionPointName<RankingModelProvider> = ExtensionPointName("com.intellij.completion.ml.model")
|
||||
private val LOG = logger<RankingSupport>()
|
||||
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
|
||||
|
||||
+1
-1
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String, MLFeatureValue> {
|
||||
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<String, MLFeatureValue> {
|
||||
invocationCount += 1
|
||||
return emptyMap()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user