module author Paolo Masci
 *  date copyright import { spawn , ChildProcess } from 'child_process' ; import * as fsUtils from '../../../common/fsUtils' ; import { Diagnostic } from 'vscode-languageserver' ; import * as path from 'path' ; export class PvsTypechecker { protected workers : { [ fname ] : ChildProcess ; } = { } ; protected processWorker ( fname , args ) { return new Promise ( ( resolve , reject ) => { const worker = spawn ( "java" , args . concat ( fname ) ) ; this . workers [ fname ] = worker ; worker . stdout . setEncoding ( "utf8" ) ; worker . stderr . setEncoding ( "utf8" ) ; worker . stdout . on ( "data" , ( diags ) => { resolve ( diags ) ; } ) ; worker . stderr . on ( "data" , ( data ) => { console . log ( "[pvs-typechecker] Error: " , data ) ; } ) ; worker . on ( "error" , ( err ) => { console . log ( "[pvs-typechecker] Process error " , err ) ; } ) ; worker . on ( "exit" , ( code , signal ) => { resolve ( null ) ; } ) ; worker . on ( "message" , ( message ) => { console . log ( "[pvs-typechecker] Process message" , message ) ; } ) ; } ) ; } param desc async typecheckFile ( desc ) { const fname = fsUtils . desc2fname ( desc ) ; console . info ( `[vscode-pvs-typechecker] Typechecking ${ fname }` ) ; let diagnostics = [ ] ; const libFolder = path . join ( __dirname , "../../../../out/core/lib" ) ; const start = Date . now ( ) ; const args = [ "-jar" , `${ libFolder }/PvsTypechecker.jar` ] ; try { const diags = await this . processWorker ( fname , args ) ; const stats = Date . now ( ) - start ; if ( diags ) { diagnostics = JSON . parse ( diags ) ; console . log ( `[vscode-pvs-typechecker] File ${ desc . fileName }${ desc . fileExtension } typechecked with errors in ${ stats }ms` ) ; } else { console . log ( `[vscode-pvs-typechecker] File ${ desc . fileName }${ desc . fileExtension } typechecked successfully in ${ stats }ms` ) ; } } catch ( typecheckError ) { console . log ( typecheckError ) ; } finally { return diagnostics ; } } }