From b155bd1d6e4fd5a963625585cf1b0c101600cb00 Mon Sep 17 00:00:00 2001 From: Daniel Biehl Date: Sun, 12 Jan 2025 23:03:31 +0100 Subject: [PATCH] feat(intellij): execute tests from project tree view on files and folders --- intellij-client/gradle.properties | 2 +- intellij-client/gradle/libs.versions.toml | 2 +- .../debugging/RobotCodeDebugProcess.kt | 21 +++++------ .../RobotCodeRunConfigurationProducer.kt | 15 +++++++- ...RobotOutputToGeneralTestEventsConverter.kt | 35 +++++++++---------- .../execution/RobotRunnerConsoleProperties.kt | 6 ++-- .../testing/RobotCodeTestManager.kt | 9 +++-- 7 files changed, 55 insertions(+), 35 deletions(-) diff --git a/intellij-client/gradle.properties b/intellij-client/gradle.properties index 0c35fc30..cd1d2258 100644 --- a/intellij-client/gradle.properties +++ b/intellij-client/gradle.properties @@ -8,7 +8,7 @@ pluginVersion = 0.105.0 # Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html pluginSinceBuild = 243 -pluginUntilBuild = 243.* +pluginUntilBuild = 251.* # IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension diff --git a/intellij-client/gradle/libs.versions.toml b/intellij-client/gradle/libs.versions.toml index ec486c92..71690abd 100644 --- a/intellij-client/gradle/libs.versions.toml +++ b/intellij-client/gradle/libs.versions.toml @@ -1,7 +1,7 @@ [versions] # libraries annotations = "26.0.1" -kotlinxSerialization = "1.8.0" +kotlinxSerialization = "1.7.3" junit = "4.13.2" lsp4j = "0.21.1" diff --git a/intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/debugging/RobotCodeDebugProcess.kt b/intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/debugging/RobotCodeDebugProcess.kt index bb38fd52..b0594907 100644 --- a/intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/debugging/RobotCodeDebugProcess.kt +++ b/intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/debugging/RobotCodeDebugProcess.kt @@ -56,16 +56,16 @@ class RobotCodeDebugProcess( debugClient.onStopped.adviseSuspend(Lifetime.Eternal, Dispatchers.IO) { args -> handleOnStopped(args) } - debugClient.onOutput.adviseSuspend(Lifetime.Eternal, Dispatchers.IO) { args -> - - session.reportMessage( - args.output, when (args.category) { - OutputEventArgumentsCategory.STDOUT, OutputEventArgumentsCategory.CONSOLE -> MessageType.INFO - OutputEventArgumentsCategory.STDERR -> MessageType.ERROR - else -> MessageType.WARNING - } - ) - } + // debugClient.onOutput.adviseSuspend(Lifetime.Eternal, Dispatchers.IO) { args -> + // + // session.reportMessage( + // args.output, when (args.category) { + // OutputEventArgumentsCategory.STDOUT, OutputEventArgumentsCategory.CONSOLE -> MessageType.INFO + // OutputEventArgumentsCategory.STDERR -> MessageType.ERROR + // else -> MessageType.WARNING + // } + // ) + // } // debugClient.onTerminated.adviseSuspend(Lifetime.Eternal, Dispatchers.IO) { // session.stop() @@ -105,6 +105,7 @@ class RobotCodeDebugProcess( "exception" -> { // TODO session.exceptionCaught() + session.positionReached(createRobotCodeSuspendContext(args.threadId)) } else -> { diff --git a/intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/execution/RobotCodeRunConfigurationProducer.kt b/intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/execution/RobotCodeRunConfigurationProducer.kt index ba017109..fe06a4a9 100644 --- a/intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/execution/RobotCodeRunConfigurationProducer.kt +++ b/intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/execution/RobotCodeRunConfigurationProducer.kt @@ -1,12 +1,14 @@ package dev.robotcode.robotcode4ij.execution import com.intellij.execution.actions.ConfigurationContext +import com.intellij.execution.actions.ConfigurationFromContext import com.intellij.execution.actions.LazyRunConfigurationProducer import com.intellij.execution.configurations.ConfigurationFactory import com.intellij.execution.configurations.runConfigurationType import com.intellij.openapi.util.Ref import com.intellij.psi.PsiElement import dev.robotcode.robotcode4ij.testing.testManger +import java.util.* class RobotCodeRunConfigurationProducer : LazyRunConfigurationProducer() { @@ -21,7 +23,13 @@ class RobotCodeRunConfigurationProducer : LazyRunConfigurationProducer ServiceMessageBuilder.testFailed(args.name).apply { addAttribute("message", args.attributes.message ?: "Error") } - } else -> null @@ -90,10 +89,6 @@ class RobotOutputToGeneralTestEventsConverter( private var configurationDone = CompletableDeferred() - private fun processConnected() { - configurationDone.complete(Unit) - } - init { consoleProperties.state?.afterInitialize?.adviseEternal { runBlocking { @@ -108,23 +103,26 @@ class RobotOutputToGeneralTestEventsConverter( } consoleProperties.state?.debugClient?.onRobotStarted?.adviseEternal(this::robotStarted) consoleProperties.state?.debugClient?.onRobotEnded?.adviseEternal(this::robotEnded) - consoleProperties.state?.debugClient?.onRobotLog?.adviseEternal { args -> // TODO: Implement this - // val msg = ServiceMessageBuilder.testStdOut("blah") - // - // msg.addAttribute("nodeId", args.itemId ?: "0").addAttribute( - // "out", "[${args.level}] ${args.message}\n" - // ) - // this.processServiceMessageFromRobot(msg) - } + + // TODO: Implement this + // consoleProperties.state?.debugClient?.onRobotLog?.adviseEternal { args -> + // val msg = ServiceMessageBuilder.testStdOut("blah") + // + // msg.addAttribute("nodeId", args.itemId ?: "0").addAttribute( + // "out", "[${args.level}] ${args.message}\n" + // ) + // this.processServiceMessageFromRobot(msg) + // } + consoleProperties.state?.debugClient?.onOutput?.adviseEternal { args -> val msg = if (args.category == OutputEventArgumentsCategory.STDERR) ServiceMessageBuilder.testStdErr(args.category) else ServiceMessageBuilder.testStdOut(args.category) msg.addAttribute("nodeId", testItemIdStack.lastOrNull() ?: "0") - msg.addAttribute("out", "${args.output}") + msg.addAttribute("out", "\u001b[38;5;243m${args.output}\u001b[0m") - this.processServiceMessageFromRobot(msg) + processServiceMessageFromRobot(msg) } } @@ -133,6 +131,7 @@ class RobotOutputToGeneralTestEventsConverter( ServiceMessage.parse(msg.toString())?.let { this.processServiceMessage(it, visitor) } + } override fun processServiceMessages(text: String, outputType: Key<*>, visitor: ServiceMessageVisitor): Boolean { @@ -140,10 +139,10 @@ class RobotOutputToGeneralTestEventsConverter( _firstCall = true this.visitor = visitor - processConnected() + configurationDone.complete(Unit) } - // TODO: make this configurable + // TODO: make this configurable or find a way to output this to another console return true } } diff --git a/intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/execution/RobotRunnerConsoleProperties.kt b/intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/execution/RobotRunnerConsoleProperties.kt index b0d17cb0..8dd2e4fc 100644 --- a/intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/execution/RobotRunnerConsoleProperties.kt +++ b/intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/execution/RobotRunnerConsoleProperties.kt @@ -13,9 +13,11 @@ class RobotRunnerConsoleProperties( var state: RobotCodeRunProfileState? = null - init { // isUsePredefinedMessageFilter = false + init { + + isUsePredefinedMessageFilter = false setIfUndefined(HIDE_PASSED_TESTS, false) - setIfUndefined(HIDE_IGNORED_TEST, true) + setIfUndefined(HIDE_IGNORED_TEST, false) setIfUndefined(SCROLL_TO_SOURCE, true) setIfUndefined(SELECT_FIRST_DEFECT, true) setIfUndefined(SHOW_STATISTICS, true) diff --git a/intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/testing/RobotCodeTestManager.kt b/intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/testing/RobotCodeTestManager.kt index d265ca39..a29802d7 100644 --- a/intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/testing/RobotCodeTestManager.kt +++ b/intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/testing/RobotCodeTestManager.kt @@ -8,6 +8,7 @@ import com.intellij.openapi.components.service import com.intellij.openapi.diagnostic.thisLogger import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.VirtualFile +import com.intellij.psi.PsiDirectory import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiElement import com.intellij.psi.util.elementType @@ -30,6 +31,7 @@ import java.net.URI val id: String, val name: String, val longname: String, + val lineno: Int? = null, val description: String? = null, val uri: String? = null, val relSource: String? = null, @@ -177,14 +179,17 @@ import java.net.URI fun findTestItem(element: PsiElement): RobotCodeTestItem? { + val directory = element as? PsiDirectory + if (directory != null) { + return findTestItem(directory.virtualFile.uri) + } val containingFile = element.containingFile ?: return null if (containingFile !is RobotSuiteFile) { return null } if (element is RobotSuiteFile) { - val result = findTestItem(containingFile.virtualFile.uri) - return result + return findTestItem(containingFile.virtualFile.uri) } if (element.elementType !is IRobotFrameworkElementType) {