Skip to content

Commit d91184b

Browse files
authored
SCM - maintain repository selection when switching profiles (microsoft#210071)
1 parent 1f715da commit d91184b

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/vs/workbench/contrib/scm/browser/scmViewService.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { basename } from 'vs/base/common/resources';
1717
import { binarySearch } from 'vs/base/common/arrays';
1818
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
1919
import { IContextKey, IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
20+
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
2021

2122
function getProviderStorageKey(provider: ISCMProvider): string {
2223
return `${provider.contextValue}:${provider.label}${provider.rootUri ? `:${provider.rootUri.toString()}` : ''}`;
@@ -159,6 +160,7 @@ export class SCMViewService implements ISCMViewService {
159160
constructor(
160161
@ISCMService scmService: ISCMService,
161162
@IContextKeyService contextKeyService: IContextKeyService,
163+
@IExtensionService extensionService: IExtensionService,
162164
@IInstantiationService instantiationService: IInstantiationService,
163165
@IConfigurationService private readonly configurationService: IConfigurationService,
164166
@IStorageService private readonly storageService: IStorageService,
@@ -184,6 +186,14 @@ export class SCMViewService implements ISCMViewService {
184186
}
185187

186188
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);
187197
}
188198

189199
private onDidAddRepository(repository: ISCMRepository): void {
@@ -197,7 +207,7 @@ export class SCMViewService implements ISCMViewService {
197207

198208
let removed: Iterable<ISCMRepository> = Iterable.empty();
199209

200-
if (this.previousState) {
210+
if (this.previousState && !this.didFinishLoading) {
201211
const index = this.previousState.all.indexOf(getProviderStorageKey(repository.provider));
202212

203213
if (index === -1) {
@@ -375,9 +385,9 @@ export class SCMViewService implements ISCMViewService {
375385

376386
const all = this.repositories.map(r => getProviderStorageKey(r.provider));
377387
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 };
379389

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);
381391
}
382392

383393
@debounce(5000)
@@ -391,7 +401,6 @@ export class SCMViewService implements ISCMViewService {
391401
}
392402

393403
this.didFinishLoading = true;
394-
this.previousState = undefined;
395404
}
396405

397406
dispose(): void {

0 commit comments

Comments
 (0)