@@ -17,6 +17,7 @@ import { basename } from 'vs/base/common/resources';
17
17
import { binarySearch } from 'vs/base/common/arrays' ;
18
18
import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
19
19
import { IContextKey , IContextKeyService , RawContextKey } from 'vs/platform/contextkey/common/contextkey' ;
20
+ import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions' ;
20
21
21
22
function getProviderStorageKey ( provider : ISCMProvider ) : string {
22
23
return `${ provider . contextValue } :${ provider . label } ${ provider . rootUri ? `:${ provider . rootUri . toString ( ) } ` : '' } ` ;
@@ -159,6 +160,7 @@ export class SCMViewService implements ISCMViewService {
159
160
constructor (
160
161
@ISCMService scmService : ISCMService ,
161
162
@IContextKeyService contextKeyService : IContextKeyService ,
163
+ @IExtensionService extensionService : IExtensionService ,
162
164
@IInstantiationService instantiationService : IInstantiationService ,
163
165
@IConfigurationService private readonly configurationService : IConfigurationService ,
164
166
@IStorageService private readonly storageService : IStorageService ,
@@ -184,6 +186,14 @@ export class SCMViewService implements ISCMViewService {
184
186
}
185
187
186
188
storageService . onWillSaveState ( this . onWillSaveState , this , this . disposables ) ;
189
+
190
+ // Maintain repository selection when the extension host restarts.
191
+ // Extension host is restarted after installing an extension update
192
+ // or during a profile switch.
193
+ extensionService . onWillStop ( ( ) => {
194
+ this . onWillSaveState ( ) ;
195
+ this . didFinishLoading = false ;
196
+ } , this , this . disposables ) ;
187
197
}
188
198
189
199
private onDidAddRepository ( repository : ISCMRepository ) : void {
@@ -197,7 +207,7 @@ export class SCMViewService implements ISCMViewService {
197
207
198
208
let removed : Iterable < ISCMRepository > = Iterable . empty ( ) ;
199
209
200
- if ( this . previousState ) {
210
+ if ( this . previousState && ! this . didFinishLoading ) {
201
211
const index = this . previousState . all . indexOf ( getProviderStorageKey ( repository . provider ) ) ;
202
212
203
213
if ( index === - 1 ) {
@@ -375,9 +385,9 @@ export class SCMViewService implements ISCMViewService {
375
385
376
386
const all = this . repositories . map ( r => getProviderStorageKey ( r . provider ) ) ;
377
387
const visible = this . visibleRepositories . map ( r => all . indexOf ( getProviderStorageKey ( r . provider ) ) ) ;
378
- const raw = JSON . stringify ( { all, sortKey : this . _repositoriesSortKey , visible } ) ;
388
+ this . previousState = { all, sortKey : this . _repositoriesSortKey , visible } ;
379
389
380
- this . storageService . store ( 'scm:view:visibleRepositories' , raw , StorageScope . WORKSPACE , StorageTarget . MACHINE ) ;
390
+ this . storageService . store ( 'scm:view:visibleRepositories' , JSON . stringify ( this . previousState ) , StorageScope . WORKSPACE , StorageTarget . MACHINE ) ;
381
391
}
382
392
383
393
@debounce ( 5000 )
@@ -391,7 +401,6 @@ export class SCMViewService implements ISCMViewService {
391
401
}
392
402
393
403
this . didFinishLoading = true ;
394
- this . previousState = undefined ;
395
404
}
396
405
397
406
dispose ( ) : void {
0 commit comments