Skip to content

Commit aa41530

Browse files
committed
Periodically print notifications logs if debug adapter is idle waiting
1 parent a2a2332 commit aa41530

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

adapter/src/main/kotlin/org/javacs/ktda/adapter/KotlinDebugAdapter.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import org.javacs.kt.LogMessage
1717
import org.javacs.kt.util.AsyncExecutor
1818
import org.javacs.ktda.util.JSON_LOG
1919
import org.javacs.ktda.util.KotlinDAException
20-
import org.javacs.ktda.util.waitUntil
20+
import org.javacs.ktda.util.waitFor
2121
import org.javacs.ktda.core.Debuggee
2222
import org.javacs.ktda.core.DebugContext
2323
import org.javacs.ktda.core.event.DebuggeeEventBus
@@ -114,7 +114,7 @@ class KotlinDebugAdapter(
114114
// (LSP4J does currently not provide a mechanism to hook into the request/response machinery)
115115

116116
LOG.trace("Waiting for configurationDoneResponse")
117-
waitUntil { (configurationDoneResponse?.numberOfDependents ?: 0) != 0 }
117+
waitFor("configuration done response") { (configurationDoneResponse?.numberOfDependents ?: 0) != 0 }
118118
LOG.trace("Done waiting for configurationDoneResponse")
119119
}
120120

@@ -373,7 +373,7 @@ class KotlinDebugAdapter(
373373
}
374374

375375
private inline fun <T> onceDebuggeeIsPresent(body: (Debuggee) -> T): T {
376-
waitUntil { debuggee != null }
376+
waitFor("debuggee") { debuggee != null }
377377
return body(debuggee!!)
378378
}
379379

adapter/src/main/kotlin/org/javacs/ktda/util/Utils.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,19 @@ fun <T> nonNull(item: T?, errorMsgIfNull: String): T =
5050
* Blocks the current thread until the condition becomes true.
5151
* Checks are performed in 80 ms intervals.
5252
*/
53-
inline fun waitUntil(condition: () -> Boolean) {
53+
inline fun waitFor(what: String, condition: () -> Boolean) {
54+
val delayUntilNotificationMs = 10_000
55+
val startTime = System.currentTimeMillis()
56+
var lastTime = startTime
57+
5458
while (!condition()) {
5559
Thread.sleep(80)
60+
61+
val now = System.currentTimeMillis()
62+
if ((now - lastTime) > delayUntilNotificationMs) {
63+
LOG.info("Waiting for {} for {} seconds...", what, (now - startTime) / 1000)
64+
lastTime = now
65+
}
5666
}
5767
}
5868

0 commit comments

Comments
 (0)