Add plugin_version and file_type features for ML completion
- This is required to be able to use ML completion infrastructure to monitor code completion quality (even without ML enhancement)
This commit is contained in:
committed by
Roman Golyshev
parent
98ea2231f1
commit
31315e2c45
+1
-5
@@ -281,11 +281,7 @@ class KotlinCompletionContributor : CompletionContributor() {
|
||||
CompletionType.CLASS_NAME -> CompletionTypeStats.BASIC //there is no class name anymore actually
|
||||
CompletionType.SMART -> CompletionTypeStats.SMART
|
||||
},
|
||||
fileType = when {
|
||||
name.endsWith(".kt") -> FileTypeStats.KT
|
||||
name.endsWith(".gradle.kts") -> FileTypeStats.GRADLEKTS
|
||||
else -> FileTypeStats.KTS
|
||||
},
|
||||
fileType = FileTypeStats.parseFromFileName(name),
|
||||
invocationCount = parameters.invocationCount
|
||||
)
|
||||
val position = parameters.position
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.completion.ml
|
||||
|
||||
import com.intellij.codeInsight.completion.ml.CompletionEnvironment
|
||||
import com.intellij.codeInsight.completion.ml.ContextFeatureProvider
|
||||
import com.intellij.codeInsight.completion.ml.MLFeatureValue
|
||||
import org.jetbrains.kotlin.idea.KotlinPluginUtil
|
||||
import org.jetbrains.kotlin.idea.statistics.FileTypeStats
|
||||
|
||||
class KotlinContextFeatureProvider : ContextFeatureProvider {
|
||||
override fun getName(): String = "kotlin"
|
||||
|
||||
override fun calculateFeatures(environment: CompletionEnvironment): Map<String, MLFeatureValue> {
|
||||
val features = mutableMapOf("plugin_version" to MLFeatureValue.categorical(KotlinVersionFakeEnum.VERSION))
|
||||
|
||||
val fileType = environment.parameters.originalFile.virtualFile?.name?.let { FileTypeStats.parseFromFileName(it) }
|
||||
if (fileType != null) {
|
||||
features["file_type"] = MLFeatureValue.categorical(fileType)
|
||||
}
|
||||
|
||||
return features
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* We do not have a enum to represent Kotlin Plugin version; because of that we cannot
|
||||
* make it a categorical feature for ML completion (`MLFeatureValue.categorical` accepts only enums).
|
||||
*
|
||||
* This fake enum is used as a workaround to this problem.
|
||||
*
|
||||
* TODO As soon as there would be a way to pass Kotlin Plugin version without this enum, it should be removed.
|
||||
*/
|
||||
private enum class KotlinVersionFakeEnum {
|
||||
VERSION;
|
||||
|
||||
override fun toString(): String = KotlinPluginUtil.getPluginVersion()
|
||||
}
|
||||
@@ -71,7 +71,16 @@ object CompletionFUSCollector {
|
||||
}
|
||||
|
||||
enum class FileTypeStats {
|
||||
KT, GRADLEKTS, KTS
|
||||
KT, GRADLEKTS, KTS;
|
||||
|
||||
companion object {
|
||||
fun parseFromFileName(fileName: String): FileTypeStats? = when {
|
||||
fileName.endsWith(".kt") -> KT
|
||||
fileName.endsWith(".gradle.kts") -> GRADLEKTS
|
||||
fileName.endsWith(".kts") -> KTS
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum class CompletionTypeStats {
|
||||
|
||||
@@ -88,5 +88,6 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
<fileTypeUsageSchemaDescriptor schema="Gradle Script" implementationClass="org.jetbrains.kotlin.idea.core.script.KotlinGradleScriptFileTypeSchemaDetector"/>
|
||||
|
||||
<completion.ml.model implementation="org.jetbrains.kotlin.idea.completion.ml.KotlinMLRankingProvider"/>
|
||||
<completion.ml.contextFeatures language="kotlin" implementationClass="org.jetbrains.kotlin.idea.completion.ml.KotlinContextFeatureProvider"/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
|
||||
Reference in New Issue
Block a user