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.
This commit is contained in:
@@ -232,7 +232,8 @@ export async function activate(ctx: ExtensionContext): Promise<CodeQLExtensionIn
|
||||
void showAndLogErrorMessage(`Can't execute ${command}: waiting to finish loading CodeQL CLI.`);
|
||||
}));
|
||||
|
||||
assertVSCodeVersionGreaterThan(MIN_VERSION);
|
||||
// Checking the vscode version should not block extension activation.
|
||||
void assertVSCodeVersionGreaterThan(MIN_VERSION, ctx);
|
||||
|
||||
interface DistributionUpdateConfig {
|
||||
isUserInitiated: boolean;
|
||||
@@ -1318,7 +1319,24 @@ function registerRemoteQueryTextProvider() {
|
||||
});
|
||||
}
|
||||
|
||||
function assertVSCodeVersionGreaterThan(minVersion: string) {
|
||||
const avoidVersionCheck = 'avoid-version-check-at-startup';
|
||||
const lastVersionChecked = 'last-version-checked';
|
||||
async function assertVSCodeVersionGreaterThan(minVersion: string, ctx: ExtensionContext) {
|
||||
|
||||
// Check if we should reset the version check.
|
||||
const lastVersion = await ctx.globalState.get(lastVersionChecked);
|
||||
await ctx.globalState.update(lastVersionChecked, vscodeVersion);
|
||||
|
||||
if (lastVersion !== minVersion) {
|
||||
// In this case, the version has changed since the last time we checked.
|
||||
// If the user has previously opted out of this check, then user has updated their
|
||||
// vscode instance since then, so we should check again. Any future warning would
|
||||
// be for a different version of vscode.
|
||||
await ctx.globalState.update(avoidVersionCheck, false);
|
||||
}
|
||||
if (await ctx.globalState.get(avoidVersionCheck)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const parsedVersion = semver.parse(vscodeVersion);
|
||||
const parsedMinVersion = semver.parse(minVersion);
|
||||
@@ -1331,7 +1349,10 @@ function assertVSCodeVersionGreaterThan(minVersion: string) {
|
||||
|
||||
if (semver.lt(parsedVersion, parsedMinVersion)) {
|
||||
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.`;
|
||||
void showAndLogWarningMessage(message);
|
||||
const result = await showBinaryChoiceDialog(message, false, 'OK', 'Don\'t show again');
|
||||
if (!result) {
|
||||
await ctx.globalState.update(avoidVersionCheck, true);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
void showAndLogWarningMessage(`Could not do a version check because of an error: ${getErrorMessage(e)}`);
|
||||
|
||||
@@ -110,15 +110,17 @@ async function internalShowAndLog(
|
||||
* @param message The message to show.
|
||||
* @param modal If true (the default), show a modal dialog box, otherwise dialog is non-modal and can
|
||||
* be closed even if the user does not make a choice.
|
||||
* @param yesTitle The text in the box indicating the affirmative choice.
|
||||
* @param noTitle The text in the box indicating the negative choice.
|
||||
*
|
||||
* @return
|
||||
* `true` if the user clicks 'Yes',
|
||||
* `false` if the user clicks 'No' or cancels the dialog,
|
||||
* `undefined` if the dialog is closed without the user making a choice.
|
||||
*/
|
||||
export async function showBinaryChoiceDialog(message: string, modal = true): Promise<boolean | undefined> {
|
||||
const yesItem = { title: 'Yes', isCloseAffordance: false };
|
||||
const noItem = { title: 'No', isCloseAffordance: true };
|
||||
export async function showBinaryChoiceDialog(message: string, modal = true, yesTitle = 'Yes', noTitle = 'No'): Promise<boolean | undefined> {
|
||||
const yesItem = { title: yesTitle, isCloseAffordance: false };
|
||||
const noItem = { title: noTitle, isCloseAffordance: true };
|
||||
const chosenItem = await Window.showInformationMessage(message, { modal }, yesItem, noItem);
|
||||
if (!chosenItem) {
|
||||
return undefined;
|
||||
|
||||
Reference in New Issue
Block a user