@@ -2125,6 +2125,7 @@ class ProjectDataProvider implements vscode.TreeDataProvider<ProjTreeItem>, vsco
21252125 if ( this . activePrjPath !== wsPath ) {
21262126 this . activePrjPath = wsPath ;
21272127 this . UpdateView ( ) ;
2128+ GlobalEvent . emit ( 'project.activeStatusChanged' , prj . getUid ( ) ) ;
21282129 }
21292130 }
21302131
@@ -3430,6 +3431,7 @@ export class ProjectExplorer implements CustomConfigurationProvider {
34303431 // register project hook
34313432 GlobalEvent . on ( 'project.opened' , ( prj ) => this . onProjectOpened ( prj ) ) ;
34323433 GlobalEvent . on ( 'project.closed' , ( uid ) => this . onProjectClosed ( uid ) ) ;
3434+ GlobalEvent . on ( 'project.activeStatusChanged' , ( uid ) => this . notifyCpptoolsRefresh ( ) ) ;
34333435
34343436 this . on ( 'request_open_project' , ( fsPath : string ) => this . dataProvider . OpenProject ( fsPath ) ) ;
34353437 this . on ( 'request_create_project' , ( option : CreateOptions ) => this . dataProvider . CreateProject ( option ) ) ;
@@ -3554,31 +3556,79 @@ export class ProjectExplorer implements CustomConfigurationProvider {
35543556 }
35553557 }
35563558
3557- private _sourceWhereFroms : Map < string , AbstractProject > = new Map ( ) ;
3559+ notifyCpptoolsRefresh ( ) {
3560+
3561+ if ( this . cppToolsApi ) {
3562+ if ( this . cppToolsApi . notifyReady ) {
3563+ this . cppToolsApi . notifyReady ( this ) ;
3564+ } else {
3565+ this . cppToolsApi . didChangeCustomConfiguration ( this ) ;
3566+ this . cppToolsApi . didChangeCustomBrowseConfiguration ( this ) ;
3567+ }
3568+ }
3569+ }
3570+
3571+ // Map<sourePath, ProjectUid[]>
3572+ private _sourceWhereFroms : Map < string , string [ ] > = new Map ( ) ;
35583573
35593574 canProvideConfiguration ( uri : vscode . Uri , token ?: vscode . CancellationToken | undefined ) : Thenable < boolean > {
35603575
35613576 this . cppToolsOut . appendLine ( `[source] cpptools request provideConfigurations for '${ uri . fsPath } '` ) ;
35623577
35633578 return new Promise ( async ( resolve ) => {
3564- let result = false ;
3579+
3580+ const providerList : string [ ] = [ ] ;
3581+
35653582 await this . dataProvider . traverseProjectsAsync ( async ( prj ) => {
3566- result = await prj . canProvideConfiguration ( uri , token ) ;
3567- if ( result ) this . _sourceWhereFroms . set ( uri . fsPath , prj ) ;
3568- return result ;
3583+
3584+ const result = await prj . canProvideConfiguration ( uri , token ) ;
3585+ if ( result ) {
3586+ providerList . push ( prj . getUid ( ) ) ;
3587+ }
3588+
3589+ return false ; // don't break loop
35693590 } ) ;
3570- resolve ( result ) ;
3591+
3592+ if ( providerList . length > 0 ) {
3593+ this . _sourceWhereFroms . set ( uri . fsPath , providerList ) ;
3594+ resolve ( true ) ;
3595+ } else {
3596+ this . _sourceWhereFroms . delete ( uri . fsPath ) ;
3597+ resolve ( false ) ;
3598+ }
35713599 } ) ;
35723600 }
35733601
35743602 provideConfigurations ( uris : vscode . Uri [ ] , token ?: vscode . CancellationToken | undefined ) : Thenable < SourceFileConfigurationItem [ ] > {
3603+
35753604 return new Promise ( async ( resolve ) => {
3605+
35763606 let result : SourceFileConfigurationItem [ ] = [ ] ;
3607+
3608+ const activePrjUid = this . getActiveProject ( ) ?. getUid ( ) ;
3609+
35773610 for ( const uri of uris ) {
3578- const prj = this . _sourceWhereFroms . get ( uri . fsPath ) ;
3579- if ( prj ) result = result . concat ( await prj . provideConfigurations ( [ uri ] , token ) ) ;
3611+
3612+ const prjList = this . _sourceWhereFroms . get ( uri . fsPath ) ;
3613+ if ( prjList == undefined || prjList . length == 0 ) continue ;
3614+
3615+ let proj : AbstractProject | undefined ;
3616+ if ( activePrjUid ) {
3617+ const pidx = prjList . findIndex ( uid => uid == activePrjUid ) ;
3618+ if ( pidx != - 1 ) {
3619+ proj = this . dataProvider . getProjectByUid ( prjList [ pidx ] ) ;
3620+ }
3621+ } else {
3622+ proj = this . dataProvider . getProjectByUid ( prjList [ 0 ] ) ;
3623+ }
3624+
3625+ if ( proj ) {
3626+ result = result . concat ( await proj . provideConfigurations ( [ uri ] , token ) ) ;
3627+ }
35803628 }
3629+
35813630 resolve ( result ) ;
3631+
35823632 this . cppToolsOut . appendLine ( `[source] provideConfigurations` ) ;
35833633 this . cppToolsOut . appendLine ( yml . stringify ( result ) ) ;
35843634 } ) ;
0 commit comments