@@ -3,19 +3,16 @@ import { DatabaseItem } from "../databases/local-databases";
33import { basename } from "path" ;
44import { QueryRunner } from "../query-server" ;
55import { CodeQLCliServer } from "../codeql-cli/cli" ;
6- import { showAndLogExceptionWithTelemetry , TeeLogger } from "../common/logging" ;
6+ import { showAndLogExceptionWithTelemetry } from "../common/logging" ;
77import { extLogger } from "../common/logging/vscode" ;
88import { extensiblePredicateDefinitions } from "./predicates" ;
99import { ProgressCallback } from "../common/vscode/progress" ;
1010import { getOnDiskWorkspaceFolders } from "../common/vscode/workspace-folders" ;
1111import { ModeledMethod , ModeledMethodType } from "./modeled-method" ;
1212import { redactableError } from "../common/errors" ;
13- import { QueryResultType } from "../query-server/new-messages" ;
14- import { file } from "tmp-promise" ;
15- import { writeFile } from "fs-extra" ;
16- import { dump } from "js-yaml" ;
17- import { qlpackOfDatabase } from "../local-queries" ;
13+ import { qlpackOfDatabase , resolveQueries } from "../local-queries" ;
1814import { telemetryListener } from "../common/vscode/telemetry" ;
15+ import { runQuery } from "../local-queries/run-query" ;
1916
2017type FlowModelOptions = {
2118 cliServer : CodeQLCliServer ;
@@ -88,35 +85,9 @@ async function resolveFlowQueries(
8885) : Promise < string [ ] > {
8986 const qlpacks = await qlpackOfDatabase ( cliServer , databaseItem ) ;
9087
91- const packsToSearch : string [ ] = [ ] ;
92-
93- // The CLI can handle both library packs and query packs, so search both packs in order.
94- packsToSearch . push ( qlpacks . dbschemePack ) ;
95- if ( qlpacks . queryPack !== undefined ) {
96- packsToSearch . push ( qlpacks . queryPack ) ;
97- }
98-
99- const suiteFile = (
100- await file ( {
101- postfix : ".qls" ,
102- } )
103- ) . path ;
104- const suiteYaml = [ ] ;
105- for ( const qlpack of packsToSearch ) {
106- suiteYaml . push ( {
107- from : qlpack ,
108- queries : "." ,
109- include : {
110- "tags contain" : "modelgenerator" ,
111- } ,
112- } ) ;
113- }
114- await writeFile ( suiteFile , dump ( suiteYaml ) , "utf8" ) ;
115-
116- return await cliServer . resolveQueriesInSuite (
117- suiteFile ,
118- getOnDiskWorkspaceFolders ( ) ,
119- ) ;
88+ return await resolveQueries ( cliServer , qlpacks , "flow model generator" , {
89+ "tags contain" : [ "modelgenerator" ] ,
90+ } ) ;
12091}
12192
12293async function runSingleFlowQuery (
@@ -132,6 +103,7 @@ async function runSingleFlowQuery(
132103 token,
133104 } : Omit < FlowModelOptions , "onResults" > ,
134105) : Promise < ModeledMethod [ ] > {
106+ // Check that the right query was found
135107 if ( queryPath === undefined ) {
136108 void showAndLogExceptionWithTelemetry (
137109 extLogger ,
@@ -141,45 +113,32 @@ async function runSingleFlowQuery(
141113 return [ ] ;
142114 }
143115
144- const definition = extensiblePredicateDefinitions [ type ] ;
145-
146- const queryRun = queryRunner . createQueryRun (
147- databaseItem . databaseUri . fsPath ,
148- {
149- queryPath,
150- quickEvalPosition : undefined ,
151- quickEvalCountOnly : false ,
152- } ,
153- false ,
154- getOnDiskWorkspaceFolders ( ) ,
155- undefined ,
116+ // Run the query
117+ const completedQuery = await runQuery ( {
118+ cliServer,
119+ queryRunner,
120+ databaseItem,
121+ queryPath,
156122 queryStorageDir,
157- undefined ,
158- undefined ,
159- ) ;
160-
161- const queryResult = await queryRun . evaluate (
162- ( { step, message } ) =>
123+ additionalPacks : getOnDiskWorkspaceFolders ( ) ,
124+ extensionPacks : undefined ,
125+ progress : ( { step, message } ) =>
163126 progress ( {
164127 message : `Generating ${ type } model: ${ message } ` ,
165128 step : queryStep * 1000 + step ,
166129 maxStep : 4000 ,
167130 } ) ,
168131 token,
169- new TeeLogger ( queryRunner . logger , queryRun . outputDir . logPath ) ,
170- ) ;
171- if ( queryResult . resultType !== QueryResultType . SUCCESS ) {
172- void showAndLogExceptionWithTelemetry (
173- extLogger ,
174- telemetryListener ,
175- redactableError `Failed to run ${ basename ( queryPath ) } query: ${
176- queryResult . message ?? "No message"
177- } `,
178- ) ;
132+ } ) ;
133+
134+ if ( ! completedQuery ) {
179135 return [ ] ;
180136 }
181137
182- const bqrsPath = queryResult . outputDir . bqrsPath ;
138+ // Interpret the results
139+ const definition = extensiblePredicateDefinitions [ type ] ;
140+
141+ const bqrsPath = completedQuery . outputDir . bqrsPath ;
183142
184143 const bqrsInfo = await cliServer . bqrsInfo ( bqrsPath ) ;
185144 if ( bqrsInfo [ "result-sets" ] . length !== 1 ) {
0 commit comments