@@ -12,7 +12,7 @@ import * as path from 'path';
1212import * as fs from 'fs' ;
1313import * as nls from 'vscode-nls' ;
1414import { fromGitUri } from './uri' ;
15- import { GitErrorCodes } from './api/git' ;
15+ import { GitErrorCodes , APIState as State } from './api/git' ;
1616
1717const localize = nls . loadMessageBundle ( ) ;
1818
@@ -63,15 +63,22 @@ export class Model {
6363
6464 private possibleGitRepositoryPaths = new Set < string > ( ) ;
6565
66+ private _onDidChangeState = new EventEmitter < State > ( ) ;
67+ readonly onDidChangeState = this . _onDidChangeState . event ;
68+
69+ private _state : State = 'uninitialized' ;
70+ get state ( ) : State { return this . _state ; }
71+
72+ setState ( state : State ) : void {
73+ this . _state = state ;
74+ this . _onDidChangeState . fire ( state ) ;
75+ }
76+
6677 private disposables : Disposable [ ] = [ ] ;
6778
6879 constructor ( readonly git : Git , private globalState : Memento , private outputChannel : OutputChannel ) {
6980 workspace . onDidChangeWorkspaceFolders ( this . onDidChangeWorkspaceFolders , this , this . disposables ) ;
70- this . onDidChangeWorkspaceFolders ( { added : workspace . workspaceFolders || [ ] , removed : [ ] } ) ;
71-
7281 window . onDidChangeVisibleTextEditors ( this . onDidChangeVisibleTextEditors , this , this . disposables ) ;
73- this . onDidChangeVisibleTextEditors ( window . visibleTextEditors ) ;
74-
7582 workspace . onDidChangeConfiguration ( this . onDidChangeConfiguration , this , this . disposables ) ;
7683
7784 const fsWatcher = workspace . createFileSystemWatcher ( '**' ) ;
@@ -82,7 +89,15 @@ export class Model {
8289 const onPossibleGitRepositoryChange = filterEvent ( onGitRepositoryChange , uri => ! this . getRepository ( uri ) ) ;
8390 onPossibleGitRepositoryChange ( this . onPossibleGitRepositoryChange , this , this . disposables ) ;
8491
85- this . scanWorkspaceFolders ( ) ;
92+ this . doInitialScan ( ) . finally ( ( ) => this . setState ( 'initialized' ) ) ;
93+ }
94+
95+ private async doInitialScan ( ) : Promise < void > {
96+ await Promise . all ( [
97+ this . onDidChangeWorkspaceFolders ( { added : workspace . workspaceFolders || [ ] , removed : [ ] } ) ,
98+ this . onDidChangeVisibleTextEditors ( window . visibleTextEditors ) ,
99+ this . scanWorkspaceFolders ( )
100+ ] ) ;
86101 }
87102
88103 /**
@@ -157,8 +172,8 @@ export class Model {
157172 . filter ( r => ! activeRepositories . has ( r ! . repository ) )
158173 . filter ( r => ! ( workspace . workspaceFolders || [ ] ) . some ( f => isDescendant ( f . uri . fsPath , r ! . repository . root ) ) ) as OpenRepository [ ] ;
159174
160- possibleRepositoryFolders . forEach ( p => this . openRepository ( p . uri . fsPath ) ) ;
161175 openRepositoriesToDispose . forEach ( r => r . dispose ( ) ) ;
176+ await Promise . all ( possibleRepositoryFolders . map ( p => this . openRepository ( p . uri . fsPath ) ) ) ;
162177 }
163178
164179 private onDidChangeConfiguration ( ) : void {
@@ -175,15 +190,15 @@ export class Model {
175190 openRepositoriesToDispose . forEach ( r => r . dispose ( ) ) ;
176191 }
177192
178- private onDidChangeVisibleTextEditors ( editors : TextEditor [ ] ) : void {
193+ private async onDidChangeVisibleTextEditors ( editors : TextEditor [ ] ) : Promise < void > {
179194 const config = workspace . getConfiguration ( 'git' ) ;
180195 const autoRepositoryDetection = config . get < boolean | 'subFolders' | 'openEditors' > ( 'autoRepositoryDetection' ) ;
181196
182197 if ( autoRepositoryDetection !== true && autoRepositoryDetection !== 'openEditors' ) {
183198 return ;
184199 }
185200
186- editors . forEach ( editor => {
201+ await Promise . all ( editors . map ( async editor => {
187202 const uri = editor . document . uri ;
188203
189204 if ( uri . scheme !== 'file' ) {
@@ -196,8 +211,8 @@ export class Model {
196211 return ;
197212 }
198213
199- this . openRepository ( path . dirname ( uri . fsPath ) ) ;
200- } ) ;
214+ await this . openRepository ( path . dirname ( uri . fsPath ) ) ;
215+ } ) ) ;
201216 }
202217
203218 @sequentialize
@@ -421,4 +436,4 @@ export class Model {
421436 this . possibleGitRepositoryPaths . clear ( ) ;
422437 this . disposables = dispose ( this . disposables ) ;
423438 }
424- }
439+ }
0 commit comments