src/vs/platform/actions/browser/toolbar.ts/WorkbenchToolBar/setActions
class WorkbenchToolBar:	override setActions(_primary: readonly IAction[], _secondary: readonly IAction[] = [], menuIds?: readonly MenuId[]): void {

		this._sessionDisposables.clear();
		const primary = _primary.slice();
		const secondary = _secondary.slice();
		const toggleActions: IAction[] = [];

		const extraSecondary: IAction[] = [];

		let someAreHidden = false;
		// unless disabled, move all hidden items to secondary group or ignore them
		if (this._options?.hiddenItemStrategy !== HiddenItemStrategy.NoHide) {
			for (let i = 0; i < primary.length; i++) {
				const action = primary[i];
				if (!(action instanceof MenuItemAction) && !(action instanceof SubmenuItemAction)) {
					// console.warn(`Action ${action.id}/${action.label} is not a MenuItemAction`);
					continue;
				}
				if (!action.hideActions) {
					continue;
				}

				// collect all toggle actions
				toggleActions.push(action.hideActions.toggle);

				// hidden items move into overflow or ignore
				if (action.hideActions.isHidden) {
					someAreHidden = true;
					primary[i] = undefined!;
					if (this._options?.hiddenItemStrategy !== HiddenItemStrategy.Ignore) {
						extraSecondary[i] = action;
					}
				}
			}
		}

		// count for max
		if (this._options?.maxNumberOfItems !== undefined) {
			let count = 0;
			for (let i = 0; i < primary.length; i++) {
				const action = primary[i];
				if (!action) {
					continue;
				}
				if (++count >= this._options.maxNumberOfItems) {
					primary[i] = undefined!;
					extraSecondary[i] = action;
				}
			}
		}

		coalesceInPlace(primary);
		coalesceInPlace(extraSecondary);
		super.setActions(primary, Separator.join(extraSecondary, secondary));

		// add context menu for toggle actions
		if (toggleActions.length > 0) {
			this._sessionDisposables.add(addDisposableListener(this.getElement(), 'contextmenu', e => {

				const action = this.getItemAction(<HTMLElement>e.target);
				if (!(action)) {
					return;
				}
				e.preventDefault();
				e.stopPropagation();

				let actions = toggleActions;

				// add "hide foo" actions
				let hideAction: IAction;
				if (action instanceof MenuItemAction || action instanceof SubmenuItemAction) {
					if (!action.hideActions) {
						// no context menu for MenuItemAction instances that support no hiding
						// those are fake actions and need to be cleaned up
						return;
					}
					hideAction = action.hideActions.hide;

				} else {
					hideAction = toAction({
						id: 'label',
						label: localize('hide', "Hide"),
						enabled: false,
						run() { }
					});
				}
				actions = [hideAction, new Separator(), ...toggleActions];

				// add "Reset Menu" action
				if (this._options?.resetMenu && !menuIds) {
					menuIds = [this._options.resetMenu];
				}
				if (someAreHidden && menuIds) {
					actions.push(new Separator());
					actions.push(toAction({
						id: 'resetThisMenu',
						label: localize('resetThisMenu', "Reset Menu"),
						run: () => this._menuService.resetHiddenStates(menuIds)
					}));
				}

				this._contextMenuService.showContextMenu({
					getAnchor: () => e,
					getActions: () => actions,
					// add context menu actions (iff appicable)
					menuId: this._options?.contextMenu,
					menuActionOptions: { renderShortTitle: true, ...this._options?.menuOptions },
					contextKeyService: this._contextKeyService,
				});
			}));
		}
	}