@@ -1146,8 +1146,7 @@ export abstract class AbstractProject implements CustomConfigurationProvider, Pr
11461146 }
11471147
11481148 getFileGroups ( ) : FileGroup [ ] {
1149- return ( < FileGroup [ ] > this . sourceRoots . getFileGroups ( ) )
1150- . concat ( this . virtualSource . getFileGroups ( ) ) ;
1149+ return ( < FileGroup [ ] > this . sourceRoots . getFileGroups ( ) ) . concat ( this . virtualSource . getFileGroups ( ) ) ;
11511150 }
11521151
11531152 /**
@@ -2669,64 +2668,76 @@ class EIDEProject extends AbstractProject {
26692668
26702669 private srcRefMap : Map < string , File [ ] > = new Map ( ) ;
26712670
2672- public async notifyUpdateSourceRefs ( toolchain_ : ToolchainName | undefined ) {
2671+ public async notifyUpdateSourceRefs ( toolchain_ : ToolchainName | undefined ) : Promise < boolean > {
26732672
2674- /* clear old */
2675- this . srcRefMap . clear ( ) ;
2673+ return new Promise ( ( resolve ) => {
26762674
2677- /* check source references is enabled ? */
2678- if ( ! SettingManager . GetInstance ( ) . isDisplaySourceRefs ( ) ) return ;
2675+ /* clear old */
2676+ this . srcRefMap . clear ( ) ;
26792677
2680- let compiler_cmd_db : CompilerCommandsDatabaseItem [ ] = [ ] ;
2681- let generate_dep_file : ( ( cmd_db : CompilerCommandsDatabaseItem [ ] , srcpath : string , deppath : string ) => void ) | undefined ;
2678+ /* check source references is enabled ? */
2679+ if ( ! SettingManager . GetInstance ( ) . isDisplaySourceRefs ( ) ) {
2680+ resolve ( false ) ;
2681+ return ; /* no refs list file, exit */
2682+ }
26822683
2683- // for COSMIC STM8, we need manual generate .d files
2684- if ( this . getToolchain ( ) . name == 'COSMIC_STM8' ) {
2685- const compilerDBFile = File . fromArray ( [ this . getOutputFolder ( ) . path , 'compile_commands.json' ] ) ;
2686- if ( compilerDBFile . IsFile ( ) ) {
2687- try {
2688- compiler_cmd_db = jsonc . parse ( compilerDBFile . Read ( ) ) ;
2689- generate_dep_file = ( cmd_db : CompilerCommandsDatabaseItem [ ] , srcpath : string , deppath : string ) => {
2690- let idx = cmd_db . findIndex ( ( e ) => e . file == srcpath ) ;
2691- if ( idx != - 1 ) {
2692- try {
2693- let cmd_item = cmd_db [ idx ] ;
2694- let command = cmd_item . command . replace ( '-co' , '-sm -co' ) ;
2695- const depcont = child_process . execSync ( command , { cwd : cmd_item . directory } ) . toString ( ) ;
2696- fs . writeFileSync ( deppath , depcont ) ;
2697- } catch ( error ) {
2698- GlobalEvent . emit ( 'globalLog' , newMessage ( 'Warning' , `Failed to make '${ deppath } ', msg: ${ ( < Error > error ) . message } ` ) ) ;
2699- try { fs . unlinkSync ( deppath ) } catch ( error ) { } // del old .d file
2684+ let compiler_cmd_db : CompilerCommandsDatabaseItem [ ] = [ ] ;
2685+ let generate_dep_file : ( ( cmd_db : CompilerCommandsDatabaseItem [ ] , srcpath : string , deppath : string ) => void ) | undefined ;
2686+
2687+ // for COSMIC STM8, we need manual generate .d files
2688+ if ( this . getToolchain ( ) . name == 'COSMIC_STM8' ) {
2689+ const compilerDBFile = File . fromArray ( [ this . getOutputFolder ( ) . path , 'compile_commands.json' ] ) ;
2690+ if ( compilerDBFile . IsFile ( ) ) {
2691+ try {
2692+ compiler_cmd_db = jsonc . parse ( compilerDBFile . Read ( ) ) ;
2693+ generate_dep_file = ( cmd_db : CompilerCommandsDatabaseItem [ ] , srcpath : string , deppath : string ) => {
2694+ 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 } ` ) ) ;
2703+ try { fs . unlinkSync ( deppath ) } catch ( error ) { } // del old .d file
2704+ }
27002705 }
2701- }
2702- } ;
2703- } catch ( error ) {
2704- GlobalEvent . emit ( 'globalLog' , ExceptionToMessage ( error , 'Warning' ) ) ;
2706+ } ;
2707+ } catch ( error ) {
2708+ GlobalEvent . emit ( 'globalLog' , ExceptionToMessage ( error , 'Warning' ) ) ;
2709+ }
27052710 }
27062711 }
2707- }
27082712
2709- const toolName = toolchain_ || this . getToolchain ( ) . name ;
2713+ const toolName = toolchain_ || this . getToolchain ( ) . name ;
27102714
2711- const outFolder = this . getOutputFolder ( ) ;
2712- const refListFile = File . fromArray ( [ outFolder . path , 'ref.json' ] ) ;
2713- if ( ! refListFile . IsFile ( ) ) return ; /* no refs list file, exit */
2715+ const outFolder = this . getOutputFolder ( ) ;
2716+ const refListFile = File . fromArray ( [ outFolder . path , 'ref.json' ] ) ;
27142717
2715- try {
2716- const refMap = JSON . parse ( refListFile . Read ( ) ) ;
2717- for ( const srcpath in refMap ) {
2718- const refFile = new File ( ( < string > refMap [ srcpath ] ) . replace ( / \. [ ^ \\ \/ \. ] + $ / , '.d' ) ) ;
2719- if ( generate_dep_file ) generate_dep_file ( compiler_cmd_db , srcpath , refFile . path ) ;
2720- if ( ! refFile . IsFile ( ) ) continue ;
2721- const refs = this . parseRefFile ( refFile , toolName ) . filter ( p => p != srcpath ) ;
2722- this . srcRefMap . set ( srcpath , refs . map ( ( path ) => new File ( path ) ) ) ;
2718+ if ( ! refListFile . IsFile ( ) ) {
2719+ resolve ( false ) ;
2720+ return ; /* no refs list file, exit */
27232721 }
2724- } catch ( error ) {
2725- GlobalEvent . emit ( 'msg' , ExceptionToMessage ( error , 'Hidden' ) ) ;
2726- }
27272722
2728- // notify update src view
2729- this . emit ( 'dataChanged' , 'files' ) ;
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' ) ) ;
2734+ }
2735+
2736+ // notify update src view
2737+ this . emit ( 'dataChanged' , 'files' ) ;
2738+
2739+ resolve ( true ) ;
2740+ } ) ;
27302741 }
27312742
27322743 public getSourceRefs ( file : File ) : File [ ] {
0 commit comments