Skip to content

Commit b155bd1

Browse files
committed
feat(intellij): execute tests from project tree view on files and folders
1 parent 678e5e8 commit b155bd1

File tree

7 files changed

+55
-35
lines changed

7 files changed

+55
-35
lines changed

intellij-client/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pluginVersion = 0.105.0
88

99
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
1010
pluginSinceBuild = 243
11-
pluginUntilBuild = 243.*
11+
pluginUntilBuild = 251.*
1212

1313

1414
# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension

intellij-client/gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[versions]
22
# libraries
33
annotations = "26.0.1"
4-
kotlinxSerialization = "1.8.0"
4+
kotlinxSerialization = "1.7.3"
55
junit = "4.13.2"
66
lsp4j = "0.21.1"
77

intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/debugging/RobotCodeDebugProcess.kt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@ class RobotCodeDebugProcess(
5656
debugClient.onStopped.adviseSuspend(Lifetime.Eternal, Dispatchers.IO) { args ->
5757
handleOnStopped(args)
5858
}
59-
debugClient.onOutput.adviseSuspend(Lifetime.Eternal, Dispatchers.IO) { args ->
60-
61-
session.reportMessage(
62-
args.output, when (args.category) {
63-
OutputEventArgumentsCategory.STDOUT, OutputEventArgumentsCategory.CONSOLE -> MessageType.INFO
64-
OutputEventArgumentsCategory.STDERR -> MessageType.ERROR
65-
else -> MessageType.WARNING
66-
}
67-
)
68-
}
59+
// debugClient.onOutput.adviseSuspend(Lifetime.Eternal, Dispatchers.IO) { args ->
60+
//
61+
// session.reportMessage(
62+
// args.output, when (args.category) {
63+
// OutputEventArgumentsCategory.STDOUT, OutputEventArgumentsCategory.CONSOLE -> MessageType.INFO
64+
// OutputEventArgumentsCategory.STDERR -> MessageType.ERROR
65+
// else -> MessageType.WARNING
66+
// }
67+
// )
68+
// }
6969

7070
// debugClient.onTerminated.adviseSuspend(Lifetime.Eternal, Dispatchers.IO) {
7171
// session.stop()
@@ -105,6 +105,7 @@ class RobotCodeDebugProcess(
105105

106106
"exception" -> {
107107
// TODO session.exceptionCaught()
108+
session.positionReached(createRobotCodeSuspendContext(args.threadId))
108109
}
109110

110111
else -> {

intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/execution/RobotCodeRunConfigurationProducer.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package dev.robotcode.robotcode4ij.execution
22

33
import com.intellij.execution.actions.ConfigurationContext
4+
import com.intellij.execution.actions.ConfigurationFromContext
45
import com.intellij.execution.actions.LazyRunConfigurationProducer
56
import com.intellij.execution.configurations.ConfigurationFactory
67
import com.intellij.execution.configurations.runConfigurationType
78
import com.intellij.openapi.util.Ref
89
import com.intellij.psi.PsiElement
910
import dev.robotcode.robotcode4ij.testing.testManger
11+
import java.util.*
1012

1113

1214
class RobotCodeRunConfigurationProducer : LazyRunConfigurationProducer<RobotCodeRunConfiguration>() {
@@ -21,7 +23,13 @@ class RobotCodeRunConfigurationProducer : LazyRunConfigurationProducer<RobotCode
2123
): Boolean {
2224
val testItem = configuration.project.testManger.findTestItem(sourceElement.get()) ?: return false
2325

24-
configuration.name = testItem.name
26+
27+
configuration.name = "${
28+
testItem.type.replaceFirstChar {
29+
if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it
30+
.toString()
31+
}
32+
} ${testItem.name}"
2533
configuration.includedTestItems = listOf(testItem)
2634

2735
return true
@@ -37,4 +45,9 @@ class RobotCodeRunConfigurationProducer : LazyRunConfigurationProducer<RobotCode
3745

3846
return configuration.includedTestItems == listOf(testItem)
3947
}
48+
49+
override fun isPreferredConfiguration(self: ConfigurationFromContext?, other: ConfigurationFromContext?): Boolean {
50+
return false
51+
}
52+
4053
}

intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/execution/RobotOutputToGeneralTestEventsConverter.kt

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import kotlinx.coroutines.withTimeout
1818
import org.eclipse.lsp4j.debug.OutputEventArgumentsCategory
1919

2020
class RobotOutputToGeneralTestEventsConverter(
21-
testFrameworkName: String, consoleProperties: RobotRunnerConsoleProperties,
21+
testFrameworkName: String, val consoleProperties: RobotRunnerConsoleProperties,
2222
) : OutputToGeneralTestEventsConverter(testFrameworkName, consoleProperties) {
2323

2424
private var _firstCall = false
@@ -54,7 +54,6 @@ class RobotOutputToGeneralTestEventsConverter(
5454
else -> ServiceMessageBuilder.testFailed(args.name).apply {
5555
addAttribute("message", args.attributes.message ?: "Error")
5656
}
57-
5857
}
5958

6059
else -> null
@@ -90,10 +89,6 @@ class RobotOutputToGeneralTestEventsConverter(
9089

9190
private var configurationDone = CompletableDeferred<Unit>()
9291

93-
private fun processConnected() {
94-
configurationDone.complete(Unit)
95-
}
96-
9792
init {
9893
consoleProperties.state?.afterInitialize?.adviseEternal {
9994
runBlocking {
@@ -108,23 +103,26 @@ class RobotOutputToGeneralTestEventsConverter(
108103
}
109104
consoleProperties.state?.debugClient?.onRobotStarted?.adviseEternal(this::robotStarted)
110105
consoleProperties.state?.debugClient?.onRobotEnded?.adviseEternal(this::robotEnded)
111-
consoleProperties.state?.debugClient?.onRobotLog?.adviseEternal { args -> // TODO: Implement this
112-
// val msg = ServiceMessageBuilder.testStdOut("blah")
113-
//
114-
// msg.addAttribute("nodeId", args.itemId ?: "0").addAttribute(
115-
// "out", "[${args.level}] ${args.message}\n"
116-
// )
117-
// this.processServiceMessageFromRobot(msg)
118-
}
106+
107+
// TODO: Implement this
108+
// consoleProperties.state?.debugClient?.onRobotLog?.adviseEternal { args ->
109+
// val msg = ServiceMessageBuilder.testStdOut("blah")
110+
//
111+
// msg.addAttribute("nodeId", args.itemId ?: "0").addAttribute(
112+
// "out", "[${args.level}] ${args.message}\n"
113+
// )
114+
// this.processServiceMessageFromRobot(msg)
115+
// }
116+
119117
consoleProperties.state?.debugClient?.onOutput?.adviseEternal { args ->
120118
val msg =
121119
if (args.category == OutputEventArgumentsCategory.STDERR) ServiceMessageBuilder.testStdErr(args.category)
122120
else ServiceMessageBuilder.testStdOut(args.category)
123121

124122
msg.addAttribute("nodeId", testItemIdStack.lastOrNull() ?: "0")
125-
msg.addAttribute("out", "${args.output}")
123+
msg.addAttribute("out", "\u001b[38;5;243m${args.output}\u001b[0m")
126124

127-
this.processServiceMessageFromRobot(msg)
125+
processServiceMessageFromRobot(msg)
128126
}
129127

130128
}
@@ -133,17 +131,18 @@ class RobotOutputToGeneralTestEventsConverter(
133131
ServiceMessage.parse(msg.toString())?.let {
134132
this.processServiceMessage(it, visitor)
135133
}
134+
136135
}
137136

138137
override fun processServiceMessages(text: String, outputType: Key<*>, visitor: ServiceMessageVisitor): Boolean {
139138
if (!_firstCall) {
140139
_firstCall = true
141140
this.visitor = visitor
142141

143-
processConnected()
142+
configurationDone.complete(Unit)
144143
}
145144

146-
// TODO: make this configurable
145+
// TODO: make this configurable or find a way to output this to another console
147146
return true
148147
}
149148
}

intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/execution/RobotRunnerConsoleProperties.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ class RobotRunnerConsoleProperties(
1313

1414
var state: RobotCodeRunProfileState? = null
1515

16-
init { // isUsePredefinedMessageFilter = false
16+
init {
17+
18+
isUsePredefinedMessageFilter = false
1719
setIfUndefined(HIDE_PASSED_TESTS, false)
18-
setIfUndefined(HIDE_IGNORED_TEST, true)
20+
setIfUndefined(HIDE_IGNORED_TEST, false)
1921
setIfUndefined(SCROLL_TO_SOURCE, true)
2022
setIfUndefined(SELECT_FIRST_DEFECT, true)
2123
setIfUndefined(SHOW_STATISTICS, true)

intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/testing/RobotCodeTestManager.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.intellij.openapi.components.service
88
import com.intellij.openapi.diagnostic.thisLogger
99
import com.intellij.openapi.project.Project
1010
import com.intellij.openapi.vfs.VirtualFile
11+
import com.intellij.psi.PsiDirectory
1112
import com.intellij.psi.PsiDocumentManager
1213
import com.intellij.psi.PsiElement
1314
import com.intellij.psi.util.elementType
@@ -30,6 +31,7 @@ import java.net.URI
3031
val id: String,
3132
val name: String,
3233
val longname: String,
34+
val lineno: Int? = null,
3335
val description: String? = null,
3436
val uri: String? = null,
3537
val relSource: String? = null,
@@ -177,14 +179,17 @@ import java.net.URI
177179

178180

179181
fun findTestItem(element: PsiElement): RobotCodeTestItem? {
182+
val directory = element as? PsiDirectory
183+
if (directory != null) {
184+
return findTestItem(directory.virtualFile.uri)
185+
}
180186
val containingFile = element.containingFile ?: return null
181187
if (containingFile !is RobotSuiteFile) {
182188
return null
183189
}
184190

185191
if (element is RobotSuiteFile) {
186-
val result = findTestItem(containingFile.virtualFile.uri)
187-
return result
192+
return findTestItem(containingFile.virtualFile.uri)
188193
}
189194

190195
if (element.elementType !is IRobotFrameworkElementType) {

0 commit comments

Comments
 (0)