Skip to content

Commit 7820e4e

Browse files
Subscribe to Java extension's SourceInvalidatedEvent and refresh the stack frames if they used the affected source (#1370)
* Subscribe to Java extension's SourceInvalidatedEvent and refresh the stack frames if they used the affected source
1 parent 77bdef3 commit 7820e4e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/extension.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { JavaTerminalLinkProvder } from "./terminalLinkProvider";
2626
import { initializeThreadOperations } from "./threadOperations";
2727
import * as utility from "./utility";
2828
import { registerVariableMenuCommands } from "./variableMenu";
29+
import { promisify } from "util";
2930

3031
export async function activate(context: vscode.ExtensionContext): Promise<any> {
3132
await initializeFromJsonFile(context.asAbsolutePath("./package.json"), {
@@ -75,6 +76,7 @@ function initializeExtension(_operationId: string, context: vscode.ExtensionCont
7576
initializeHotCodeReplace(context);
7677
initializeCodeLensProvider(context);
7778
initializeThreadOperations(context);
79+
subscribeToJavaExtensionEvents();
7880

7981
context.subscriptions.push(vscode.languages.registerInlineValuesProvider("java", new JavaInlineValuesProvider()));
8082
return {
@@ -87,6 +89,35 @@ export async function deactivate() {
8789
await disposeTelemetryWrapper();
8890
}
8991

92+
const delay = promisify(setTimeout);
93+
async function subscribeToJavaExtensionEvents(): Promise<void> {
94+
const javaExt = vscode.extensions.getExtension("redhat.java");
95+
if (!javaExt) {
96+
return;
97+
}
98+
99+
// wait javaExt to activate
100+
const timeout = 30 * 60 * 1000; // wait 30 min at most
101+
let count = 0;
102+
while (!javaExt.isActive && count < timeout) {
103+
await delay(1000);
104+
count += 1000;
105+
}
106+
107+
if (javaExt.isActive) {
108+
javaExt.exports?.onDidSourceInvalidate?.((event: any) => {
109+
if (event?.affectedRootPaths?.length) {
110+
const activeDebugSession = vscode.debug.activeDebugSession;
111+
if (activeDebugSession?.type === "java") {
112+
activeDebugSession.customRequest("refreshFrames", {
113+
affectedRootPaths: event.affectedRootPaths,
114+
});
115+
}
116+
}
117+
});
118+
}
119+
}
120+
90121
function registerDebugEventListener(context: vscode.ExtensionContext) {
91122
const measureKeys = ["duration"];
92123
context.subscriptions.push(vscode.debug.onDidTerminateDebugSession((e) => {

0 commit comments

Comments
 (0)