@@ -73,6 +73,11 @@ export interface UpgradesInfo {
7373 */
7474export type QlpacksInfo = { [ name : string ] : string [ ] } ;
7575
76+ /**
77+ * The expected output of `codeql resolve qlref`.
78+ */
79+ export type QlrefInfo = { resolvedPath : string } ;
80+
7681// `codeql bqrs interpret` requires both of these to be present or
7782// both absent.
7883export interface SourceInfo {
@@ -143,6 +148,11 @@ export class CodeQLCliServer implements Disposable {
143148 */
144149 private static CLI_VERSION_WITH_DOWNGRADES = new SemVer ( '2.4.4' ) ;
145150
151+ /**
152+ * CLI version where the `codeql resolve qlref` command is available.
153+ */
154+ private static CLI_VERSION_WITH_RESOLVE_QLREF = new SemVer ( '2.5.1' ) ;
155+
146156 /** The process for the cli server, or undefined if one doesn't exist yet */
147157 process ?: child_process . ChildProcessWithoutNullStreams ;
148158 /** Queue of future commands*/
@@ -461,12 +471,15 @@ export class CodeQLCliServer implements Disposable {
461471 * @param command The `codeql` command to be run, provided as an array of command/subcommand names.
462472 * @param commandArgs The arguments to pass to the `codeql` command.
463473 * @param description Description of the action being run, to be shown in log and error messages.
474+ * @param addFormat Whether or not to add commandline arguments to specify the format as JSON.
464475 * @param progressReporter Used to output progress messages, e.g. to the status bar.
465476 * @returns The contents of the command's stdout, if the command succeeded.
466477 */
467- async runJsonCodeQlCliCommand < OutputType > ( command : string [ ] , commandArgs : string [ ] , description : string , progressReporter ?: ProgressReporter ) : Promise < OutputType > {
468- // Add format argument first, in case commandArgs contains positional parameters.
469- const args = [ '--format' , 'json' ] . concat ( commandArgs ) ;
478+ async runJsonCodeQlCliCommand < OutputType > ( command : string [ ] , commandArgs : string [ ] , description : string , addFormat = true , progressReporter ?: ProgressReporter ) : Promise < OutputType > {
479+ let args : string [ ] = [ ] ;
480+ if ( addFormat ) // Add format argument first, in case commandArgs contains positional parameters.
481+ args = args . concat ( [ '--format' , 'json' ] ) ;
482+ args = args . concat ( commandArgs ) ;
470483 const result = await this . runCodeQlCliCommand ( command , args , description , progressReporter ) ;
471484 try {
472485 return JSON . parse ( result ) as OutputType ;
@@ -505,6 +518,18 @@ export class CodeQLCliServer implements Disposable {
505518 ) ;
506519 }
507520
521+ public async resolveQlref ( qlref : string ) : Promise < QlrefInfo > {
522+ const subcommandArgs = [
523+ qlref
524+ ] ;
525+ return await this . runJsonCodeQlCliCommand < QlrefInfo > (
526+ [ 'resolve' , 'qlref' ] ,
527+ subcommandArgs ,
528+ 'Resolving qlref' ,
529+ false
530+ ) ;
531+ }
532+
508533 /**
509534 * Runs QL tests.
510535 * @param testPaths Full paths of the tests to run.
@@ -549,7 +574,7 @@ export class CodeQLCliServer implements Disposable {
549574 if ( queryMemoryMb !== undefined ) {
550575 args . push ( '--ram' , queryMemoryMb . toString ( ) ) ;
551576 }
552- return await this . runJsonCodeQlCliCommand < string [ ] > ( [ 'resolve' , 'ram' ] , args , 'Resolving RAM settings' , progressReporter ) ;
577+ return await this . runJsonCodeQlCliCommand < string [ ] > ( [ 'resolve' , 'ram' ] , args , 'Resolving RAM settings' , true , progressReporter ) ;
553578 }
554579 /**
555580 * Gets the headers (and optionally pagination info) of a bqrs.
@@ -773,6 +798,10 @@ export class CodeQLCliServer implements Disposable {
773798 return ( await this . getVersion ( ) ) . compare ( CodeQLCliServer . CLI_VERSION_WITH_DOWNGRADES ) >= 0 ;
774799 }
775800
801+ public async supportsResolveQlref ( ) {
802+ return ( await this . getVersion ( ) ) . compare ( CodeQLCliServer . CLI_VERSION_WITH_RESOLVE_QLREF ) >= 0 ;
803+ }
804+
776805 private async refreshVersion ( ) {
777806 const distribution = await this . distributionProvider . getDistribution ( ) ;
778807 switch ( distribution . kind ) {
0 commit comments