From f592d91cf36297727f5bfc8708ac524739f36fac Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Sun, 13 Mar 2022 10:06:46 +0100 Subject: [PATCH] history - limit long running shutdown handling to desktop only --- .../browser/workingCopyHistoryService.ts | 33 +++++++++++ .../common/workingCopyHistoryService.ts | 35 ++---------- .../workingCopyHistoryService.ts | 56 +++++++++++++++++++ .../workingCopyHistoryService.test.ts | 4 +- src/vs/workbench/workbench.common.main.ts | 1 - src/vs/workbench/workbench.sandbox.main.ts | 1 + src/vs/workbench/workbench.web.main.ts | 1 + 7 files changed, 98 insertions(+), 33 deletions(-) create mode 100644 src/vs/workbench/services/workingCopy/browser/workingCopyHistoryService.ts create mode 100644 src/vs/workbench/services/workingCopy/electron-sandbox/workingCopyHistoryService.ts diff --git a/src/vs/workbench/services/workingCopy/browser/workingCopyHistoryService.ts b/src/vs/workbench/services/workingCopy/browser/workingCopyHistoryService.ts new file mode 100644 index 00000000000..7a86ccf770c --- /dev/null +++ b/src/vs/workbench/services/workingCopy/browser/workingCopyHistoryService.ts @@ -0,0 +1,33 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { IFileService } from 'vs/platform/files/common/files'; +import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService'; +import { IEnvironmentService } from 'vs/platform/environment/common/environment'; +import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity'; +import { ILabelService } from 'vs/platform/label/common/label'; +import { ILogService } from 'vs/platform/log/common/log'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; +import { WorkingCopyHistoryService } from 'vs/workbench/services/workingCopy/common/workingCopyHistoryService'; +import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; +import { IWorkingCopyHistoryService } from 'vs/workbench/services/workingCopy/common/workingCopyHistory'; + +export class BrowserWorkingCopyHistoryService extends WorkingCopyHistoryService { + + constructor( + @IFileService fileService: IFileService, + @IRemoteAgentService remoteAgentService: IRemoteAgentService, + @IEnvironmentService environmentService: IEnvironmentService, + @IUriIdentityService uriIdentityService: IUriIdentityService, + @ILabelService labelService: ILabelService, + @ILogService logService: ILogService, + @IConfigurationService configurationService: IConfigurationService + ) { + super(fileService, remoteAgentService, environmentService, uriIdentityService, labelService, logService, configurationService); + } +} + +// Register Service +registerSingleton(IWorkingCopyHistoryService, BrowserWorkingCopyHistoryService, true); diff --git a/src/vs/workbench/services/workingCopy/common/workingCopyHistoryService.ts b/src/vs/workbench/services/workingCopy/common/workingCopyHistoryService.ts index 292cab4947b..d552b0bb76e 100644 --- a/src/vs/workbench/services/workingCopy/common/workingCopyHistoryService.ts +++ b/src/vs/workbench/services/workingCopy/common/workingCopyHistoryService.ts @@ -5,10 +5,9 @@ import { localize } from 'vs/nls'; import { Emitter } from 'vs/base/common/event'; -import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { Registry } from 'vs/platform/registry/common/platform'; import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions'; -import { ILifecycleService, LifecyclePhase, WillShutdownEvent } from 'vs/workbench/services/lifecycle/common/lifecycle'; +import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle'; import { WorkingCopyHistoryTracker } from 'vs/workbench/services/workingCopy/common/workingCopyHistoryTracker'; import { Disposable } from 'vs/base/common/lifecycle'; import { IWorkingCopyHistoryEntry, IWorkingCopyHistoryEntryDescriptor, IWorkingCopyHistoryEvent, IWorkingCopyHistoryService } from 'vs/workbench/services/workingCopy/common/workingCopyHistory'; @@ -182,7 +181,7 @@ class WorkingCopyHistoryModel { return entries; } - async notifyWillShutdown(): Promise { + async store(): Promise { // Cleanup based on max-entries setting await this.cleanUpEntries(); @@ -276,7 +275,7 @@ class WorkingCopyHistoryModel { } } -export class WorkingCopyHistoryService extends Disposable implements IWorkingCopyHistoryService { +export abstract class WorkingCopyHistoryService extends Disposable implements IWorkingCopyHistoryService { declare readonly _serviceBrand: undefined; @@ -285,7 +284,7 @@ export class WorkingCopyHistoryService extends Disposable implements IWorkingCop private readonly localHistoryHome = new DeferredPromise(); - private readonly models = new ResourceMap(resource => this.uriIdentityService.extUri.getComparisonKey(resource)); + protected readonly models = new ResourceMap(resource => this.uriIdentityService.extUri.getComparisonKey(resource)); constructor( @IFileService private readonly fileService: IFileService, @@ -293,14 +292,12 @@ export class WorkingCopyHistoryService extends Disposable implements IWorkingCop @IEnvironmentService private readonly environmentService: IEnvironmentService, @IUriIdentityService private readonly uriIdentityService: IUriIdentityService, @ILabelService private readonly labelService: ILabelService, - @ILifecycleService private readonly lifecycleService: ILifecycleService, - @ILogService private readonly logService: ILogService, + @ILogService protected readonly logService: ILogService, @IConfigurationService private readonly configurationService: IConfigurationService ) { super(); this.resolveLocalHistoryHome(); - this.registerListeners(); } private async resolveLocalHistoryHome(): Promise { @@ -324,25 +321,6 @@ export class WorkingCopyHistoryService extends Disposable implements IWorkingCop this.localHistoryHome.complete(historyHome); } - private registerListeners(): void { - this.lifecycleService.onWillShutdown(e => this.onWillShutdown(e)); - } - - private onWillShutdown(e: WillShutdownEvent): void { - - // Prolong shutdown for orderly model shutdown - e.join((async () => { - const models = Array.from(this.models.values()); - for (const model of models) { - try { - await model.notifyWillShutdown(); - } catch (error) { - this.logService.trace(error); - } - } - })(), 'join.workingCopyHistory'); - } - async addEntry({ workingCopy, source }: IWorkingCopyHistoryEntryDescriptor, token: CancellationToken): Promise { if (!this.fileService.hasProvider(workingCopy.resource)) { return undefined; // we require the working copy resource to be file service accessible @@ -386,8 +364,5 @@ export class WorkingCopyHistoryService extends Disposable implements IWorkingCop } } -// Register Service -registerSingleton(IWorkingCopyHistoryService, WorkingCopyHistoryService, true); - // Register History Tracker Registry.as(WorkbenchExtensions.Workbench).registerWorkbenchContribution(WorkingCopyHistoryTracker, LifecyclePhase.Restored); diff --git a/src/vs/workbench/services/workingCopy/electron-sandbox/workingCopyHistoryService.ts b/src/vs/workbench/services/workingCopy/electron-sandbox/workingCopyHistoryService.ts new file mode 100644 index 00000000000..f1ffc942c71 --- /dev/null +++ b/src/vs/workbench/services/workingCopy/electron-sandbox/workingCopyHistoryService.ts @@ -0,0 +1,56 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { ILifecycleService, WillShutdownEvent } from 'vs/workbench/services/lifecycle/common/lifecycle'; +import { IFileService } from 'vs/platform/files/common/files'; +import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService'; +import { IEnvironmentService } from 'vs/platform/environment/common/environment'; +import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity'; +import { ILabelService } from 'vs/platform/label/common/label'; +import { ILogService } from 'vs/platform/log/common/log'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; +import { WorkingCopyHistoryService } from 'vs/workbench/services/workingCopy/common/workingCopyHistoryService'; +import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; +import { IWorkingCopyHistoryService } from 'vs/workbench/services/workingCopy/common/workingCopyHistory'; + +export class NativeWorkingCopyHistoryService extends WorkingCopyHistoryService { + + constructor( + @IFileService fileService: IFileService, + @IRemoteAgentService remoteAgentService: IRemoteAgentService, + @IEnvironmentService environmentService: IEnvironmentService, + @IUriIdentityService uriIdentityService: IUriIdentityService, + @ILabelService labelService: ILabelService, + @ILifecycleService private readonly lifecycleService: ILifecycleService, + @ILogService logService: ILogService, + @IConfigurationService configurationService: IConfigurationService + ) { + super(fileService, remoteAgentService, environmentService, uriIdentityService, labelService, logService, configurationService); + + this.registerListeners(); + } + + private registerListeners(): void { + this.lifecycleService.onWillShutdown(e => this.onWillShutdown(e)); + } + + private onWillShutdown(e: WillShutdownEvent): void { + + // Prolong shutdown for orderly model shutdown + e.join((async () => { + const models = Array.from(this.models.values()); + for (const model of models) { + try { + await model.store(); + } catch (error) { + this.logService.trace(error); + } + } + })(), 'join.workingCopyHistory'); + } +} + +// Register Service +registerSingleton(IWorkingCopyHistoryService, NativeWorkingCopyHistoryService, true); diff --git a/src/vs/workbench/services/workingCopy/test/electron-browser/workingCopyHistoryService.test.ts b/src/vs/workbench/services/workingCopy/test/electron-browser/workingCopyHistoryService.test.ts index 5b491583455..81b63cc6adf 100644 --- a/src/vs/workbench/services/workingCopy/test/electron-browser/workingCopyHistoryService.test.ts +++ b/src/vs/workbench/services/workingCopy/test/electron-browser/workingCopyHistoryService.test.ts @@ -8,7 +8,6 @@ import { flakySuite } from 'vs/base/test/common/testUtils'; import { NativeWorkbenchEnvironmentService } from 'vs/workbench/services/environment/electron-sandbox/environmentService'; import { TestNativePathService, TestNativeWindowConfiguration } from 'vs/workbench/test/electron-browser/workbenchTestServices'; import { TestContextService, TestProductService, TestWorkingCopy } from 'vs/workbench/test/common/workbenchTestServices'; -import { WorkingCopyHistoryService } from 'vs/workbench/services/workingCopy/common/workingCopyHistoryService'; import { NullLogService } from 'vs/platform/log/common/log'; import { FileService } from 'vs/platform/files/common/fileService'; import { DiskFileSystemProvider } from 'vs/platform/files/node/diskFileSystemProvider'; @@ -28,6 +27,7 @@ import { LabelService } from 'vs/workbench/services/label/common/labelService'; import { TestLifecycleService, TestWillShutdownEvent } from 'vs/workbench/test/browser/workbenchTestServices'; import { dirname } from 'path'; import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService'; +import { NativeWorkingCopyHistoryService } from 'vs/workbench/services/workingCopy/electron-sandbox/workingCopyHistoryService'; class TestWorkbenchEnvironmentService extends NativeWorkbenchEnvironmentService { @@ -36,7 +36,7 @@ class TestWorkbenchEnvironmentService extends NativeWorkbenchEnvironmentService } } -export class TestWorkingCopyHistoryService extends WorkingCopyHistoryService { +export class TestWorkingCopyHistoryService extends NativeWorkingCopyHistoryService { readonly _fileService: IFileService; readonly _configurationService: TestConfigurationService; diff --git a/src/vs/workbench/workbench.common.main.ts b/src/vs/workbench/workbench.common.main.ts index d9911cce29d..dfc2bcadef0 100644 --- a/src/vs/workbench/workbench.common.main.ts +++ b/src/vs/workbench/workbench.common.main.ts @@ -97,7 +97,6 @@ import 'vs/workbench/services/assignment/common/assignmentService'; import 'vs/workbench/services/outline/browser/outlineService'; import 'vs/workbench/services/languageDetection/browser/languageDetectionWorkerServiceImpl'; import 'vs/editor/common/services/languageFeaturesService'; -import 'vs/workbench/services/workingCopy/common/workingCopyHistoryService'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { ExtensionGalleryService } from 'vs/platform/extensionManagement/common/extensionGalleryService'; diff --git a/src/vs/workbench/workbench.sandbox.main.ts b/src/vs/workbench/workbench.sandbox.main.ts index 4b363e7b336..5a9a2b64769 100644 --- a/src/vs/workbench/workbench.sandbox.main.ts +++ b/src/vs/workbench/workbench.sandbox.main.ts @@ -80,6 +80,7 @@ import 'vs/platform/profiling/electron-sandbox/profilingService'; import 'vs/platform/telemetry/electron-sandbox/customEndpointTelemetryService'; import 'vs/workbench/services/files/electron-sandbox/elevatedFileService'; import 'vs/workbench/services/search/electron-sandbox/searchService'; +import 'vs/workbench/services/workingCopy/electron-sandbox/workingCopyHistoryService'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { IUserDataInitializationService, UserDataInitializationService } from 'vs/workbench/services/userData/browser/userDataInit'; diff --git a/src/vs/workbench/workbench.web.main.ts b/src/vs/workbench/workbench.web.main.ts index 757d9d91f7a..cb8ee5c4ce7 100644 --- a/src/vs/workbench/workbench.web.main.ts +++ b/src/vs/workbench/workbench.web.main.ts @@ -59,6 +59,7 @@ import 'vs/workbench/services/encryption/browser/encryptionService'; import 'vs/workbench/services/workingCopy/browser/workingCopyBackupService'; import 'vs/workbench/services/tunnel/browser/tunnelService'; import 'vs/workbench/services/files/browser/elevatedFileService'; +import 'vs/workbench/services/workingCopy/browser/workingCopyHistoryService'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';