diff --git a/package.json b/package.json index b085e2d19..c9baca7d1 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -391,7 +394,6 @@ { "command": "cmake.resetState", "title": "%cmake-tools.command.cmake.resetState.title%", - "when": "cmake:enableFullFeatureSet", "category": "CMake" }, { @@ -477,7 +479,6 @@ "command": "cmake.selectActiveFolder" }, { - "when": "cmake:enableFullFeatureSet", "command": "cmake.resetState" }, { @@ -544,7 +545,8 @@ "when": "cmake:multiRoot && cmake:enableFullFeatureSet" }, { - "command": "cmake.openConfiguration" + "command": "cmake.editCacheUI", + "when": "cmake:enableFullFeatureSet" }, { "when": "cmake:enableFullFeatureSet", @@ -635,7 +637,7 @@ "when": "never" }, { - "command": "cmake.outline.openConfiguration", + "command": "cmake.outline.editCacheUI", "when": "never" }, { @@ -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" } ], diff --git a/package.nls.json b/package.nls.json index 772da4afb..ab62845b1 100644 --- a/package.nls.json +++ b/package.nls.json @@ -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", diff --git a/src/extension.ts b/src/extension.ts index bac03ffd1..9442b6e1b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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'; @@ -36,7 +37,6 @@ import {ProjectOutlineProvider, TargetNode, SourceFileNode, WorkspaceFolderNode} import * as util from '@cmt/util'; import {ProgressHandle, DummyDisposable, reportProgress} from '@cmt/util'; import {DEFAULT_VARIANTS} from '@cmt/variant'; -import paths from './paths'; nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })(); const localize: nls.LocalizeFunc = nls.loadMessageBundle(); @@ -348,6 +348,14 @@ class ExtensionManager implements vscode.Disposable { await telemetry.deactivate(); } + async configureInternal(trigger: ConfigureTrigger, cmt: CMakeTools): Promise { + if (!await this._ensureActiveKit(cmt)) { + return; + } + + await cmt.configureInternal(trigger, [], ConfigureType.Normal); + } + async _postWorkspaceOpen(info: CMakeToolsFolder) { const ws = info.folder; const cmt = info.cmakeTools; @@ -408,30 +416,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); } @@ -748,6 +785,7 @@ class ExtensionManager implements vscode.Disposable { if (kitName) { return true; } + return false; } @@ -1127,9 +1165,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(name: K) { return vscode.commands.registerCommand(`cmake.${name}`, (...args: any[]) => {