@@ -51,7 +51,10 @@ import getBaseServiceOverride from './service-override/base'
5151import { injectCss } from './css'
5252import deprecatedProduct from 'vs/platform/product/common/product'
5353import { mixin } from 'vs/base/common/objects'
54-
54+ import { CommandsRegistry } from 'vs/platform/commands/common/commands'
55+ import { asArray } from 'vs/base/common/arrays'
56+ import { MenuId , MenuRegistry } from 'vs/platform/actions/common/actions'
57+ import { Menu } from 'vs/workbench/browser/web.api'
5558declare global {
5659 interface Window {
5760 monacoVscodeApiBuildId ?: string
@@ -66,6 +69,40 @@ if (window.monacoVscodeApiBuildId != null && window.monacoVscodeApiBuildId !== B
6669
6770window . monacoVscodeApiBuildId = BUILD_ID
6871
72+ /**
73+ * This function comes from VSCode (vs/workbench/browser/web.factory.ts)
74+ * It's duplicated here because it's not exported and used in a code we can't simply run
75+ */
76+ function registerCommands ( options : IWorkbenchConstructionOptions ) {
77+ function asMenuId ( menu : Menu ) : MenuId {
78+ switch ( menu ) {
79+ case Menu . CommandPalette :
80+ return MenuId . CommandPalette
81+ case Menu . StatusBarWindowIndicatorMenu :
82+ return MenuId . StatusBarWindowIndicatorMenu
83+ }
84+ }
85+
86+ if ( Array . isArray ( options . commands ) ) {
87+ for ( const command of options . commands ) {
88+ CommandsRegistry . registerCommand ( command . id , ( accessor , ...args ) => {
89+ // we currently only pass on the arguments but not the accessor
90+ // to the command to reduce our exposure of internal API.
91+ return command . handler ( ...args )
92+ } )
93+
94+ // Commands with labels appear in the command palette
95+ if ( command . label ) {
96+ for ( const menu of asArray ( command . menu ?? Menu . CommandPalette ) ) {
97+ MenuRegistry . appendMenuItem ( asMenuId ( menu ) , {
98+ command : { id : command . id , title : command . label }
99+ } )
100+ }
101+ }
102+ }
103+ }
104+ }
105+
69106export async function initialize (
70107 overrides : IEditorOverrideServices ,
71108 container : HTMLElement = document . body ,
@@ -75,6 +112,7 @@ export async function initialize(
75112 checkServicesNotInitialized ( )
76113
77114 injectCss ( container )
115+ registerCommands ( configuration )
78116 initializeWorkbench ( container , configuration , env )
79117
80118 const productService : IProductService = mixin (
0 commit comments