import { Diagnostic } from 'vscode-languageserver/node' ; import { TextDocument } from 'vscode-languageserver-textdocument' ; import * as child from 'child_process' ; import { DocumentCompiler } from './DocumentCompiler' ; import { DiagnosticData , isDiagnosticDataUndefined } from './DiagnosticData' ; /**
 * Verible Compiler class contains functionality for compiling SystemVerilog/Verilog files using verible-lint.
 * Generates and takes in predefined runtime arguments,
 * and eventually parses the errors/warnings in `stdout` into `Diagnostic` array mapped to each unique document's uri.
 */ export class VeribleCompiler extends DocumentCompiler { param _error param stdout param _stderr param compiledDocument param documentFilePath param collection returns public parseDiagnostics ( _error , stdout , _stderr , compiledDocument , documentFilePath , collection ) { if ( stdout === undefined || stdout == null || ! compiledDocument ) { return ; } const regexError = new RegExp ( `^(.+):(\\d+):(\\d+): (.+)(\\(syntax-error\\)).*$` ) ; const regexInfo = new RegExp ( `^(.+):(\\d+):(\\d+): (.+)(\\[Style.*)$` ) ; stdout = stdout . replace ( /\r\n/g , '\n' ) . trim ( ) ; const errors = stdout . split ( /\n/g ) ; const visitedDocuments = new Map < string , boolean > ( ) ; for ( let i = 0 ; i < errors . length ; i ++ ) { const error = errors [ i ] ; const diagnosticData = new DiagnosticData ( ) ; let matches ; if ( ( matches = regexError . exec ( error ) ) ) { diagnosticData . filePath = matches [ 1 ] ; diagnosticData . line = parseInt ( matches [ 2 ] , 10 ) - 1 ; diagnosticData . charPosition = parseInt ( matches [ 3 ] , 10 ) - 1 ; diagnosticData . diagnosticSeverity = this . getDiagnosticSeverity ( 'Error' ) ; const problem = [ ] ; problem . push ( matches [ 4 ] ) ; diagnosticData . problem = problem . join ( '' ) . trim ( ) ; } if ( ( matches = regexInfo . exec ( error ) ) ) { diagnosticData . filePath = matches [ 1 ] ; diagnosticData . line = parseInt ( matches [ 2 ] , 10 ) - 1 ; diagnosticData . charPosition = parseInt ( matches [ 3 ] , 10 ) - 1 ; diagnosticData . diagnosticSeverity = this . getDiagnosticSeverity ( 'Info' ) ; const problem = [ ] ; problem . push ( matches [ 4 ] ) ; problem . push ( matches [ 5 ] ) ; diagnosticData . problem = problem . join ( '' ) . trim ( ) ; } if ( ! isDiagnosticDataUndefined ( diagnosticData ) ) { if ( visitedDocuments . has ( diagnosticData . filePath ) ) { this . publishDiagnosticForDocument ( compiledDocument , false , diagnosticData , collection ) ; } else { this . publishDiagnosticForDocument ( compiledDocument , true , diagnosticData , collection ) ; visitedDocuments . set ( diagnosticData . filePath , true ) ; } } } } }