Skip to content

Commit 67d2fe5

Browse files
committed
Add a way to disable version checks
Version checks are re-enabled whenever the version of vscode changes. This is because the user would have needed to manually update their vscode version in order to get this new version. And another failing version check would mean there is a newer version that needs to be downloaded.
1 parent 47ae6e2 commit 67d2fe5

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

extensions/ql-vscode/src/extension.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ export async function activate(ctx: ExtensionContext): Promise<CodeQLExtensionIn
232232
void showAndLogErrorMessage(`Can't execute ${command}: waiting to finish loading CodeQL CLI.`);
233233
}));
234234

235-
assertVSCodeVersionGreaterThan(MIN_VERSION);
235+
// Checking the vscode version should not block extension activation.
236+
void assertVSCodeVersionGreaterThan(MIN_VERSION, ctx);
236237

237238
interface DistributionUpdateConfig {
238239
isUserInitiated: boolean;
@@ -1318,7 +1319,24 @@ function registerRemoteQueryTextProvider() {
13181319
});
13191320
}
13201321

1321-
function assertVSCodeVersionGreaterThan(minVersion: string) {
1322+
const avoidVersionCheck = 'avoid-version-check-at-startup';
1323+
const lastVersionChecked = 'last-version-checked';
1324+
async function assertVSCodeVersionGreaterThan(minVersion: string, ctx: ExtensionContext) {
1325+
1326+
// Check if we should reset the version check.
1327+
const lastVersion = await ctx.globalState.get(lastVersionChecked);
1328+
await ctx.globalState.update(lastVersionChecked, vscodeVersion);
1329+
1330+
if (lastVersion !== minVersion) {
1331+
// In this case, the version has changed since the last time we checked.
1332+
// If the user has previously opted out of this check, then user has updated their
1333+
// vscode instance since then, so we should check again. Any future warning would
1334+
// be for a different version of vscode.
1335+
await ctx.globalState.update(avoidVersionCheck, false);
1336+
}
1337+
if (await ctx.globalState.get(avoidVersionCheck)) {
1338+
return;
1339+
}
13221340
try {
13231341
const parsedVersion = semver.parse(vscodeVersion);
13241342
const parsedMinVersion = semver.parse(minVersion);
@@ -1331,7 +1349,10 @@ function assertVSCodeVersionGreaterThan(minVersion: string) {
13311349

13321350
if (semver.lt(parsedVersion, parsedMinVersion)) {
13331351
const message = `The CodeQL extension requires VS Code version ${minVersion} or later. Current version is ${vscodeVersion}. Please update VS Code to get the latest features of CodeQL.`;
1334-
void showAndLogWarningMessage(message);
1352+
const result = await showBinaryChoiceDialog(message, false, 'OK', 'Don\'t show again');
1353+
if (!result) {
1354+
await ctx.globalState.update(avoidVersionCheck, true);
1355+
}
13351356
}
13361357
} catch (e) {
13371358
void showAndLogWarningMessage(`Could not do a version check because of an error: ${getErrorMessage(e)}`);

extensions/ql-vscode/src/helpers.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,17 @@ async function internalShowAndLog(
110110
* @param message The message to show.
111111
* @param modal If true (the default), show a modal dialog box, otherwise dialog is non-modal and can
112112
* be closed even if the user does not make a choice.
113+
* @param yesTitle The text in the box indicating the affirmative choice.
114+
* @param noTitle The text in the box indicating the negative choice.
113115
*
114116
* @return
115117
* `true` if the user clicks 'Yes',
116118
* `false` if the user clicks 'No' or cancels the dialog,
117119
* `undefined` if the dialog is closed without the user making a choice.
118120
*/
119-
export async function showBinaryChoiceDialog(message: string, modal = true): Promise<boolean | undefined> {
120-
const yesItem = { title: 'Yes', isCloseAffordance: false };
121-
const noItem = { title: 'No', isCloseAffordance: true };
121+
export async function showBinaryChoiceDialog(message: string, modal = true, yesTitle = 'Yes', noTitle = 'No'): Promise<boolean | undefined> {
122+
const yesItem = { title: yesTitle, isCloseAffordance: false };
123+
const noItem = { title: noTitle, isCloseAffordance: true };
122124
const chosenItem = await Window.showInformationMessage(message, { modal }, yesItem, noItem);
123125
if (!chosenItem) {
124126
return undefined;

0 commit comments

Comments
 (0)