Skip to content

Commit 211d0b8

Browse files
committed
Refactor CLI feature checks
1 parent 21192d8 commit 211d0b8

File tree

3 files changed

+26
-38
lines changed

3 files changed

+26
-38
lines changed

extensions/ql-vscode/src/codeql-cli/cli.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ import { ExitCodeError, getCliError } from "./cli-errors";
4141
import { UserCancellationException } from "../common/vscode/progress";
4242
import type { LanguageClient } from "vscode-languageclient/node";
4343

44+
/**
45+
* The oldest version of the CLI that we support. This is used to determine
46+
* whether to show a warning about the CLI being too old on startup.
47+
*/
48+
export const OLDEST_SUPPORTED_CLI_VERSION = new SemVer("2.20.7");
49+
4450
/**
4551
* The version of the SARIF format that we are using.
4652
*/
@@ -273,8 +279,6 @@ export class CodeQLCliServer implements Disposable {
273279
/** Path to current codeQL executable, or undefined if not running yet. */
274280
codeQlPath: string | undefined;
275281

276-
cliConstraints = new CliVersionConstraint(this);
277-
278282
/**
279283
* When set to true, ignore some modal popups and assume user has clicked "yes".
280284
*/
@@ -1816,6 +1820,11 @@ export class CodeQLCliServer implements Disposable {
18161820
public async setUseExtensionPacks(useExtensionPacks: boolean) {
18171821
await this.cliConfig.setUseExtensionPacks(useExtensionPacks);
18181822
}
1823+
1824+
/** Checks if the CLI supports a specific feature. */
1825+
public async supportsFeature(feature: keyof CliFeatures): Promise<boolean> {
1826+
return (await this.getFeatures())[feature] === true;
1827+
}
18191828
}
18201829

18211830
/**
@@ -1922,17 +1931,3 @@ export function shouldDebugQueryServer() {
19221931
function shouldDebugCliServer() {
19231932
return isEnvTrue("CLI_SERVER_JAVA_DEBUG");
19241933
}
1925-
1926-
export class CliVersionConstraint {
1927-
// The oldest version of the CLI that we support. This is used to determine
1928-
// whether to show a warning about the CLI being too old on startup.
1929-
public static OLDEST_SUPPORTED_CLI_VERSION = new SemVer("2.20.7");
1930-
1931-
constructor(private readonly cli: CodeQLCliServer) {
1932-
/**/
1933-
}
1934-
1935-
async supportsQueryServerRunQueries(): Promise<boolean> {
1936-
return (await this.cli.getFeatures()).queryServerRunQueries === true;
1937-
}
1938-
}

extensions/ql-vscode/src/extension.ts

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ import {
2121
activate as archiveFilesystemProvider_activate,
2222
zipArchiveScheme,
2323
} from "./common/vscode/archive-filesystem-provider";
24-
import { CliVersionConstraint, CodeQLCliServer } from "./codeql-cli/cli";
24+
import {
25+
CodeQLCliServer,
26+
OLDEST_SUPPORTED_CLI_VERSION,
27+
} from "./codeql-cli/cli";
2528
import {
2629
ADD_DATABASE_SOURCE_TO_WORKSPACE_SETTING,
2730
addDatabaseSourceToWorkspace,
@@ -451,29 +454,19 @@ export async function activate(
451454

452455
let unsupportedWarningShown = false;
453456
codeQlExtension.cliServer.addVersionChangedListener((ver) => {
454-
if (!ver) {
455-
return;
456-
}
457-
458-
if (unsupportedWarningShown) {
459-
return;
460-
}
461-
462457
if (
463-
CliVersionConstraint.OLDEST_SUPPORTED_CLI_VERSION.compare(
464-
ver.version,
465-
) <= 0
458+
ver &&
459+
!unsupportedWarningShown &&
460+
OLDEST_SUPPORTED_CLI_VERSION.compare(ver.version) === 1
466461
) {
467-
return;
462+
void showAndLogWarningMessage(
463+
extLogger,
464+
`You are using an unsupported version of the CodeQL CLI (${ver.version.toString()}). ` +
465+
`The minimum supported version is ${OLDEST_SUPPORTED_CLI_VERSION.toString()}. ` +
466+
`Please upgrade to a newer version of the CodeQL CLI.`,
467+
);
468+
unsupportedWarningShown = true;
468469
}
469-
470-
void showAndLogWarningMessage(
471-
extLogger,
472-
`You are using an unsupported version of the CodeQL CLI (${ver.version.toString()}). ` +
473-
`The minimum supported version is ${CliVersionConstraint.OLDEST_SUPPORTED_CLI_VERSION.toString()}. ` +
474-
`Please upgrade to a newer version of the CodeQL CLI.`,
475-
);
476-
unsupportedWarningShown = true;
477470
});
478471

479472
// Expose the CodeQL CLI features to the extension context under `codeQL.cliFeatures.*`.

extensions/ql-vscode/src/query-server/query-server-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export class QueryServerClient extends DisposableObject {
101101
* queries at once.
102102
*/
103103
async supportsRunQueriesMethod(): Promise<boolean> {
104-
return await this.cliServer.cliConstraints.supportsQueryServerRunQueries();
104+
return await this.cliServer.supportsFeature("queryServerRunQueries");
105105
}
106106

107107
/** Stops the query server by disposing of the current server process. */

0 commit comments

Comments
 (0)