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

Scan silently if there are no available kits #1192

Merged
Merged
Changes from 1 commit
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
70 changes: 16 additions & 54 deletions src/kitsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
kitsPathForWorkspaceFolder,
OLD_USER_KITS_FILEPATH,
SpecialKits,
UnspecifiedKit,
SpecialKitsCount
} from '@cmt/kit';
import * as logging from '@cmt/logging';
Expand Down Expand Up @@ -43,6 +42,8 @@ export class KitsController {
*/
static userKits: Kit[] = [];

private static checkingHaveKits = false;

folderKits: Kit[] = [];

private constructor(readonly cmakeTools: CMakeTools, private readonly _kitsWatcher: chokidar.FSWatcher) { }
Expand Down Expand Up @@ -164,62 +165,31 @@ export class KitsController {
return raw_name;
}

private async _checkHaveKits(): Promise<UnspecifiedKit|'ok'|'cancel'> {
private async _checkHaveKits(): Promise<boolean> {
const avail = this.availableKits;
if (avail.length > SpecialKitsCount) {
// We have kits. Okay.
return 'ok';
return true;
}
if (!avail.find(kit => kit.name == SpecialKits.Unspecified)) {
// We should _always_ have the 'UnspecifiedKit'.
rollbar.error(localize('invalid.only.kit', 'Invalid only kit. Expected to find `{0}`', SpecialKits.Unspecified));
return 'ok';
}
// We don't have any kits defined. Ask the user what to do. This is safe to block
// because it is a modal dialog
interface FirstScanItem extends vscode.MessageItem {
action: 'scan'|UnspecifiedKit|'cancel';
}
const choices: FirstScanItem[] = [
{
title: localize('scan.for.kits.button', 'Scan for kits'),
action: 'scan',
},
{
title: localize('do.not.use.kit.button', 'Do not use a kit'),
action: SpecialKits.Unspecified,
},
{
title: localize('close.button', 'Close'),
isCloseAffordance: true,
action: 'cancel',
}
];
const chosen = await vscode.window.showInformationMessage(
localize('no.kits.available', 'No CMake kits are available. What would you like to do?'),
{modal: true},
...choices,
);
if (!chosen) {
// User closed the dialog
return 'cancel';
return false;
}
switch (chosen.action) {
case 'scan': {

// We don't have any kits defined. Scan for kits
if (!KitsController.checkingHaveKits) {
KitsController.checkingHaveKits = true;
if (!KitsController.minGWSearchDirs) {
await KitsController.scanForKits();
} else {
await vscode.commands.executeCommand('cmake.scanForKits');
}
return 'ok';
}
case SpecialKits.Unspecified: {
await this.setFolderActiveKit({name: SpecialKits.Unspecified});
return SpecialKits.Unspecified as UnspecifiedKit;
}
case 'cancel': {
return 'cancel';
}
KitsController.checkingHaveKits = false;
return true;
} else {
rollbar.error(localize('already.checking.kits', 'Already checking kits. Please try again later.'));
return false;
}
}

Expand All @@ -229,18 +199,10 @@ export class KitsController {
* Show UI to allow the user to select an active kit
*/
async selectKit(): Promise<boolean> {
// Check that we have kits, or if the user doesn't want to use a kit.
// Check that we have kits
const state = await this._checkHaveKits();
switch (state) {
case 'cancel':
// The user doesn't want to perform any special action
if (!state) {
return false;
case SpecialKits.Unspecified:
// The user chose to use the 'UnspecifiedKit'
return true;
case 'ok':
// 'ok' means we have kits defined and should do regular kit selection
break;
}

const avail = this.availableKits;
Expand Down