1- import { writeFile , promises } from "fs-extra" ;
2- import { dump } from "js-yaml" ;
3- import { file } from "tmp-promise" ;
1+ import { promises } from "fs-extra" ;
42import { basename , dirname , resolve } from "path" ;
53
64import { getOnDiskWorkspaceFolders } from "../../common/vscode/workspace-folders" ;
7- import {
8- getPrimaryDbscheme ,
9- getQlPackForDbscheme ,
10- QlPacksForLanguage ,
11- } from "../../databases/qlpack" ;
5+ import { QlPacksForLanguage } from "../../databases/qlpack" ;
126import {
137 KeyType ,
148 kindOfKeyType ,
@@ -17,97 +11,23 @@ import {
1711} from "./key-type" ;
1812import { CodeQLCliServer } from "../../codeql-cli/cli" ;
1913import { DatabaseItem } from "../../databases/local-databases" ;
14+ import { resolveQueries as resolveLocalQueries } from "../../local-queries/query-resolver" ;
2015import { extLogger } from "../../common/logging/vscode" ;
21- import {
22- showAndLogExceptionWithTelemetry ,
23- TeeLogger ,
24- } from "../../common/logging" ;
16+ import { TeeLogger } from "../../common/logging" ;
2517import { CancellationToken } from "vscode" ;
2618import { ProgressCallback } from "../../common/vscode/progress" ;
2719import { CoreCompletedQuery , QueryRunner } from "../../query-server" ;
28- import { redactableError } from "../../common/errors" ;
2920import { QLPACK_FILENAMES } from "../../common/ql" ;
30- import { telemetryListener } from "../../common/vscode/telemetry" ;
31-
32- export async function qlpackOfDatabase (
33- cli : Pick < CodeQLCliServer , "resolveQlpacks" > ,
34- db : Pick < DatabaseItem , "contents" > ,
35- ) : Promise < QlPacksForLanguage > {
36- if ( db . contents === undefined ) {
37- throw new Error ( "Database is invalid and cannot infer QLPack." ) ;
38- }
39- const datasetPath = db . contents . datasetUri . fsPath ;
40- const dbscheme = await getPrimaryDbscheme ( datasetPath ) ;
41- return await getQlPackForDbscheme ( cli , dbscheme ) ;
42- }
43-
44- /**
45- * Finds the contextual queries with the specified key in a list of CodeQL packs.
46- *
47- * @param cli The CLI instance to use.
48- * @param qlpacks The list of packs to search.
49- * @param keyType The contextual query key of the query to search for.
50- * @returns The found queries from the first pack in which any matching queries were found.
51- */
52- async function resolveQueriesFromPacks (
53- cli : CodeQLCliServer ,
54- qlpacks : string [ ] ,
55- keyType : KeyType ,
56- ) : Promise < string [ ] > {
57- const suiteFile = (
58- await file ( {
59- postfix : ".qls" ,
60- } )
61- ) . path ;
62- const suiteYaml = [ ] ;
63- for ( const qlpack of qlpacks ) {
64- suiteYaml . push ( {
65- from : qlpack ,
66- queries : "." ,
67- include : {
68- kind : kindOfKeyType ( keyType ) ,
69- "tags contain" : tagOfKeyType ( keyType ) ,
70- } ,
71- } ) ;
72- }
73- await writeFile ( suiteFile , dump ( suiteYaml ) , "utf8" ) ;
74-
75- const queries = await cli . resolveQueriesInSuite (
76- suiteFile ,
77- getOnDiskWorkspaceFolders ( ) ,
78- ) ;
79- return queries ;
80- }
8121
8222export async function resolveQueries (
8323 cli : CodeQLCliServer ,
8424 qlpacks : QlPacksForLanguage ,
8525 keyType : KeyType ,
8626) : Promise < string [ ] > {
87- const packsToSearch : string [ ] = [ ] ;
88-
89- // The CLI can handle both library packs and query packs, so search both packs in order.
90- packsToSearch . push ( qlpacks . dbschemePack ) ;
91- if ( qlpacks . queryPack !== undefined ) {
92- packsToSearch . push ( qlpacks . queryPack ) ;
93- }
94-
95- const queries = await resolveQueriesFromPacks ( cli , packsToSearch , keyType ) ;
96- if ( queries . length > 0 ) {
97- return queries ;
98- }
99-
100- // No queries found. Determine the correct error message for the various scenarios.
101- const keyTypeName = nameOfKeyType ( keyType ) ;
102- const keyTypeTag = tagOfKeyType ( keyType ) ;
103- const joinedPacksToSearch = packsToSearch . join ( ", " ) ;
104- const error = redactableError `No ${ keyTypeName } queries (tagged "${ keyTypeTag } ") could be found in the \
105- current library path (tried searching the following packs: ${ joinedPacksToSearch } ). \
106- Try upgrading the CodeQL libraries. If that doesn't work, then ${ keyTypeName } queries are not yet available \
107- for this language.` ;
108-
109- void showAndLogExceptionWithTelemetry ( extLogger , telemetryListener , error ) ;
110- throw error ;
27+ return resolveLocalQueries ( cli , qlpacks , nameOfKeyType ( keyType ) , {
28+ kind : kindOfKeyType ( keyType ) ,
29+ "tags contain" : [ tagOfKeyType ( keyType ) ] ,
30+ } ) ;
11131}
11232
11333async function resolveContextualQuery (
0 commit comments