From 91732297a2b833a2341dea9ba62e7b22476179ce Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 28 Feb 2023 11:59:29 -0500 Subject: [PATCH] Adds flag to avoid eventing during shutdown Debounces Git extension close event to avoid eventing on shutdown --- src/container.ts | 9 +++++++++ src/env/node/git/localGitProvider.ts | 9 ++++++++- src/extension.ts | 4 ++-- src/git/gitProviderService.ts | 17 +++++++++++++---- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/container.ts b/src/container.ts index 038bd33..a4ca819 100644 --- a/src/container.ts +++ b/src/container.ts @@ -241,6 +241,15 @@ export class Container { ); } + deactivate() { + this._deactivating = true; + } + + private _deactivating: boolean = false; + get deactivating() { + return this._deactivating; + } + private _ready: boolean = false; async ready() { diff --git a/src/env/node/git/localGitProvider.ts b/src/env/node/git/localGitProvider.ts index c1dc906..d9b5624 100644 --- a/src/env/node/git/localGitProvider.ts +++ b/src/env/node/git/localGitProvider.ts @@ -137,6 +137,7 @@ import { countStringLength, filterMap } from '../../../system/array'; import { TimedCancellationSource } from '../../../system/cancellation'; import { gate } from '../../../system/decorators/gate'; import { debug, log } from '../../../system/decorators/log'; +import { debounce } from '../../../system/function'; import { filterMap as filterMapIterable, find, first, join, last, map, some } from '../../../system/iterable'; import { commonBaseIndex, @@ -309,7 +310,13 @@ export class LocalGitProvider implements GitProvider, Disposable { if (scmGit == null) return; this._disposables.push( - scmGit.onDidCloseRepository(e => this._onDidCloseRepository.fire({ uri: e.rootUri })), + // Since we will get "close" events for repos when vscode is shutting down, debounce the event so ensure we aren't shutting down + scmGit.onDidCloseRepository( + debounce(e => { + if (this.container.deactivating) return; + this._onDidCloseRepository.fire({ uri: e.rootUri }); + }, 1000), + ), scmGit.onDidOpenRepository(e => this._onDidOpenRepository.fire({ uri: e.rootUri })), ); diff --git a/src/extension.ts b/src/extension.ts index 90046a4..acb7505 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -236,8 +236,8 @@ export async function activate(context: ExtensionContext): Promise { - this.fireRepositoriesChanged([], removed); + if (!deactivating) { + this.fireRepositoriesChanged([], removed); + } removed.forEach(r => r.dispose()); }); } - this.fireProvidersChanged([], [provider]); + if (!deactivating) { + this.fireProvidersChanged([], [provider]); + } }, }; } @@ -820,11 +827,13 @@ export class GitProviderService implements Disposable { await Promise.allSettled(promises); if (!this._initializing) { - void this.container.storage.storeWorkspace('assumeRepositoriesOnStartup', enabled); + void this.container.storage.storeWorkspace('assumeRepositoriesOnStartup', enabled).catch(); } } private updateContext() { + if (this.container.deactivating) return; + const openRepositoryCount = this.openRepositoryCount; const hasRepositories = openRepositoryCount !== 0;