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

Ensure kit selection quickPick doesn't show on non CMake projects #1689

Merged
merged 8 commits into from
Mar 2, 2021
22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"onCommand:cmake.debugTarget",
"onCommand:cmake.debugTargetAll",
"onCommand:cmake.editCache",
"onCommand:cmake.editCacheUI",
"onCommand:cmake.editKits",
"onCommand:cmake.viewLog",
"onCommand:cmake.install",
Expand Down Expand Up @@ -297,13 +298,15 @@
"title": "%cmake-tools.command.cmake.cleanRebuildAll.title%"
},
{
"command": "cmake.openConfiguration",
"title": "%cmake-tools.command.cmake.openConfiguration.title%",
"command": "cmake.editCacheUI",
"when": "cmake:enableFullFeatureSet",
"title": "%cmake-tools.command.cmake.editCacheUI.title%",
"category": "CMake"
},
{
"command": "cmake.outline.openConfiguration",
"title": "%cmake-tools.command.cmake.openConfiguration.title%"
"command": "cmake.outline.editCacheUI",
"when": "cmake:enableFullFeatureSet",
"title": "%cmake-tools.command.cmake.editCacheUI.title%"
},
{
"command": "cmake.ctest",
Expand Down Expand Up @@ -391,7 +394,6 @@
{
"command": "cmake.resetState",
"title": "%cmake-tools.command.cmake.resetState.title%",
"when": "cmake:enableFullFeatureSet",
"category": "CMake"
},
{
Expand Down Expand Up @@ -477,7 +479,6 @@
"command": "cmake.selectActiveFolder"
},
{
"when": "cmake:enableFullFeatureSet",
"command": "cmake.resetState"
},
{
Expand Down Expand Up @@ -544,7 +545,8 @@
"when": "cmake:multiRoot && cmake:enableFullFeatureSet"
},
{
"command": "cmake.openConfiguration"
"command": "cmake.editCacheUI",
"when": "cmake:enableFullFeatureSet"
},
{
"when": "cmake:enableFullFeatureSet",
Expand Down Expand Up @@ -635,7 +637,7 @@
"when": "never"
},
{
"command": "cmake.outline.openConfiguration",
"command": "cmake.outline.editCacheUI",
"when": "never"
},
{
Expand Down Expand Up @@ -707,8 +709,8 @@
"group": "1_cmakeOutline"
},
{
"command": "cmake.outline.openConfiguration",
"when": "view == cmake.outline",
"command": "cmake.outline.editCacheUI",
"when": "view == cmake.outline && cmake:enableFullFeatureSet",
"group": "1_cmakeOutline"
}
],
Expand Down
2 changes: 1 addition & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"cmake-tools.command.cmake.setDefaultTarget.title": "Set Build Target",
"cmake-tools.command.cmake.cleanConfigure.title": "Delete Cache and Reconfigure",
"cmake-tools.command.cmake.cleanConfigureAll.title": "Delete Cache and Reconfigure All Projects",
"cmake-tools.command.cmake.openConfiguration.title": "Edit CMake Cache (UI)",
"cmake-tools.command.cmake.editCacheUI.title": "Edit CMake Cache (UI)",
"cmake-tools.command.cmake.outline.cleanConfigure.title": "Clean Reconfigure",
"cmake-tools.command.cmake.outline.cleanConfigureAll.title": "Clean Reconfigure All Projects",
"cmake-tools.command.cmake.clean.title": "Clean",
Expand Down
84 changes: 60 additions & 24 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as path from 'path';
import * as vscode from 'vscode';
import * as cpt from 'vscode-cpptools';
import * as nls from 'vscode-nls';
import paths from './paths';

import {CMakeCache} from '@cmt/cache';
import {CMakeTools, ConfigureType, ConfigureTrigger} from '@cmt/cmake-tools';
Expand Down Expand Up @@ -348,6 +349,14 @@ class ExtensionManager implements vscode.Disposable {
await telemetry.deactivate();
}

async configureInternal(trigger: ConfigureTrigger, cmt: CMakeTools): Promise<void> {
if (!await this._ensureActiveKit(cmt)) {
return;
}

await cmt.configureInternal(trigger, [], ConfigureType.Normal);
}

