export async function remoteDebugJavaFunctionApp()

in src/commands/remoteDebugJava/remoteDebugJavaFunctionApp.ts [21:82]


export async function remoteDebugJavaFunctionApp(context: IActionContext, node?: SlotTreeItemBase): Promise<void> {
    if (!node) {
        node = await ext.tree.showTreeItemPicker<SlotTreeItemBase>(ProductionSlotTreeItem.contextValue, context);
    }
    const client: SiteClient = await node.site.createClient(context);
    const portNumber: number = await portfinder.getPortPromise();
    const publishCredential: WebSiteManagementModels.User = await client.getWebAppPublishCredential();
    const debugProxy: DebugProxy = new DebugProxy(node.site, portNumber, publishCredential);

    debugProxy.on('error', (err: Error) => {
        debugProxy.dispose();
        throw err;
    });

    await vscode.window.withProgress({ location: vscode.ProgressLocation.Window }, async (p: vscode.Progress<{}>) => {
        // eslint-disable-next-line @typescript-eslint/no-misused-promises, @typescript-eslint/no-explicit-any, no-async-promise-executor
        return new Promise(async (resolve: (value: unknown) => void, reject: (e: any) => void): Promise<void> => {
            try {
                const siteConfig: WebSiteManagementModels.SiteConfigResource = await client.getSiteConfig();
                const appSettings: WebSiteManagementModels.StringDictionary = await client.listApplicationSettings();
                if (needUpdateSiteConfig(siteConfig) || (appSettings.properties && needUpdateAppSettings(appSettings.properties))) {
                    const confirmMsg: string = localize('confirmRemoteDebug', 'The configurations of the selected app will be changed before debugging. Would you like to continue?');
                    const result: vscode.MessageItem = await context.ui.showWarningMessage(confirmMsg, { modal: true }, DialogResponses.yes, DialogResponses.learnMore);
                    if (result === DialogResponses.learnMore) {
                        await openUrl('https://aka.ms/azfunc-remotedebug');
                        return;
                    } else {
                        await updateSiteConfig(client, p, siteConfig);
                        await updateAppSettings(client, p, appSettings);
                    }
                }

                p.report({ message: 'starting debug proxy...' });
                ext.outputChannel.appendLog('starting debug proxy...');
                void debugProxy.startProxy(context);
                debugProxy.on('start', resolve);
            } catch (error) {
                reject(error);
            }
        });
    });

    const sessionId: string = Date.now().toString();

    await vscode.debug.startDebugging(undefined, {
        name: sessionId,
        type: 'java',
        request: 'attach',
        hostName: 'localhost',
        port: portNumber
    });

    const terminateDebugListener: vscode.Disposable = vscode.debug.onDidTerminateDebugSession((event: vscode.DebugSession) => {
        if (event.name === sessionId) {
            if (debugProxy !== undefined) {
                debugProxy.dispose();
            }
            terminateDebugListener.dispose();
        }
    });

}