import { TextDocument } from 'vscode-languageserver-textdocument' ; import { SystemVerilogSymbol } from './svsymbol' ; import { MacroInfo , PreprocIncInfo } from './svpreprocessor' ; import { SystemVerilogParser } from './svparser' ; import { ConnectionLogger , fsReadFile , pathToUri } from './genutils' ; let _parser = new SystemVerilogParser ( ) ; let _includeCache = new Map ( ) ; let _includeFilePaths = [ ] ; let _userDefinesMacroInfo = new Map ( ) ; process . on ( 'message' , ( args ) => { try { if ( args [ 0 ] == 'exit' ) { process . exit ( ) ; } else if ( args [ 0 ] == 'config' ) { _includeFilePaths = args [ 1 ] ; if ( args [ 2 ] != undefined ) { _userDefinesMacroInfo = new Map ( args [ 2 ] . map ( d => [ d [ 0 ] , { args : undefined , default : undefined , definition : d [ 1 ] , symbol : undefined , file : "" } ] ) ) ; } } else if ( args [ 0 ] == 'done' ) { let includeCache = SystemVerilogParser . includeCacheToJSON ( _includeCache ) ; process . send ( [ includeCache , [ ] ] ) ; } else { let file = args [ 1 ] ; if ( _includeCache . has ( file ) ) { process . send ( [ [ ] , [ ] ] ) ; } else { fsReadFile ( file ) . then ( ( data ) => { let document = TextDocument . create ( pathToUri ( file ) , "SystemVerilog" , 0 , data . toString ( ) ) ; let fileSymbolsInfo ; let pkgdeps ; [ fileSymbolsInfo , pkgdeps ] = _parser . parse ( document , _includeFilePaths , _includeCache , _userDefinesMacroInfo , "full" ) ; process . send ( [ fileSymbolsInfo , pkgdeps ] ) ; } ) . catch ( ( err ) => { process . send ( [ [ ] , [ ] ] ) ; } ) ; } } } catch ( error ) { ConnectionLogger . error ( error ) ; process . send ( [ [ ] , [ ] ] ) ; } } ) ;