Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscribe to Java extension's SourceInvalidatedEvent and refresh the stack frames if they used the affected source #1370

Merged
merged 2 commits into from
Jul 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading