@@ -679,42 +679,48 @@ export class CodeQLCliServer implements Disposable {
679679 const fakeSarifPath = '/Users/marcjaramillo/MLH/jdk11-tainted-path.sarif' ;
680680 try {
681681 const p = parser ( ) ;
682- console . log ( 'Created parser' ) ;
682+ //TODO: see if there is a way to create a parser that will return the count of codeFlow
683+ // paths first and then parse the SARIF based on whether it exceeds a certain threshhold.
684+ // Also, see if it's possible to parse only the first 5 or so codeFlows right up front
685+ // rather than parsing everything and then getting rid of the paths we don't want.
683686 const pipeline = chain ( [
684687 fs . createReadStream ( fakeSarifPath ) ,
685688 p ,
686689 pick ( { filter : 'runs.0.results' } )
687690 ] ) ;
688- console . log ( 'Created pipeline' ) ;
691+
689692 const asm = Assembler . connectTo ( pipeline ) ;
690- console . log ( 'Created assembler' ) ;
691- let chunkCount = 0 ;
692693 //TODO: figure out error handling for Assembler
693694 return await new Promise ( ( resolve ) => {
694- p . on ( 'data' , ( _ ) => {
695- chunkCount ++ ;
696- if ( chunkCount % 10000000 === 0 ) {
697- console . log ( 'Chunks processed:' , chunkCount ) ;
698- }
699- } ) ;
700- console . log ( 'Created parser counter' ) ;
701-
702695 asm . on ( 'done' , ( asm ) => {
703696 const dummyTool : sarif . Tool = { driver : { name : '' } } ;
697+ // Counts number of paths for each result and totals them
698+ // so we can let the user know how many paths exist even
699+ // when there are too many to display
700+ const pathsTotal = asm . current . map ( ( result : sarif . Result ) => (
701+ result . codeFlows ! . length
702+ ) ) as number [ ] ;
703+
704+ const sum = pathsTotal . reduce ( ( prev : number , curr : number ) => prev + curr , 0 ) ;
705+
706+ const filteredResults = asm . current . map ( ( result : sarif . Result ) => (
707+ Object . assign ( { } , result , { codeFlows : result . codeFlows ! . slice ( 0 , 5 ) } )
708+ ) ) ;
709+
704710 const log : sarif . Log = {
705711 version : '2.1.0' ,
706712 runs : [
707713 {
708714 tool : dummyTool ,
709- results : asm . current
715+ results : filteredResults
710716 }
711717 ]
712718 } ;
713- console . log ( 'Number of results:' , log . runs [ 0 ] ! . results ?. length ) ;
714- console . log ( log . runs [ 0 ] ! . results ! [ 0 ] ) ;
719+ console . log ( 'Number of results: ' , log . runs [ 0 ] ! . results ?. length ) ;
720+ console . log ( 'Total paths: ' , sum ) ;
721+ console . log ( log ) ;
715722 resolve ( log ) ;
716723 } ) ;
717- console . log ( 'Created assembler done listener' ) ;
718724 } ) ;
719725 } catch ( err ) {
720726 throw new Error ( `Parsing output of interpretation failed: ${ err . stderr || err } ` ) ;
0 commit comments