Skip to content

Commit ebf232e

Browse files
Continue working on implementing JSON streaming
1 parent 58a2f21 commit ebf232e

1 file changed

Lines changed: 30 additions & 23 deletions

File tree

  • extensions/ql-vscode/src

extensions/ql-vscode/src/cli.ts

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import * as cpp from 'child-process-promise';
22
import * as child_process from 'child_process';
33
import * as fs from 'fs-extra';
44
import * as path from 'path';
5+
import { parser } from 'stream-json';
56
import { chain } from 'stream-chain';
6-
import { Parser } from 'stream-json';
77
import Assembler = require('stream-json/Assembler');
88
import * as sarif from 'sarif';
99
import { SemVer } from 'semver';
@@ -20,6 +20,10 @@ import { assertNever } from './pure/helpers-pure';
2020
import { QueryMetadata, SortDirection } from './pure/interface-types';
2121
import { Logger, ProgressReporter } from './logging';
2222
import { CompilationMessage } from './pure/messages';
23+
// import Chain = require('stream-chain');
24+
import { pick } from 'stream-json/filters/Pick';
25+
// import { filter } from 'stream-json/filters/Filter';
26+
2327

2428
/**
2529
* The version of the SARIF format that we are using.
@@ -672,29 +676,32 @@ export class CodeQLCliServer implements Disposable {
672676

673677
async interpretBqrs(metadata: QueryMetadata, resultsPath: string, interpretedResultsPath: string, sourceInfo?: SourceInfo): Promise<sarif.Log> {
674678
await this.runInterpretCommand(SARIF_FORMAT, metadata, resultsPath, interpretedResultsPath, sourceInfo);
675-
676-
const pipeline = chain([
677-
fs.createReadStream(interpretedResultsPath),
678-
new Parser()
679-
]);
680-
681-
const asm = Assembler.connectTo(pipeline);
682-
asm.on('done', asm => console.log(asm.current));
683-
try {
684-
// output = fs.createReadStream('/Users/marcjaramillo/MLH/vscode-codeql-starter/jdk11-tainted-path.sarif').pipe(parsedSarif);
685-
} catch (e) {
686-
const rawMessage = e.stderr || e.message;
687-
const errorMessage = rawMessage.startsWith('Cannot create a string')
688-
? `SARIF too large. ${rawMessage}`
689-
: rawMessage;
690-
throw new Error(`Reading output of interpretation failed: ${errorMessage}`);
691-
}
679+
692680
try {
693-
// output.on('data', data => {
694-
// console.log(data);
695-
// });
696-
// output.on('end', () => { console.log('done'); });
697-
return {} as unknown as sarif.Log;
681+
//TODO: figure out error handling for Assembler
682+
return await new Promise((resolve) => {
683+
const pipeline = chain([
684+
fs.createReadStream('/Users/marcjaramillo/MLH/jdk11-tainted-path.sarif'),
685+
parser(),
686+
pick({filter: 'runs.0.results'})
687+
]);
688+
689+
const asm = Assembler.connectTo(pipeline);
690+
asm.on('done', (asm) => {
691+
const dummyTool : sarif.Tool = {driver: {name: ''}};
692+
const log : sarif.Log = {
693+
version: '2.1.0',
694+
runs: [
695+
{
696+
tool: dummyTool,
697+
results: asm.current
698+
}
699+
]
700+
};
701+
console.log(log);
702+
resolve(log);
703+
});
704+
});
698705
} catch (err) {
699706
throw new Error(`Parsing output of interpretation failed: ${err.stderr || err}`);
700707
}

0 commit comments

Comments
 (0)