Skip to content

Commit 47ae6e2

Browse files
committed
Assert minimum version of vscode
1 parent 9f03db2 commit 47ae6e2

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

extensions/ql-vscode/src/extension.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ import {
1616
QuickPickItem,
1717
Range,
1818
workspace,
19-
ProviderResult
19+
ProviderResult,
20+
version as vscodeVersion
2021
} from 'vscode';
2122
import { LanguageClient } from 'vscode-languageclient';
2223
import * as os from 'os';
2324
import * as fs from 'fs-extra';
2425
import * as path from 'path';
2526
import * as tmp from 'tmp-promise';
2627
import { testExplorerExtensionId, TestHub } from 'vscode-test-adapter-api';
28+
import * as semver from 'semver';
2729

2830
import { AstViewer } from './astViewer';
2931
import * as archiveFilesystemProvider from './archive-filesystem-provider';
@@ -188,6 +190,13 @@ export interface CodeQLExtensionInterface {
188190
readonly dispose: () => void;
189191
}
190192

193+
// This is the minimum version of vscode that we _want_ to support. We want to update the language server library, but that
194+
// requires 1.67 or later. If we change the minimum version in the package.json, then anyone on an older version of vscode
195+
// silently be unable to upgrade. So, the solution is to first bump the minimum version here and release. Then
196+
// bump the version in the package.json and release again. This way, anyone on an older version of vscode will get a warning
197+
// before silently being refused to upgrade.
198+
const MIN_VERSION = '1.67.0';
199+
191200
/**
192201
* Returns the CodeQLExtensionInterface, or an empty object if the interface is not
193202
* available after activation is complete. This will happen if there is no cli
@@ -223,6 +232,8 @@ export async function activate(ctx: ExtensionContext): Promise<CodeQLExtensionIn
223232
void showAndLogErrorMessage(`Can't execute ${command}: waiting to finish loading CodeQL CLI.`);
224233
}));
225234

235+
assertVSCodeVersionGreaterThan(MIN_VERSION);
236+
226237
interface DistributionUpdateConfig {
227238
isUserInitiated: boolean;
228239
shouldDisplayMessageWhenNoUpdates: boolean;
@@ -1306,3 +1317,23 @@ function registerRemoteQueryTextProvider() {
13061317
},
13071318
});
13081319
}
1320+
1321+
function assertVSCodeVersionGreaterThan(minVersion: string) {
1322+
try {
1323+
const parsedVersion = semver.parse(vscodeVersion);
1324+
const parsedMinVersion = semver.parse(minVersion);
1325+
if (!parsedVersion || !parsedMinVersion) {
1326+
void showAndLogWarningMessage(
1327+
`Could not do a version check of vscode because could not parse version number: actual vscode version ${vscodeVersion} or minimum supported vscode version ${minVersion}.`
1328+
);
1329+
return;
1330+
}
1331+
1332+
if (semver.lt(parsedVersion, parsedMinVersion)) {
1333+
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);
1335+
}
1336+
} catch (e) {
1337+
void showAndLogWarningMessage(`Could not do a version check because of an error: ${getErrorMessage(e)}`);
1338+
}
1339+
}

0 commit comments

Comments
 (0)