async configureInternal()

in src/cmake-tools.ts [1233:1314]


    async configureInternal(trigger: ConfigureTrigger = ConfigureTrigger.api, extra_args: string[] = [], type: ConfigureType = ConfigureType.Normal): Promise<number> {
        const drv: CMakeDriver | null = await this.getCMakeDriverInstance();
        // Don't show a progress bar when the extension is using Cache for configuration.
        // Using cache for configuration happens only one time.
        if (drv && drv.shouldUseCachedConfiguration(trigger)) {
            const retc: number = await drv.configure(trigger, []);
            if (retc === 0) {
                await this._refreshCompileDatabase(drv.expansionOptions);
            }
            await this._ctestController.reloadTests(drv);
            this._onReconfiguredEmitter.fire();
            return retc;
        }

        return vscode.window.withProgress(
            {
                location: vscode.ProgressLocation.Notification,
                title: localize('configuring.project', 'Configuring project')
            },
            async progress => {
                progress.report({ message: localize('preparing.to.configure', 'Preparing to configure') });
                if (type !== ConfigureType.ShowCommandOnly) {
                    log.info(localize('run.configure', 'Configuring folder: {0}', this.folderName), extra_args);
                }

                return this._doConfigure(type, progress, async consumer => {
                    const IS_CONFIGURING_KEY = 'cmake:isConfiguring';
                    if (drv) {
                        let old_prog = 0;
                        const prog_sub = drv.onProgress(pr => {
                            const new_prog = 100 * (pr.progressCurrent - pr.progressMinimum) / (pr.progressMaximum - pr.progressMinimum);
                            const increment = new_prog - old_prog;
                            if (increment >= 1) {
                                old_prog += increment;
                                progress.report({ increment });
                            }
                        });
                        try {
                            progress.report({ message: localize('configuring.project', 'Configuring project') });
                            let retc: number;
                            await setContextValue(IS_CONFIGURING_KEY, true);
                            if (type === ConfigureType.Cache) {
                                retc = await drv.configure(trigger, [], consumer, true);
                            } else {
                                switch (type) {
                                    case ConfigureType.Normal:
                                        retc = await drv.configure(trigger, extra_args, consumer);
                                        break;
                                    case ConfigureType.Clean:
                                        retc = await drv.cleanConfigure(trigger, extra_args, consumer);
                                        break;
                                    case ConfigureType.ShowCommandOnly:
                                        retc = await drv.configure(trigger, extra_args, consumer, undefined, true);
                                        break;
                                    default:
                                        rollbar.error(localize('unexpected.configure.type', 'Unexpected configure type'), { type });
                                        retc = await this.configureInternal(trigger, extra_args, ConfigureType.Normal);
                                        break;
                                }
                                await setContextValue(IS_CONFIGURING_KEY, false);
                            }
                            if (retc === 0) {
                                await enableFullFeatureSet(true);
                                await this._refreshCompileDatabase(drv.expansionOptions);
                            }

                            await this._ctestController.reloadTests(drv);
                            this._onReconfiguredEmitter.fire();
                            return retc;
                        } finally {
                            await setContextValue(IS_CONFIGURING_KEY, false);
                            progress.report({ message: localize('finishing.configure', 'Finishing configure') });
                            prog_sub.dispose();
                        }
                    } else {
                        progress.report({ message: localize('configure.failed', 'Failed to configure project') });
                        return -1;
                    }
                });
            }
        );
    }