Skip to content

Commit b85bc6c

Browse files
committed
Automate initialization sequence in test fixture
1 parent 4fac439 commit b85bc6c

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

adapter/src/test/kotlin/org/javacs/ktda/DebugAdapterTestFixture.kt

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,46 @@ package org.javacs.ktda
22

33
import java.nio.file.Path
44
import java.nio.file.Paths
5+
import org.eclipse.lsp4j.debug.ConfigurationDoneArguments
6+
import org.eclipse.lsp4j.debug.InitializeRequestArguments
57
import org.eclipse.lsp4j.debug.DisconnectArguments
68
import org.eclipse.lsp4j.debug.OutputEventArguments
79
import org.eclipse.lsp4j.debug.services.IDebugProtocolClient
810
import org.javacs.ktda.adapter.KotlinDebugAdapter
911
import org.javacs.ktda.jdi.launch.JDILauncher
1012
import org.junit.After
1113

12-
abstract class DebugAdapterTestFixture(relativeWorkspaceRoot: String, mainClass: String) : IDebugProtocolClient {
14+
abstract class DebugAdapterTestFixture(
15+
relativeWorkspaceRoot: String,
16+
private val mainClass: String
17+
) : IDebugProtocolClient {
1318
val absoluteWorkspaceRoot: Path = Paths.get(DebugAdapterTestFixture::class.java.getResource("/").toURI()).resolve(relativeWorkspaceRoot)
1419
val debugAdapter: KotlinDebugAdapter = JDILauncher()
1520
.let(::KotlinDebugAdapter)
16-
.also { it.connect(this) }
21+
.also {
22+
it.connect(this)
23+
val configDone = it.configurationDone(ConfigurationDoneArguments())
24+
it.initialize(InitializeRequestArguments().apply {
25+
adapterID = "test-debug-adapter"
26+
linesStartAt1 = true
27+
columnsStartAt1 = true
28+
}).join()
29+
// Slightly hacky workaround to ensure someone is
30+
// waiting on the ConfigurationDoneResponse. See
31+
// KotlinDebugAdapter.kt:performInitialization for
32+
// details.
33+
Thread {
34+
configDone.join()
35+
}.start()
36+
}
1737

1838
fun launch() {
39+
println("Launching...")
1940
debugAdapter.launch(mapOf(
2041
"projectRoot" to absoluteWorkspaceRoot.toString(),
21-
"mainClass" to "sample.workspace.AppKt"
22-
))
42+
"mainClass" to mainClass
43+
)).join()
44+
println("Launched")
2345
}
2446

2547
@After fun closeDebugAdapter() {

0 commit comments

Comments
 (0)