From 6a315f2d4317489f256b158650f5458ac6e6e57a Mon Sep 17 00:00:00 2001 From: Bhavya U Date: Tue, 6 Feb 2024 01:25:50 -0800 Subject: [PATCH] Adopt registerWorkbenchContribution2 for welcome page (#204440) * Adopt registerWorkbenchContribution2 for welcome page * create GettingStartedInput editor before opening it * split resolver and runner * Set StartupPageRunnerContribution to instantiate after Restore * Update comment --------- Co-authored-by: Benjamin Pasero --- src/vs/workbench/common/contributions.ts | 3 ++ .../browser/gettingStarted.contribution.ts | 16 +++---- .../browser/startupPage.ts | 43 ++++++++++++------- 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/src/vs/workbench/common/contributions.ts b/src/vs/workbench/common/contributions.ts index be5d2a78808f8..b96df67819647 100644 --- a/src/vs/workbench/common/contributions.ts +++ b/src/vs/workbench/common/contributions.ts @@ -22,6 +22,9 @@ export interface IWorkbenchContribution { } export namespace Extensions { + /** + * @deprecated use `registerWorkbenchContribution2` instead. + */ export const Workbench = 'workbench.contributions.kind'; } diff --git a/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.contribution.ts b/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.contribution.ts index 683831a49f295..fc6c589ca160c 100644 --- a/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.contribution.ts +++ b/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.contribution.ts @@ -17,8 +17,7 @@ import { EditorPaneDescriptor, IEditorPaneRegistry } from 'vs/workbench/browser/ import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; import { IWalkthroughsService } from 'vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedService'; import { GettingStartedEditorOptions, GettingStartedInput } from 'vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedInput'; -import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions'; -import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle'; +import { registerWorkbenchContribution2, WorkbenchPhase } from 'vs/workbench/common/contributions'; import { ConfigurationScope, Extensions as ConfigurationExtensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry'; import { workbenchConfigurationNodeBase } from 'vs/workbench/common/configuration'; import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; @@ -28,7 +27,7 @@ import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteA import { isLinux, isMacintosh, isWindows, OperatingSystem as OS } from 'vs/base/common/platform'; import { IExtensionManagementServerService } from 'vs/workbench/services/extensionManagement/common/extensionManagement'; import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; -import { StartupPageContribution, } from 'vs/workbench/contrib/welcomeGettingStarted/browser/startupPage'; +import { StartupPageEditorResolverContribution, StartupPageRunnerContribution } from 'vs/workbench/contrib/welcomeGettingStarted/browser/startupPage'; import { ExtensionsInput } from 'vs/workbench/contrib/extensions/common/extensionsInput'; import { Categories } from 'vs/platform/action/common/actionCommonCategories'; @@ -269,6 +268,9 @@ registerAction2(class extends Action2 { export const WorkspacePlatform = new RawContextKey<'mac' | 'linux' | 'windows' | 'webworker' | undefined>('workspacePlatform', undefined, localize('workspacePlatform', "The platform of the current workspace, which in remote or serverless contexts may be different from the platform of the UI")); class WorkspacePlatformContribution { + + static readonly ID = 'workbench.contrib.workspacePlatform'; + constructor( @IExtensionManagementServerService private readonly extensionManagementServerService: IExtensionManagementServerService, @IRemoteAgentService private readonly remoteAgentService: IRemoteAgentService, @@ -301,9 +303,6 @@ class WorkspacePlatformContribution { } } -Registry.as(WorkbenchExtensions.Workbench) - .registerWorkbenchContribution(WorkspacePlatformContribution, LifecyclePhase.Restored); - const configurationRegistry = Registry.as(ConfigurationExtensions.Configuration); configurationRegistry.registerConfiguration({ ...workbenchConfigurationNodeBase, @@ -339,5 +338,6 @@ configurationRegistry.registerConfiguration({ } }); -Registry.as(WorkbenchExtensions.Workbench) - .registerWorkbenchContribution(StartupPageContribution, LifecyclePhase.Restored); +registerWorkbenchContribution2(WorkspacePlatformContribution.ID, WorkspacePlatformContribution, WorkbenchPhase.AfterRestored); +registerWorkbenchContribution2(StartupPageEditorResolverContribution.ID, StartupPageEditorResolverContribution, WorkbenchPhase.BlockRestore); +registerWorkbenchContribution2(StartupPageRunnerContribution.ID, StartupPageRunnerContribution, WorkbenchPhase.AfterRestored); diff --git a/src/vs/workbench/contrib/welcomeGettingStarted/browser/startupPage.ts b/src/vs/workbench/contrib/welcomeGettingStarted/browser/startupPage.ts index da1a4f35e0fcc..a79946bb52578 100644 --- a/src/vs/workbench/contrib/welcomeGettingStarted/browser/startupPage.ts +++ b/src/vs/workbench/contrib/welcomeGettingStarted/browser/startupPage.ts @@ -13,7 +13,7 @@ import { onUnexpectedError } from 'vs/base/common/errors'; import { IWorkspaceContextService, UNKNOWN_EMPTY_WINDOW_WORKSPACE, WorkbenchState } from 'vs/platform/workspace/common/workspace'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IWorkingCopyBackupService } from 'vs/workbench/services/workingCopy/common/workingCopyBackup'; -import { ILifecycleService, StartupKind } from 'vs/workbench/services/lifecycle/common/lifecycle'; +import { ILifecycleService, LifecyclePhase, StartupKind } from 'vs/workbench/services/lifecycle/common/lifecycle'; import { IFileService } from 'vs/platform/files/common/files'; import { joinPath } from 'vs/base/common/resources'; import { IEditorOptions } from 'vs/platform/editor/common/editor'; @@ -37,23 +37,12 @@ const configurationKey = 'workbench.startupEditor'; const oldConfigurationKey = 'workbench.welcome.enabled'; const telemetryOptOutStorageKey = 'workbench.telemetryOptOutShown'; -export class StartupPageContribution implements IWorkbenchContribution { +export class StartupPageEditorResolverContribution implements IWorkbenchContribution { + + static readonly ID = 'workbench.contrib.startupPageEditorResolver'; constructor( @IInstantiationService private readonly instantiationService: IInstantiationService, - @IConfigurationService private readonly configurationService: IConfigurationService, - @IEditorService private readonly editorService: IEditorService, - @IWorkingCopyBackupService private readonly workingCopyBackupService: IWorkingCopyBackupService, - @IFileService private readonly fileService: IFileService, - @IWorkspaceContextService private readonly contextService: IWorkspaceContextService, - @ILifecycleService private readonly lifecycleService: ILifecycleService, - @IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService, - @IProductService private readonly productService: IProductService, - @ICommandService private readonly commandService: ICommandService, - @IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService, - @IStorageService private readonly storageService: IStorageService, - @ILogService private readonly logService: ILogService, - @INotificationService private readonly notificationService: INotificationService, @IEditorResolverService editorResolverService: IEditorResolverService ) { editorResolverService.registerEditor( @@ -79,12 +68,36 @@ export class StartupPageContribution implements IWorkbenchContribution { } } ); + } +} + +export class StartupPageRunnerContribution implements IWorkbenchContribution { + static readonly ID = 'workbench.contrib.startupPageRunner'; + + constructor( + @IConfigurationService private readonly configurationService: IConfigurationService, + @IEditorService private readonly editorService: IEditorService, + @IWorkingCopyBackupService private readonly workingCopyBackupService: IWorkingCopyBackupService, + @IFileService private readonly fileService: IFileService, + @IWorkspaceContextService private readonly contextService: IWorkspaceContextService, + @ILifecycleService private readonly lifecycleService: ILifecycleService, + @IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService, + @IProductService private readonly productService: IProductService, + @ICommandService private readonly commandService: ICommandService, + @IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService, + @IStorageService private readonly storageService: IStorageService, + @ILogService private readonly logService: ILogService, + @INotificationService private readonly notificationService: INotificationService + ) { this.run().then(undefined, onUnexpectedError); } private async run() { + // Wait for resolving startup editor until we are restored to reduce startup pressure + await this.lifecycleService.when(LifecyclePhase.Restored); + // Always open Welcome page for first-launch, no matter what is open or which startupEditor is set. if ( this.productService.enableTelemetry