protected launchRequest()

in src/debugger/cordovaDebugSession.ts [184:284]


    protected launchRequest(response: DebugProtocol.LaunchResponse, launchArgs: ICordovaLaunchRequestArgs, request?: DebugProtocol.Request): Promise<void> {
        return new Promise<void>((resolve, reject) => {
            if (isNullOrUndefined(launchArgs.cwd)) {
                reject(new Error(localize("CwdUndefined", "Launch argument 'cwd' is undefined, please add it to your launch.json. Example: 'cwd': '${workspaceFolder}' to point to your current working directory.")));
            }
            return this.initializeTelemetry(launchArgs.cwd)
            .then(() => {
                this.initializeSettings(launchArgs);
            })
            .then(() => TelemetryHelper.generate("launch", (generator) => {
                launchArgs.port = launchArgs.port || 9222;
                if (!launchArgs.target) {
                    if (launchArgs.platform === PlatformType.Browser) {
                        launchArgs.target = "chrome";
                    } else {
                        launchArgs.target = TargetType.Emulator;
                    }
                    this.outputLogger(`Parameter target is not set - ${launchArgs.target} will be used`);
                }
                generator.add("target", CordovaDebugSession.getTargetType(launchArgs.target), false);
                if (launchArgs.cwd === null) {
                    throw new Error(localize("CurrentCWDDoesntContainACordovaProject", "Current working directory doesn't contain a Cordova project. Please open a Cordova project as a workspace root and try again."));
                }
                launchArgs.timeout = launchArgs.attachTimeout;

                let platform = launchArgs.platform && launchArgs.platform.toLowerCase();

                TelemetryHelper.sendPluginsList(launchArgs.cwd, CordovaProjectHelper.getInstalledPlugins(launchArgs.cwd));

                return Promise.all([
                    TelemetryHelper.determineProjectTypes(launchArgs.cwd),
                    this.workspaceManager.getRunArguments(launchArgs.cwd),
                    this.workspaceManager.getCordovaExecutable(launchArgs.cwd),
                    ])
                    .then(([projectType, runArguments, cordovaExecutable]) => {
                        launchArgs.cordovaExecutable = launchArgs.cordovaExecutable || cordovaExecutable;
                        launchArgs.allEnv = CordovaProjectHelper.getEnvArgument(launchArgs);
                        generator.add("projectType", TelemetryHelper.prepareProjectTypesTelemetry(projectType), false);
                        this.outputLogger(localize("LaunchingForPlatform", "Launching for {0} (This may take a while)...", platform));

                        switch (platform) {
                            case PlatformType.Android:
                                generator.add("platform", platform, false);
                                if (SimulateHelper.isSimulateTarget(launchArgs.target)) {
                                    return this.launchSimulate(launchArgs, projectType, generator);
                                } else {
                                    return this.launchAndroid(launchArgs, projectType, runArguments);
                                }
                            case PlatformType.IOS:
                                generator.add("platform", platform, false);
                                if (SimulateHelper.isSimulateTarget(launchArgs.target)) {
                                    return this.launchSimulate(launchArgs, projectType, generator);
                                } else {
                                    return this.launchIos(launchArgs, projectType, runArguments);
                                }
                            case PlatformType.Windows:
                                generator.add("platform", platform, false);
                                if (SimulateHelper.isSimulateTarget(launchArgs.target)) {
                                    return this.launchSimulate(launchArgs, projectType, generator);
                                } else {
                                    throw new Error(`Debugging ${platform} platform is not supported.`);
                                }
                            case PlatformType.Serve:
                                generator.add("platform", platform, false);
                                return this.launchServe(launchArgs, projectType, runArguments);
                            // https://github.com/apache/cordova-serve/blob/4ad258947c0e347ad5c0f20d3b48e3125eb24111/src/util.js#L27-L37
                            case PlatformType.AmazonFireos:
                            case PlatformType.Blackberry10:
                            case PlatformType.Firefoxos:
                            case PlatformType.Ubuntu:
                            case PlatformType.Wp8:
                            case PlatformType.Browser:
                                generator.add("platform", platform, false);
                                return this.launchSimulate(launchArgs, projectType, generator);
                            default:
                                generator.add("unknownPlatform", platform, true);
                                throw new Error(localize("UnknownPlatform", "Unknown Platform: {0}", platform));
                        }
                    })
                    .catch((err) => {
                        this.outputLogger(err.message || err, true);
                        return this.cleanUp().then(() => {
                            throw err;
                        });
                    })
                    .then(() => {
                        // For the browser platforms, we call super.launch(), which already attaches. For other platforms, attach here
                        if (platform !== PlatformType.Serve && platform !== PlatformType.Browser && !SimulateHelper.isSimulateTarget(launchArgs.target)) {
                            return this.vsCodeDebugSession.customRequest("attach", launchArgs);
                        }
                    });
            })
            .then(() => {
                this.sendResponse(response);
                this.cordovaSession.setStatus(CordovaSessionStatus.Activated);
                resolve();
            }))
            .catch(err => reject(err));
        })
        .catch(err => this.showError(err, response));
    }