@@ -218,7 +218,7 @@ export class CodeQLCliServer implements Disposable {
218218 private readonly app : App ,
219219 private distributionProvider : DistributionProvider ,
220220 private cliConfig : CliConfig ,
221- private logger : Logger ,
221+ public readonly logger : Logger ,
222222 ) {
223223 this . commandQueue = [ ] ;
224224 this . commandInProcess = false ;
@@ -330,6 +330,7 @@ export class CodeQLCliServer implements Disposable {
330330 commandArgs : string [ ] ,
331331 description : string ,
332332 onLine ?: OnLineCallback ,
333+ silent ?: boolean ,
333334 ) : Promise < string > {
334335 const stderrBuffers : Buffer [ ] = [ ] ;
335336 if ( this . commandInProcess ) {
@@ -349,7 +350,12 @@ export class CodeQLCliServer implements Disposable {
349350 // Compute the full args array
350351 const args = command . concat ( LOGGING_FLAGS ) . concat ( commandArgs ) ;
351352 const argsString = args . join ( " " ) ;
352- void this . logger . log ( `${ description } using CodeQL CLI: ${ argsString } ...` ) ;
353+ // If we are running silently, we don't want to print anything to the console.
354+ if ( ! silent ) {
355+ void this . logger . log (
356+ `${ description } using CodeQL CLI: ${ argsString } ...` ,
357+ ) ;
358+ }
353359 try {
354360 await new Promise < void > ( ( resolve , reject ) => {
355361 // Start listening to stdout
@@ -395,24 +401,30 @@ export class CodeQLCliServer implements Disposable {
395401 const fullBuffer = Buffer . concat ( stdoutBuffers ) ;
396402 // Make sure we remove the terminator;
397403 const data = fullBuffer . toString ( "utf8" , 0 , fullBuffer . length - 1 ) ;
398- void this . logger . log ( "CLI command succeeded." ) ;
404+ if ( ! silent ) {
405+ void this . logger . log ( "CLI command succeeded." ) ;
406+ }
399407 return data ;
400408 } catch ( err ) {
401409 // Kill the process if it isn't already dead.
402410 this . killProcessIfRunning ( ) ;
403- // Report the error (if there is a stderr then use that otherwise just report the error cod or nodejs error)
411+ // Report the error (if there is a stderr then use that otherwise just report the error code or nodejs error)
404412 const newError =
405413 stderrBuffers . length === 0
406- ? new Error ( `${ description } failed: ${ err } ` )
414+ ? new Error (
415+ `${ description } failed with args:${ EOL } ${ argsString } ${ EOL } ${ err } ` ,
416+ )
407417 : new Error (
408- `${ description } failed: ${ Buffer . concat ( stderrBuffers ) . toString (
409- "utf8" ,
410- ) } `,
418+ `${ description } failed with args: ${ EOL } ${ argsString } ${ EOL } ${ Buffer . concat (
419+ stderrBuffers ,
420+ ) . toString ( "utf8" ) } `,
411421 ) ;
412422 newError . stack += getErrorStack ( err ) ;
413423 throw newError ;
414424 } finally {
415- void this . logger . log ( Buffer . concat ( stderrBuffers ) . toString ( "utf8" ) ) ;
425+ if ( ! silent ) {
426+ void this . logger . log ( Buffer . concat ( stderrBuffers ) . toString ( "utf8" ) ) ;
427+ }
416428 // Remove the listeners we set up.
417429 process . stdout . removeAllListeners ( "data" ) ;
418430 process . stderr . removeAllListeners ( "data" ) ;
@@ -549,9 +561,11 @@ export class CodeQLCliServer implements Disposable {
549561 {
550562 progressReporter,
551563 onLine,
564+ silent = false ,
552565 } : {
553566 progressReporter ?: ProgressReporter ;
554567 onLine ?: OnLineCallback ;
568+ silent ?: boolean ;
555569 } = { } ,
556570 ) : Promise < string > {
557571 if ( progressReporter ) {
@@ -567,6 +581,7 @@ export class CodeQLCliServer implements Disposable {
567581 commandArgs ,
568582 description ,
569583 onLine ,
584+ silent ,
570585 ) . then ( resolve , reject ) ;
571586 } catch ( err ) {
572587 reject ( err ) ;
@@ -600,10 +615,12 @@ export class CodeQLCliServer implements Disposable {
600615 addFormat = true ,
601616 progressReporter,
602617 onLine,
618+ silent = false ,
603619 } : {
604620 addFormat ?: boolean ;
605621 progressReporter ?: ProgressReporter ;
606622 onLine ?: OnLineCallback ;
623+ silent ?: boolean ;
607624 } = { } ,
608625 ) : Promise < OutputType > {
609626 let args : string [ ] = [ ] ;
@@ -614,6 +631,7 @@ export class CodeQLCliServer implements Disposable {
614631 const result = await this . runCodeQlCliCommand ( command , args , description , {
615632 progressReporter,
616633 onLine,
634+ silent,
617635 } ) ;
618636 try {
619637 return JSON . parse ( result ) as OutputType ;
@@ -739,14 +757,19 @@ export class CodeQLCliServer implements Disposable {
739757 /**
740758 * Finds all available queries in a given directory.
741759 * @param queryDir Root of directory tree to search for queries.
760+ * @param silent If true, don't print logs to the CodeQL extension log.
742761 * @returns The list of queries that were found.
743762 */
744- public async resolveQueries ( queryDir : string ) : Promise < ResolvedQueries > {
763+ public async resolveQueries (
764+ queryDir : string ,
765+ silent ?: boolean ,
766+ ) : Promise < ResolvedQueries > {
745767 const subcommandArgs = [ queryDir ] ;
746768 return await this . runJsonCodeQlCliCommand < ResolvedQueries > (
747769 [ "resolve" , "queries" ] ,
748770 subcommandArgs ,
749771 "Resolving queries" ,
772+ { silent } ,
750773 ) ;
751774 }
752775
0 commit comments