|
1 | 1 | import { |
2 | 2 | ensureDirSync, |
3 | | - readFile, |
4 | 3 | pathExists, |
5 | 4 | ensureDir, |
6 | 5 | writeFile, |
7 | 6 | opendir, |
8 | 7 | } from "fs-extra"; |
9 | 8 | import { glob } from "glob"; |
10 | | -import { load } from "js-yaml"; |
11 | 9 | import { join, basename, dirname } from "path"; |
12 | 10 | import { dirSync } from "tmp-promise"; |
13 | 11 | import { Uri, window as Window, workspace, env, WorkspaceFolder } from "vscode"; |
14 | | -import { CodeQLCliServer, QlpacksInfo } from "./codeql-cli/cli"; |
| 12 | +import { CodeQLCliServer } from "./codeql-cli/cli"; |
15 | 13 | import { UserCancellationException } from "./common/vscode/progress"; |
16 | 14 | import { extLogger, OutputChannelLogger } from "./common"; |
17 | 15 | import { QueryMetadata } from "./pure/interface-types"; |
18 | 16 | import { telemetryListener } from "./telemetry"; |
19 | 17 | import { RedactableError } from "./pure/errors"; |
20 | | -import { getQlPackPath } from "./pure/ql"; |
21 | 18 | import { dbSchemeToLanguage, QueryLanguage } from "./common/query-language"; |
22 | 19 | import { isCodespacesTemplate } from "./config"; |
23 | 20 | import { AppCommandManager } from "./common/commands"; |
@@ -356,127 +353,6 @@ export async function prepareCodeTour( |
356 | 353 | } |
357 | 354 | } |
358 | 355 |
|
359 | | -export interface QlPacksForLanguage { |
360 | | - /** The name of the pack containing the dbscheme. */ |
361 | | - dbschemePack: string; |
362 | | - /** `true` if `dbschemePack` is a library pack. */ |
363 | | - dbschemePackIsLibraryPack: boolean; |
364 | | - /** |
365 | | - * The name of the corresponding standard query pack. |
366 | | - * Only defined if `dbschemePack` is a library pack. |
367 | | - */ |
368 | | - queryPack?: string; |
369 | | -} |
370 | | - |
371 | | -interface QlPackWithPath { |
372 | | - packName: string; |
373 | | - packDir: string | undefined; |
374 | | -} |
375 | | - |
376 | | -async function findDbschemePack( |
377 | | - packs: QlPackWithPath[], |
378 | | - dbschemePath: string, |
379 | | -): Promise<{ name: string; isLibraryPack: boolean }> { |
380 | | - for (const { packDir, packName } of packs) { |
381 | | - if (packDir !== undefined) { |
382 | | - const qlpackPath = await getQlPackPath(packDir); |
383 | | - |
384 | | - if (qlpackPath !== undefined) { |
385 | | - const qlpack = load(await readFile(qlpackPath, "utf8")) as { |
386 | | - dbscheme?: string; |
387 | | - library?: boolean; |
388 | | - }; |
389 | | - if ( |
390 | | - qlpack.dbscheme !== undefined && |
391 | | - basename(qlpack.dbscheme) === basename(dbschemePath) |
392 | | - ) { |
393 | | - return { |
394 | | - name: packName, |
395 | | - isLibraryPack: qlpack.library === true, |
396 | | - }; |
397 | | - } |
398 | | - } |
399 | | - } |
400 | | - } |
401 | | - throw new Error(`Could not find qlpack file for dbscheme ${dbschemePath}`); |
402 | | -} |
403 | | - |
404 | | -function findStandardQueryPack( |
405 | | - qlpacks: QlpacksInfo, |
406 | | - dbschemePackName: string, |
407 | | -): string | undefined { |
408 | | - const matches = dbschemePackName.match(/^codeql\/(?<language>[a-z]+)-all$/); |
409 | | - if (matches) { |
410 | | - const queryPackName = `codeql/${matches.groups!.language}-queries`; |
411 | | - if (qlpacks[queryPackName] !== undefined) { |
412 | | - return queryPackName; |
413 | | - } |
414 | | - } |
415 | | - |
416 | | - // Either the dbscheme pack didn't look like one where the queries might be in the query pack, or |
417 | | - // no query pack was found in the search path. Either is OK. |
418 | | - return undefined; |
419 | | -} |
420 | | - |
421 | | -export async function getQlPackForDbscheme( |
422 | | - cliServer: Pick<CodeQLCliServer, "resolveQlpacks">, |
423 | | - dbschemePath: string, |
424 | | -): Promise<QlPacksForLanguage> { |
425 | | - const qlpacks = await cliServer.resolveQlpacks(getOnDiskWorkspaceFolders()); |
426 | | - const packs: QlPackWithPath[] = Object.entries(qlpacks).map( |
427 | | - ([packName, dirs]) => { |
428 | | - if (dirs.length < 1) { |
429 | | - void extLogger.log( |
430 | | - `In getQlPackFor ${dbschemePath}, qlpack ${packName} has no directories`, |
431 | | - ); |
432 | | - return { packName, packDir: undefined }; |
433 | | - } |
434 | | - if (dirs.length > 1) { |
435 | | - void extLogger.log( |
436 | | - `In getQlPackFor ${dbschemePath}, qlpack ${packName} has more than one directory; arbitrarily choosing the first`, |
437 | | - ); |
438 | | - } |
439 | | - return { |
440 | | - packName, |
441 | | - packDir: dirs[0], |
442 | | - }; |
443 | | - }, |
444 | | - ); |
445 | | - const dbschemePack = await findDbschemePack(packs, dbschemePath); |
446 | | - const queryPack = dbschemePack.isLibraryPack |
447 | | - ? findStandardQueryPack(qlpacks, dbschemePack.name) |
448 | | - : undefined; |
449 | | - return { |
450 | | - dbschemePack: dbschemePack.name, |
451 | | - dbschemePackIsLibraryPack: dbschemePack.isLibraryPack, |
452 | | - queryPack, |
453 | | - }; |
454 | | -} |
455 | | - |
456 | | -export async function getPrimaryDbscheme( |
457 | | - datasetFolder: string, |
458 | | -): Promise<string> { |
459 | | - const dbschemes = await glob("*.dbscheme", { |
460 | | - cwd: datasetFolder, |
461 | | - }); |
462 | | - |
463 | | - if (dbschemes.length < 1) { |
464 | | - throw new Error( |
465 | | - `Can't find dbscheme for current database in ${datasetFolder}`, |
466 | | - ); |
467 | | - } |
468 | | - |
469 | | - dbschemes.sort(); |
470 | | - const dbscheme = dbschemes[0]; |
471 | | - |
472 | | - if (dbschemes.length > 1) { |
473 | | - void Window.showErrorMessage( |
474 | | - `Found multiple dbschemes in ${datasetFolder} during quick query; arbitrarily choosing the first, ${dbscheme}, to decide what library to use.`, |
475 | | - ); |
476 | | - } |
477 | | - return dbscheme; |
478 | | -} |
479 | | - |
480 | 356 | /** |
481 | 357 | * The following functions al heuristically determine metadata about databases. |
482 | 358 | */ |
|
0 commit comments