Skip to content

Commit

Permalink
Subscribe to Java extension's SourceInvalidatedEvent and refresh the …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
testforstephen authored Jul 24, 2023
1 parent 77bdef3 commit 7820e4e
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { JavaTerminalLinkProvder } from "./terminalLinkProvider";
import { initializeThreadOperations } from "./threadOperations";
import * as utility from "./utility";
import { registerVariableMenuCommands } from "./variableMenu";
import { promisify } from "util";

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

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

const delay = promisify(setTimeout);
async function subscribeToJavaExtensionEvents(): Promise<void> {
const javaExt = vscode.extensions.getExtension("redhat.java");
if (!javaExt) {
return;
}

// wait javaExt to activate
const timeout = 30 * 60 * 1000; // wait 30 min at most
let count = 0;
while (!javaExt.isActive && count < timeout) {
await delay(1000);
count += 1000;
}

if (javaExt.isActive) {
javaExt.exports?.onDidSourceInvalidate?.((event: any) => {
if (event?.affectedRootPaths?.length) {
const activeDebugSession = vscode.debug.activeDebugSession;
if (activeDebugSession?.type === "java") {
activeDebugSession.customRequest("refreshFrames", {
affectedRootPaths: event.affectedRootPaths,
});
}
}
});
}
}

function registerDebugEventListener(context: vscode.ExtensionContext) {
const measureKeys = ["duration"];
context.subscriptions.push(vscode.debug.onDidTerminateDebugSession((e) => {
Expand Down

0 comments on commit 7820e4e

Please sign in to comment.