mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[recommenders] introduce feature providers for recommenders features
(cherry picked from commit de5a0200302516736d2d459a56c3ff62c9b5820e) IJ-MR-27840 GitOrigin-RevId: dcea1afa474c3f4bbf4967cc3258dc21df6779d4
This commit is contained in:
committed by
intellij-monorepo-bot
parent
abf179d107
commit
71bc043aa3
+37
@@ -0,0 +1,37 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.completion.ml
|
||||
|
||||
import com.intellij.lang.Language
|
||||
import com.intellij.lang.LanguageExtension
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import kotlin.system.measureTimeMillis
|
||||
|
||||
@ApiStatus.Internal
|
||||
interface GenericFeatureProvider {
|
||||
val name: String
|
||||
fun knownFeatures(): Set<String>
|
||||
fun calculateFeatures(context: MLContext): Map<String, Any>
|
||||
fun isApplicable(context: MLContext): Boolean
|
||||
|
||||
data class FeaturesCalculationResult(val features: Map<String, Any>, val performance: Map<String, Long>)
|
||||
|
||||
companion object {
|
||||
private val EP_NAME = LanguageExtension<GenericFeatureProvider>("com.intellij.completion.ml.genericFeatures")
|
||||
|
||||
fun forLanguage(language: Language): List<GenericFeatureProvider> = EP_NAME.allForLanguageOrAny(language)
|
||||
|
||||
fun calculateFeatures(context: MLContext, features: Set<String>): FeaturesCalculationResult {
|
||||
val featureValues = mutableMapOf<String, Any>()
|
||||
val performance = mutableMapOf<String, Long>()
|
||||
for (provider in forLanguage(context.position.language)) {
|
||||
if (provider.knownFeatures().any { it in features }) {
|
||||
val time = measureTimeMillis {
|
||||
featureValues.putAll(provider.calculateFeatures(context))
|
||||
}
|
||||
performance[provider.name] = time
|
||||
}
|
||||
}
|
||||
return FeaturesCalculationResult(featureValues, performance)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.completion.ml
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
|
||||
@ApiStatus.Internal
|
||||
interface MLContext {
|
||||
val position: PsiElement
|
||||
}
|
||||
@@ -15,6 +15,10 @@
|
||||
<with attribute="implementationClass" implements="com.intellij.codeInsight.completion.ml.ElementFeatureProvider"/>
|
||||
</extensionPoint>
|
||||
|
||||
<extensionPoint name="completion.ml.genericFeatures" beanClass="com.intellij.lang.LanguageExtensionPoint" dynamic="true">
|
||||
<with attribute="implementationClass" implements="com.intellij.codeInsight.completion.ml.GenericFeatureProvider"/>
|
||||
</extensionPoint>
|
||||
|
||||
<extensionPoint name="completion.plainTextSymbol" beanClass="com.intellij.codeInsight.completion.PlainTextSymbolCompletionContributorEP" dynamic="true">
|
||||
<with attribute="implementationClass" implements="com.intellij.codeInsight.completion.PlainTextSymbolCompletionContributor"/>
|
||||
</extensionPoint>
|
||||
|
||||
+5
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2020 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.
|
||||
// Copyright 2000-2022 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.completion.ml.performance
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
@@ -31,6 +31,10 @@ class CompletionPerformanceTracker {
|
||||
addByKey("context.features.$providerName", timeSpent)
|
||||
}
|
||||
|
||||
fun recommendersFeaturesCalculated(providerName: String, timeSpent: Long) {
|
||||
addByKey("recommenders.features.$providerName", timeSpent)
|
||||
}
|
||||
|
||||
fun itemsScored(itemsCount: Int, timeSpent: Long) {
|
||||
addByKey("model.items.$sortingCount", itemsCount.toLong())
|
||||
addByKey("model.time.$sortingCount", timeSpent)
|
||||
|
||||
Reference in New Issue
Block a user