Browse Source

Adds flag to avoid eventing during shutdown

Debounces Git extension close event to avoid eventing on shutdown
main
Eric Amodio 1 year ago
parent
commit
91732297a2
4 changed files with 32 additions and 7 deletions
  1. +9
    -0
      src/container.ts
  2. +8
    -1
      src/env/node/git/localGitProvider.ts
  3. +2
    -2
      src/extension.ts
  4. +13
    -4
      src/git/gitProviderService.ts

+ 9
- 0
src/container.ts View File

@ -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() {

+ 8
- 1
src/env/node/git/localGitProvider.ts View File

@ -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 })),
);

+ 2
- 2
src/extension.ts View File

@ -236,8 +236,8 @@ export async function activate(context: ExtensionContext): Promise
}
export function deactivate() {
// nothing to do
Logger.log('GitLens deactivated');
Logger.log('GitLens deactivating...');
Container.instance.deactivate();
}
// async function migrateSettings(context: ExtensionContext, previousVersion: string | undefined) {

+ 13
- 4
src/git/gitProviderService.ts View File

@ -437,17 +437,24 @@ export class GitProviderService implements Disposable {
}
}
this.updateContext();
const { deactivating } = this.container;
if (!deactivating) {
this.updateContext();
}
if (removed.length) {
// Defer the event trigger enough to let everything unwind
queueMicrotask(() => {
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;

Loading…
Cancel
Save