@@ -2668,76 +2668,74 @@ class EIDEProject extends AbstractProject {
26682668
26692669 private srcRefMap : Map < string , File [ ] > = new Map ( ) ;
26702670
2671- public async notifyUpdateSourceRefs ( toolchain_ : ToolchainName | undefined ) : Promise < boolean > {
2671+ public async notifyUpdateSourceRefs ( toolchain_ : ToolchainName | undefined ) {
26722672
2673- return new Promise ( ( resolve ) => {
2674-
2675- /* clear old */
2676- this . srcRefMap . clear ( ) ;
2673+ /* clear old */
2674+ this . srcRefMap . clear ( ) ;
26772675
2678- /* check source references is enabled ? */
2679- if ( ! SettingManager . GetInstance ( ) . isDisplaySourceRefs ( ) ) {
2680- resolve ( false ) ;
2681- return ; /* no refs list file, exit */
2682- }
2676+ /* check source references is enabled ? */
2677+ if ( ! SettingManager . GetInstance ( ) . isDisplaySourceRefs ( ) ) {
2678+ return ;
2679+ }
26832680
2684- let compiler_cmd_db : CompilerCommandsDatabaseItem [ ] = [ ] ;
2685- let generate_dep_file : ( ( cmd_db : CompilerCommandsDatabaseItem [ ] , srcpath : string , deppath : string ) => void ) | undefined ;
2681+ let compiler_cmd_db : CompilerCommandsDatabaseItem [ ] = [ ] ;
2682+ let generate_dep_file : ( ( cmd_db : CompilerCommandsDatabaseItem [ ] , srcpath : string , deppath : string ) => Promise < void > ) | undefined ;
26862683
2687- // for COSMIC STM8, we need manual generate .d files
2684+ // for COSMIC STM8, we need manual generate .d files
2685+ try {
26882686 if ( this . getToolchain ( ) . name == 'COSMIC_STM8' ) {
26892687 const compilerDBFile = File . fromArray ( [ this . getOutputFolder ( ) . path , 'compile_commands.json' ] ) ;
26902688 if ( compilerDBFile . IsFile ( ) ) {
2691- try {
2692- compiler_cmd_db = jsonc . parse ( compilerDBFile . Read ( ) ) ;
2693- generate_dep_file = ( cmd_db : CompilerCommandsDatabaseItem [ ] , srcpath : string , deppath : string ) => {
2689+ compiler_cmd_db = jsonc . parse ( compilerDBFile . Read ( ) ) ;
2690+ generate_dep_file = ( cmd_db : CompilerCommandsDatabaseItem [ ] , srcpath : string , deppath : string ) : Promise < void > => {
2691+ return new Promise ( ( resolve ) => {
26942692 let idx = cmd_db . findIndex ( ( e ) => e . file == srcpath ) ;
2695- if ( idx != - 1 ) {
2696- try {
2697- let cmd_item = cmd_db [ idx ] ;
2698- let command = cmd_item . command . replace ( '-co' , '-sm -co' ) ;
2699- const depcont = child_process . execSync ( command , { cwd : cmd_item . directory } ) . toString ( ) ;
2700- fs . writeFileSync ( deppath , depcont ) ;
2701- } catch ( error ) {
2702- GlobalEvent . emit ( 'globalLog' , newMessage ( 'Warning' , `Failed to make '${ deppath } ', msg: ${ ( < Error > error ) . message } ` ) ) ;
2693+ if ( idx == - 1 ) { resolve ( ) ; return ; }
2694+ let cmd_item = cmd_db [ idx ] ;
2695+ let command = cmd_item . command . replace ( '-co' , '-sm -co' ) ;
2696+ child_process . exec ( command , { cwd : cmd_item . directory } , ( error : child_process . ExecException | null , stdout : string , stderr : string ) => {
2697+ if ( error ) {
2698+ const msg = `Failed to make '${ deppath } ', msg: ${ ( < Error > error ) . message } ` ;
2699+ GlobalEvent . emit ( 'globalLog' , newMessage ( 'Warning' , msg ) ) ;
27032700 try { fs . unlinkSync ( deppath ) } catch ( error ) { } // del old .d file
2701+ resolve ( ) ;
2702+ } else {
2703+ fs . writeFileSync ( deppath , stdout ) ;
2704+ resolve ( ) ;
27042705 }
2705- }
2706- } ;
2707- } catch ( error ) {
2708- GlobalEvent . emit ( 'globalLog' , ExceptionToMessage ( error , 'Warning' ) ) ;
2709- }
2706+ } ) ;
2707+ } ) ;
2708+ } ;
27102709 }
27112710 }
2711+ } catch ( error ) {
2712+ GlobalEvent . emit ( 'globalLog' , ExceptionToMessage ( error , 'Warning' ) ) ;
2713+ }
27122714
2713- const toolName = toolchain_ || this . getToolchain ( ) . name ;
2715+ const toolName = toolchain_ || this . getToolchain ( ) . name ;
27142716
2715- const outFolder = this . getOutputFolder ( ) ;
2716- const refListFile = File . fromArray ( [ outFolder . path , 'ref.json' ] ) ;
2717+ const outFolder = this . getOutputFolder ( ) ;
2718+ const refListFile = File . fromArray ( [ outFolder . path , 'ref.json' ] ) ;
27172719
2718- if ( ! refListFile . IsFile ( ) ) {
2719- resolve ( false ) ;
2720- return ; /* no refs list file, exit */
2721- }
2720+ if ( ! refListFile . IsFile ( ) ) {
2721+ return ; /* no refs list file, exit */
2722+ }
27222723
2723- try {
2724- const refMap = JSON . parse ( refListFile . Read ( ) ) ;
2725- for ( const srcpath in refMap ) {
2726- const refFile = new File ( ( < string > refMap [ srcpath ] ) . replace ( / \. [ ^ \\ \/ \. ] + $ / , '.d' ) ) ;
2727- if ( generate_dep_file ) generate_dep_file ( compiler_cmd_db , srcpath , refFile . path ) ;
2728- if ( ! refFile . IsFile ( ) ) continue ;
2729- const refs = this . parseRefFile ( refFile , toolName ) . filter ( p => p != srcpath ) ;
2730- this . srcRefMap . set ( srcpath , refs . map ( ( path ) => new File ( path ) ) ) ;
2731- }
2732- } catch ( error ) {
2733- GlobalEvent . emit ( 'msg' , ExceptionToMessage ( error , 'Hidden' ) ) ;
2724+ try {
2725+ const refMap = JSON . parse ( refListFile . Read ( ) ) ;
2726+ for ( const srcpath in refMap ) {
2727+ const refFile = new File ( ( < string > refMap [ srcpath ] ) . replace ( / \. [ ^ \\ \/ \. ] + $ / , '.d' ) ) ;
2728+ if ( generate_dep_file ) await generate_dep_file ( compiler_cmd_db , srcpath , refFile . path ) ;
2729+ if ( ! refFile . IsFile ( ) ) continue ;
2730+ const refs = this . parseRefFile ( refFile , toolName ) . filter ( p => p != srcpath ) ;
2731+ this . srcRefMap . set ( srcpath , refs . map ( ( path ) => new File ( path ) ) ) ;
27342732 }
2733+ } catch ( error ) {
2734+ GlobalEvent . emit ( 'globalLog' , ExceptionToMessage ( error , 'Warning' ) ) ;
2735+ }
27352736
2736- // notify update src view
2737- this . emit ( 'dataChanged' , 'files' ) ;
2738-
2739- resolve ( true ) ;
2740- } ) ;
2737+ // notify update src view
2738+ this . emit ( 'dataChanged' , 'files' ) ;
27412739 }
27422740
27432741 public getSourceRefs ( file : File ) : File [ ] {
0 commit comments