PY-39742 Turn on ml completion by default

GitOrigin-RevId: 275f9b984e674473b8bc4f37f487f196d213b4a2
This commit is contained in:
andrey.matveev
2019-12-20 12:08:35 +00:00
committed by intellij-monorepo-bot
parent 138392e594
commit 024cdece96
4 changed files with 14 additions and 6 deletions
@@ -8,6 +8,7 @@ import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.util.PlatformUtils;
import com.jetbrains.completion.ranker.WeakModelProvider;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -32,6 +33,10 @@ public class CompletionMLRankingSettings implements PersistentStateComponent<Com
return myState.rankingEnabled;
}
public boolean isShowDiffEnabled() {
return myState.showDiff;
}
void setRankingEnabled(boolean value) {
myState.rankingEnabled = value;
}
@@ -75,6 +80,7 @@ public class CompletionMLRankingSettings implements PersistentStateComponent<Com
public static class State {
public boolean rankingEnabled = !ENABLED_BY_DEFAULT.isEmpty();
public boolean showDiff = PlatformUtils.isPyCharm();
// this map stores only different compare to default values to have ability to enable/disable models from build to build
public Map<String, Boolean> language2state = new HashMap<>();
}
@@ -34,8 +34,8 @@ class ItemsDiffCustomizingContributor : CompletionContributor() {
}
private fun shouldShowDiff(parameters: CompletionParameters): Boolean {
if (!Registry.`is`("completion.stats.show.ml.ranking.diff")) return false
val mlRankingSettings = CompletionMLRankingSettings.getInstance()
if (!mlRankingSettings.isShowDiffEnabled && !Registry.`is`("completion.stats.show.ml.ranking.diff")) return false
if (!mlRankingSettings.isRankingEnabled) return false
val lookup = LookupManager.getActiveLookup(parameters.editor) as? LookupImpl ?: return false
return LookupStorage.get(lookup)?.model != null
+3 -3
View File
@@ -38,13 +38,13 @@
<orderEntry type="module" module-name="intellij.python.psi.impl" exported="" />
<orderEntry type="module-library">
<library name="completion-ranking-python" type="repository">
<properties include-transitive-deps="false" maven-id="org.jetbrains.intellij.deps.completion:completion-ranking-python:0.0.4" />
<properties include-transitive-deps="false" maven-id="org.jetbrains.intellij.deps.completion:completion-ranking-python:0.0.6" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/intellij/deps/completion/completion-ranking-python/0.0.4/completion-ranking-python-0.0.4.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/intellij/deps/completion/completion-ranking-python/0.0.6/completion-ranking-python-0.0.6.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/intellij/deps/completion/completion-ranking-python/0.0.4/completion-ranking-python-0.0.4-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/intellij/deps/completion/completion-ranking-python/0.0.6/completion-ranking-python-0.0.6-sources.jar!/" />
</SOURCES>
</library>
</orderEntry>
@@ -1,7 +1,7 @@
// 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.jetbrains.python.codeInsight.mlcompletion
import com.completion.ranker.model.python.MLWhiteBox
import com.completion.ranker.model.python.MLCompletionModel
import com.intellij.internal.ml.DecisionFunction
import com.intellij.internal.ml.ModelMetadata
import com.intellij.internal.ml.completion.CompletionRankingModelBase
@@ -11,9 +11,11 @@ import com.intellij.lang.Language
class PythonMLRankingProvider : JarCompletionModelProvider("Python", "python_features") {
override fun createModel(metadata: ModelMetadata): DecisionFunction {
return object : CompletionRankingModelBase(metadata) {
override fun predict(features: DoubleArray?): Double = MLWhiteBox.makePredict(features)
override fun predict(features: DoubleArray?): Double = MLCompletionModel.makePredict(features)
}
}
override fun isLanguageSupported(language: Language): Boolean = language.id.compareTo("python", ignoreCase = true) == 0
override fun isEnabledByDefault() = true
}