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

Assert VSCode version is high enough #1674

Merged
merged 6 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Alternatively, you can build the extension within VS Code via `Terminal > Run Bu

Before running any of the launch commands, be sure to have run the `build` command to ensure that the JavaScript is compiled and the resources are copied to the proper location.

We recommend that you keep `npm run watch` running in the backgound and you only need to re-run `npm run build` in the following situations:
We recommend that you keep `npm run watch` running in the background and you only need to re-run `npm run build` in the following situations:

1. on first checkout
2. whenever any of the non-TypeScript resources have changed
Expand Down Expand Up @@ -146,7 +146,7 @@ The CLI integration tests require the CodeQL standard libraries in order to run

#### Using a mock GitHub API server

Multi-Repo Variant Analyses (MRVA) rely on the GitHub API. In order to make development and testing easy, we have functionality that allows us to intercept requests to the GitHub API and provide mock responses.
Multi-Repo Variant Analyses (MRVA) rely on the GitHub API. In order to make development and testing easy, we have functionality that allows us to intercept requests to the GitHub API and provide mock responses.

##### Using a pre-recorded test scenario

Expand Down
2 changes: 1 addition & 1 deletion extensions/ql-vscode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ When the results are ready, they're displayed in the CodeQL Query Results view.

If there are any problems running a query, a notification is displayed in the bottom right corner of the application. In addition to the error message, the notification includes details of how to fix the problem.

### Keyboad navigation
### Keyboard navigation

If you wish to navigate the query results from your keyboard, you can bind shortcuts to the **CodeQL: Navigate Up/Down/Left/Right in Result Viewer** commands.

Expand Down
33 changes: 32 additions & 1 deletion extensions/ql-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ import {
QuickPickItem,
Range,
workspace,
ProviderResult
ProviderResult,
version as vscodeVersion
} from 'vscode';
import { LanguageClient } from 'vscode-languageclient';
import * as os from 'os';
import * as fs from 'fs-extra';
import * as path from 'path';
import * as tmp from 'tmp-promise';
import { testExplorerExtensionId, TestHub } from 'vscode-test-adapter-api';
import * as semver from 'semver';

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

// This is the minimum version of vscode that we _want_ to support. We want to update the language server library, but that
// requires 1.67 or later. If we change the minimum version in the package.json, then anyone on an older version of vscode
// silently be unable to upgrade. So, the solution is to first bump the minimum version here and release. Then
// bump the version in the package.json and release again. This way, anyone on an older version of vscode will get a warning
// before silently being refused to upgrade.
const MIN_VERSION = '1.67.0';

/**
* Returns the CodeQLExtensionInterface, or an empty object if the interface is not
* available after activation is complete. This will happen if there is no cli
Expand Down Expand Up @@ -223,6 +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);

interface DistributionUpdateConfig {
isUserInitiated: boolean;
shouldDisplayMessageWhenNoUpdates: boolean;
Expand Down Expand Up @@ -1306,3 +1317,23 @@ function registerRemoteQueryTextProvider() {
},
});
}

function assertVSCodeVersionGreaterThan(minVersion: string) {
try {
const parsedVersion = semver.parse(vscodeVersion);
const parsedMinVersion = semver.parse(minVersion);
if (!parsedVersion || !parsedMinVersion) {
void showAndLogWarningMessage(
`Could not do a version check of vscode because could not parse version number: actual vscode version ${vscodeVersion} or minimum supported vscode version ${minVersion}.`
);
return;
}

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);
}
} catch (e) {
void showAndLogWarningMessage(`Could not do a version check because of an error: ${getErrorMessage(e)}`);
}
}