Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix intellisense and launch when using multi config generators in presets #2130

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/cpptools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,11 @@ export class CppConfigurationProvider implements cpt.CustomConfigurationProvider
throw new MissingCompilerException();
}

const buildType = opts.cache.get('CMAKE_BUILD_TYPE');
if (buildType) {
opts.activeBuildTypeVariant = buildType.as<string>();
}

const targetFromToolchains = comp_toolchains?.target;
const targetArchFromToolchains = targetFromToolchains ? parseTargetArch(targetFromToolchains) : undefined;

Expand Down
2 changes: 1 addition & 1 deletion src/drivers/codemodel-driver-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export interface CodeModelContent {
*/
activeTarget: string|null;
/**
* The active build_type variant
* CMAKE_BUILD_TYPE for single config generators, and build config for multi config ones.
*/
activeBuildTypeVariant: string|null;
/**
Expand Down
17 changes: 12 additions & 5 deletions src/drivers/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,9 @@ export abstract class CMakeDriver implements vscode.Disposable {
*/
get currentBuildType(): string {
if (this.useCMakePresets) {
if ((this.isMultiConfig || this.isMultiConfFast) && this._buildPreset?.configuration) {
return this._buildPreset.configuration;
}
const buildType = this._configurePreset?.cacheVariables?.['CMAKE_BUILD_TYPE'];
if (util.isString(buildType)) {
return buildType;
Expand All @@ -696,8 +699,12 @@ export abstract class CMakeDriver implements vscode.Disposable {
}
}

get isMultiConf(): boolean {
return this.generatorName ? util.isMultiConfGenerator(this.generatorName) : false;
private _isMultiConfig: boolean = false;
get isMultiConfig(): boolean { return this._isMultiConfig; }
set isMultiConfig(v: boolean) { this._isMultiConfig = v; }

get isMultiConfFast(): boolean {
return this.generatorName ? util.isMultiConfGeneratorFast(this.generatorName) : false;
}

/**
Expand Down Expand Up @@ -1229,7 +1236,7 @@ export abstract class CMakeDriver implements vscode.Disposable {
telemetryProperties = {
CMakeExecutableVersion: cmakeVersion ? util.versionToString(cmakeVersion) : '',
CMakeGenerator: this.generatorName || '',
ConfigType: this.isMultiConf ? 'MultiConf' : this.currentBuildType || '',
ConfigType: this.isMultiConfFast ? 'MultiConf' : this.currentBuildType || '',
Toolchain: this._kit?.toolchainFile ? 'true' : 'false', // UseToolchain?
Trigger: trigger
};
Expand Down Expand Up @@ -1354,7 +1361,7 @@ export abstract class CMakeDriver implements vscode.Disposable {

const allowBuildTypeOnMultiConfig = config.get("cmake.setBuildTypeOnMultiConfig") || false;

if (!this.isMultiConf || (this.isMultiConf && allowBuildTypeOnMultiConfig)) {
if (!this.isMultiConfFast || (this.isMultiConfFast && allowBuildTypeOnMultiConfig)) {
// Mutliconf generators do not need the CMAKE_BUILD_TYPE property
settingMap.CMAKE_BUILD_TYPE = util.cmakeify(this.currentBuildType);
}
Expand Down Expand Up @@ -1416,7 +1423,7 @@ export abstract class CMakeDriver implements vscode.Disposable {
const child = await this._doCMakeBuild(target, consumer);
const timeEnd: number = new Date().getTime();
const telemetryProperties: telemetry.Properties | undefined = this.useCMakePresets ? undefined : {
ConfigType: this.isMultiConf ? 'MultiConf' : this.currentBuildType || ''
ConfigType: this.isMultiConfFast ? 'MultiConf' : this.currentBuildType || ''
};
const telemetryMeasures: telemetry.Measures = {
Duration: timeEnd - timeStart
Expand Down
13 changes: 10 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class ExtensionManager implements vscode.Disposable {
subs.push(new_cmt.onCodeModelChanged(FireLate, () => this._updateCodeModel(cmtFolder)));
subs.push(new_cmt.onTargetNameChanged(FireLate, () => this._updateCodeModel(cmtFolder)));
subs.push(new_cmt.onLaunchTargetNameChanged(FireLate, () => this._updateCodeModel(cmtFolder)));
subs.push(new_cmt.onActiveBuildPresetChanged(FireLate, () => this._updateCodeModel(cmtFolder)));
this._codeModelUpdateSubs.set(new_cmt.folder.uri.fsPath, subs);
}
rollbar.takePromise('Post-folder-open', {folder: cmtFolder.folder}, this._postWorkspaceOpen(cmtFolder));
Expand Down Expand Up @@ -209,7 +210,8 @@ class ExtensionManager implements vscode.Disposable {
this._codeModelUpdateSubs.set(cmtFolder.folder.uri.fsPath, [
cmtFolder.cmakeTools.onCodeModelChanged(FireLate, () => this._updateCodeModel(cmtFolder)),
cmtFolder.cmakeTools.onTargetNameChanged(FireLate, () => this._updateCodeModel(cmtFolder)),
cmtFolder.cmakeTools.onLaunchTargetNameChanged(FireLate, () => this._updateCodeModel(cmtFolder))
cmtFolder.cmakeTools.onLaunchTargetNameChanged(FireLate, () => this._updateCodeModel(cmtFolder)),
cmtFolder.cmakeTools.onActiveBuildPresetChanged(FireLate, () => this._updateCodeModel(cmtFolder))
]);
rollbar.takePromise('Post-folder-open', {folder: cmtFolder.folder}, this._postWorkspaceOpen(cmtFolder));
}
Expand Down Expand Up @@ -734,15 +736,20 @@ class ExtensionManager implements vscode.Disposable {
}
}

const isMultiConfig = !!cache.get('CMAKE_CONFIGURATION_TYPES');
if (drv) {
drv.isMultiConfig = isMultiConfig;
}
const actualBuildType = isMultiConfig && cmt.useCMakePresets ? cmt.buildPreset?.configuration || null : cmt.activeVariant;
const clCompilerPath = await findCLCompilerPath(env);
this._configProvider.cpptoolsVersion = cpptools.getVersion();
let codeModelContent;
if (cmt.codeModelContent) {
codeModelContent = cmt.codeModelContent;
this._configProvider.updateConfigurationData({ cache, codeModelContent, clCompilerPath, activeTarget: cmt.defaultBuildTarget, activeBuildTypeVariant: cmt.activeVariant, folder: cmt.folder.uri.fsPath });
this._configProvider.updateConfigurationData({ cache, codeModelContent, clCompilerPath, activeTarget: cmt.defaultBuildTarget, activeBuildTypeVariant: actualBuildType, folder: cmt.folder.uri.fsPath });
} else if (drv && drv.codeModelContent) {
codeModelContent = drv.codeModelContent;
this._configProvider.updateConfigurationData({ cache, codeModelContent, clCompilerPath, activeTarget: cmt.defaultBuildTarget, activeBuildTypeVariant: cmt.activeVariant, folder: cmt.folder.uri.fsPath });
this._configProvider.updateConfigurationData({ cache, codeModelContent, clCompilerPath, activeTarget: cmt.defaultBuildTarget, activeBuildTypeVariant: actualBuildType, folder: cmt.folder.uri.fsPath });
this._projectOutlineProvider.updateCodeModel(
cmt.workspaceContext.folder,
codeModelContent,
Expand Down
7 changes: 5 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,11 @@ export function splitCommandLine(cmd: string): string[] {
return quoted_args!.map(arg => arg.replace(/\\(")/g, '$1').replace(/^"(.*)"$/g, '$1'));
}

export function isMultiConfGenerator(gen: string): boolean {
return gen.includes('Visual Studio') || gen.includes('Xcode');
/**
* This is an initial check without atually configuring. It may or may not be accurate.
*/
export function isMultiConfGeneratorFast(gen: string): boolean {
return gen.includes('Visual Studio') || gen.includes('Xcode') || gen.includes('Multi-Config');
}

export class InvalidVersionString extends Error {}
Expand Down