async _postWorkspaceOpen(info: CMakeToolsFolder) {
const ws = info.folder;
const cmt = info.cmakeTools;
Expand Down Expand Up @@ -408,30 +417,59 @@ class ExtensionManager implements vscode.Disposable {
rollbar.takePromise(localize('persist.config.on.open.setting', 'Persist config-on-open setting'), {}, persist_pr);
should_configure = chosen.doConfigure;
}
if (should_configure) {
// We've opened a new workspace folder, and the user wants us to
// configure it now.
log.debug(localize('configuring.workspace.on.open', 'Configuring workspace on open {0}', ws.uri.toString()));
// Ensure that there is a kit. This is required for new instances.
if (!await this._ensureActiveKit(cmt)) {
return;
}
await cmt.configureInternal(ConfigureTrigger.configureOnOpen, [], ConfigureType.Normal);
} else if (silentScanForKitsNeeded) {
// This popup will show up the first time after deciding not to configure, if a version change has been detected
// in the kits definition. This may happen during a CMake Tools extension upgrade.
// The warning is emitted only once because scanForKitsIfNeeded returns true only once after such change,
// being tied to a global state variable.
const configureButtonMessage = localize('configure.now.button', 'Configure Now');
const result = await vscode.window.showWarningMessage(localize('configure.recommended', 'It is recommended to reconfigure after upgrading to a new kits definition.'), configureButtonMessage);
if (result === configureButtonMessage) {
// Ensure that there is a kit. This is required for new instances.
if (!await this._ensureActiveKit(cmt)) {
return;

const optsVars: ExpansionVars = {
userHome: paths.userHome,
workspaceFolder: cmt.workspaceContext.folder.uri.fsPath,
workspaceFolderBasename: cmt.workspaceContext.folder.name,
workspaceRoot: cmt.workspaceContext.folder.uri.fsPath,
workspaceRootFolderName: cmt.workspaceContext.folder.name,

// sourceDirectory cannot be defined based on any of the below variables.
buildKit: "",
buildType: "",
generator: "",
buildKitVendor: "",
buildKitTriple: "",
buildKitVersion: "",
buildKitHostOs: "",
buildKitTargetOs: "",
buildKitTargetArch: "",
buildKitVersionMajor: "",
buildKitVersionMinor: "",
workspaceHash: "",
};

// Don't configure if the current project is not CMake based (it doesn't have a CMakeLists.txt in the sourceDirectory).
const sourceDirectory: string = cmt.workspaceContext.config.sourceDirectory;
let expandedSourceDirectory: string = util.lightNormalizePath(await expandString(sourceDirectory, { vars: optsVars }));
if (path.basename(expandedSourceDirectory).toLocaleLowerCase() !== "cmakelists.txt") {
expandedSourceDirectory = path.join(expandedSourceDirectory, "CMakeLists.txt");
}
if (await fs.exists(expandedSourceDirectory)) {
if (should_configure) {
// We've opened a new workspace folder, and the user wants us to
// configure it now.
log.debug(localize('configuring.workspace.on.open', 'Configuring workspace on open {0}', ws.uri.toString()));
await this.configureInternal(ConfigureTrigger.configureOnOpen, cmt);
} else if (silentScanForKitsNeeded) {
// This popup will show up the first time after deciding not to configure, if a version change has been detected
// in the kits definition. This may happen during a CMake Tools extension upgrade.
// The warning is emitted only once because scanForKitsIfNeeded returns true only once after such change,
// being tied to a global state variable.
const configureButtonMessage = localize('configure.now.button', 'Configure Now');
const result = await vscode.window.showWarningMessage(localize('configure.recommended', 'It is recommended to reconfigure after upgrading to a new kits definition.'), configureButtonMessage);
if (result === configureButtonMessage) {
await this.configureInternal(ConfigureTrigger.buttonNewKitsDefinition, cmt);
}
await cmt.configureInternal(ConfigureTrigger.buttonNewKitsDefinition, [], ConfigureType.Normal);
}
} else {
await enableFullFeatureSet(false, cmt.folder);
}

// Enable full or partial feature set for each workspace folder, depending on their state variable.
this.enableWorkspaceFoldersFullFeatureSet();

this._updateCodeModel(info);
}

Expand Down Expand Up @@ -748,6 +786,7 @@ class ExtensionManager implements vscode.Disposable {
if (kitName) {
return true;
}

return false;
}

Expand Down Expand Up @@ -1127,9 +1166,6 @@ async function setup(context: vscode.ExtensionContext, progress: ProgressHandle)
// Load a new extension manager
const ext = _EXT_MANAGER = await ExtensionManager.create(context);

// Enable full or partial feature set for each workspace folder, depending on their state variable.
ext.enableWorkspaceFoldersFullFeatureSet();

// A register function that helps us bind the commands to the extension
function register<K extends keyof ExtensionManager>(name: K) {
return vscode.commands.registerCommand(`cmake.${name}`, (...args: any[]) => {
Expand Down