diff --git a/build.gradle.kts b/build.gradle.kts index 9399b33d051..3e41edc4d42 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -164,6 +164,7 @@ extra["versions.org.springframework"] = "4.2.0.RELEASE" extra["versions.jflex"] = "1.7.0" extra["versions.markdown"] = "0.1.25" extra["versions.trove4j"] = "1.0.20181211" +extra["versions.completion-ranking-kotlin"] = "0.0.2" // NOTE: please, also change KTOR_NAME in pathUtil.kt and all versions in corresponding jar names in daemon tests. extra["versions.ktor-network"] = "1.0.1" diff --git a/idea/build.gradle.kts b/idea/build.gradle.kts index a155b9e561b..ea4a5443ae6 100644 --- a/idea/build.gradle.kts +++ b/idea/build.gradle.kts @@ -5,6 +5,7 @@ plugins { repositories { maven("https://jetbrains.bintray.com/markdown") + maven("https://jetbrains.bintray.com/intellij-third-party-dependencies") } sourceSets { @@ -103,6 +104,10 @@ dependencies { testRuntime(intellijPluginDep("java")) } + Platform[193].orHigher { + implementation(commonDep("org.jetbrains.intellij.deps.completion", "completion-ranking-kotlin")) + } + compileOnly(commonDep("org.jetbrains", "markdown")) compileOnly(commonDep("com.google.code.findbugs", "jsr305")) compileOnly(intellijPluginDep("IntelliLang")) diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/ml/KotlinMLRankingProvider.kt.193 b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/ml/KotlinMLRankingProvider.kt.193 new file mode 100644 index 00000000000..76c78a40452 --- /dev/null +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/ml/KotlinMLRankingProvider.kt.193 @@ -0,0 +1,24 @@ +/* + * Copyright 2010-2019 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.completion.ranker.model.kotlin.MLWhiteBox +import com.intellij.internal.ml.DecisionFunction +import com.intellij.internal.ml.ModelMetadata +import com.intellij.internal.ml.completion.CompletionRankingModelBase +import com.intellij.internal.ml.completion.JarCompletionModelProvider +import com.intellij.lang.Language + +@Suppress("UnstableApiUsage") +class KotlinMLRankingProvider : JarCompletionModelProvider("Kotlin", "kotlin_features") { + override fun createModel(metadata: ModelMetadata): DecisionFunction { + return object : CompletionRankingModelBase(metadata) { + override fun predict(features: DoubleArray?): Double = MLWhiteBox.makePredict(features) + } + } + + override fun isLanguageSupported(language: Language): Boolean = language.id.equals("kotlin", ignoreCase = true) +} \ No newline at end of file diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KotlinModelMetadataTest.kt.193 b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KotlinModelMetadataTest.kt.193 new file mode 100644 index 00000000000..aee1ab4dcdd --- /dev/null +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KotlinModelMetadataTest.kt.193 @@ -0,0 +1,14 @@ +/* + * Copyright 2010-2019 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.test + +import org.jetbrains.kotlin.idea.completion.ml.KotlinMLRankingProvider +import org.junit.Test + +class KotlinModelMetadataTest { + @Test + fun testMetadataConsistent() = KotlinMLRankingProvider().assertModelMetadataConsistent() +} \ No newline at end of file diff --git a/idea/resources/META-INF/plugin.xml.193 b/idea/resources/META-INF/plugin.xml.193 index 6331c3ea9b9..b18746a72cb 100644 --- a/idea/resources/META-INF/plugin.xml.193 +++ b/idea/resources/META-INF/plugin.xml.193 @@ -81,5 +81,7 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio. + +