diff --git a/extensions/ql-vscode/CHANGELOG.md b/extensions/ql-vscode/CHANGELOG.md index f8891966ccd..7f5d42f422b 100644 --- a/extensions/ql-vscode/CHANGELOG.md +++ b/extensions/ql-vscode/CHANGELOG.md @@ -3,6 +3,7 @@ ## [UNRELEASED] - Renamed command "CodeQL: Run Query" to "CodeQL: Run Query on Selected Dababase". +- Remove support for CodeQL CLI versions older than 2.7.6. [#1788](https://github.com/github/vscode-codeql/pull/1788) ## 1.7.7 - 13 December 2022 diff --git a/extensions/ql-vscode/src/cli.ts b/extensions/ql-vscode/src/cli.ts index 93bba9a1c2b..ba5048ec2e7 100644 --- a/extensions/ql-vscode/src/cli.ts +++ b/extensions/ql-vscode/src/cli.ts @@ -1125,10 +1125,7 @@ export class CodeQLCliServer implements Disposable { ]; if (targetDbScheme) { args.push("--target-dbscheme", targetDbScheme); - if ( - allowDowngradesIfPossible && - (await this.cliConstraints.supportsDowngrades()) - ) { + if (allowDowngradesIfPossible) { args.push("--allow-downgrades"); } } @@ -1210,10 +1207,8 @@ export class CodeQLCliServer implements Disposable { if (searchPath !== undefined) { args.push("--search-path", join(...searchPath)); } - if (await this.cliConstraints.supportsAllowLibraryPacksInResolveQueries()) { - // All of our usage of `codeql resolve queries` needs to handle library packs. - args.push("--allow-library-packs"); - } + // All of our usage of `codeql resolve queries` needs to handle library packs. + args.push("--allow-library-packs"); args.push(suite); return this.runJsonCodeQlCliCommand( ["resolve", "queries"], @@ -1300,12 +1295,9 @@ export class CodeQLCliServer implements Disposable { } async generateDil(qloFile: string, outFile: string): Promise { - const extraArgs = (await this.cliConstraints.supportsDecompileDil()) - ? ["--kind", "dil", "-o", outFile, qloFile] - : ["-o", outFile, qloFile]; await this.runCodeQlCliCommand( ["query", "decompile"], - extraArgs, + ["--kind", "dil", "-o", outFile, qloFile], "Generating DIL", ); } @@ -1583,56 +1575,6 @@ export function shouldDebugCliServer() { } export class CliVersionConstraint { - /** - * CLI version where --kind=DIL was introduced - */ - public static CLI_VERSION_WITH_DECOMPILE_KIND_DIL = new SemVer("2.3.0"); - - /** - * CLI version where languages are exposed during a `codeql resolve database` command. - */ - public static CLI_VERSION_WITH_LANGUAGE = new SemVer("2.4.1"); - - public static CLI_VERSION_WITH_NONDESTURCTIVE_UPGRADES = new SemVer("2.4.2"); - - /** - * CLI version where `codeql resolve upgrades` supports - * the `--allow-downgrades` flag - */ - public static CLI_VERSION_WITH_DOWNGRADES = new SemVer("2.4.4"); - - /** - * CLI version where the `codeql resolve qlref` command is available. - */ - public static CLI_VERSION_WITH_RESOLVE_QLREF = new SemVer("2.5.1"); - - /** - * CLI version where database registration was introduced - */ - public static CLI_VERSION_WITH_DB_REGISTRATION = new SemVer("2.4.1"); - - /** - * CLI version where the `--allow-library-packs` option to `codeql resolve queries` was - * introduced. - */ - public static CLI_VERSION_WITH_ALLOW_LIBRARY_PACKS_IN_RESOLVE_QUERIES = - new SemVer("2.6.1"); - - /** - * CLI version where the `database unbundle` subcommand was introduced. - */ - public static CLI_VERSION_WITH_DATABASE_UNBUNDLE = new SemVer("2.6.0"); - - /** - * CLI version where the `--no-precompile` option for pack creation was introduced. - */ - public static CLI_VERSION_WITH_NO_PRECOMPILE = new SemVer("2.7.1"); - - /** - * CLI version where remote queries (variant analysis) are supported. - */ - public static CLI_VERSION_REMOTE_QUERIES = new SemVer("2.6.3"); - /** * CLI version where building QLX packs for remote queries is supported. * (The options were _accepted_ by a few earlier versions, but only from @@ -1640,11 +1582,6 @@ export class CliVersionConstraint { */ public static CLI_VERSION_QLX_REMOTE = new SemVer("2.11.3"); - /** - * CLI version where the `resolve ml-models` subcommand was introduced. - */ - public static CLI_VERSION_WITH_RESOLVE_ML_MODELS = new SemVer("2.7.3"); - /** * CLI version where the `resolve ml-models` subcommand was enhanced to work with packaging. */ @@ -1652,16 +1589,6 @@ export class CliVersionConstraint { "2.10.0", ); - /** - * CLI version where the `--old-eval-stats` option to the query server was introduced. - */ - public static CLI_VERSION_WITH_OLD_EVAL_STATS = new SemVer("2.7.4"); - - /** - * CLI version where packaging was introduced. - */ - public static CLI_VERSION_WITH_PACKAGING = new SemVer("2.6.0"); - /** * CLI version where the `--evaluator-log` and related options to the query server were introduced, * on a per-query server basis. @@ -1702,94 +1629,16 @@ export class CliVersionConstraint { return (await this.cli.getVersion()).compare(v) >= 0; } - public async supportsDecompileDil() { - return this.isVersionAtLeast( - CliVersionConstraint.CLI_VERSION_WITH_DECOMPILE_KIND_DIL, - ); - } - - public async supportsLanguageName() { - return this.isVersionAtLeast( - CliVersionConstraint.CLI_VERSION_WITH_LANGUAGE, - ); - } - - public async supportsNonDestructiveUpgrades() { - return this.isVersionAtLeast( - CliVersionConstraint.CLI_VERSION_WITH_NONDESTURCTIVE_UPGRADES, - ); - } - - public async supportsDowngrades() { - return this.isVersionAtLeast( - CliVersionConstraint.CLI_VERSION_WITH_DOWNGRADES, - ); - } - - public async supportsResolveQlref() { - return this.isVersionAtLeast( - CliVersionConstraint.CLI_VERSION_WITH_RESOLVE_QLREF, - ); - } - - public async supportsAllowLibraryPacksInResolveQueries() { - return this.isVersionAtLeast( - CliVersionConstraint.CLI_VERSION_WITH_ALLOW_LIBRARY_PACKS_IN_RESOLVE_QUERIES, - ); - } - - async supportsDatabaseRegistration() { - return this.isVersionAtLeast( - CliVersionConstraint.CLI_VERSION_WITH_DB_REGISTRATION, - ); - } - - async supportsDatabaseUnbundle() { - return this.isVersionAtLeast( - CliVersionConstraint.CLI_VERSION_WITH_DATABASE_UNBUNDLE, - ); - } - - async supportsNoPrecompile() { - return this.isVersionAtLeast( - CliVersionConstraint.CLI_VERSION_WITH_NO_PRECOMPILE, - ); - } - - async supportsRemoteQueries() { - return this.isVersionAtLeast( - CliVersionConstraint.CLI_VERSION_REMOTE_QUERIES, - ); - } - async supportsQlxRemote() { return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_QLX_REMOTE); } - async supportsResolveMlModels() { - return this.isVersionAtLeast( - CliVersionConstraint.CLI_VERSION_WITH_RESOLVE_ML_MODELS, - ); - } - async supportsPreciseResolveMlModels() { return this.isVersionAtLeast( CliVersionConstraint.CLI_VERSION_WITH_PRECISE_RESOLVE_ML_MODELS, ); } - async supportsOldEvalStats() { - return this.isVersionAtLeast( - CliVersionConstraint.CLI_VERSION_WITH_OLD_EVAL_STATS, - ); - } - - async supportsPackaging() { - return this.isVersionAtLeast( - CliVersionConstraint.CLI_VERSION_WITH_PACKAGING, - ); - } - async supportsStructuredEvalLog() { return this.isVersionAtLeast( CliVersionConstraint.CLI_VERSION_WITH_STRUCTURED_EVAL_LOG, diff --git a/extensions/ql-vscode/src/contextual/queryResolver.ts b/extensions/ql-vscode/src/contextual/queryResolver.ts index 5425161aed9..1494990db99 100644 --- a/extensions/ql-vscode/src/contextual/queryResolver.ts +++ b/extensions/ql-vscode/src/contextual/queryResolver.ts @@ -74,39 +74,12 @@ export async function resolveQueries( qlpacks: QlPacksForLanguage, keyType: KeyType, ): Promise { - const cliCanHandleLibraryPack = - await cli.cliConstraints.supportsAllowLibraryPacksInResolveQueries(); const packsToSearch: string[] = []; - let blameCli: boolean; - if (cliCanHandleLibraryPack) { - // The CLI can handle both library packs and query packs, so search both packs in order. - packsToSearch.push(qlpacks.dbschemePack); - if (qlpacks.queryPack !== undefined) { - packsToSearch.push(qlpacks.queryPack); - } - // If we don't find the query, it's because it's not there, not because the CLI was unable to - // search the pack. - blameCli = false; - } else { - // Older CLIs can't handle `codeql resolve queries` with a suite that references a library pack. - if (qlpacks.dbschemePackIsLibraryPack) { - if (qlpacks.queryPack !== undefined) { - // Just search the query pack, because some older library/query releases still had the - // contextual queries in the query pack. - packsToSearch.push(qlpacks.queryPack); - } - // If we don't find it, it's because the CLI was unable to search the library pack that - // actually contains the query. Blame any failure on the CLI, not the packs. - blameCli = true; - } else { - // We have an old CLI, but the dbscheme pack is old enough that it's still a unified pack with - // both libraries and queries. Just search that pack. - packsToSearch.push(qlpacks.dbschemePack); - // Any CLI should be able to search the single query pack, so if we don't find it, it's - // because the language doesn't support it. - blameCli = false; - } + // The CLI can handle both library packs and query packs, so search both packs in order. + packsToSearch.push(qlpacks.dbschemePack); + if (qlpacks.queryPack !== undefined) { + packsToSearch.push(qlpacks.queryPack); } const queries = await resolveQueriesFromPacks(cli, packsToSearch, keyType); @@ -115,15 +88,11 @@ export async function resolveQueries( } // No queries found. Determine the correct error message for the various scenarios. - const errorMessage = blameCli - ? `Your current version of the CodeQL CLI, '${ - (await cli.getVersion()).version - }', \ - is unable to use contextual queries from recent versions of the standard CodeQL libraries. \ - Please upgrade to the latest version of the CodeQL CLI.` - : `No ${nameOfKeyType(keyType)} queries (tagged "${tagOfKeyType( - keyType, - )}") could be found in the current library path. \ + const errorMessage = `No ${nameOfKeyType( + keyType, + )} queries (tagged "${tagOfKeyType( + keyType, + )}") could be found in the current library path. \ Try upgrading the CodeQL libraries. If that doesn't work, then ${nameOfKeyType( keyType, )} queries are not yet available \ diff --git a/extensions/ql-vscode/src/databaseFetcher.ts b/extensions/ql-vscode/src/databaseFetcher.ts index d3280bea12f..f2a2f719852 100644 --- a/extensions/ql-vscode/src/databaseFetcher.ts +++ b/extensions/ql-vscode/src/databaseFetcher.ts @@ -321,7 +321,7 @@ async function readAndUnzip( step: 9, message: `Unzipping into ${basename(unzipPath)}`, }); - if (cli && (await cli.cliConstraints.supportsDatabaseUnbundle())) { + if (cli) { // Use the `database unbundle` command if the installed cli version supports it await cli.databaseUnbundle(zipFile, unzipPath); } else { diff --git a/extensions/ql-vscode/src/databases.ts b/extensions/ql-vscode/src/databases.ts index f1f0a4e2d32..60f12ab3127 100644 --- a/extensions/ql-vscode/src/databases.ts +++ b/extensions/ql-vscode/src/databases.ts @@ -990,12 +990,6 @@ export class DatabaseManager extends DisposableObject { } private async getPrimaryLanguage(dbPath: string) { - if (!(await this.cli.cliConstraints.supportsLanguageName())) { - // return undefined so that we recalculate on restart until the cli is at a version that - // supports this feature. This recalculation is cheap since we avoid calling into the cli - // unless we know it can return the langauges property. - return undefined; - } const dbInfo = await this.cli.resolveDatabase(dbPath); return dbInfo.languages?.[0] || ""; } diff --git a/extensions/ql-vscode/src/extension.ts b/extensions/ql-vscode/src/extension.ts index a26ddc2099f..99361f6a33d 100644 --- a/extensions/ql-vscode/src/extension.ts +++ b/extensions/ql-vscode/src/extension.ts @@ -33,7 +33,7 @@ import { zipArchiveScheme, } from "./archive-filesystem-provider"; import QuickEvalCodeLensProvider from "./quickEvalCodeLensProvider"; -import { CodeQLCliServer, CliVersionConstraint } from "./cli"; +import { CodeQLCliServer } from "./cli"; import { CliConfigListener, DistributionConfigListener, @@ -820,17 +820,9 @@ async function activateWithInstalledDistribution( const path = selectedQuery?.fsPath || window.activeTextEditor?.document.uri.fsPath; if (qs !== undefined && path) { - if (await cliServer.cliConstraints.supportsResolveQlref()) { - const resolved = await cliServer.resolveQlref(path); - const uri = Uri.file(resolved.resolvedPath); - await window.showTextDocument(uri, { preview: false }); - } else { - void showAndLogErrorMessage( - "Jumping from a .qlref file to the .ql file it references is not " + - "supported with the CLI version you are running.\n" + - `Please upgrade your CLI to version ${CliVersionConstraint.CLI_VERSION_WITH_RESOLVE_QLREF} or later to use this feature.`, - ); - } + const resolved = await cliServer.resolveQlref(path); + const uri = Uri.file(resolved.resolvedPath); + await window.showTextDocument(uri, { preview: false }); } } @@ -1014,19 +1006,6 @@ async function activateWithInstalledDistribution( }); } - if ( - queryUris.length > 1 && - !(await cliServer.cliConstraints.supportsNonDestructiveUpgrades()) - ) { - // Try to upgrade the current database before running any queries - // so that the user isn't confronted with multiple upgrade - // requests for each query to run. - // Only do it if running multiple queries since this check is - // performed on each query run anyway. - // Don't do this with non destructive upgrades as the user won't see anything anyway. - await databaseUI.tryUpgradeCurrentDatabase(progress, token); - } - wrappedProgress({ maxStep: queryUris.length, step: queryUris.length - queriesRemaining, diff --git a/extensions/ql-vscode/src/helpers.ts b/extensions/ql-vscode/src/helpers.ts index 1bdb0772ee8..fa6101a38b7 100644 --- a/extensions/ql-vscode/src/helpers.ts +++ b/extensions/ql-vscode/src/helpers.ts @@ -540,7 +540,6 @@ export class CachedOperation { * `cli.CodeQLCliServer.resolveDatabase` and use the first entry in the * `languages` property. * - * @see cli.CliVersionConstraint.supportsLanguageName * @see cli.CodeQLCliServer.resolveDatabase */ export const dbSchemeToLanguage = { diff --git a/extensions/ql-vscode/src/legacy-query-server/legacyRunner.ts b/extensions/ql-vscode/src/legacy-query-server/legacyRunner.ts index 172df4e6570..933d346cfc1 100644 --- a/extensions/ql-vscode/src/legacy-query-server/legacyRunner.ts +++ b/extensions/ql-vscode/src/legacy-query-server/legacyRunner.ts @@ -74,10 +74,7 @@ export class LegacyQueryRunner extends QueryRunner { token: CancellationToken, dbItem: DatabaseItem, ): Promise { - if ( - dbItem.contents && - (await this.qs.cliServer.cliConstraints.supportsDatabaseRegistration()) - ) { + if (dbItem.contents) { const databases: Dataset[] = [ { dbDir: dbItem.contents.datasetUri.fsPath, @@ -97,10 +94,7 @@ export class LegacyQueryRunner extends QueryRunner { token: CancellationToken, dbItem: DatabaseItem, ): Promise { - if ( - dbItem.contents && - (await this.qs.cliServer.cliConstraints.supportsDatabaseRegistration()) - ) { + if (dbItem.contents) { const databases: Dataset[] = [ { dbDir: dbItem.contents.datasetUri.fsPath, diff --git a/extensions/ql-vscode/src/legacy-query-server/queryserver-client.ts b/extensions/ql-vscode/src/legacy-query-server/queryserver-client.ts index 8355f73fab4..36146da31e9 100644 --- a/extensions/ql-vscode/src/legacy-query-server/queryserver-client.ts +++ b/extensions/ql-vscode/src/legacy-query-server/queryserver-client.ts @@ -141,14 +141,9 @@ export class QueryServerClient extends DisposableObject { args.push(this.config.cacheSize.toString()); } - if (await this.cliServer.cliConstraints.supportsDatabaseRegistration()) { - args.push("--require-db-registration"); - } + args.push("--require-db-registration"); - if ( - (await this.cliServer.cliConstraints.supportsOldEvalStats()) && - !(await this.cliServer.cliConstraints.supportsPerQueryEvalLog()) - ) { + if (!(await this.cliServer.cliConstraints.supportsPerQueryEvalLog())) { args.push("--old-eval-stats"); } diff --git a/extensions/ql-vscode/src/legacy-query-server/run-queries.ts b/extensions/ql-vscode/src/legacy-query-server/run-queries.ts index 09bb79f1881..758edcc96a3 100644 --- a/extensions/ql-vscode/src/legacy-query-server/run-queries.ts +++ b/extensions/ql-vscode/src/legacy-query-server/run-queries.ts @@ -1,5 +1,3 @@ -import { createHash } from "crypto"; -import { readFile } from "fs-extra"; import * as tmp from "tmp-promise"; import { basename, join } from "path"; import { CancellationToken, Uri } from "vscode"; @@ -21,10 +19,7 @@ import * as messages from "../pure/legacy-messages"; import { InitialQueryInfo, LocalQueryInfo } from "../query-results"; import * as qsClient from "./queryserver-client"; import { getErrorMessage } from "../pure/helpers-pure"; -import { - compileDatabaseUpgradeSequence, - upgradeDatabaseExplicit, -} from "./upgrades"; +import { compileDatabaseUpgradeSequence } from "./upgrades"; import { QueryEvaluationInfo, QueryWithResults } from "../run-queries-shared"; /** @@ -233,57 +228,6 @@ export async function clearCacheInDatabase( return qs.sendRequest(messages.clearCache, params, token, progress); } -/** - * Compare the dbscheme implied by the query `query` and that of the current database. - * - If they are compatible, do nothing. - * - If they are incompatible but the database can be upgraded, suggest that upgrade. - * - If they are incompatible and the database cannot be upgraded, throw an error. - */ -async function checkDbschemeCompatibility( - cliServer: cli.CodeQLCliServer, - qs: qsClient.QueryServerClient, - query: QueryInProgress, - qlProgram: messages.QlProgram, - dbItem: DatabaseItem, - progress: ProgressCallback, - token: CancellationToken, -): Promise { - const searchPath = getOnDiskWorkspaceFolders(); - - if (dbItem.contents?.dbSchemeUri !== undefined) { - const { finalDbscheme } = await cliServer.resolveUpgrades( - dbItem.contents.dbSchemeUri.fsPath, - searchPath, - false, - ); - const hash = async function (filename: string): Promise { - return createHash("sha256") - .update(await readFile(filename)) - .digest("hex"); - }; - - // At this point, we have learned about three dbschemes: - - // the dbscheme of the actual database we're querying. - const dbschemeOfDb = await hash(dbItem.contents.dbSchemeUri.fsPath); - - // the dbscheme of the query we're running, including the library we've resolved it to use. - const dbschemeOfLib = await hash(query.queryDbscheme); - - // the database we're able to upgrade to - const upgradableTo = await hash(finalDbscheme); - - if (upgradableTo != dbschemeOfLib) { - reportNoUpgradePath(qlProgram, query); - } - - if (upgradableTo == dbschemeOfLib && dbschemeOfDb != dbschemeOfLib) { - // Try to upgrade the database - await upgradeDatabaseExplicit(qs, dbItem, progress, token); - } - } -} - function reportNoUpgradePath( qlProgram: messages.QlProgram, query: QueryInProgress, @@ -309,11 +253,8 @@ async function compileNonDestructiveUpgrade( throw new Error("Database is invalid, and cannot be upgraded."); } - // When packaging is used, dependencies may exist outside of the workspace and they are always on the resolved search path. - // When packaging is not used, all dependencies are in the workspace. - const upgradesPath = (await qs.cliServer.cliConstraints.supportsPackaging()) - ? qlProgram.libraryPath - : getOnDiskWorkspaceFolders(); + // Dependencies may exist outside of the workspace and they are always on the resolved search path. + const upgradesPath = qlProgram.libraryPath; const { scripts, matchesTarget } = await qs.cliServer.resolveUpgrades( dbItem.contents.dbSchemeUri.fsPath, @@ -409,33 +350,27 @@ export async function compileAndRunQueryAgainstDatabase( const metadata = await tryGetQueryMetadata(cliServer, qlProgram.queryPath); let availableMlModels: cli.MlModelInfo[] = []; - if (!(await cliServer.cliConstraints.supportsResolveMlModels())) { - void extLogger.log( - "Resolving ML models is unsupported by this version of the CLI. Running the query without any ML models.", - ); - } else { - try { - availableMlModels = ( - await cliServer.resolveMlModels( - diskWorkspaceFolders, - initialInfo.queryPath, - ) - ).models; - if (availableMlModels.length) { - void extLogger.log( - `Found available ML models at the following paths: ${availableMlModels - .map((x) => `'${x.path}'`) - .join(", ")}.`, - ); - } else { - void extLogger.log("Did not find any available ML models."); - } - } catch (e) { - const message = - `Couldn't resolve available ML models for ${qlProgram.queryPath}. Running the ` + - `query without any ML models: ${e}.`; - void showAndLogErrorMessage(message); + try { + availableMlModels = ( + await cliServer.resolveMlModels( + diskWorkspaceFolders, + initialInfo.queryPath, + ) + ).models; + if (availableMlModels.length) { + void extLogger.log( + `Found available ML models at the following paths: ${availableMlModels + .map((x) => `'${x.path}'`) + .join(", ")}.`, + ); + } else { + void extLogger.log("Did not find any available ML models."); } + } catch (e) { + const message = + `Couldn't resolve available ML models for ${qlProgram.queryPath}. Running the ` + + `query without any ML models: ${e}.`; + void showAndLogErrorMessage(message); } const hasMetadataFile = await dbItem.hasMetadataFile(); @@ -452,29 +387,16 @@ export async function compileAndRunQueryAgainstDatabase( let upgradeDir: tmp.DirectoryResult | undefined; try { - let upgradeQlo; - if (await cliServer.cliConstraints.supportsNonDestructiveUpgrades()) { - upgradeDir = await tmp.dir({ dir: upgradesTmpDir, unsafeCleanup: true }); - upgradeQlo = await compileNonDestructiveUpgrade( - qs, - upgradeDir, - query, - qlProgram, - dbItem, - progress, - token, - ); - } else { - await checkDbschemeCompatibility( - cliServer, - qs, - query, - qlProgram, - dbItem, - progress, - token, - ); - } + upgradeDir = await tmp.dir({ dir: upgradesTmpDir, unsafeCleanup: true }); + const upgradeQlo = await compileNonDestructiveUpgrade( + qs, + upgradeDir, + query, + qlProgram, + dbItem, + progress, + token, + ); let errors; try { errors = await query.compile(qs, qlProgram, progress, token); diff --git a/extensions/ql-vscode/src/legacy-query-server/upgrades.ts b/extensions/ql-vscode/src/legacy-query-server/upgrades.ts index de605b8857c..bc69775fa45 100644 --- a/extensions/ql-vscode/src/legacy-query-server/upgrades.ts +++ b/extensions/ql-vscode/src/legacy-query-server/upgrades.ts @@ -37,11 +37,6 @@ export async function compileDatabaseUpgradeSequence( ) { throw new Error("Database is invalid, and cannot be upgraded."); } - if (!(await qs.cliServer.cliConstraints.supportsNonDestructiveUpgrades())) { - throw new Error( - "The version of codeql is too old to run non-destructive upgrades.", - ); - } // If possible just compile the upgrade sequence return await qs.sendRequest( messages.compileUpgradeSequence, diff --git a/extensions/ql-vscode/src/packaging.ts b/extensions/ql-vscode/src/packaging.ts index 4bd6e4b1162..cfb4e00a9ca 100644 --- a/extensions/ql-vscode/src/packaging.ts +++ b/extensions/ql-vscode/src/packaging.ts @@ -1,4 +1,4 @@ -import { CliVersionConstraint, CodeQLCliServer } from "./cli"; +import { CodeQLCliServer } from "./cli"; import { getOnDiskWorkspaceFolders, showAndLogErrorMessage, @@ -30,11 +30,6 @@ export async function handleDownloadPacks( cliServer: CodeQLCliServer, progress: ProgressCallback, ): Promise { - if (!(await cliServer.cliConstraints.supportsPackaging())) { - throw new Error( - `Packaging commands are not supported by this version of CodeQL. Please upgrade to v${CliVersionConstraint.CLI_VERSION_WITH_PACKAGING} or later.`, - ); - } progress({ message: "Choose packs to download", step: 1, @@ -92,11 +87,6 @@ export async function handleInstallPackDependencies( cliServer: CodeQLCliServer, progress: ProgressCallback, ): Promise { - if (!(await cliServer.cliConstraints.supportsPackaging())) { - throw new Error( - `Packaging commands are not supported by this version of CodeQL. Please upgrade to v${CliVersionConstraint.CLI_VERSION_WITH_PACKAGING} or later.`, - ); - } progress({ message: "Choose packs to install dependencies for", step: 1, diff --git a/extensions/ql-vscode/src/query-server/query-runner.ts b/extensions/ql-vscode/src/query-server/query-runner.ts index 0cd218cf0c9..755d1d04fef 100644 --- a/extensions/ql-vscode/src/query-server/query-runner.ts +++ b/extensions/ql-vscode/src/query-server/query-runner.ts @@ -84,10 +84,7 @@ export class NewQueryRunner extends QueryRunner { token: CancellationToken, dbItem: DatabaseItem, ): Promise { - if ( - dbItem.contents && - (await this.qs.cliServer.cliConstraints.supportsDatabaseRegistration()) - ) { + if (dbItem.contents) { const databases: string[] = [dbItem.databaseUri.fsPath]; await this.qs.sendRequest( deregisterDatabases, @@ -102,10 +99,7 @@ export class NewQueryRunner extends QueryRunner { token: CancellationToken, dbItem: DatabaseItem, ): Promise { - if ( - dbItem.contents && - (await this.qs.cliServer.cliConstraints.supportsDatabaseRegistration()) - ) { + if (dbItem.contents) { const databases: string[] = [dbItem.databaseUri.fsPath]; await this.qs.sendRequest( registerDatabases, @@ -129,7 +123,7 @@ export class NewQueryRunner extends QueryRunner { const noItem = { title: "No", isCloseAffordance: true }; const dialogOptions: vscode.MessageItem[] = [yesItem, noItem]; - const message = `Should the database ${dbItem.databaseUri.fsPath} be destructively upgraded?\n\nThis should not be necessary to run queries + const message = `Should the database ${dbItem.databaseUri.fsPath} be destructively upgraded?\n\nThis should not be necessary to run queries as we will non-destructively update it anyway.`; const chosenItem = await vscode.window.showInformationMessage( message, diff --git a/extensions/ql-vscode/src/remote-queries/run-remote-query.ts b/extensions/ql-vscode/src/remote-queries/run-remote-query.ts index 50146b750a5..cddc9977a76 100644 --- a/extensions/ql-vscode/src/remote-queries/run-remote-query.ts +++ b/extensions/ql-vscode/src/remote-queries/run-remote-query.ts @@ -137,7 +137,7 @@ async function generateQueryPack( "--no-default-compilation-cache", `--compilation-cache=${ccache}`, ]; - } else if (await cliServer.cliConstraints.supportsNoPrecompile()) { + } else { precompilationOpts = ["--no-precompile"]; } @@ -227,12 +227,6 @@ export async function prepareRemoteQueryRun( token: CancellationToken, dbManager?: DbManager, // the dbManager is only needed when variantAnalysisReposPanel is enabled ): Promise { - if (!(await cliServer.cliConstraints.supportsRemoteQueries())) { - throw new Error( - `Variant analysis is not supported by this version of CodeQL. Please upgrade to v${cli.CliVersionConstraint.CLI_VERSION_REMOTE_QUERIES} or later.`, - ); - } - if (!uri?.fsPath.endsWith(".ql")) { throw new UserCancellationException("Not a CodeQL query file."); } diff --git a/extensions/ql-vscode/test/vscode-tests/cli-integration/legacy-query.test.ts b/extensions/ql-vscode/test/vscode-tests/cli-integration/legacy-query.test.ts index fa7312ae2e8..5c0a3574149 100644 --- a/extensions/ql-vscode/test/vscode-tests/cli-integration/legacy-query.test.ts +++ b/extensions/ql-vscode/test/vscode-tests/cli-integration/legacy-query.test.ts @@ -154,16 +154,14 @@ describeWithCodeQL()("using the legacy query server", () => { const parsedResults = new Checkpoint(); it("should register the database if necessary", async () => { - if (await cliServer.cliConstraints.supportsDatabaseRegistration()) { - await qs.sendRequest( - messages.registerDatabases, - { databases: [db] }, - token, - (() => { - /**/ - }) as any, - ); - } + await qs.sendRequest( + messages.registerDatabases, + { databases: [db] }, + token, + (() => { + /**/ + }) as any, + ); }); it(`should be able to compile query ${queryName}`, async () => { diff --git a/extensions/ql-vscode/test/vscode-tests/minimal-workspace/databases.test.ts b/extensions/ql-vscode/test/vscode-tests/minimal-workspace/databases.test.ts index d2a5e9e9bf8..ef6282c7076 100644 --- a/extensions/ql-vscode/test/vscode-tests/minimal-workspace/databases.test.ts +++ b/extensions/ql-vscode/test/vscode-tests/minimal-workspace/databases.test.ts @@ -33,7 +33,6 @@ describe("databases", () => { let updateSpy: jest.Mock, []>; let registerSpy: jest.Mock, []>; let deregisterSpy: jest.Mock, []>; - let supportsLanguageNameSpy: jest.Mock, []>; let resolveDatabaseSpy: jest.Mock, []>; let dir: tmp.DirResult; @@ -44,7 +43,6 @@ describe("databases", () => { updateSpy = jest.fn(() => Promise.resolve(undefined)); registerSpy = jest.fn(() => Promise.resolve(undefined)); deregisterSpy = jest.fn(() => Promise.resolve(undefined)); - supportsLanguageNameSpy = jest.fn(() => Promise.resolve(true)); resolveDatabaseSpy = jest.fn(() => Promise.resolve({} as DbInfo)); databaseManager = new DatabaseManager( @@ -65,10 +63,6 @@ describe("databases", () => { }, } as unknown as QueryRunner, { - cliConstraints: { - supportsLanguageName: supportsLanguageNameSpy, - supportsDatabaseRegistration: () => true, - }, resolveDatabase: resolveDatabaseSpy, } as unknown as CodeQLCliServer, { @@ -384,15 +378,7 @@ describe("databases", () => { }); }); - it("should not support the primary language", async () => { - supportsLanguageNameSpy.mockResolvedValue(false); - - const result = await (databaseManager as any).getPrimaryLanguage("hucairz"); - expect(result).toBeUndefined(); - }); - it("should get the primary language", async () => { - supportsLanguageNameSpy.mockResolvedValue(true); resolveDatabaseSpy.mockResolvedValue({ languages: ["python"], } as unknown as DbInfo); @@ -401,7 +387,6 @@ describe("databases", () => { }); it("should handle missing the primary language", async () => { - supportsLanguageNameSpy.mockResolvedValue(true); resolveDatabaseSpy.mockResolvedValue({ languages: [], } as unknown as DbInfo); diff --git a/extensions/ql-vscode/test/vscode-tests/no-workspace/contextual/queryResolver.test.ts b/extensions/ql-vscode/test/vscode-tests/no-workspace/contextual/queryResolver.test.ts index d06f9a51f7b..26d000814f4 100644 --- a/extensions/ql-vscode/test/vscode-tests/no-workspace/contextual/queryResolver.test.ts +++ b/extensions/ql-vscode/test/vscode-tests/no-workspace/contextual/queryResolver.test.ts @@ -22,9 +22,6 @@ describe("queryResolver", () => { const mockCli = { resolveQueriesInSuite: jest.fn(), - cliConstraints: { - supportsAllowLibraryPacksInResolveQueries: jest.fn(), - }, }; beforeEach(() => { @@ -40,10 +37,6 @@ describe("queryResolver", () => { jest.spyOn(helpers, "getOnDiskWorkspaceFolders").mockReturnValue([]); jest.spyOn(helpers, "showAndLogErrorMessage").mockResolvedValue(undefined); - - mockCli.cliConstraints.supportsAllowLibraryPacksInResolveQueries.mockReturnValue( - true, - ); }); describe("resolveQueries", () => { @@ -75,42 +68,6 @@ describe("queryResolver", () => { ]); }); - it("should resolve a query from the queries pack if this is an old CLI", async () => { - // pretend this is an older CLI - mockCli.cliConstraints.supportsAllowLibraryPacksInResolveQueries.mockReturnValue( - false, - ); - mockCli.resolveQueriesInSuite.mockReturnValue(["a", "b"]); - const result = await resolveQueries( - mockCli as unknown as CodeQLCliServer, - { - dbschemePackIsLibraryPack: true, - dbschemePack: "my-qlpack", - queryPack: "my-qlpack2", - }, - KeyType.DefinitionQuery, - ); - expect(result).toEqual(["a", "b"]); - - expect(mockCli.resolveQueriesInSuite).toHaveBeenCalledWith( - expect.stringMatching(/\.qls$/), - [], - ); - - const fileName = mockCli.resolveQueriesInSuite.mock.calls[0][0]; - - expect(load(await fs.readFile(fileName, "utf-8"))).toEqual([ - { - from: "my-qlpack2", - queries: ".", - include: { - kind: "definitions", - "tags contain": "ide-contextual-queries/local-definitions", - }, - }, - ]); - }); - it("should throw an error when there are no queries found", async () => { mockCli.resolveQueriesInSuite.mockReturnValue([]); diff --git a/extensions/ql-vscode/test/vscode-tests/no-workspace/run-queries.test.ts b/extensions/ql-vscode/test/vscode-tests/no-workspace/run-queries.test.ts index 0d0b705c4ac..ead279e1603 100644 --- a/extensions/ql-vscode/test/vscode-tests/no-workspace/run-queries.test.ts +++ b/extensions/ql-vscode/test/vscode-tests/no-workspace/run-queries.test.ts @@ -222,11 +222,7 @@ describe("run-queries", () => { describe("register", () => { it("should register", async () => { - const qs = createMockQueryServerClient({ - cliConstraints: { - supportsDatabaseRegistration: () => true, - }, - } as any); + const qs = createMockQueryServerClient(); const runner = new LegacyQueryRunner(qs); const mockProgress = "progress-monitor"; const mockCancel = "cancel-token"; @@ -261,11 +257,7 @@ describe("run-queries", () => { }); it("should deregister", async () => { - const qs = createMockQueryServerClient({ - cliConstraints: { - supportsDatabaseRegistration: () => true, - }, - } as any); + const qs = createMockQueryServerClient(); const runner = new LegacyQueryRunner(qs); const mockProgress = "progress-monitor"; const mockCancel = "cancel-token"; @@ -298,54 +290,6 @@ describe("run-queries", () => { mockProgress, ); }); - - it("should not register if unsupported", async () => { - const qs = createMockQueryServerClient({ - cliConstraints: { - supportsDatabaseRegistration: () => false, - }, - } as any); - const runner = new LegacyQueryRunner(qs); - const mockProgress = "progress-monitor"; - const mockCancel = "cancel-token"; - const datasetUri = Uri.file("dataset-uri"); - - const dbItem: DatabaseItem = { - contents: { - datasetUri, - }, - } as any; - await runner.registerDatabase( - mockProgress as any, - mockCancel as any, - dbItem, - ); - expect(qs.sendRequest).not.toHaveBeenCalled(); - }); - - it("should not deregister if unsupported", async () => { - const qs = createMockQueryServerClient({ - cliConstraints: { - supportsDatabaseRegistration: () => false, - }, - } as any); - const runner = new LegacyQueryRunner(qs); - const mockProgress = "progress-monitor"; - const mockCancel = "cancel-token"; - const datasetUri = Uri.file("dataset-uri"); - - const dbItem: DatabaseItem = { - contents: { - datasetUri, - }, - } as any; - await runner.registerDatabase( - mockProgress as any, - mockCancel as any, - dbItem, - ); - expect(qs.sendRequest).not.toBeCalled(); - }); }); let queryNum = 0;