From 442c513c9747cda9448e636e2fd3f89a80e59339 Mon Sep 17 00:00:00 2001 From: Maria Sokolova Date: Sun, 2 Nov 2025 18:00:50 +0100 Subject: [PATCH] [rd debugger] XDebugProcess API to provide debug session events (cherry picked from commit ea021a766d74f68ca6ca58f41159c4e826d0494f) (cherry picked from commit 256519c7ac630edcf19d5a02a03798b0da22e4dd) IJ-CR-182318 GitOrigin-RevId: 11dc0c87dc515e5ddce504aa98682a402a8a0f7c --- .../debugger/engine/JavaDebugProcess.java | 7 +++++ .../engine/JavaDebugSessionEventsProvider.kt | 31 +++++++++++++++++++ .../com/intellij/xdebugger/XDebugProcess.java | 5 +++ .../xdebugger/XDebugSessionEventsProvider.kt | 13 ++++++++ .../impl/backend/BackendXDebugSessionApi.kt | 5 +++ .../debugger/impl/rpc/XDebugSessionApi.kt | 2 ++ 6 files changed, 63 insertions(+) create mode 100644 java/debugger/impl/src/com/intellij/debugger/engine/JavaDebugSessionEventsProvider.kt create mode 100644 platform/xdebugger-api/src/com/intellij/xdebugger/XDebugSessionEventsProvider.kt diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/JavaDebugProcess.java b/java/debugger/impl/src/com/intellij/debugger/engine/JavaDebugProcess.java index 17f116348144..0844fc1b2b19 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/JavaDebugProcess.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/JavaDebugProcess.java @@ -78,6 +78,7 @@ public class JavaDebugProcess extends XDebugProcess { private final NodeManagerImpl myNodeManager; private final JvmSmartStepIntoActionHandler mySmartStepIntoActionHandler; private final JvmDropFrameActionHandler myDropFrameActionActionHandler; + private final JavaDebugSessionEventsProvider myJavaDebugSessionEventsProvider; private static final JavaBreakpointHandlerFactory[] ourDefaultBreakpointHandlerFactories = { process -> new JavaBreakpointHandler.JavaLineBreakpointHandler(process), @@ -226,6 +227,7 @@ public class JavaDebugProcess extends XDebugProcess { mySmartStepIntoActionHandler = new JvmSmartStepIntoActionHandler(javaSession); myDropFrameActionActionHandler = new JvmDropFrameActionHandler(javaSession); + myJavaDebugSessionEventsProvider = new JavaDebugSessionEventsProvider(this); } private boolean shouldApplyContext(DebuggerContextImpl context) { @@ -257,6 +259,11 @@ public class JavaDebugProcess extends XDebugProcess { return myJavaSession; } + @Override + public XDebugSessionEventsProvider getSessionEventsProvider() { + return myJavaDebugSessionEventsProvider; + } + @Override public @NotNull XDebuggerEditorsProvider getEditorsProvider() { return myEditorsProvider; diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/JavaDebugSessionEventsProvider.kt b/java/debugger/impl/src/com/intellij/debugger/engine/JavaDebugSessionEventsProvider.kt new file mode 100644 index 000000000000..15be548a33d5 --- /dev/null +++ b/java/debugger/impl/src/com/intellij/debugger/engine/JavaDebugSessionEventsProvider.kt @@ -0,0 +1,31 @@ +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.debugger.engine + +import com.intellij.debugger.impl.DebuggerContextListener +import com.intellij.debugger.impl.DebuggerSession +import com.intellij.xdebugger.XDebugSessionEventsProvider +import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.channels.awaitClose +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.buffer +import kotlinx.coroutines.flow.channelFlow +import org.jetbrains.annotations.ApiStatus + +@ApiStatus.Internal +class JavaDebugSessionEventsProvider(private val debugProcess: JavaDebugProcess) : XDebugSessionEventsProvider { + override fun getUiUpdateEventsFlow(): Flow { + val stateManager = debugProcess.debuggerSession.contextManager + return channelFlow { + val listener = DebuggerContextListener { _, event -> + if (event == DebuggerSession.Event.THREADS_REFRESH) { + trySend(Unit) + } + } + stateManager.addListener(listener) + + awaitClose { + stateManager.removeListener(listener) + } + }.buffer(Channel.CONFLATED) + } +} \ No newline at end of file diff --git a/platform/xdebugger-api/src/com/intellij/xdebugger/XDebugProcess.java b/platform/xdebugger-api/src/com/intellij/xdebugger/XDebugProcess.java index dd9ee300a09e..4dc760307414 100644 --- a/platform/xdebugger-api/src/com/intellij/xdebugger/XDebugProcess.java +++ b/platform/xdebugger-api/src/com/intellij/xdebugger/XDebugProcess.java @@ -295,6 +295,11 @@ public abstract class XDebugProcess { return frame == null ? null : frame.getEvaluator(); } + @ApiStatus.Internal + public XDebugSessionEventsProvider getSessionEventsProvider() { + return null; + } + /** * Whether the "isShowLibraryStackFrames" setting is respected. * If true, the ShowLibraryFramesAction will be shown, for example. diff --git a/platform/xdebugger-api/src/com/intellij/xdebugger/XDebugSessionEventsProvider.kt b/platform/xdebugger-api/src/com/intellij/xdebugger/XDebugSessionEventsProvider.kt new file mode 100644 index 000000000000..1bb4a4a80af6 --- /dev/null +++ b/platform/xdebugger-api/src/com/intellij/xdebugger/XDebugSessionEventsProvider.kt @@ -0,0 +1,13 @@ +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.xdebugger + +import kotlinx.coroutines.flow.Flow +import org.jetbrains.annotations.ApiStatus + +/** + * A provider of events from [XDebugSession] which could trigger UI updates. + */ +@ApiStatus.Internal +interface XDebugSessionEventsProvider { + fun getUiUpdateEventsFlow(): Flow +} \ No newline at end of file diff --git a/platform/xdebugger-impl/backend/src/com/intellij/platform/debugger/impl/backend/BackendXDebugSessionApi.kt b/platform/xdebugger-impl/backend/src/com/intellij/platform/debugger/impl/backend/BackendXDebugSessionApi.kt index 8acd3dbc3635..68b57ed591eb 100644 --- a/platform/xdebugger-impl/backend/src/com/intellij/platform/debugger/impl/backend/BackendXDebugSessionApi.kt +++ b/platform/xdebugger-impl/backend/src/com/intellij/platform/debugger/impl/backend/BackendXDebugSessionApi.kt @@ -240,6 +240,11 @@ internal class BackendXDebugSessionApi : XDebugSessionApi { session.setBreakpointMuted(muted) } } + + override suspend fun getUiUpdateEventsFlow(sessionId: XDebugSessionId): Flow { + val session = sessionId.findValue() ?: return emptyFlow() + return session.debugProcess.sessionEventsProvider.getUiUpdateEventsFlow() + } } internal suspend fun createBackendDocument( diff --git a/platform/xdebugger-impl/rpc/src/com/intellij/platform/debugger/impl/rpc/XDebugSessionApi.kt b/platform/xdebugger-impl/rpc/src/com/intellij/platform/debugger/impl/rpc/XDebugSessionApi.kt index fb5a877c2759..72edc4ba0af3 100644 --- a/platform/xdebugger-impl/rpc/src/com/intellij/platform/debugger/impl/rpc/XDebugSessionApi.kt +++ b/platform/xdebugger-impl/rpc/src/com/intellij/platform/debugger/impl/rpc/XDebugSessionApi.kt @@ -67,6 +67,8 @@ interface XDebugSessionApi : RemoteApi { suspend fun muteBreakpoints(sessionDataId: XDebugSessionDataId, muted: Boolean) + suspend fun getUiUpdateEventsFlow(sessionId: XDebugSessionId): Flow + companion object { @JvmStatic suspend fun getInstance(): XDebugSessionApi {