updateConfigurationData()

in src/cpptools.ts [539:607]


    updateConfigurationData(opts: codemodel_api.CodeModelParams) {
        // Reset the counters for diagnostics
        this.requests.clear();
        this.responses.clear();
        this.buildTypesSeen.clear();
        this.targets = [];

        let hadMissingCompilers = false;
        this._workspaceBrowseConfiguration = { browsePath: [] };
        this._activeTarget = opts.activeTarget;
        this.activeBuildType = opts.activeBuildTypeVariant;
        for (const config of opts.codeModelContent.configurations) {
            this.buildTypesSeen.add(config.name);
        }
        if (this.buildTypesSeen.size > 0 && !this.buildTypesSeen.has(opts.activeBuildTypeVariant || "")) {
            const configName = opts.codeModelContent.configurations[0].name;
            log.warning(localize('build.type.out.of.sync',
                "The build configurations generated do not contain the active build configuration. Using {0} for CMAKE_BUILD_TYPE instead of {1} to ensure that IntelliSense configurations can be found",
                `"${configName}"`, `"${opts.activeBuildTypeVariant}"`));
            opts.activeBuildTypeVariant = configName;
        }
        for (const config of opts.codeModelContent.configurations) {
            // Update only the active build type variant.
            if (config.name === opts.activeBuildTypeVariant) {
                for (const project of config.projects) {
                    for (const target of project.targets) {
                        // Now some shenanigans since header files don't have config data:
                        // 1. Accumulate some "defaults" based on the set of all options for each file group
                        // 2. Pass these "defaults" down when rebuilding the config data
                        // 3. Any `fileGroup` that does not have the associated attribute will receive the `default`
                        const grps = target.fileGroups || [];
                        const includePath = [...new Set(util.flatMap(grps, grp => grp.includePath || []))].map(item => item.path);
                        const compileFlags = [...util.flatMap(grps, grp => shlex.split(grp.compileFlags || ''))];
                        const defines = [...new Set(util.flatMap(grps, grp => grp.defines || []))];
                        const sysroot = target.sysroot ? shlex.quote(target.sysroot) : '';
                        this.targets.push({ name: target.name, type: target.type });
                        for (const grp of target.fileGroups || []) {
                            try {
                                this._updateFileGroup(
                                    target.sourceDirectory || '',
                                    grp,
                                    opts,
                                    {
                                        name: target.name,
                                        compileFlags,
                                        includePath,
                                        defines
                                    },
                                    sysroot
                                );
                            } catch (e) {
                                if (e instanceof MissingCompilerException) {
                                    hadMissingCompilers = true;
                                } else {
                                    throw e;
                                }
                            }
                        }
                    }
                }
                break;
            }
        }
        if (hadMissingCompilers && this._lastUpdateSucceeded) {
            void vscode.window.showErrorMessage(localize('path.not.found.in.cmake.cache',
                'The path to the compiler for one or more source files was not found in the CMake cache. If you are using a toolchain file, this probably means that you need to specify the CACHE option when you set your C and/or C++ compiler path'));
        }
        this._lastUpdateSucceeded = !hadMissingCompilers;
    }