[evaluation-plugin] LME-7 CodeGen. Support delay between requests in evaluation plugin

GitOrigin-RevId: 34aae34a2dcd2e2312ccdfbdabe5a07b041a73f2
This commit is contained in:
Alexey Kalina
2024-07-11 15:54:23 +02:00
committed by intellij-monorepo-bot
parent 2fa85150a2
commit a3648aa3cb
4 changed files with 16 additions and 2 deletions

View File

@@ -11,7 +11,7 @@ sealed interface Action {
val sessionId: UUID
enum class ActionType {
MOVE_CARET, CALL_FEATURE, PRINT_TEXT, DELETE_RANGE, SELECT_RANGE, RENAME
MOVE_CARET, CALL_FEATURE, PRINT_TEXT, DELETE_RANGE, SELECT_RANGE, RENAME, DELAY
}
object JsonAdapter : JsonDeserializer<Action>, JsonSerializer<Action> {
@@ -23,6 +23,7 @@ sealed interface Action {
ActionType.DELETE_RANGE -> context.deserialize(json, DeleteRange::class.java)
ActionType.SELECT_RANGE -> context.deserialize(json, SelectRange::class.java)
ActionType.RENAME -> context.deserialize(json, Rename::class.java)
ActionType.DELAY -> context.deserialize(json, Delay::class.java)
}
}
@@ -58,6 +59,10 @@ data class SelectRange internal constructor(override val sessionId: UUID, val be
override val type: Action.ActionType = Action.ActionType.SELECT_RANGE
}
data class Delay internal constructor(override val sessionId: UUID, val seconds: Int) : Action {
override val type: Action.ActionType = Action.ActionType.DELAY
}
data class TextRange(val start: Int, val end: Int)
@@ -82,5 +87,6 @@ class ActionsBuilder {
fun printText(text: String) = actions.add(PrintText(sessionId, text))
fun deleteRange(begin: Int, end: Int) = actions.add(DeleteRange(sessionId, begin, end))
fun selectRange(begin: Int, end: Int) = actions.add(SelectRange(sessionId, begin, end))
fun delay(seconds: Int) = actions.add(Delay(sessionId, seconds))
}
}

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.cce.interpreter
interface ActionsInvoker {
@@ -7,6 +7,7 @@ interface ActionsInvoker {
fun printText(text: String)
fun deleteRange(begin: Int, end: Int)
fun selectRange(begin: Int, end: Int)
fun delay(seconds: Int)
fun openFile(file: String): String
fun closeFile(file: String)
fun isOpen(file: String): Boolean

View File

@@ -47,6 +47,7 @@ class Interpreter(private val invokersFactory: InvokersFactory,
is PrintText -> actionsInvoker.printText(action.text)
is DeleteRange -> actionsInvoker.deleteRange(action.begin, action.end)
is SelectRange -> actionsInvoker.selectRange(action.begin, action.end)
is Delay -> actionsInvoker.delay(action.seconds)
}
if (isCanceled) break
}

View File

@@ -23,6 +23,7 @@ import com.intellij.psi.PsiNameIdentifierOwner
import com.intellij.psi.search.searches.ReferencesSearch
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.testFramework.TestModeFlags
import com.intellij.util.progress.sleepCancellable
import java.io.File
class CommonActionsInvoker(private val project: Project) : ActionsInvoker {
@@ -94,6 +95,11 @@ class CommonActionsInvoker(private val project: Project) : ActionsInvoker {
editor.scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE)
}
override fun delay(seconds: Int) {
LOG.info("Delay for $seconds seconds")
sleepCancellable(seconds * 1000L)
}
override fun openFile(file: String): String = readActionInSmartMode(project) {
LOG.info("Open file: $file")
val virtualFile = LocalFileSystem.getInstance().findFileByIoFile(File(file))