mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 11:50:54 +07:00
[evaluation-plugin] ML-1915 Add evaluation mode for invoking completion in reverse order within a file
GitOrigin-RevId: f8479f6716d2719946a352cead19d9274b3f5bb3
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0be43058cc
commit
1b524c27f8
@@ -0,0 +1,8 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.cce.interpreter
|
||||
|
||||
enum class InterpretationOrder {
|
||||
LINEAR,
|
||||
REVERSED,
|
||||
RANDOM
|
||||
}
|
||||
@@ -6,10 +6,12 @@ import com.intellij.cce.core.Session
|
||||
import com.intellij.cce.util.FileTextUtil.computeChecksum
|
||||
import com.intellij.cce.util.FileTextUtil.getDiff
|
||||
import java.nio.file.Paths
|
||||
import kotlin.random.Random
|
||||
|
||||
class Interpreter(private val invokersFactory: InvokersFactory,
|
||||
private val handler: InterpretationHandler,
|
||||
private val filter: InterpretFilter,
|
||||
private val order: InterpretationOrder,
|
||||
private val projectPath: String?) {
|
||||
|
||||
fun interpret(fileActions: FileActions, sessionHandler: (Session) -> Unit): List<Session> {
|
||||
@@ -25,8 +27,8 @@ class Interpreter(private val invokersFactory: InvokersFactory,
|
||||
}
|
||||
var shouldCompleteToken = filter.shouldCompleteToken()
|
||||
var isCanceled = false
|
||||
|
||||
for (action in fileActions.actions) {
|
||||
val actions = fileActions.actions.reorder(order)
|
||||
for (action in actions) {
|
||||
handler.onActionStarted(action)
|
||||
when (action) {
|
||||
is MoveCaret -> {
|
||||
@@ -58,6 +60,30 @@ class Interpreter(private val invokersFactory: InvokersFactory,
|
||||
}
|
||||
if (needToClose) actionsInvoker.closeFile(filePath)
|
||||
handler.onFileProcessed(fileActions.path)
|
||||
return sessions
|
||||
return sessions.sortedBy { it.offset }
|
||||
}
|
||||
|
||||
private fun List<Action>.reorder(order: InterpretationOrder): List<Action> {
|
||||
val groups = groupActions(this)
|
||||
return when (order) {
|
||||
InterpretationOrder.LINEAR -> groups.flatten()
|
||||
InterpretationOrder.REVERSED -> groups.reversed().flatten()
|
||||
InterpretationOrder.RANDOM -> groups.shuffled(ORDER_RANDOM).flatten()
|
||||
}
|
||||
}
|
||||
|
||||
private fun groupActions(actions: List<Action>): List<List<Action>> {
|
||||
val groups = mutableListOf<List<Action>>()
|
||||
var currentGroup = mutableListOf<Action>()
|
||||
for (action in actions) {
|
||||
currentGroup.add(action)
|
||||
if (action is CallFeature) {
|
||||
groups.add(currentGroup)
|
||||
currentGroup = mutableListOf()
|
||||
}
|
||||
}
|
||||
return groups
|
||||
}
|
||||
}
|
||||
|
||||
private val ORDER_RANDOM = Random(42)
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.intellij.cce.workspace
|
||||
|
||||
import com.intellij.cce.evaluable.EvaluationStrategy
|
||||
import com.intellij.cce.filter.EvaluationFilter
|
||||
import com.intellij.cce.interpreter.InterpretationOrder
|
||||
import com.intellij.cce.workspace.filter.CompareSessionsFilter
|
||||
import com.intellij.cce.workspace.filter.NamedFilter
|
||||
import com.intellij.cce.workspace.filter.SessionsFilter
|
||||
@@ -43,6 +44,7 @@ data class Config private constructor(
|
||||
val sessionsLimit: Int?,
|
||||
val sessionProbability: Double,
|
||||
val sessionSeed: Long?,
|
||||
val order: InterpretationOrder,
|
||||
val saveLogs: Boolean,
|
||||
val saveFeatures: Boolean,
|
||||
val saveContent: Boolean,
|
||||
@@ -76,6 +78,7 @@ data class Config private constructor(
|
||||
var sessionsLimit: Int? = null
|
||||
var sessionProbability: Double = 1.0
|
||||
var sessionSeed: Long? = null
|
||||
var order: InterpretationOrder = InterpretationOrder.LINEAR
|
||||
var useReordering: Boolean = false
|
||||
var reorderingTitle: String = evaluationTitle
|
||||
var featuresForReordering = mutableListOf<String>()
|
||||
@@ -132,6 +135,7 @@ data class Config private constructor(
|
||||
sessionsLimit,
|
||||
sessionProbability,
|
||||
sessionSeed,
|
||||
order,
|
||||
saveLogs,
|
||||
saveFeatures,
|
||||
saveContent,
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.google.gson.*
|
||||
import com.intellij.cce.evaluable.EvaluationStrategy
|
||||
import com.intellij.cce.evaluable.StrategySerializer
|
||||
import com.intellij.cce.filter.EvaluationFilterReader
|
||||
import com.intellij.cce.interpreter.InterpretationOrder
|
||||
import com.intellij.cce.util.getAs
|
||||
import com.intellij.cce.util.getIfExists
|
||||
import com.intellij.cce.workspace.filter.CompareSessionsFilter
|
||||
@@ -77,6 +78,9 @@ object ConfigFactory {
|
||||
}
|
||||
builder.sessionProbability = map.getAs("sessionProbability")
|
||||
builder.sessionSeed = map.getAs<Double?>("sessionSeed")?.toLong()
|
||||
if (map.containsKey("order")) {
|
||||
builder.order = InterpretationOrder.valueOf(map.getAs<String>("order"))
|
||||
}
|
||||
builder.saveLogs = map.getAs("saveLogs")
|
||||
if (map.containsKey("saveFeatures")) {
|
||||
builder.saveFeatures = map.getAs("saveFeatures")
|
||||
|
||||
@@ -41,7 +41,7 @@ class ActionsInterpretationHandler(
|
||||
if (interpretationConfig.sessionProbability < 1)
|
||||
RandomInterpretFilter(interpretationConfig.sessionProbability, interpretationConfig.sessionSeed)
|
||||
else InterpretFilter.default()
|
||||
val interpreter = Interpreter(invokersFactory, handler, filter, project.basePath)
|
||||
val interpreter = Interpreter(invokersFactory, handler, filter, config.interpret.order, project.basePath)
|
||||
val featuresStorage = if (interpretationConfig.saveFeatures) workspace2.featuresStorage else FeaturesStorage.EMPTY
|
||||
LOG.info("Start interpreting actions")
|
||||
if (interpretationConfig.sessionProbability < 1) {
|
||||
|
||||
Reference in New Issue
Block a user