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 3 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 @@ -14,6 +14,7 @@ Improvements:
- Show cmake output when version probe fails. [#3650](https://github.com/microsoft/vscode-cmake-tools/issues/3650)
- Improve various settings scopes [#3601](https://github.com/microsoft/vscode-cmake-tools/issues/3601)
- 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)
- Make it easier for users to select a CMakeLists.txt or stop the quick pick from appearing (non-CMake projects) [#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 @@ -2563,7 +2563,7 @@
},
"cmake.configureOnOpen": {
"type": "boolean",
"default": null,
"default": true,
"description": "%cmake-tools.configuration.cmake.configureOnOpen.description%",
"scope": "resource"
},
Expand Down
10 changes: 8 additions & 2 deletions src/cmakeProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -876,11 +876,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", "[Do not ask 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.descriptoin", "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 @@ -896,6 +898,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
7 changes: 2 additions & 5 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,9 +424,6 @@ export class ConfigurationReader implements vscode.Disposable {
return this.configData.cpackArgs;
}
get configureOnOpen() {
if (util.isCodespaces() && this.configData.configureOnOpen === null) {
return true;
}
return this.configData.configureOnOpen;
}
get configureOnEdit() {
Expand Down Expand Up @@ -590,7 +587,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
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 @@ -1297,7 +1250,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 @@ -1308,7 +1260,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 @@ -1319,7 +1270,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 @@ -1329,7 +1279,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);
}
});
});
}
Loading