in src/BootAppManager.ts [77:120]
private async _startAppListSynchronisation(): Promise<void> {
//TODO: The code below will fail if jdt language server has not yet been started
// How should we deal with that?
const callbackId = uuid.v4();
vscode.commands.registerCommand(callbackId, (location: string, name: string, isDeleted: boolean, entries: ClassPathData, ..._args: any[]) => {
if (isDeleted) {
this._boot_projects.delete(location);
} else {
if (entries && isBootAppClasspath(entries)) {
const current: BootApp | undefined = this._boot_projects.get(location);
if (current) {
current.name = name;
current.classpath = entries;
} else {
this._boot_projects.set(location, new BootApp(location, name, entries, AppState.INACTIVE));
}
} else {
this._boot_projects.delete(location);
}
}
this.fireDidChangeApps();
});
async function registerClasspathListener(): Promise<void> {
const MAX_RETRIES = 10;
const WAIT_IN_SECONDS = 2;
let available_tries = MAX_RETRIES;
while (available_tries > 0) {
available_tries--;
try {
await vscode.commands.executeCommand('java.execute.workspaceCommand', 'sts.java.addClasspathListener', callbackId);
return;
} catch (error) {
if (available_tries > 0) {
await sleep(WAIT_IN_SECONDS * 1000);
} else {
throw new Error(`Failed to register classpath listener after ${MAX_RETRIES} retries.`);
}
}
}
}
return await registerClasspathListener();
}