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

Update CMake Tools experience on open #3703

Closed
wants to merge 8 commits into from
Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Improvements:
- Improve various settings scopes [#3601](https://github.com/microsoft/vscode-cmake-tools/issues/3601)
- Refactor the Project Outline view to show a flat list of targets [#491](https://github.com/microsoft/vscode-cmake-tools/issues/491), [#3684](https://github.com/microsoft/vscode-cmake-tools/issues/3684)
- Add the ability to pin CMake Commands to the sidebar [#2984](https://github.com/microsoft/vscode-cmake-tools/issues/2984) & [#3296](https://github.com/microsoft/vscode-cmake-tools/issues/3296)
- Improve CMake Tools experience when opening a folder [#3588](https://github.com/microsoft/vscode-cmake-tools/issues/3588)

Bug Fixes:

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2597,7 +2597,7 @@
},
"cmake.configureOnOpen": {
"type": "boolean",
"default": null,
"default": true,
"description": "%cmake-tools.configuration.cmake.configureOnOpen.description%",
"scope": "resource"
},
Expand Down
12 changes: 9 additions & 3 deletions src/cmakeProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -885,11 +885,13 @@ export class CMakeProject {
fullPath: file
})) : [];
const browse: string = localize("browse.for.cmakelists", "[Browse for CMakeLists.txt]");
items.push({ label: browse, fullPath: "", description: "Search for CMakeLists.txt on this computer" });
const dontAskAgain: string = localize("do.not.ask.again", "[Don't Show Again]");
items.push({ label: browse, fullPath: "", description: localize("search.for.cmakelists", "Search for CMakeLists.txt on this computer") });
items.push({ label: dontAskAgain, fullPath: "", description: localize("do.not.ask.again.description", "Do not ask for CMakeLists.txt again in this folder. This will enable the cmake.ignoreCMakeListsMissing setting.") });
const selection: FileItem | undefined = await vscode.window.showQuickPick(items, {
placeHolder: (items.length === 1 ? localize("cmakelists.not.found", "No CMakeLists.txt was found.") : localize("select.cmakelists", "Select CMakeLists.txt"))
});
telemetryProperties["missingCMakeListsUserAction"] = (selection === undefined) ? "cancel" : (selection.label === browse) ? "browse" : "pick";
telemetryProperties["missingCMakeListsUserAction"] = (selection === undefined) ? "cancel" : (selection.label === browse) ? "browse" : (selection.label === dontAskAgain) ? "dontAskAgain" : "pick";
let selectedFile: string | undefined;
if (!selection) {
break; // User canceled it.
Expand All @@ -905,6 +907,10 @@ export class CMakeProject {
// Keep the absolute path for CMakeLists.txt files that are located outside of the workspace folder.
selectedFile = cmakeListsFile[0].fsPath;
}
} else if (selection.label === dontAskAgain) {
if (config !== undefined) {
await vscode.workspace.getConfiguration('cmake', this.workspaceFolder).update('ignoreCMakeListsMissing', true, vscode.ConfigurationTarget.WorkspaceFolder);
}
} else {
// Keep the relative path for CMakeLists.txt files that are located inside of the workspace folder.
// selection.label is the relative path to the selected CMakeLists.txt.
Expand Down Expand Up @@ -1611,7 +1617,7 @@ export class CMakeProject {
"yes.configureWithDebugger.button",
"Debug"
);
const doNotShowAgainTitle = localize('options.configureWithDebuggerOnFail.do.not.show', 'Do Not Show Again');
const doNotShowAgainTitle = localize('options.configureWithDebuggerOnFail.do.not.show', "Don't Show Again");
void vscode.window.showErrorMessage<MessageItem>(
localize('configure.failed.tryWithDebugger', 'Configure failed. Would you like to attempt to configure with the CMake Debugger?'),
{title: yesButtonTitle},
Expand Down
6 changes: 3 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export interface ExtensionConfigurationSettings {
mergedCompileCommands: string | null;
copyCompileCommands: string | null;
loadCompileCommands: boolean;
configureOnOpen: boolean | null;
configureOnOpen: boolean;
configureOnEdit: boolean;
skipConfigureIfCachePresent: boolean | null;
useCMakeServer: boolean;
Expand Down Expand Up @@ -424,7 +424,7 @@ export class ConfigurationReader implements vscode.Disposable {
return this.configData.cpackArgs;
}
get configureOnOpen() {
if (util.isCodespaces() && this.configData.configureOnOpen === null) {
if (this.configData.configureOnOpen === null) {
return true;
}
return this.configData.configureOnOpen;
Expand Down Expand Up @@ -590,7 +590,7 @@ export class ConfigurationReader implements vscode.Disposable {
mergedCompileCommands: new vscode.EventEmitter<string | null>(),
copyCompileCommands: new vscode.EventEmitter<string | null>(),
loadCompileCommands: new vscode.EventEmitter<boolean>(),
configureOnOpen: new vscode.EventEmitter<boolean | null>(),
configureOnOpen: new vscode.EventEmitter<boolean>(),
configureOnEdit: new vscode.EventEmitter<boolean>(),
skipConfigureIfCachePresent: new vscode.EventEmitter<boolean | null>(),
useCMakeServer: new vscode.EventEmitter<boolean>(),
Expand Down
4 changes: 2 additions & 2 deletions src/drivers/cmakeFileApiDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class CMakeFileApiDriver extends CMakeDriver {
if (cacheExists && this.generator?.name === await this.getGeneratorFromCache(this.cachePath)) {
await this.loadGeneratorInformationFromCache(this.cachePath);
const code_model_exist = await this.updateCodeModel();
if (!code_model_exist && this.config.configureOnOpen === true) {
if (!code_model_exist && this.config.configureOnOpen) {
await this.doConfigure([], undefined, undefined);
}
} else {
Expand All @@ -137,7 +137,7 @@ export class CMakeFileApiDriver extends CMakeDriver {
// Since this setting will prevent configure anyway (until a configure command is invoked
// or build/test will trigger automatic configuring), there is no need to delete the cache now
// even if this is not a project configured from outside VSCode.
if (cacheExists && this.config.configureOnOpen !== false) {
if (cacheExists && this.config.configureOnOpen) {
// No need to remove the other CMake files for the generator change to work properly
log.info(localize('removing', 'Removing {0}', this.cachePath));
try {
Expand Down
57 changes: 3 additions & 54 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,60 +590,13 @@ export class ExtensionManager implements vscode.Disposable {
vscode.workspace.workspaceFolders[0] === rootFolder &&
await scanForKitsIfNeeded(project);

let shouldConfigure = project?.workspaceContext.config.configureOnOpen;
if (shouldConfigure === null && !util.isTestMode()) {
interface Choice1 {
title: string;
doConfigure: boolean;
}
const chosen = await vscode.window.showInformationMessage<Choice1>(
localize('configure.this.project', 'Would you like to configure project {0}?', `"${rootFolder.name}"`),
{},
{ title: localize('yes.button', 'Yes'), doConfigure: true },
{ title: localize('not.now.button', 'Not now'), doConfigure: false }
);
if (!chosen) {
// User cancelled.
shouldConfigure = null;
} else {
const persistMessage = chosen.doConfigure ?
localize('always.configure.on.open', 'Always configure projects upon opening?') :
localize('never.configure.on.open', 'Configure projects on opening?');
const buttonMessages = chosen.doConfigure ?
[localize('yes.button', 'Yes'), localize('no.button', 'No')] :
[localize('never.button', 'Never'), localize('never.for.this.workspace.button', 'Not this workspace')];
interface Choice2 {
title: string;
persistMode: 'user' | 'workspace';
}
// Try to persist the user's selection to a `settings.json`
const prompt = vscode.window.showInformationMessage<Choice2>(
persistMessage,
{},
{ title: buttonMessages[0], persistMode: 'user' },
{ title: buttonMessages[1], persistMode: 'workspace' })
.then(async choice => {
if (!choice) {
// Use cancelled. Do nothing.
return;
}
const config = vscode.workspace.getConfiguration(undefined, rootFolder.uri);
let configTarget = vscode.ConfigurationTarget.Global;
if (choice.persistMode === 'workspace') {
configTarget = vscode.ConfigurationTarget.WorkspaceFolder;
}
await config.update('cmake.configureOnOpen', chosen.doConfigure, configTarget);
});
rollbar.takePromise(localize('persist.config.on.open.setting', 'Persist config-on-open setting'), {}, prompt);
shouldConfigure = chosen.doConfigure;
}
}
const shouldConfigure = project.workspaceContext.config.configureOnOpen;
if (!project.hasCMakeLists()) {
if (shouldConfigure === true) {
if (shouldConfigure && (await util.globForFileName("CMakeLists.txt", 3, project.folderPath))) {
await project.cmakePreConditionProblemHandler(CMakePreconditionProblems.MissingCMakeListsFile, false, this.workspaceConfig);
}
} else {
if (shouldConfigure === true) {
if (shouldConfigure) {
// 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}', project.folderPath));
Expand Down Expand Up @@ -1299,7 +1252,6 @@ export class ExtensionManager implements vscode.Disposable {
}

configure(folder?: vscode.WorkspaceFolder, showCommandOnly?: boolean, sourceDir?: string) {
telemetry.logEvent("configure", { all: "false", debug: "false"});
return this.runCMakeCommand(
async cmakeProject => (await cmakeProject.configureInternal(ConfigureTrigger.commandConfigure, [], showCommandOnly ? ConfigureType.ShowCommandOnly : ConfigureType.Normal)).result,
folder, undefined, true, sourceDir);
Expand All @@ -1310,7 +1262,6 @@ export class ExtensionManager implements vscode.Disposable {
}

configureWithDebuggerInternal(debuggerInformation: DebuggerInformation, folder?: vscode.WorkspaceFolder, showCommandOnly?: boolean, sourceDir?: string, trigger?: ConfigureTrigger) {
telemetry.logEvent("configure", { all: "false", debug: "true"});
return this.runCMakeCommand(
async cmakeProject => (await cmakeProject.configureInternal(trigger ?? ConfigureTrigger.commandConfigureWithDebugger, [], showCommandOnly ? ConfigureType.ShowCommandOnly : ConfigureType.NormalWithDebugger, debuggerInformation)).result,
folder, undefined, true, sourceDir);
Expand All @@ -1321,7 +1272,6 @@ export class ExtensionManager implements vscode.Disposable {
}

configureAll() {
telemetry.logEvent("configure", { all: "true", debug: "false"});
return this.runCMakeCommandForAll(async cmakeProject => ((await cmakeProject.configureInternal(ConfigureTrigger.commandCleanConfigureAll, [], ConfigureType.Normal)).result), undefined, true);
}

Expand All @@ -1331,7 +1281,6 @@ export class ExtensionManager implements vscode.Disposable {

configureAllWithDebuggerInternal(debuggerInformation: DebuggerInformation, trigger?: ConfigureTrigger) {
// I need to add ConfigureTriggers that account for coming from the project status view or project outline.
telemetry.logEvent("configure", { all: "true", debug: "true"});
return this.runCMakeCommandForAll(async cmakeProject => (await cmakeProject.configureInternal(trigger ?? ConfigureTrigger.commandConfigureAllWithDebugger, [], ConfigureType.NormalWithDebugger, debuggerInformation)).result, undefined, true);
}

Expand Down
28 changes: 28 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Environment, EnvironmentUtils } from './environmentVariables';
import { TargetPopulation } from 'vscode-tas-client';
import { expandString, ExpansionOptions } from './expand';
import { ExtensionManager } from './extension';
import * as glob from "glob";

nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
Expand Down Expand Up @@ -973,3 +974,30 @@ export function getHostArchitecture() {
export function runCommand(key: keyof ExtensionManager, ...args: any[]) {
return vscode.commands.executeCommand(`cmake.${key}`, ...args);
}

export async function globForFileName(fileName: string, depth: number, cwd: string): Promise<boolean> {
let starString = "*";
for (let i = 1; i <= depth; i++) {
if (await globWrapper(`${starString}/${fileName}`, cwd)) {
return true;
}
starString += "/*";
}
return false;
}

function globWrapper(globPattern: string, cwd: string): Promise<boolean> {
return new Promise((resolve, reject) => {
glob(globPattern, { cwd }, (err, files) => {
if (err) {
return reject(false);
}

if (files.length > 0) {
resolve(true);
} else {
resolve(false);
}
});
});
}
2 changes: 1 addition & 1 deletion test/unit-tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function createConfig(conf: Partial<ExtensionConfigurationSettings>): Configurat
mergedCompileCommands: null,
copyCompileCommands: null,
loadCompileCommands: true,
configureOnOpen: null,
configureOnOpen: true,
configureOnEdit: true,
skipConfigureIfCachePresent: null,
useCMakeServer: true,
Expand Down
Loading