From 21ccfc1c1fb71901bff12dcd722e0b88b22c836c Mon Sep 17 00:00:00 2001 From: Bhavya U Date: Mon, 5 Feb 2024 18:40:02 -0800 Subject: [PATCH 1/5] Adopt registerWorkbenchContribution2 for welcome page --- .../browser/gettingStarted.contribution.ts | 11 ++++------- .../welcomeGettingStarted/browser/startupPage.ts | 2 ++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.contribution.ts b/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.contribution.ts index 683831a49f295..bd294c822c2d6 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 { Extensions as WorkbenchExtensions, 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,9 +27,9 @@ 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 { ExtensionsInput } from 'vs/workbench/contrib/extensions/common/extensionsInput'; import { Categories } from 'vs/platform/action/common/actionCommonCategories'; +import { StartupPageContribution } from 'vs/workbench/contrib/welcomeGettingStarted/browser/startupPage'; export * as icons from 'vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedIcons'; @@ -301,8 +300,7 @@ class WorkspacePlatformContribution { } } -Registry.as(WorkbenchExtensions.Workbench) - .registerWorkbenchContribution(WorkspacePlatformContribution, LifecyclePhase.Restored); +registerWorkbenchContribution2(WorkbenchExtensions.Workbench, WorkspacePlatformContribution, WorkbenchPhase.AfterRestored); const configurationRegistry = Registry.as(ConfigurationExtensions.Configuration); configurationRegistry.registerConfiguration({ @@ -339,5 +337,4 @@ configurationRegistry.registerConfiguration({ } }); -Registry.as(WorkbenchExtensions.Workbench) - .registerWorkbenchContribution(StartupPageContribution, LifecyclePhase.Restored); +registerWorkbenchContribution2(StartupPageContribution.ID, StartupPageContribution, WorkbenchPhase.AfterRestored); diff --git a/src/vs/workbench/contrib/welcomeGettingStarted/browser/startupPage.ts b/src/vs/workbench/contrib/welcomeGettingStarted/browser/startupPage.ts index da1a4f35e0fcc..f22030229a639 100644 --- a/src/vs/workbench/contrib/welcomeGettingStarted/browser/startupPage.ts +++ b/src/vs/workbench/contrib/welcomeGettingStarted/browser/startupPage.ts @@ -39,6 +39,8 @@ const telemetryOptOutStorageKey = 'workbench.telemetryOptOutShown'; export class StartupPageContribution implements IWorkbenchContribution { + static readonly ID = 'workbench.contrib.startupPage'; + constructor( @IInstantiationService private readonly instantiationService: IInstantiationService, @IConfigurationService private readonly configurationService: IConfigurationService, From 398c0950a02c1fd386ce6665d2ac6133c247d93c Mon Sep 17 00:00:00 2001 From: Bhavya U Date: Mon, 5 Feb 2024 21:53:03 -0800 Subject: [PATCH 2/5] create GettingStartedInput editor before opening it --- .../browser/gettingStarted.contribution.ts | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.contribution.ts b/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.contribution.ts index bd294c822c2d6..e91b789adda94 100644 --- a/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.contribution.ts +++ b/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.contribution.ts @@ -16,7 +16,7 @@ import { KeyCode } from 'vs/base/common/keyCodes'; import { EditorPaneDescriptor, IEditorPaneRegistry } from 'vs/workbench/browser/editor'; 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 { GettingStartedInput } from 'vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedInput'; import { Extensions as WorkbenchExtensions, 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'; @@ -61,13 +61,16 @@ registerAction2(class extends Action2 { if (walkthroughID) { const selectedCategory = typeof walkthroughID === 'string' ? walkthroughID : walkthroughID.category; const selectedStep = typeof walkthroughID === 'string' ? undefined : walkthroughID.step; + const editor = instantiationService.createInstance(GettingStartedInput, + { + selectedCategory: selectedCategory, + selectedStep: selectedStep, + preserveFocus: toSide ?? false + }); // We're trying to open the welcome page from the Help menu if (!selectedCategory && !selectedStep) { - editorService.openEditor({ - resource: GettingStartedInput.RESOURCE, - options: { preserveFocus: toSide ?? false } - }, toSide ? SIDE_GROUP : undefined); + editorService.openEditor(editor, toSide ? SIDE_GROUP : undefined); return; } @@ -105,23 +108,18 @@ registerAction2(class extends Action2 { const activeGroup = editorGroupsService.activeGroup; activeGroup.replaceEditors([{ editor: activeEditor, - replacement: instantiationService.createInstance(GettingStartedInput, { selectedCategory: selectedCategory, selectedStep: selectedStep }) + replacement: editor }]); } else { // else open respecting toSide - editorService.openEditor({ - resource: GettingStartedInput.RESOURCE, - options: { selectedCategory: selectedCategory, selectedStep: selectedStep, preserveFocus: toSide ?? false } - }, toSide ? SIDE_GROUP : undefined).then((editor) => { + editorService.openEditor(editor, toSide ? SIDE_GROUP : undefined).then((editor) => { (editor as GettingStartedPage)?.makeCategoryVisibleWhenAvailable(selectedCategory, selectedStep); }); } } else { - editorService.openEditor({ - resource: GettingStartedInput.RESOURCE, - options: { preserveFocus: toSide ?? false } - }, toSide ? SIDE_GROUP : undefined); + const editor = instantiationService.createInstance(GettingStartedInput, { preserveFocus: toSide ?? false }); + editorService.openEditor(editor, toSide ? SIDE_GROUP : undefined); } } }); From ee5fd707f68121bcc195745424ed4b425acdd781 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Tue, 6 Feb 2024 07:18:54 +0100 Subject: [PATCH 3/5] split resolver and runner --- src/vs/workbench/common/contributions.ts | 3 ++ .../browser/gettingStarted.contribution.ts | 13 ++++--- .../browser/startupPage.ts | 38 +++++++++++-------- 3 files changed, 34 insertions(+), 20 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 e91b789adda94..c30198bc916a2 100644 --- a/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.contribution.ts +++ b/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.contribution.ts @@ -17,7 +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 { GettingStartedInput } from 'vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedInput'; -import { Extensions as WorkbenchExtensions, registerWorkbenchContribution2, WorkbenchPhase } from 'vs/workbench/common/contributions'; +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'; @@ -27,9 +27,9 @@ 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 { 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'; -import { StartupPageContribution } from 'vs/workbench/contrib/welcomeGettingStarted/browser/startupPage'; export * as icons from 'vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedIcons'; @@ -266,6 +266,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, @@ -298,8 +301,6 @@ class WorkspacePlatformContribution { } } -registerWorkbenchContribution2(WorkbenchExtensions.Workbench, WorkspacePlatformContribution, WorkbenchPhase.AfterRestored); - const configurationRegistry = Registry.as(ConfigurationExtensions.Configuration); configurationRegistry.registerConfiguration({ ...workbenchConfigurationNodeBase, @@ -335,4 +336,6 @@ configurationRegistry.registerConfiguration({ } }); -registerWorkbenchContribution2(StartupPageContribution.ID, StartupPageContribution, WorkbenchPhase.AfterRestored); +registerWorkbenchContribution2(WorkspacePlatformContribution.ID, WorkspacePlatformContribution, WorkbenchPhase.AfterRestored); +registerWorkbenchContribution2(StartupPageEditorResolverContribution.ID, StartupPageEditorResolverContribution, WorkbenchPhase.BlockRestore); +registerWorkbenchContribution2(StartupPageRunnerContribution.ID, StartupPageRunnerContribution, { editorTypeId: GettingStartedPage.ID, }); diff --git a/src/vs/workbench/contrib/welcomeGettingStarted/browser/startupPage.ts b/src/vs/workbench/contrib/welcomeGettingStarted/browser/startupPage.ts index f22030229a639..17a7a470f96dc 100644 --- a/src/vs/workbench/contrib/welcomeGettingStarted/browser/startupPage.ts +++ b/src/vs/workbench/contrib/welcomeGettingStarted/browser/startupPage.ts @@ -37,25 +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.startupPage'; + 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( @@ -81,7 +68,28 @@ 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); } From 600ffdacd168e89485b3d9cb8a34965f02be1818 Mon Sep 17 00:00:00 2001 From: Bhavya U Date: Mon, 5 Feb 2024 23:07:26 -0800 Subject: [PATCH 4/5] Set StartupPageRunnerContribution to instantiate after Restore --- .../browser/gettingStarted.contribution.ts | 28 ++++++++++--------- .../browser/startupPage.ts | 4 ++- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.contribution.ts b/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.contribution.ts index c30198bc916a2..fc6c589ca160c 100644 --- a/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.contribution.ts +++ b/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.contribution.ts @@ -16,7 +16,7 @@ import { KeyCode } from 'vs/base/common/keyCodes'; import { EditorPaneDescriptor, IEditorPaneRegistry } from 'vs/workbench/browser/editor'; import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; import { IWalkthroughsService } from 'vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedService'; -import { GettingStartedInput } from 'vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedInput'; +import { GettingStartedEditorOptions, GettingStartedInput } from 'vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedInput'; 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'; @@ -61,16 +61,13 @@ registerAction2(class extends Action2 { if (walkthroughID) { const selectedCategory = typeof walkthroughID === 'string' ? walkthroughID : walkthroughID.category; const selectedStep = typeof walkthroughID === 'string' ? undefined : walkthroughID.step; - const editor = instantiationService.createInstance(GettingStartedInput, - { - selectedCategory: selectedCategory, - selectedStep: selectedStep, - preserveFocus: toSide ?? false - }); // We're trying to open the welcome page from the Help menu if (!selectedCategory && !selectedStep) { - editorService.openEditor(editor, toSide ? SIDE_GROUP : undefined); + editorService.openEditor({ + resource: GettingStartedInput.RESOURCE, + options: { preserveFocus: toSide ?? false } + }, toSide ? SIDE_GROUP : undefined); return; } @@ -108,18 +105,23 @@ registerAction2(class extends Action2 { const activeGroup = editorGroupsService.activeGroup; activeGroup.replaceEditors([{ editor: activeEditor, - replacement: editor + replacement: instantiationService.createInstance(GettingStartedInput, { selectedCategory: selectedCategory, selectedStep: selectedStep }) }]); } else { // else open respecting toSide - editorService.openEditor(editor, toSide ? SIDE_GROUP : undefined).then((editor) => { + editorService.openEditor({ + resource: GettingStartedInput.RESOURCE, + options: { selectedCategory: selectedCategory, selectedStep: selectedStep, preserveFocus: toSide ?? false } + }, toSide ? SIDE_GROUP : undefined).then((editor) => { (editor as GettingStartedPage)?.makeCategoryVisibleWhenAvailable(selectedCategory, selectedStep); }); } } else { - const editor = instantiationService.createInstance(GettingStartedInput, { preserveFocus: toSide ?? false }); - editorService.openEditor(editor, toSide ? SIDE_GROUP : undefined); + editorService.openEditor({ + resource: GettingStartedInput.RESOURCE, + options: { preserveFocus: toSide ?? false } + }, toSide ? SIDE_GROUP : undefined); } } }); @@ -338,4 +340,4 @@ configurationRegistry.registerConfiguration({ registerWorkbenchContribution2(WorkspacePlatformContribution.ID, WorkspacePlatformContribution, WorkbenchPhase.AfterRestored); registerWorkbenchContribution2(StartupPageEditorResolverContribution.ID, StartupPageEditorResolverContribution, WorkbenchPhase.BlockRestore); -registerWorkbenchContribution2(StartupPageRunnerContribution.ID, StartupPageRunnerContribution, { editorTypeId: GettingStartedPage.ID, }); +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 17a7a470f96dc..c93d7ce87d2b0 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'; @@ -95,6 +95,8 @@ export class StartupPageRunnerContribution implements IWorkbenchContribution { private async run() { + 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 From 96cf2c2d997dbda9213f42627dc1c3e62fb1d3d1 Mon Sep 17 00:00:00 2001 From: Bhavya U Date: Mon, 5 Feb 2024 23:13:35 -0800 Subject: [PATCH 5/5] Update comment --- .../contrib/welcomeGettingStarted/browser/startupPage.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/vs/workbench/contrib/welcomeGettingStarted/browser/startupPage.ts b/src/vs/workbench/contrib/welcomeGettingStarted/browser/startupPage.ts index c93d7ce87d2b0..a79946bb52578 100644 --- a/src/vs/workbench/contrib/welcomeGettingStarted/browser/startupPage.ts +++ b/src/vs/workbench/contrib/welcomeGettingStarted/browser/startupPage.ts @@ -95,6 +95,7 @@ export class StartupPageRunnerContribution implements IWorkbenchContribution { 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.