File tree Expand file tree Collapse file tree 3 files changed +25
-5
lines changed
workbench/services/actions/common Expand file tree Collapse file tree 3 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ export function isISubmenuItem(item: IMenuItem | ISubmenuItem): item is ISubmenu
45
45
46
46
export class MenuId {
47
47
48
- private static readonly _idPool = new Set < string > ( ) ;
48
+ private static readonly _instances = new Map < string , MenuId > ( ) ;
49
49
50
50
static readonly CommandPalette = new MenuId ( 'CommandPalette' ) ;
51
51
static readonly DebugBreakpointsContext = new MenuId ( 'DebugBreakpointsContext' ) ;
@@ -162,14 +162,25 @@ export class MenuId {
162
162
static readonly NewFile = new MenuId ( 'NewFile' ) ;
163
163
static readonly MergeToolbar = new MenuId ( 'MergeToolbar' ) ;
164
164
165
+ /**
166
+ * Create or reuse a `MenuId` with the given identifier
167
+ */
168
+ static for ( identifier : string ) : MenuId {
169
+ return MenuId . _instances . get ( identifier ) ?? new MenuId ( identifier ) ;
170
+ }
165
171
166
172
readonly id : string ;
167
173
174
+ /**
175
+ * Create a new `MenuId` with the unique identifier. Will throw if a menu
176
+ * with the identifier already exists, use `MenuId.for(ident)` or a unique
177
+ * identifier
178
+ */
168
179
constructor ( identifier : string ) {
169
- if ( MenuId . _idPool . has ( identifier ) ) {
170
- throw new Error ( `Duplicate menu identifier ${ identifier } `) ;
180
+ if ( MenuId . _instances . has ( identifier ) ) {
181
+ throw new TypeError ( `MenuId with identifier ' ${ identifier } ' already exists. Use MenuId.for(ident) or a unique identifier `) ;
171
182
}
172
- MenuId . _idPool . add ( identifier ) ;
183
+ MenuId . _instances . set ( identifier , this ) ;
173
184
this . id = identifier ;
174
185
}
175
186
}
Original file line number Diff line number Diff line change @@ -202,4 +202,13 @@ suite('MenuService', function () {
202
202
assert . strictEqual ( foundA , true ) ;
203
203
assert . strictEqual ( foundB , true ) ;
204
204
} ) ;
205
+
206
+ test ( 'Extension contributed submenus missing with errors in output #155030' , function ( ) {
207
+
208
+ const id = generateUuid ( ) ;
209
+ const menu = new MenuId ( id ) ;
210
+
211
+ assert . throws ( ( ) => new MenuId ( id ) ) ;
212
+ assert . ok ( menu === MenuId . for ( id ) ) ;
213
+ } ) ;
205
214
} ) ;
Original file line number Diff line number Diff line change @@ -717,7 +717,7 @@ submenusExtensionPoint.setHandler(extensions => {
717
717
}
718
718
719
719
const item : IRegisteredSubmenu = {
720
- id : new MenuId ( `api:${ submenuInfo . id } ` ) ,
720
+ id : MenuId . for ( `api:${ submenuInfo . id } ` ) ,
721
721
label : submenuInfo . label ,
722
722
icon : absoluteIcon
723
723
} ;
You can’t perform that action at this time.
0 commit comments