From a3648aa3cba6135c435fb5fc9eff4d5b68f1f98b Mon Sep 17 00:00:00 2001 From: Alexey Kalina Date: Thu, 11 Jul 2024 15:54:23 +0200 Subject: [PATCH] [evaluation-plugin] LME-7 CodeGen. Support delay between requests in evaluation plugin GitOrigin-RevId: 34aae34a2dcd2e2312ccdfbdabe5a07b041a73f2 --- .../core/src/com/intellij/cce/actions/Actions.kt | 8 +++++++- .../src/com/intellij/cce/interpreter/ActionsInvoker.kt | 3 ++- .../core/src/com/intellij/cce/interpreter/Interpreter.kt | 1 + .../intellij/cce/evaluable/common/CommonActionsInvoker.kt | 6 ++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/plugins/evaluation-plugin/core/src/com/intellij/cce/actions/Actions.kt b/plugins/evaluation-plugin/core/src/com/intellij/cce/actions/Actions.kt index f07bd72b6298..fd4c58dec458 100644 --- a/plugins/evaluation-plugin/core/src/com/intellij/cce/actions/Actions.kt +++ b/plugins/evaluation-plugin/core/src/com/intellij/cce/actions/Actions.kt @@ -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, JsonSerializer { @@ -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)) } } diff --git a/plugins/evaluation-plugin/core/src/com/intellij/cce/interpreter/ActionsInvoker.kt b/plugins/evaluation-plugin/core/src/com/intellij/cce/interpreter/ActionsInvoker.kt index 0a534f6bf9f7..0a9f2e34c0a6 100644 --- a/plugins/evaluation-plugin/core/src/com/intellij/cce/interpreter/ActionsInvoker.kt +++ b/plugins/evaluation-plugin/core/src/com/intellij/cce/interpreter/ActionsInvoker.kt @@ -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 diff --git a/plugins/evaluation-plugin/core/src/com/intellij/cce/interpreter/Interpreter.kt b/plugins/evaluation-plugin/core/src/com/intellij/cce/interpreter/Interpreter.kt index 18ec0f0fd911..92110131ab49 100644 --- a/plugins/evaluation-plugin/core/src/com/intellij/cce/interpreter/Interpreter.kt +++ b/plugins/evaluation-plugin/core/src/com/intellij/cce/interpreter/Interpreter.kt @@ -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 } diff --git a/plugins/evaluation-plugin/src/com/intellij/cce/evaluable/common/CommonActionsInvoker.kt b/plugins/evaluation-plugin/src/com/intellij/cce/evaluable/common/CommonActionsInvoker.kt index 666c46ee9df5..09ae56622bc0 100644 --- a/plugins/evaluation-plugin/src/com/intellij/cce/evaluable/common/CommonActionsInvoker.kt +++ b/plugins/evaluation-plugin/src/com/intellij/cce/evaluable/common/CommonActionsInvoker.kt @@ -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))