Skip to content

Visual Studio Code, rebuilt in Rust

Rust
138 KB
Raw Blame
//! Menus of platform/actions/common/actions.ts (`MenuRegistry`, `MenuId`) and menuService.ts: items with a
//! group, an order and a `when`, sorted and grouped as `MenuInfo.compareMenuItems`, flattened with separators
//! between groups as `getFlatContextMenuActions`.

#[cfg(test)]
mod tests;

use std::cmp::Ordering;
use std::sync::LazyLock;

use exthost::scan::ScannedExtension;
use regex::Regex;
use serde_json::Value;

use crate::command_palette::locale_compare;
use crate::contextkey::{Context, Expr};
use crate::notifications::Severity;

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[allow(clippy::enum_variant_names, reason = "upstream MenuId names")]
pub enum MenuId {
    MenubarMainMenu,
    MenubarFileMenu,
    NewFile,
    MenubarRecentMenu,
    MenubarEditMenu,
    MenubarSelectionMenu,
    MenubarViewMenu,
    MenubarGoMenu,
    MenubarLayoutMenu,
    MenubarSwitchEditorMenu,
    MenubarSwitchGroupMenu,
    MenubarHelpMenu,
    MenubarPreferencesMenu,
    MenubarAppearanceMenu,
    /// `MenuId.EditorTabsBarShowTabsSubmenu`, its zen mode variant and `MenuId.EditorActionsPositionSubmenu`.
    EditorTabsBarShowTabsSubmenu,
    EditorTabsBarShowTabsZenModeSubmenu,
    EditorActionsPositionSubmenu,
    /// `MenuId.EditorTabsBarContext`: the context menu of the tab bar's empty space.
    EditorTabsBarContext,
    ActivityBarPositionMenu,
    PanelPositionMenu,
    PanelAlignmentMenu,
    /// layoutDensityActions.ts `LayoutDensityMenu`.
    LayoutDensityMenu,
    ThemesSubMenu,
    /// userDataProfile.ts `ProfilesMenu` and `OpenProfileMenu`.
    ProfilesMenu,
    OpenProfileMenu,
    GlobalActivity,
    MenubarCopy,
    MenubarShare,
    ExplorerContext,
    ExplorerContextShare,
    OpenEditorsContext,
    SearchContext,
    EditorContext,
    EditorContextCopy,
    EditorContextShare,
    EditorContextPeek,
    EditorTitleContext,
    EditorLineNumberContext,
    EditorTitleContextShare,
    EditorSplitMoveSubmenu,
    /// `MenuId.DiffEditorViewSubmenu`: the editor title `...`'s Diff View.
    DiffEditorViewSubmenu,
    /// `MenuId.MultiDiffEditorFilesViewAndPosition`: the multi diff editor title `...`'s Files View & Position.
    MultiDiffEditorFilesViewAndPosition,
    /// `MenuId.EmptyEditorGroupContext`: the context menu of an empty editor group.
    EmptyEditorGroupContext,
    StickyScrollContext,
    /// `MenuId.ModalEditorEditorTitle`: the modal editor part's editor actions.
    ModalEditorEditorTitle,
    /// `MenuId.InlineSuggestionToolbar`: the inline suggestion hover's toolbar, `primary*` groups as buttons.
    InlineSuggestionToolbar,
    /// `MenuId.InlineCompletionsActions`: the inline suggestion hover toolbar's extra `...` items.
    InlineCompletionsActions,
    /// `MenuId.TitleBar`: the title bar's global toolbar.
    TitleBar,
    TitleBarContext,
    TitleBarTitleContext,
    ScmTitle,
    ScmResourceGroupContext,
    ScmResourceStateContext,
    /// `MenuId.SCMResourceFolderContext`: a tree mode folder row's actions and context menu.
    ScmResourceFolderContext,
    ScmInputBox,
    /// `MenuId.SCMSourceControl`: a repository row's context menu.
    ScmSourceControl,
    /// `MenuId.SCMSourceControlTitle`: the Repositories view's title.
    ScmSourceControlTitle,
    /// `MenuId.SCMSourceControlInline`: a Repositories view row's actions.
    ScmSourceControlInline,
    /// `MenuId.SCMArtifactGroupContext`: an artifact group row's actions in the Repositories view.
    ScmArtifactGroupContext,
    /// `MenuId.SCMArtifactContext`: an artifact row's actions and context menu.
    ScmArtifactContext,
    /// scmViewPane.ts `Menus.ViewSort`: the View & Sort submenu.
    ScmViewSort,
    /// scmViewPane.ts `Menus.Repositories`: the View & Sort submenu's Repositories submenu.
    ScmRepositories,
    ScmHistoryTitle,
    ScmHistoryItemContext,
    ScmHistoryItemChangeContext,
    /// `MenuId.SCMHistoryItemRefContext`: read per ref by a history item's context menu, never shown itself.
    ScmHistoryItemRefContext,
    /// `MenuId.for(actionId)`: the refs submenu of the `index`th `ScmHistoryItemRefContext` item.
    ScmHistoryItemRefAction(usize),
    ScmChangeContext,
    DiffEditorHunkToolbar,
    /// `MenuId.DiffEditorSelectionToolbar`: the diff gutter's one toolbar over the selected changes.
    DiffEditorSelectionToolbar,
    /// `MenuId.MultiDiffEditorFileToolbar`: a multi diff editor file header's toolbar.
    MultiDiffEditorFileToolbar,
    /// `MenuId.MultiDiffEditorContent`: the floating toolbar over the multi diff editor.
    MultiDiffEditorContent,
    /// `MenuId.MergeInputResultToolbar`: the merge editor result's title toolbar.
    MergeInputResultToolbar,
    EditorTitle,
    /// `MenuId.EditorTitleRun`: the editor title's Run or Debug... split button.
    EditorTitleRun,
    /// `MenuId.InteractiveToolbar`: the interactive window's and REPL editor's toolbar.
    InteractiveToolbar,
    /// `MenuId.NotebookOutputToolbar`: the `...` dropdown left of a notebook output.
    NotebookOutputToolbar,
    /// `MenuId.NotebookEditorLayoutConfigure`: the notebook editor title's Customize Notebook... submenu.
    NotebookEditorLayoutConfigure,
    /// `MenuId.NotebookToolbar`: the notebook editor's toolbar, its secondary items in the `...` dropdown.
    NotebookToolbar,
    /// `MenuId.NotebookCellTitle`: a cell's toolbar, `inline*` groups as buttons, the rest in its `...` dropdown.
    NotebookCellTitle,
    /// `MenuId.NotebookCellDelete`: the cell toolbar's last button.
    NotebookCellDelete,
    /// `MenuId.NotebookCellInsert`: the cell toolbar's Insert Cell submenu.
    NotebookCellInsert,
    /// `MenuId.NotebookCellExecute`: the dropdown beside a code cell's run button.
    NotebookCellExecute,
    /// `MenuId.NotebookKernelSource`: the kernel sources the kernel picker offers.
    NotebookKernelSource,
    /// `MenuId.NotebookVariablesContext`: a Notebook Variables row's context menu.
    NotebookVariablesContext,
    /// `MenuId.InteractiveCellTitle` and `InteractiveCellDelete`: the cell toolbar of an interactive window or REPL.
    InteractiveCellTitle,
    InteractiveCellDelete,
    TimelineTitle,
    TimelineItemContext,
    /// `MenuId.TestItem`: a test row's inline actions and context menu in the Testing view.
    TestItem,
    TestProfilesContext,
    /// `MenuId.TestItemGutter`: a test's items in the editor gutter's menu.
    TestItemGutter,
    /// `MenuId.TestPeekElement`, `TestMessageContext` and `TestMessageContent`: a Test Results row's actions, a
    /// message row's, and the message view's floating button.
    TestPeekElement,
    TestMessageContext,
    TestMessageContent,
    /// `MenuId.TestCallStack` and `DebugCallStackToolbar`: the actions of a Test Results call stack's message frame
    /// and of a frame with a source.
    TestCallStack,
    DebugCallStackToolbar,
    /// `MenuId.DebugCallStackContext`: a Call Stack row's context menu.
    DebugCallStackContext,
    /// `MenuId.DebugVariablesContext`: a Variables row's context menu.
    DebugVariablesContext,
    /// `MenuId.DebugWatchContext`: a Watch row's context menu.
    DebugWatchContext,
    /// `MenuId.DebugConsoleContext`: a Debug Console row's context menu.
    DebugConsoleContext,
    /// `MenuId.DebugHoverContext`: a debug hover tree row's context menu.
    DebugHoverContext,
    /// `MenuId.DebugToolBar`: the floating debug toolbar's actions.
    DebugToolBar,
    /// `MenuId.DebugToolBarStop`: the dropdown beside the debug toolbar's Stop or Disconnect.
    DebugToolBarStop,
    /// `MenuId.DebugCreateConfiguration`: items appended to the Select Debugger picker.
    DebugCreateConfiguration,
    /// timeline.contribution.ts "Filter Timeline": a toggle per timeline source.
    TimelineFilterSubMenu,
    ViewTitle,
    /// `MenuId.ViewContainerTitle`: a view container's title actions and `...`, read with `viewContainer` set.
    ViewContainerTitle,
    /// `MenuId.ExtensionContext`: an extension's Manage menu and its list row's context menu, read with the extension's keys.
    ExtensionContext,
    ViewItemContext,
    EditorContent,
    /// `MenuId.WebviewContext`: a webview's context menu.
    WebviewContext,
    /// suggest.ts `suggestWidgetStatusbarMenu`.
    SuggestWidgetStatusBar,
    TerminalEditorInstanceContext,
    TerminalInstanceContext,
    TerminalTabContext,
    CommentThreadTitle,
    CommentThreadActions,
    /// `MenuId.CommentThreadAdditionalActions`: secondary buttons below a thread widget's body.
    CommentThreadAdditionalActions,
    CommentTitle,
    CommentActions,
    CommentsViewThreadActions,
    /// `MenuId.CommentEditorActions`: secondary buttons left of a reply or edit form's actions.
    CommentEditorActions,
    /// `MenuId.CommentThreadTitleContext`: the context menu of a thread widget's header.
    CommentThreadTitleContext,
    /// `MenuId.CommentThreadCommentContext`: the context menu of a comment in a thread widget.
    CommentThreadCommentContext,
    TerminalStickyScrollContext,
    /// A `contributes.submenus` entry, `MenuId.for('api:<id>')`, by registration order.
    Api(usize),
    #[cfg(test)]
    Test,
}

#[derive(Clone, Debug)]
#[allow(clippy::large_enum_variant, reason = "a few dozen items, built once")]
pub enum Entry {
    Command { id: String, precondition: Option<Expr>, toggled: Option<Toggled>, alt: Option<Alt> },
    Submenu { submenu: MenuId, toggled: Option<Expr> },
}

/// `ICommandAction.toggled`: checked while `condition` holds, with `title` as the label and `icon` as the codicon then.
#[derive(Clone, Debug)]
pub struct Toggled {
    pub condition: Expr,
    pub title: Option<String>,
    pub icon: Option<String>,
}

impl Toggled {
    pub fn when(condition: Option<Expr>) -> Option<Self> {
        condition.map(|condition| Self { condition, title: None, icon: None })
    }
}

/// `IMenuItem.alt`: the command shown while Alt is held.
#[derive(Clone, Debug)]
pub struct Alt {
    pub id: String,
    pub title: String,
    pub precondition: Option<Expr>,
}

/// `IMenuItem` or `ISubmenuItem`; `title` keeps upstream's `&&` mnemonics.
#[derive(Clone, Debug)]
pub struct MenuItem {
    pub menu: MenuId,
    pub entry: Entry,
    pub title: String,
    pub group: String,
    pub order: f64,
    pub when: Option<Expr>,
}

/// `MenuItemAction`, `SubmenuItemAction` or `Separator`, as a menu shows them.
#[derive(Clone, Debug, PartialEq)]
pub enum MenuAction {
    /// `alt` is set only while its precondition holds, as `getActionForAltMode` shows it only then.
    Command { id: String, title: String, enabled: bool, checked: bool, alt: Option<(String, String)> },
    Submenu { title: String, actions: Vec<MenuAction>, checked: bool },
    Separator,
}

/// The workbench's registrations of the features the port has: menu, submenu or command id, title, group, order,
/// `when`, and the command's precondition.
type Row = (MenuId, Option<MenuId>, &'static str, &'static str, &'static str, f64, Option<&'static str>, Option<&'static str>);
/// taskService.ts `TaskExecutionSupportedContext`.
const TASK_EXECUTION_SUPPORTED: &str = "shellExecutionSupported && processExecutionSupported || customExecutionSupported";

const WORKBENCH_MENUS: &[Row] = &[
    // menubar.contribution.ts
    (MenuId::MenubarMainMenu, Some(MenuId::MenubarFileMenu), "", "&&File", "", 1., None, None),
    (MenuId::MenubarMainMenu, Some(MenuId::MenubarEditMenu), "", "&&Edit", "", 2., None, None),
    (MenuId::MenubarMainMenu, Some(MenuId::MenubarSelectionMenu), "", "&&Selection", "", 3., None, None),
    (MenuId::MenubarMainMenu, Some(MenuId::MenubarViewMenu), "", "&&View", "", 4., None, None),
    (MenuId::MenubarMainMenu, Some(MenuId::MenubarGoMenu), "", "&&Go", "", 5., None, None),
    (MenuId::MenubarMainMenu, Some(MenuId::MenubarHelpMenu), "", "&&Help", "", 8., None, None),
    (MenuId::MenubarMainMenu, Some(MenuId::MenubarPreferencesMenu), "", "&&Preferences", "", 9., Some("isMacNative"), None),
    // workspaceActions.ts, windowActions.ts and editor.contribution.ts
    (MenuId::MenubarFileMenu, None, "workbench.action.files.openFileFolder", "&&Open...", "2_open", 1., Some("isMacNative && openFolderWorkspaceSupport"), Some("isMacNative && openFolderWorkspaceSupport")),
    (MenuId::MenubarFileMenu, None, "workbench.action.files.openFile", "&&Open File...", "2_open", 1., Some("!isMacNative"), None),
    (MenuId::MenubarFileMenu, None, "workbench.action.files.openFolder", "Open &&Folder...", "2_open", 2., Some("openFolderWorkspaceSupport"), Some("openFolderWorkspaceSupport")),
    (MenuId::MenubarFileMenu, None, "workbench.action.openWorkspace", "Open Wor&&kspace from File...", "2_open", 3., Some("enterMultiRootWorkspaceSupport"), Some("enterMultiRootWorkspaceSupport")),
    (MenuId::MenubarFileMenu, Some(MenuId::MenubarRecentMenu), "", "Open &&Recent", "2_open", 4., None, None),
    (MenuId::MenubarFileMenu, None, "addRootFolder", "A&&dd Folder to Workspace...", "3_workspace", 1., Some("enterMultiRootWorkspaceSupport && !isSessionsWindow || !isSessionsWindow && workbenchState == 'workspace'"), None),
    (MenuId::MenubarFileMenu, None, "workbench.action.saveWorkspaceAs", "Save Workspace As...", "3_workspace", 2., Some("enterMultiRootWorkspaceSupport && !isSessionsWindow"), Some("enterMultiRootWorkspaceSupport && !isSessionsWindow")),
    (MenuId::MenubarFileMenu, None, "workbench.action.duplicateWorkspaceInNewWindow", "Duplicate Workspace", "3_workspace", 3., Some("enterMultiRootWorkspaceSupport && !isSessionsWindow"), Some("enterMultiRootWorkspaceSupport && !isSessionsWindow")),
    (MenuId::MenubarFileMenu, None, "workbench.action.closeFolder", "Close &&Folder", "6_close", 3., Some("workbenchState == 'folder' && emptyWorkspaceSupport && !isSessionsWindow"), Some("workbenchState != 'empty' && emptyWorkspaceSupport && !isSessionsWindow")),
    (MenuId::MenubarFileMenu, None, "workbench.action.closeFolder", "Close &&Workspace", "6_close", 3., Some("workbenchState == 'workspace' && emptyWorkspaceSupport && !isSessionsWindow"), Some("workbenchState != 'empty' && emptyWorkspaceSupport && !isSessionsWindow")),
    // windowActions.ts (electron-browser) `CloseWindowAction`
    (MenuId::MenubarFileMenu, None, "workbench.action.closeWindow", "Clos&&e Window", "6_close", 4., None, None),
    (MenuId::MenubarFileMenu, None, "workbench.action.newWindow", "New &&Window", "1_new", 3., None, None),
    // preferences.contribution.ts: macOS shows it under the application menu.
    (MenuId::MenubarFileMenu, Some(MenuId::MenubarPreferencesMenu), "", "&&Preferences", "5_autosave", 2., Some("!isMacNative"), None),
    // desktop.contribution.ts
    (MenuId::MenubarFileMenu, None, "workbench.action.quit", "E&&xit", "z_Exit", 1., Some("!isMac"), None),
    (MenuId::MenubarRecentMenu, None, "workbench.action.openRecent", "&&More...", "y_more", 1., None, None),
    (MenuId::MenubarRecentMenu, None, "workbench.action.clearRecentFiles", "&&Clear Recently Opened...", "z_clear", 1., None, None),
    // suggestController.ts: the suggest widget's status bar
    (MenuId::SuggestWidgetStatusBar, None, "selectNextSuggestion", "Select", "left", 0., Some("!suggestWidgetHasFocusedSuggestion"), None),
    (MenuId::SuggestWidgetStatusBar, None, "acceptSelectedSuggestion", "Insert", "left", 1., Some("suggestWidgetHasFocusedSuggestion && !suggestionHasInsertAndReplaceRange"), None),
    (MenuId::SuggestWidgetStatusBar, None, "acceptSelectedSuggestion", "Insert", "left", 1., Some("suggestWidgetHasFocusedSuggestion && suggestionHasInsertAndReplaceRange && suggestionInsertMode == 'insert'"), None),
    (MenuId::SuggestWidgetStatusBar, None, "acceptSelectedSuggestion", "Replace", "left", 1., Some("suggestWidgetHasFocusedSuggestion && suggestionHasInsertAndReplaceRange && suggestionInsertMode == 'replace'"), None),
    (MenuId::SuggestWidgetStatusBar, None, "acceptAlternativeSelectedSuggestion", "Replace", "left", 2., Some("suggestWidgetHasFocusedSuggestion && suggestionHasInsertAndReplaceRange && suggestionInsertMode == 'insert'"), None),
    (MenuId::SuggestWidgetStatusBar, None, "acceptAlternativeSelectedSuggestion", "Insert", "left", 2., Some("suggestWidgetHasFocusedSuggestion && suggestionHasInsertAndReplaceRange && suggestionInsertMode == 'replace'"), None),
    (MenuId::SuggestWidgetStatusBar, None, "toggleSuggestionDetails", "Show Less", "right", 1., Some("suggestWidgetDetailsVisible && suggestionCanResolve"), None),
    (MenuId::SuggestWidgetStatusBar, None, "toggleSuggestionDetails", "Show More", "right", 1., Some("!suggestWidgetDetailsVisible && suggestionCanResolve"), None),
    // fileActions.contribution.ts
    (MenuId::MenubarFileMenu, None, "workbench.action.files.newUntitledFile", "&&New Text File", "1_new", 1., None, None),
    // newFile.contribution.ts
    (MenuId::MenubarFileMenu, None, "welcome.showNewFileEntries", "New File...", "1_new", 2., Some("!isSessionsWindow"), Some("!isSessionsWindow")),
    (MenuId::NewFile, None, "workbench.action.files.newUntitledFile", "Text File", "file", 1., None, None),
    (MenuId::MenubarFileMenu, None, "workbench.action.files.save", "&&Save", "4_save", 1., None, Some("activeEditor || foldersViewVisible && sideBarFocus")),
    (MenuId::MenubarFileMenu, None, "workbench.action.files.saveAs", "Save &&As...", "4_save", 2., None, Some("activeEditor || foldersViewVisible && sideBarFocus")),
    (MenuId::MenubarFileMenu, None, "saveAll", "Save A&&ll", "4_save", 3., None, Some("dirtyWorkingCopies")),
    (
        MenuId::MenubarFileMenu,
        None,
        "workbench.action.files.revert",
        "Re&&vert File",
        "6_close",
        1.,
        None,
        Some("activeEditorCanRevert || resourceScheme != 'untitled' && foldersViewVisible && sideBarFocus"),
    ),
    (MenuId::MenubarGoMenu, None, "workbench.action.quickOpen", "Go to &&File...", "3_global_nav", 1., None, None),
    (MenuId::MenubarGoMenu, None, "editor.action.dirtydiff.next", "Next &&Change", "7_change_nav", 0., None, None),
    (MenuId::MenubarGoMenu, None, "editor.action.dirtydiff.previous", "Previous &&Change", "7_change_nav", 0., None, None),
    // searchActionsSymbol.ts and gotoSymbolQuickAccess.ts
    (MenuId::MenubarGoMenu, None, "workbench.action.showAllSymbols", "Go to Symbol in &&Workspace...", "3_global_nav", 2., None, None),
    (MenuId::MenubarGoMenu, None, "workbench.action.gotoSymbol", "Go to &&Symbol in Editor...", "4_symbol_nav", 1., None, None),
    // editor.contribution.ts, editorActions.ts and openEditorsView.ts: the editor group items of the menu bar.
    (MenuId::MenubarRecentMenu, None, "workbench.action.reopenClosedEditor", "&&Reopen Closed Editor", "1_editor", 1., None, Some("canReopenClosedEditor")),
    (MenuId::MenubarViewMenu, Some(MenuId::MenubarLayoutMenu), "", "Editor &&Layout", "2_appearance", 2., Some("!isSessionsWindow"), None),
    (MenuId::MenubarLayoutMenu, None, "workbench.action.splitEditorUp", "Split &&Up", "1_split", 1., None, None),
    (MenuId::MenubarLayoutMenu, None, "workbench.action.splitEditorDown", "Split &&Down", "1_split", 2., None, None),
    (MenuId::MenubarLayoutMenu, None, "workbench.action.splitEditorLeft", "Split &&Left", "1_split", 3., None, None),
    (MenuId::MenubarLayoutMenu, None, "workbench.action.splitEditorRight", "Split &&Right", "1_split", 4., None, None),
    (MenuId::MenubarLayoutMenu, None, "workbench.action.editorLayoutSingle", "&&Single", "4_layouts", 1., None, None),
    (MenuId::MenubarLayoutMenu, None, "workbench.action.editorLayoutTwoColumns", "&&Two Columns", "4_layouts", 3., None, None),
    (MenuId::MenubarLayoutMenu, None, "workbench.action.editorLayoutThreeColumns", "T&&hree Columns", "4_layouts", 4., None, None),
    (MenuId::MenubarLayoutMenu, None, "workbench.action.editorLayoutTwoRows", "T&&wo Rows", "4_layouts", 5., None, None),
    (MenuId::MenubarLayoutMenu, None, "workbench.action.editorLayoutThreeRows", "Three &&Rows", "4_layouts", 6., None, None),
    (MenuId::MenubarLayoutMenu, None, "workbench.action.editorLayoutTwoByTwoGrid", "&&Grid (2x2)", "4_layouts", 7., None, None),
    (MenuId::MenubarLayoutMenu, None, "workbench.action.editorLayoutTwoRowsRight", "Two R&&ows Right", "4_layouts", 8., None, None),
    (MenuId::MenubarLayoutMenu, None, "workbench.action.editorLayoutTwoColumnsBottom", "Two &&Columns Bottom", "4_layouts", 9., None, None),
    (MenuId::MenubarLayoutMenu, None, "workbench.action.moveEditorToNewWindow", "&&Move Editor into New Window", "3_new_window", 1., None, None),
    (MenuId::MenubarLayoutMenu, None, "workbench.action.copyEditorToNewWindow", "&&Copy Editor into New Window", "3_new_window", 2., None, None),
    (MenuId::MenubarLayoutMenu, None, "workbench.action.toggleEditorGroupLayout", "Flip &&Layout", "5_flip", 1., None, None),
    (MenuId::MenubarGoMenu, None, "workbench.action.navigateBack", "&&Back", "1_history_nav", 1., None, Some("canNavigateBack")),
    (MenuId::MenubarGoMenu, None, "workbench.action.navigateForward", "&&Forward", "1_history_nav", 2., None, Some("canNavigateForward")),
    (MenuId::MenubarGoMenu, None, "workbench.action.navigateToLastEditLocation", "&&Last Edit Location", "1_history_nav", 3., None, Some("canNavigateToLastEditLocation")),
    (MenuId::MenubarGoMenu, Some(MenuId::MenubarSwitchEditorMenu), "", "Switch &&Editor", "2_editor_nav", 1., None, None),
    (MenuId::MenubarSwitchEditorMenu, None, "workbench.action.openNextRecentlyUsedEditor", "&&Next Used Editor", "3_any_used", 1., None, None),
    (MenuId::MenubarSwitchEditorMenu, None, "workbench.action.openPreviousRecentlyUsedEditor", "&&Previous Used Editor", "3_any_used", 2., None, None),
    (MenuId::MenubarSwitchEditorMenu, None, "workbench.action.openNextRecentlyUsedEditorInGroup", "&&Next Used Editor in Group", "5_group_used", 1., None, None),
    (MenuId::MenubarSwitchEditorMenu, None, "workbench.action.openPreviousRecentlyUsedEditorInGroup", "&&Previous Used Editor in Group", "5_group_used", 2., None, None),
    (MenuId::MenubarGoMenu, Some(MenuId::MenubarSwitchGroupMenu), "", "Switch &&Group", "2_editor_nav", 2., None, None),
    (MenuId::MenubarSwitchGroupMenu, None, "workbench.action.focusFirstEditorGroup", "Group &&1", "1_focus_index", 1., None, None),
    (MenuId::MenubarSwitchGroupMenu, None, "workbench.action.focusSecondEditorGroup", "Group &&2", "1_focus_index", 2., None, None),
    (MenuId::MenubarSwitchGroupMenu, None, "workbench.action.focusThirdEditorGroup", "Group &&3", "1_focus_index", 3., None, Some("multipleEditorGroups")),
    (MenuId::MenubarSwitchGroupMenu, None, "workbench.action.focusFourthEditorGroup", "Group &&4", "1_focus_index", 4., None, Some("multipleEditorGroups")),
    (MenuId::MenubarSwitchGroupMenu, None, "workbench.action.focusFifthEditorGroup", "Group &&5", "1_focus_index", 5., None, Some("multipleEditorGroups")),
    (MenuId::MenubarSwitchGroupMenu, None, "workbench.action.focusNextGroup", "&&Next Group", "2_next_prev", 1., None, Some("multipleEditorGroups")),
    (MenuId::MenubarSwitchGroupMenu, None, "workbench.action.focusPreviousGroup", "&&Previous Group", "2_next_prev", 2., None, Some("multipleEditorGroups")),
    (MenuId::MenubarSwitchGroupMenu, None, "workbench.action.focusLeftGroup", "Group &&Left", "3_directional", 1., None, Some("multipleEditorGroups")),
    (MenuId::MenubarSwitchGroupMenu, None, "workbench.action.focusRightGroup", "Group &&Right", "3_directional", 2., None, Some("multipleEditorGroups")),
    (MenuId::MenubarSwitchGroupMenu, None, "workbench.action.focusAboveGroup", "Group &&Above", "3_directional", 3., None, Some("multipleEditorGroups")),
    (MenuId::MenubarSwitchGroupMenu, None, "workbench.action.focusBelowGroup", "Group &&Below", "3_directional", 4., None, Some("multipleEditorGroups")),
    // bracketMatching.ts
    (MenuId::MenubarGoMenu, None, "editor.action.jumpToBracket", "Go to &&Bracket", "5_infile_nav", 2., None, None),
    // editorExtensions.ts and clipboard.ts
    (MenuId::MenubarEditMenu, None, "undo", "&&Undo", "1_do", 1., None, None),
    (MenuId::MenubarEditMenu, None, "redo", "&&Redo", "1_do", 2., None, None),
    (MenuId::MenubarEditMenu, None, "editor.action.clipboardCutAction", "Cu&&t", "2_ccp", 1., None, None),
    (MenuId::MenubarEditMenu, None, "editor.action.clipboardCopyAction", "&&Copy", "2_ccp", 2., None, None),
    (MenuId::MenubarEditMenu, None, "editor.action.clipboardPasteAction", "&&Paste", "2_ccp", 4., None, None),
    // comment.ts
    (MenuId::MenubarEditMenu, None, "editor.action.commentLine", "&&Toggle Line Comment", "5_insert", 1., None, Some("!editorReadonly")),
    (MenuId::MenubarEditMenu, None, "editor.action.blockComment", "Toggle &&Block Comment", "5_insert", 2., None, Some("!editorReadonly")),
    // expandAbbreviation.ts.
    (MenuId::MenubarEditMenu, None, "editor.emmet.action.expandAbbreviation", "Emmet: E&&xpand Abbreviation", "5_insert", 3., Some("!isSessionsWindow"), Some("!editorReadonly")),
    (MenuId::MenubarSelectionMenu, None, "editor.action.selectAll", "&&Select All", "1_basic", 1., None, None),
    // smartSelect.ts
    (MenuId::MenubarSelectionMenu, None, "editor.action.smartSelect.expand", "&&Expand Selection", "1_basic", 2., None, None),
    (MenuId::MenubarSelectionMenu, None, "editor.action.smartSelect.shrink", "&&Shrink Selection", "1_basic", 3., None, None),
    // linesOperations.ts
    (MenuId::MenubarSelectionMenu, None, "editor.action.copyLinesUpAction", "&&Copy Line Up", "2_line", 1., None, Some("!editorReadonly")),
    (MenuId::MenubarSelectionMenu, None, "editor.action.copyLinesDownAction", "Co&&py Line Down", "2_line", 2., None, Some("!editorReadonly")),
    (MenuId::MenubarSelectionMenu, None, "editor.action.moveLinesUpAction", "Mo&&ve Line Up", "2_line", 3., None, Some("!editorReadonly")),
    (MenuId::MenubarSelectionMenu, None, "editor.action.moveLinesDownAction", "Move &&Line Down", "2_line", 4., None, Some("!editorReadonly")),
    (MenuId::MenubarSelectionMenu, None, "editor.action.duplicateSelection", "&&Duplicate Selection", "2_line", 5., None, Some("!editorReadonly")),
    // multicursor.ts
    (MenuId::MenubarSelectionMenu, None, "editor.action.insertCursorAbove", "&&Add Cursor Above", "3_multi", 2., None, None),
    (MenuId::MenubarSelectionMenu, None, "editor.action.insertCursorBelow", "A&&dd Cursor Below", "3_multi", 3., None, None),
    (MenuId::MenubarSelectionMenu, None, "editor.action.insertCursorAtEndOfEachLineSelected", "Add C&&ursors to Line Ends", "3_multi", 4., None, None),
    (MenuId::MenubarSelectionMenu, None, "editor.action.addSelectionToNextFindMatch", "Add &&Next Occurrence", "3_multi", 5., None, None),
    (MenuId::MenubarSelectionMenu, None, "editor.action.addSelectionToPreviousFindMatch", "Add P&&revious Occurrence", "3_multi", 6., None, None),
    (MenuId::MenubarSelectionMenu, None, "editor.action.selectHighlights", "Select All &&Occurrences", "3_multi", 7., None, None),
    // quickAccess.contribution.ts
    (MenuId::MenubarViewMenu, None, "workbench.action.showCommands", "&&Command Palette...", "1_open", 1., None, None),
    (MenuId::MenubarViewMenu, None, "workbench.action.openView", "&&Open View...", "1_open", 2., None, None),
    // layoutActions.ts, activitybarPart.ts and viewsService.ts `openCommandActionDescriptor` entries of the views the port has.
    (MenuId::MenubarViewMenu, Some(MenuId::MenubarAppearanceMenu), "", "&&Appearance", "2_appearance", 1., Some("!isSessionsWindow"), None),
    (MenuId::MenubarAppearanceMenu, None, "workbench.action.toggleSidebarPosition", "&&Move Primary Side Bar Right", "3_workbench_layout_move", 2., Some("config.workbench.sideBar.location != 'right' && !isSessionsWindow"), None),
    (MenuId::MenubarAppearanceMenu, None, "workbench.action.toggleSidebarPosition", "&&Move Primary Side Bar Left", "3_workbench_layout_move", 2., Some("config.workbench.sideBar.location == 'right' && !isSessionsWindow"), None),
    (MenuId::MenubarAppearanceMenu, Some(MenuId::ActivityBarPositionMenu), "", "Activity Bar Position", "3_workbench_layout_move", 2., Some("!isSessionsWindow"), None),
    // panelActions.ts
    (MenuId::MenubarAppearanceMenu, Some(MenuId::PanelPositionMenu), "", "Panel Position", "3_workbench_layout_move", 4., Some("!isSessionsWindow"), None),
    (MenuId::MenubarAppearanceMenu, Some(MenuId::PanelAlignmentMenu), "", "Align Panel", "3_workbench_layout_move", 5., None, None),
    // layoutActions.ts and workbench.zenMode.contribution.ts
    (MenuId::MenubarAppearanceMenu, Some(MenuId::EditorTabsBarShowTabsSubmenu), "", "Tab Bar", "3_workbench_layout_move", 10., Some("!inZenMode && !isSessionsWindow"), None),
    (MenuId::MenubarAppearanceMenu, Some(MenuId::EditorTabsBarShowTabsZenModeSubmenu), "", "Tab Bar", "3_workbench_layout_move", 10., Some("inZenMode"), None),
    (MenuId::MenubarAppearanceMenu, Some(MenuId::EditorActionsPositionSubmenu), "", "Editor Actions Position", "3_workbench_layout_move", 11., Some("!isSessionsWindow"), None),
    (MenuId::MenubarViewMenu, None, "workbench.view.explorer", "&&Explorer", "3_sidebar", 0., Some("viewContainer.workbench.view.explorer.enabled"), Some("viewContainer.workbench.view.explorer.enabled")),
    (MenuId::MenubarViewMenu, None, "workbench.view.search", "&&Search", "3_sidebar", 1., Some("workbench.view.search.active"), Some("workbench.view.search.active")),
    (MenuId::MenubarViewMenu, None, "workbench.view.scm", "Source &&Control", "3_sidebar", 2., Some("workbench.scm.active"), Some("workbench.scm.active")),
    (MenuId::MenubarViewMenu, None, "workbench.view.debug", "&&Run", "3_sidebar", 3., Some("viewContainer.workbench.view.debug.enabled"), Some("viewContainer.workbench.view.debug.enabled")),
    (MenuId::MenubarViewMenu, None, "workbench.view.extensions", "E&&xtensions", "3_sidebar", 4., Some("viewContainer.workbench.view.extensions.enabled"), Some("viewContainer.workbench.view.extensions.enabled")),
    // repl.ts: Debug Console in the panel group.
    (MenuId::MenubarViewMenu, None, "workbench.debug.action.toggleRepl", "De&&bug Console", "5_panel", 2., None, None),
    // preferences.contribution.ts
    (MenuId::MenubarPreferencesMenu, None, "workbench.action.openSettings", "&&Settings", "2_configuration", 2., None, None),
    (MenuId::MenubarViewMenu, None, "workbench.action.terminal.toggleTerminal", "&&Terminal", "5_panel", 3., Some("terminal.active"), Some("terminal.active")),
    (MenuId::MenubarPreferencesMenu, None, "workbench.view.extensions", "&&Extensions", "2_configuration", 3., Some("!isSessionsWindow"), Some("viewContainer.workbench.view.extensions.enabled")),
    // fileActions.contribution.ts, findController.ts, searchActionsFind.ts, searchActionsNav.ts, quickAccess.contribution.ts and gotoError.ts
    (MenuId::MenubarFileMenu, None, "workbench.action.closeActiveEditor", "&&Close Editor", "6_close", 2., None, Some("activeEditor || foldersViewVisible && sideBarFocus")),
    (MenuId::MenubarEditMenu, None, "actions.find", "&&Find", "3_find", 1., None, Some("editorFocus || editorIsOpen")),
    (MenuId::MenubarEditMenu, None, "editor.action.startFindReplaceAction", "&&Replace", "3_find", 2., None, Some("editorFocus || editorIsOpen")),
    (MenuId::MenubarEditMenu, None, "workbench.action.findInFiles", "Find &&in Files", "4_find_global", 1., Some("!isSessionsWindow"), Some("!isSessionsWindow")),
    (MenuId::MenubarEditMenu, None, "workbench.action.replaceInFiles", "Replace in Files", "4_find_global", 2., Some("!isSessionsWindow"), Some("!isSessionsWindow")),
    (MenuId::MenubarGoMenu, None, "workbench.action.gotoLine", "Go to &&Line/Column...", "5_infile_nav", 1., None, None),
    (MenuId::MenubarGoMenu, None, "editor.action.marker.nextInFiles", "Next &&Problem", "6_problem_nav", 1., None, None),
    (MenuId::MenubarGoMenu, None, "editor.action.marker.prevInFiles", "Previous &&Problem", "6_problem_nav", 2., None, None),
    (MenuId::MenubarHelpMenu, None, "workbench.action.showCommands", "Show All Commands", "1_welcome", 2., None, None),
    // update.contribution.ts `ShowReleaseNotesAction`, registered as product.json has `releaseNotesUrl`.
    (MenuId::MenubarHelpMenu, None, "update.showCurrentReleaseNotes", "Show &&Release Notes", "1_welcome", 5., None, None),
    // gettingStarted.contribution.ts and processExplorer.contribution.ts
    (MenuId::MenubarHelpMenu, None, "workbench.action.openWalkthrough", "Welcome", "1_welcome", 1., None, None),
    (MenuId::MenubarHelpMenu, None, "welcome.showAllWalkthroughs", "Open Walkthrough...", "1_welcome", 3., None, None),
    // walkThrough.contribution.ts
    (MenuId::MenubarHelpMenu, None, "workbench.action.showInteractivePlayground", "Editor Playgrou&&nd", "1_welcome", 3., None, None),
    (MenuId::MenubarHelpMenu, None, "workbench.action.openProcessExplorer", "Open &&Process Explorer", "5_tools", 2., None, None),
    // windowActions.ts `ShowAboutDialogAction`: macOS shows it in the application menu.
    (MenuId::MenubarHelpMenu, None, "workbench.action.showAboutDialog", "&&About", "z_about", 1., Some("!isMacNative"), None),
    // preferences.contribution.ts
    (MenuId::MenubarPreferencesMenu, None, "workbench.action.openGlobalKeybindings", "Keyboard Shortcuts", "2_configuration", 4., None, None),
    // configureSnippets.ts `ConfigureSnippetsAction`; the native menu shows the title, as the reference does.
    (MenuId::MenubarPreferencesMenu, None, "workbench.action.openSnippets", "Configure Snippets", "2_configuration", 5., None, None),
    // themes.contribution.ts
    (MenuId::MenubarPreferencesMenu, Some(MenuId::ThemesSubMenu), "", "&&Themes", "2_configuration", 7., None, None),
    // task.contribution.ts `UserTasksGlobalActionContribution`, `TaskExecutionSupportedContext`.
    (MenuId::MenubarPreferencesMenu, None, "workbench.action.tasks.openUserTasks", "Tasks", "2_configuration", 6., Some(TASK_EXECUTION_SUPPORTED), None),
    // The activity bar's Manage menu (quickAccess, preferences, extensions, tasks and themes contributions).
    (MenuId::GlobalActivity, None, "workbench.action.showCommands", "Command Palette...", "1_command", 1., None, None),
    (MenuId::GlobalActivity, None, "workbench.action.openSettings", "Settings", "2_configuration", 2., None, None),
    (MenuId::GlobalActivity, None, "workbench.view.extensions", "Extensions", "2_configuration", 3., None, None),
    (MenuId::GlobalActivity, None, "workbench.action.tasks.openUserTasks", "Tasks", "2_configuration", 6., Some(TASK_EXECUTION_SUPPORTED), None),
    (MenuId::GlobalActivity, None, "workbench.action.openGlobalKeybindings", "Keyboard Shortcuts", "2_configuration", 4., None, None),
    (MenuId::GlobalActivity, None, "workbench.action.openSnippets", "Snippets", "2_configuration", 5., None, None),
    (MenuId::GlobalActivity, Some(MenuId::ThemesSubMenu), "", "Themes", "2_configuration", 7., None, None),
    // update.ts `appendUpdateMenuItems`; Installing Update... and Cancelling Update... are for states macOS does not
    // reach in the port (crate::update::State).
    (MenuId::GlobalActivity, None, "update.check", "Check for Updates...", "7_update", 0., Some("updateState == 'idle'"), None),
    (MenuId::GlobalActivity, None, "update.checking", "Checking for Updates...", "7_update", 0., Some("updateState == 'checking for updates'"), Some("false")),
    (MenuId::GlobalActivity, None, "update.downloadNow", "Download Update (1)", "7_update", 0., Some("updateState == 'available for download'"), None),
    (MenuId::GlobalActivity, None, "update.downloading", "Downloading Update...", "7_update", 0., Some("updateState == 'downloading'"), Some("false")),
    (MenuId::GlobalActivity, None, "update.install", "Install Update... (1)", "7_update", 0., Some("updateState == 'downloaded'"), None),
    (MenuId::GlobalActivity, None, "update.restart", "Restart to Update (1)", "7_update", 2., Some("updateState == 'ready'"), None),
    // modernUI.contribution.ts
    (MenuId::GlobalActivity, Some(MenuId::LayoutDensityMenu), "", "Layout Density", "2_configuration", 8., Some("config.workbench.experimental.modernUI == true"), None),
    // clipboard.ts, editor.contribution.ts: the Copy As and Share submenus, shown once an extension fills them.
    (MenuId::MenubarEditMenu, Some(MenuId::MenubarCopy), "", "Copy As", "2_ccp", 3., None, None),
    (MenuId::MenubarFileMenu, Some(MenuId::MenubarShare), "", "Share", "45_share", 1., Some("!isSessionsWindow"), None),
    (MenuId::EditorContext, Some(MenuId::EditorContextCopy), "", "Copy As", "9_cutcopypaste", 3., None, None),
    (MenuId::EditorContext, Some(MenuId::EditorContextShare), "", "Share", "11_share", -1., Some("resourceScheme != 'output' && editorTextFocus"), None),
    (MenuId::ExplorerContext, Some(MenuId::ExplorerContextShare), "", "Share", "11_share", -1., None, None),
    (MenuId::EditorTitleContext, Some(MenuId::EditorTitleContextShare), "", "Share", "11_share", -1., Some("!multipleEditorsSelectedInGroup"), None),
    // goToCommands.ts
    (MenuId::EditorContext, None, "editor.action.revealDefinition", "Go to Definition", "navigation", 1.1, None, Some("editorHasDefinitionProvider")),
    (MenuId::EditorContext, None, "editor.action.revealDeclaration", "Go to Declaration", "navigation", 1.3, None, Some("editorHasDeclarationProvider && !isInEmbeddedEditor")),
    (MenuId::EditorContext, None, "editor.action.goToTypeDefinition", "Go to Type Definition", "navigation", 1.4, None, Some("editorHasTypeDefinitionProvider")),
    (MenuId::EditorContext, None, "editor.action.goToImplementation", "Go to Implementations", "navigation", 1.45, None, Some("editorHasImplementationProvider")),
    (MenuId::EditorContext, None, "editor.action.goToReferences", "Go to References", "navigation", 1.45, None, Some("editorHasReferenceProvider && !inReferenceSearchEditor && !isInEmbeddedEditor")),
    (MenuId::EditorContext, Some(MenuId::EditorContextPeek), "", "Peek", "navigation", 100., None, None),
    (MenuId::EditorContextPeek, None, "editor.action.peekDefinition", "Peek Definition", "peek", 2., None, Some("editorHasDefinitionProvider && !inReferenceSearchEditor && !isInEmbeddedEditor")),
    (MenuId::EditorContextPeek, None, "editor.action.peekDeclaration", "Peek Declaration", "peek", 3., None, Some("editorHasDeclarationProvider && !inReferenceSearchEditor && !isInEmbeddedEditor")),
    (MenuId::EditorContextPeek, None, "editor.action.peekTypeDefinition", "Peek Type Definition", "peek", 4., None, Some("editorHasTypeDefinitionProvider && !inReferenceSearchEditor && !isInEmbeddedEditor")),
    (MenuId::EditorContextPeek, None, "editor.action.peekImplementation", "Peek Implementations", "peek", 5., None, Some("editorHasImplementationProvider && !inReferenceSearchEditor && !isInEmbeddedEditor")),
    (MenuId::EditorContextPeek, None, "editor.action.referenceSearch.trigger", "Peek References", "peek", 6., None, Some("editorHasReferenceProvider && !inReferenceSearchEditor && !isInEmbeddedEditor")),
    // callHierarchy.contribution.ts and typeHierarchy.contribution.ts
    (MenuId::EditorContextPeek, None, "editor.showCallHierarchy", "Peek Call Hierarchy", "navigation", 1000., None, Some("editorHasCallHierarchyProvider && !inReferenceSearchEditor && !isInEmbeddedEditor")),
    (MenuId::EditorContextPeek, None, "editor.showTypeHierarchy", "Peek Type Hierarchy", "navigation", 1000., None, Some("editorHasTypeHierarchyProvider && !inReferenceSearchEditor && !isInEmbeddedEditor")),
    (MenuId::MenubarGoMenu, None, "editor.action.revealDefinition", "Go to &&Definition", "4_symbol_nav", 2., None, None),
    (MenuId::MenubarGoMenu, None, "editor.action.revealDeclaration", "Go to &&Declaration", "4_symbol_nav", 3., None, None),
    (MenuId::MenubarGoMenu, None, "editor.action.goToTypeDefinition", "Go to &&Type Definition", "4_symbol_nav", 3., None, None),
    (MenuId::MenubarGoMenu, None, "editor.action.goToImplementation", "Go to &&Implementations", "4_symbol_nav", 4., None, None),
    (MenuId::MenubarGoMenu, None, "editor.action.goToReferences", "Go to &&References", "4_symbol_nav", 5., None, None),
    // rename.ts, multicursor.ts, clipboard.ts and quickAccess.contribution.ts: the EditorContext items of the commands the port has.
    (MenuId::EditorContext, None, "editor.action.rename", "Rename Symbol", "1_modification", 1.1, Some("!editorReadonly && editorHasRenameProvider"), Some("!editorReadonly && editorHasRenameProvider")),
    // formatActions.ts, formatActionsMultiple.ts
    (MenuId::EditorContext, None, "editor.action.formatDocument", "Format Document", "1_modification", 1.3, Some("!inCompositeEditor && !editorReadonly && editorHasDocumentFormattingProvider"), Some("!inCompositeEditor && !editorReadonly && editorHasDocumentFormattingProvider")),
    (MenuId::EditorContext, None, "editor.action.formatDocument.multiple", "Format Document With...", "1_modification", 1.3, Some("!editorReadonly && editorHasMultipleDocumentFormattingProvider"), Some("!editorReadonly && editorHasMultipleDocumentFormattingProvider")),
    (MenuId::EditorContext, None, "editor.action.formatSelection", "Format Selection", "1_modification", 1.31, Some("!editorReadonly && editorHasDocumentSelectionFormattingProvider && editorHasSelection"), Some("!editorReadonly && editorHasDocumentSelectionFormattingProvider")),
    (MenuId::EditorContext, None, "editor.action.formatSelection.multiple", "Format Selection With...", "1_modification", 1.31, Some("!editorReadonly && editorHasMultipleDocumentSelectionFormattingProvider && editorHasSelection"), Some("!editorReadonly && editorHasMultipleDocumentSelectionFormattingProvider")),
    (MenuId::EditorContext, None, "editor.action.changeAll", "Change All Occurrences", "1_modification", 1.2, Some("!editorReadonly && editorTextFocus"), None),
    // codeActionCommands.ts `contextKeyForSupportedActions`: shown when a provider offers the kind.
    (MenuId::EditorContext, None, "editor.action.refactor", "Refactor...", "1_modification", 2., Some("!editorReadonly && supportedCodeAction =~ /(\\s|^)refactor\\b/"), Some("!editorReadonly && editorHasCodeActionsProvider")),
    (MenuId::EditorContext, None, "editor.action.sourceAction", "Source Action...", "1_modification", 2.1, Some("!editorReadonly && supportedCodeAction =~ /(\\s|^)source\\b/"), Some("!editorReadonly && editorHasCodeActionsProvider")),
    (MenuId::EditorContext, None, "editor.action.clipboardCutAction", "Cut", "9_cutcopypaste", 1., Some("!editorReadonly"), None),
    (MenuId::EditorContext, None, "editor.action.clipboardCopyAction", "Copy", "9_cutcopypaste", 2., None, None),
    (MenuId::EditorContext, None, "editor.action.clipboardPasteAction", "Paste", "9_cutcopypaste", 4., Some("!editorReadonly"), None),
    // webview.contribution.ts.
    (MenuId::WebviewContext, None, "editor.action.clipboardCutAction", "Cut", "5_cutcopypaste", 1., Some("!preventDefaultContextMenuItems"), None),
    (MenuId::WebviewContext, None, "editor.action.clipboardCopyAction", "Copy", "5_cutcopypaste", 2., Some("!preventDefaultContextMenuItems"), None),
    (MenuId::WebviewContext, None, "editor.action.clipboardPasteAction", "Paste", "5_cutcopypaste", 3., Some("!preventDefaultContextMenuItems"), None),
    // debugEditorActions.ts `OpenDisassemblyViewAction`.
    (MenuId::EditorContext, None, "debug.action.openDisassemblyView", "Open Disassembly View", "debug", 5., Some("inDebugMode && !panelFocus && debugState == 'stopped' && editorTextFocus && disassembleRequestSupported && languageSupportsDisassembleRequest"), Some("focusedStackFrameHasInstructionReference")),
    (MenuId::EditorContext, None, "workbench.action.showCommands", "Command Palette...", "z_commands", 1., Some("!editorSimpleInput"), None),
    // testResultsViewContent.ts `testing.callStack.run` and `testing.callStack.debug`; callStackWidget.ts `callStackWidget.goToFile`.
    (MenuId::TestCallStack, None, "testing.callStack.run", "Rerun Test", "navigation", 0., Some("testing.hasRunnableTests"), None),
    (MenuId::TestCallStack, None, "testing.callStack.debug", "Debug Test", "navigation", 0., Some("testing.hasDebuggableTests"), None),
    (MenuId::DebugCallStackToolbar, None, "callStackWidget.goToFile", "Open File", "navigation", 22., None, None),
    // debug.contribution.ts `registerDebugViewMenuItem(MenuId.DebugCallStackContext, ...)`, then OpenDisassemblyViewAction.
    (MenuId::DebugCallStackContext, None, "workbench.action.debug.restart", "Restart", "3_modification", 10., Some("callStackItemType == 'session'"), None),
    (MenuId::DebugCallStackContext, None, "workbench.action.debug.disconnect", "Disconnect", "3_modification", 20., Some("callStackItemType == 'session'"), None),
    (MenuId::DebugCallStackContext, None, "workbench.action.debug.disconnectAndSuspend", "Disconnect and Suspend", "3_modification", 21., Some("callStackItemType == 'session' && suspendDebuggeeSupported && terminateDebuggeeSupported"), None),
    (MenuId::DebugCallStackContext, None, "workbench.action.debug.stop", "Stop", "3_modification", 30., Some("callStackItemType == 'session'"), None),
    (MenuId::DebugCallStackContext, None, "workbench.action.debug.pause", "Pause", "navigation", 10., Some("callStackItemType == 'thread' && debugState == 'running' && !focusedSessionIsNoDebug"), None),
    (MenuId::DebugCallStackContext, None, "workbench.action.debug.continue", "Continue", "navigation", 10., Some("callStackItemType == 'thread' && debugState == 'stopped'"), None),
    (MenuId::DebugCallStackContext, None, "workbench.action.debug.stepOver", "Step Over", "navigation", 20., Some("callStackItemType == 'thread'"), Some("debugState == 'stopped'")),
    (MenuId::DebugCallStackContext, None, "workbench.action.debug.stepInto", "Step Into", "navigation", 30., Some("callStackItemType == 'thread'"), Some("debugState == 'stopped'")),
    (MenuId::DebugCallStackContext, None, "workbench.action.debug.stepOut", "Step Out", "navigation", 40., Some("callStackItemType == 'thread'"), Some("debugState == 'stopped' && threadHasMultipleStackFrames")),
    (MenuId::DebugCallStackContext, None, "workbench.action.debug.terminateThread", "Terminate Thread", "termination", 10., Some("callStackItemType == 'thread'"), Some("terminateThreadsSupported")),
    (MenuId::DebugCallStackContext, None, "workbench.action.debug.restartFrame", "Restart Frame", "navigation", 10., Some("callStackItemType == 'stackFrame' && restartFrameSupported"), Some("stackFrameSupportsRestart")),
    (MenuId::DebugCallStackContext, None, "debug.copyStackTrace", "Copy Call Stack", "3_modification", 20., Some("callStackItemType == 'stackFrame'"), None),
    (MenuId::DebugCallStackContext, None, "debug.action.openDisassemblyView", "Open Disassembly View", "z_commands", 50., Some("inDebugMode && debugState == 'stopped' && callStackItemType == 'stackFrame' && disassembleRequestSupported"), Some("focusedStackFrameHasInstructionReference")),
    // debugToolBar.ts `registerDebugToolBarItem`; Stop and Disconnect get their alts in `workbench_menus`.
    (MenuId::DebugToolBar, None, "workbench.action.debug.continue", "Continue", "navigation", 10., Some("debugState == 'stopped'"), None),
    (MenuId::DebugToolBar, None, "workbench.action.debug.pause", "Pause", "navigation", 10., Some("debugState != 'stopped'"), Some("debugState == 'running' && !focusedSessionIsNoDebug")),
    (MenuId::DebugToolBar, None, "workbench.action.debug.stop", "Stop", "navigation", 70., Some("!focusedSessionIsAttach"), None),
    (MenuId::DebugToolBar, None, "workbench.action.debug.disconnect", "Disconnect", "navigation", 70., Some("focusedSessionIsAttach"), None),
    (MenuId::DebugToolBar, None, "workbench.action.debug.stepOver", "Step Over", "navigation", 20., None, Some("debugState == 'stopped'")),
    (MenuId::DebugToolBar, None, "workbench.action.debug.stepInto", "Step Into", "navigation", 30., None, Some("debugState == 'stopped'")),
    (MenuId::DebugToolBar, None, "workbench.action.debug.stepOut", "Step Out", "navigation", 40., None, Some("debugState == 'stopped' && threadHasMultipleStackFrames")),
    (MenuId::DebugToolBar, None, "workbench.action.debug.restart", "Restart", "navigation", 60., None, None),
    (MenuId::DebugToolBar, None, "workbench.action.debug.stepBack", "Step Back", "navigation", 50., Some("stepBackSupported"), Some("debugState == 'stopped'")),
    (MenuId::DebugToolBar, None, "workbench.action.debug.reverseContinue", "Reverse", "navigation", 55., Some("stepBackSupported"), Some("debugState == 'stopped'")),
    (MenuId::DebugToolBar, None, "workbench.action.debug.focusProcess", "Focus Session", "navigation", 100., Some("multiSessionDebug && config.debug.toolBarLocation != 'commandCenter'"), None),
    (MenuId::DebugToolBarStop, None, "workbench.action.debug.disconnect", "Disconnect", "navigation", 0., Some("!focusedSessionIsAttach && terminateDebuggeeSupported"), None),
    (MenuId::DebugToolBarStop, None, "workbench.action.debug.stop", "Stop", "navigation", 0., Some("focusedSessionIsAttach && terminateDebuggeeSupported"), None),
    (MenuId::DebugToolBarStop, None, "workbench.action.debug.disconnectAndSuspend", "Disconnect and Suspend", "navigation", 0., Some("!focusedSessionIsAttach && suspendDebuggeeSupported && terminateDebuggeeSupported || focusedSessionIsAttach && suspendDebuggeeSupported"), None),
    // debugViewlet.ts: the Run and Debug container's title; `debug_container_actions` adds the docked toolbar's items.
    (MenuId::ViewContainerTitle, None, "workbench.action.debug.start", "Start Debugging", "navigation", 10., Some("viewContainer == 'workbench.view.debug' && debugUx != 'simple' && workbenchState != 'empty' && (debugState == 'inactive' || config.debug.toolBarLocation != 'docked') && (!config.debug.hideLauncherWhileDebugging || !inDebugMode)"), Some("debugState != 'initializing'")),
    (MenuId::ViewContainerTitle, None, "workbench.action.debug.configure", "Open 'launch.json'", "navigation", 20., Some("viewContainer == 'workbench.view.debug' && debugUx != 'simple' && workbenchState != 'empty' && (debugState == 'inactive' || config.debug.toolBarLocation != 'docked')"), Some("debugUx != 'simple'")),
    (MenuId::ViewContainerTitle, None, "workbench.action.debug.configure", "Open 'launch.json'", "", 20., Some("viewContainer == 'workbench.view.debug' && debugState != 'inactive' && config.debug.toolBarLocation == 'docked'"), Some("debugUx != 'simple'")),
    // extensions.contribution.ts: the ExtensionContext items the port has commands for.
    (MenuId::ExtensionContext, None, "workbench.extensions.action.setColorTheme", "Set Color Theme", "_theme_", 0., Some("!inExtensionEditor && extensionStatus == 'installed' && extensionHasColorThemes"), None),
    (MenuId::ExtensionContext, None, "workbench.extensions.action.setFileIconTheme", "Set File Icon Theme", "_theme_", 0., Some("!inExtensionEditor && extensionStatus == 'installed' && extensionHasFileIconThemes"), None),
    (MenuId::ExtensionContext, None, "workbench.extensions.action.setProductIconTheme", "Set Product Icon Theme", "_theme_", 0., Some("!inExtensionEditor && extensionStatus == 'installed' && extensionHasProductIconThemes"), None),
    (MenuId::ExtensionContext, None, "workbench.extensions.action.toggleAutoUpdatesForPublisher", "Auto Update (Publisher)", "0_update", 2., Some("extensionStatus == 'installed' && !isBuiltinExtension"), Some("config.extensions.autoUpdate == 'off'")),
    (MenuId::ExtensionContext, None, "workbench.extensions.action.installUnsigned", "Install", "0_install", 1., Some("extensionStatus == 'uninstalled' && isGalleryExtension && !extensionDisallowInstall && extensionIsUnsigned && (galleryAllPublicRepositorySigned && !extensionIsPrivate || galleryAllPrivateRepositorySigned && extensionIsPrivate)"), None),
    (MenuId::ExtensionContext, None, "workbench.extensions.action.switchToPreRlease", "Switch to Pre-Release Version", "0_install", 2., Some("hasGallery && galleryExtensionHasPreReleaseVersion && isPreReleaseExtensionAllowed && !installedExtensionIsOptedToPreRelease && !inExtensionEditor && extensionStatus == 'installed' && !isBuiltinExtension"), None),
    (MenuId::ExtensionContext, None, "workbench.extensions.action.switchToRelease", "Switch to Release Version", "0_install", 2., Some("hasGallery && galleryExtensionHasPreReleaseVersion && isExtensionAllowed && installedExtensionIsOptedToPreRelease && !inExtensionEditor && extensionStatus == 'installed' && !isBuiltinExtension"), None),
    (MenuId::ExtensionContext, None, "workbench.extensions.action.install.anotherVersion", "Install Specific Version...", "0_install", 3., Some("extensionStatus == 'uninstalled' && isGalleryExtension && isExtensionAllowed && !extensionDisallowInstall"), None),
    (MenuId::ExtensionContext, None, "workbench.extensions.action.copyExtension", "Copy", "1_copy", 0., None, None),
    (MenuId::ExtensionContext, None, "workbench.extensions.action.copyExtensionId", "Copy Extension ID", "1_copy", 0., None, None),
    (MenuId::ExtensionContext, None, "workbench.extensions.action.copyLink", "Copy Link", "1_copy", 0., Some("isGalleryExtension && galleryHasExtensionLink"), None),
    (MenuId::ExtensionContext, None, "workbench.extensions.action.configure", "Settings", "2_configure", 1., Some("extensionStatus == 'installed' && extensionHasConfiguration"), None),
    (MenuId::ExtensionContext, None, "workbench.extensions.action.configureKeybindings", "Keyboard Shortcuts", "2_configure", 2., Some("extensionStatus == 'installed' && extensionHasKeybindings"), None),
    (MenuId::ExtensionContext, None, "workbench.extensions.action.ignoreRecommendation", "Ignore Recommendation", "3_recommendations", 1., Some("isExtensionRecommended"), None),
    (MenuId::ExtensionContext, None, "workbench.extensions.action.undoIgnoredRecommendation", "Undo Ignored Recommendation", "3_recommendations", 1., Some("isUserIgnoredRecommendation"), None),
    (MenuId::ExtensionContext, None, "workbench.extensions.action.addExtensionToWorkspaceRecommendations", "Add to Workspace Recommendations", "3_recommendations", 2., Some("workbenchState != 'empty' && !isBuiltinExtension && !isExtensionWorkspaceRecommended && !isUserIgnoredRecommendation && extensionSource != 'resource'"), None),
    (MenuId::ExtensionContext, None, "workbench.extensions.action.downloadSpecificVersion", "Download Specific Version VSIX...", "", 2., Some("!extensionDisallowInstall && isGalleryExtension"), None),
    (MenuId::ExtensionContext, None, "workbench.extensions.action.removeExtensionFromWorkspaceRecommendations", "Remove from Workspace Recommendations", "3_recommendations", 2., Some("workbenchState != 'empty' && !isBuiltinExtension && isExtensionWorkspaceRecommended"), None),
    (MenuId::ViewContainerTitle, None, "workbench.action.debug.selectandstart", "Start Additional Session", "", 10., Some("viewContainer == 'workbench.view.debug' && debugState != 'inactive' && (config.debug.toolBarLocation == 'docked' || config.debug.hideLauncherWhileDebugging)"), None),
    // repl.ts's actions in `MenuId.DebugConsoleContext`.
    (MenuId::DebugConsoleContext, None, "debug.replCopy", "Copy", "2_cutcopypaste", 10., None, None),
    (MenuId::DebugConsoleContext, None, "workbench.debug.action.copyAll", "Copy All", "2_cutcopypaste", 20., None, None),
    (MenuId::DebugConsoleContext, None, "debug.replPaste", "Paste", "2_cutcopypaste", 30., None, Some("debugState != 'inactive'")),
    (MenuId::DebugConsoleContext, None, "debug.collapseRepl", "Collapse All", "z_commands", 10., None, None),
    (MenuId::DebugConsoleContext, None, "workbench.debug.panel.action.clearReplAction", "Clear Console", "z_commands", 20., None, None),
    (MenuId::DebugConsoleContext, None, "repl.action.find", "Debug Console: Focus Find", "z_commands", 25., None, None),
    // debug.contribution.ts `registerDebugViewMenuItem(MenuId.DebugVariablesContext/DebugHoverContext/DebugWatchContext, ...)`.
    (MenuId::DebugVariablesContext, None, "workbench.debug.viewlet.action.viewMemory", "View Binary Data", "inline", 15., Some("canViewMemory"), Some("inDebugMode")),
    (MenuId::DebugHoverContext, None, "workbench.debug.viewlet.action.viewMemory", "View Binary Data", "inline", 15., Some("canViewMemory"), Some("inDebugMode")),
    (MenuId::DebugWatchContext, None, "workbench.debug.viewlet.action.viewMemory", "View Binary Data", "inline", 10., Some("canViewMemory"), None),
    (MenuId::DebugVariablesContext, None, "debug.setVariable", "Set Value", "3_modification", 10., Some("debugSetVariableSupported || variableEvaluateNamePresent && debugSetExpressionSupported"), Some("!variableIsReadonly")),
    (MenuId::DebugVariablesContext, None, "workbench.debug.viewlet.action.copyValue", "Copy Value", "5_cutcopypaste", 10., None, None),
    (MenuId::NotebookVariablesContext, None, "workbench.debug.viewlet.action.copyWorkspaceVariableValue", "Copy Value", "navigation", 20., Some("variableValue"), None),
    (MenuId::DebugVariablesContext, None, "debug.copyEvaluatePath", "Copy as Expression", "5_cutcopypaste", 20., Some("variableEvaluateNamePresent"), None),
    (MenuId::DebugVariablesContext, None, "debug.addToWatchExpressions", "Add to Watch", "z_commands", 100., Some("variableEvaluateNamePresent"), None),
    (MenuId::DebugVariablesContext, None, "debug.breakWhenValueIsRead", "Break on Value Read", "z_commands", 200., Some("breakWhenValueIsReadSupported"), None),
    (MenuId::DebugVariablesContext, None, "debug.breakWhenValueChanges", "Break on Value Change", "z_commands", 210., Some("breakWhenValueChangesSupported"), None),
    (MenuId::DebugVariablesContext, None, "debug.breakWhenValueIsAccessed", "Break on Value Access", "z_commands", 220., Some("breakWhenValueIsAccessedSupported"), None),
    (MenuId::DebugHoverContext, None, "workbench.debug.viewlet.action.copyValue", "Copy Value", "5_cutcopypaste", 10., None, None),
    (MenuId::DebugHoverContext, None, "debug.copyEvaluatePath", "Copy as Expression", "5_cutcopypaste", 20., Some("variableEvaluateNamePresent"), None),
    (MenuId::DebugHoverContext, None, "debug.addToWatchExpressions", "Add to Watch", "z_commands", 100., Some("variableEvaluateNamePresent"), None),
    (MenuId::DebugHoverContext, None, "debug.breakWhenValueIsRead", "Break on Value Read", "z_commands", 200., Some("breakWhenValueIsReadSupported"), None),
    (MenuId::DebugHoverContext, None, "debug.breakWhenValueChanges", "Break on Value Change", "z_commands", 210., Some("breakWhenValueChangesSupported"), None),
    (MenuId::DebugHoverContext, None, "debug.breakWhenValueIsAccessed", "Break on Value Access", "z_commands", 220., Some("breakWhenValueIsAccessedSupported"), None),
    (MenuId::DebugWatchContext, None, "workbench.debug.viewlet.action.addWatchExpression", "Add Expression", "3_modification", 10., None, None),
    (MenuId::DebugWatchContext, None, "debug.copyWatchExpression", "Copy Expression", "3_modification", 20., Some("watchItemType == 'expression'"), Some("watchExpressionsExist")),
    (MenuId::DebugWatchContext, None, "debug.renameWatchExpression", "Edit Expression", "3_modification", 20., Some("watchItemType == 'expression'"), None),
    (MenuId::DebugWatchContext, None, "debug.setWatchExpression", "Set Value", "3_modification", 30., Some("watchItemType == 'expression' && debugSetExpressionSupported || watchItemType == 'variable' && debugSetVariableSupported"), Some("!variableIsReadonly")),
    (MenuId::DebugWatchContext, None, "workbench.debug.viewlet.action.copyValue", "Copy Value", "3_modification", 40., Some("watchItemType == 'expression' || watchItemType == 'variable'"), Some("inDebugMode")),
    (MenuId::DebugWatchContext, None, "workbench.debug.viewlet.action.copyAllWatchExpressions", "Copy All", "3_modification", 45., None, Some("watchExpressionsExist")),
    (MenuId::DebugWatchContext, None, "debug.copyEvaluatePath", "Copy as Expression", "3_modification", 50., Some("variableEvaluateNamePresent"), Some("inDebugMode")),
    (MenuId::DebugWatchContext, None, "debug.removeWatchExpression", "Remove Expression", "inline", 20., Some("watchItemType == 'expression'"), None),
    (MenuId::DebugWatchContext, None, "workbench.debug.viewlet.action.removeAllWatchExpressions", "Remove All Expressions", "z_commands", 20., None, None),
    (MenuId::DebugWatchContext, None, "debug.breakWhenValueIsRead", "Break on Value Read", "z_commands", 200., Some("breakWhenValueIsReadSupported"), None),
    (MenuId::DebugWatchContext, None, "debug.breakWhenValueChanges", "Break on Value Change", "z_commands", 210., Some("breakWhenValueChangesSupported"), None),
    (MenuId::DebugWatchContext, None, "debug.breakWhenValueIsAccessed", "Break on Value Access", "z_commands", 220., Some("breakWhenValueIsAccessedSupported"), None),
    // output.contribution.ts and viewsService.ts `openCommandActionDescriptor.mnemonicTitle`
    (MenuId::EditorContext, None, "workbench.output.action.clearOutput", "Clear Output", "", 0., Some("inOutput"), None),
    // markers.contribution.ts: Problems before Output in the panel group.
    (MenuId::MenubarViewMenu, None, "workbench.actions.view.problems", "&&Problems", "5_panel", 0., None, None),
    (MenuId::MenubarViewMenu, None, "workbench.action.output.toggleOutput", "&&Output", "5_panel", 1., Some("workbench.panel.output.active"), None),
    // terminalMenus.ts: the TerminalEditorInstanceContext items of the commands the port has.
    (MenuId::TerminalEditorInstanceContext, None, "workbench.action.terminal.split", "Split Terminal", "1_create", 0., None, None),
    (MenuId::TerminalEditorInstanceContext, None, "workbench.action.terminal.new", "New Terminal", "1_create", 0., None, None),
    (MenuId::TerminalEditorInstanceContext, None, "workbench.action.terminal.killEditor", "Kill Terminal", "7_kill", 0., None, None),
    (MenuId::TerminalEditorInstanceContext, None, "workbench.action.terminal.copySelection", "Copy", "3_edit", 1., None, None),
    (MenuId::TerminalEditorInstanceContext, None, "workbench.action.terminal.copySelectionAsHtml", "Copy as HTML", "3_edit", 2., None, None),
    (MenuId::TerminalEditorInstanceContext, None, "workbench.action.terminal.paste", "Paste", "3_edit", 3., None, None),
    (MenuId::TerminalEditorInstanceContext, None, "workbench.action.terminal.clear", "Clear", "5_clear", 0., None, None),
    (MenuId::TerminalEditorInstanceContext, None, "workbench.action.terminal.selectAll", "Select All", "3_edit", 3., None, None),
    (MenuId::TerminalEditorInstanceContext, None, "workbench.action.terminal.sizeToContentWidth", "Toggle Size to Content Width", "9_config", 0., None, None),
    // terminalMenus.ts: the TerminalInstanceContext items of the commands the port has, the menu of the panel's terminal.
    (MenuId::TerminalInstanceContext, None, "workbench.action.terminal.killViewOrEditor", "Kill Terminal", "7_kill", 0., None, None),
    (MenuId::TerminalInstanceContext, None, "workbench.action.terminal.copySelection", "Copy", "3_edit", 1., None, None),
    (MenuId::TerminalInstanceContext, None, "workbench.action.terminal.copySelectionAsHtml", "Copy as HTML", "3_edit", 2., None, None),
    (MenuId::TerminalInstanceContext, None, "workbench.action.terminal.paste", "Paste", "3_edit", 3., None, None),
    (MenuId::TerminalInstanceContext, None, "workbench.action.terminal.clear", "Clear", "5_clear", 0., None, None),
    (MenuId::TerminalInstanceContext, None, "workbench.action.terminal.selectAll", "Select All", "3_edit", 3., None, None),
    // terminalMenus.ts: the TerminalTabContext items of the commands the port has; the tab list selects one row, so the
    // Join (not tabsSingularSelection) and Unsplit items stay out with their commands.
    (MenuId::TerminalTabContext, None, "workbench.action.terminal.splitActiveTab", "Split Terminal", "1_create", 1., None, None),
    (MenuId::TerminalTabContext, None, "workbench.action.terminal.moveToEditor", "Move Terminal into Editor Area", "1_create", 2., None, None),
    (MenuId::TerminalTabContext, None, "workbench.action.terminal.moveIntoNewWindow", "Move Terminal into New Window", "1_create", 2., None, None),
    (MenuId::TerminalTabContext, None, "workbench.action.terminal.renameActiveTab", "Rename...", "3_edit", 0., None, None),
    (MenuId::TerminalTabContext, None, "workbench.action.terminal.changeIconActiveTab", "Change Icon...", "3_edit", 0., None, None),
    (MenuId::TerminalTabContext, None, "workbench.action.terminal.changeColorActiveTab", "Change Color...", "3_edit", 0., None, None),
    (MenuId::TerminalTabContext, None, "workbench.action.terminal.sizeToContentWidth", "Toggle Size to Content Width", "3_edit", 0., None, None),
    (MenuId::TerminalTabContext, None, "workbench.action.terminal.killActiveTab", "Kill Terminal", "7_kill", 0., None, None),
    // editor.contribution.ts: the EditorTitleContext items of the commands the port has.
    (MenuId::EditorTitleContext, None, "workbench.action.closeActiveEditor", "Close", "1_close", 10., Some("!activeEditorCannotClose"), None),
    (MenuId::EditorTitleContext, None, "workbench.action.closeOtherEditors", "Close Others", "1_close", 20., None, Some("groupEditorsCount != '1'")),
    (MenuId::EditorTitleContext, None, "workbench.action.closeEditorsToTheRight", "Close to the Right", "1_close", 30., Some("editorTabsVisible"), Some("!activeEditorIsLastInGroup && !multipleEditorsSelectedInGroup")),
    (MenuId::EditorTitleContext, None, "workbench.action.closeUnmodifiedEditors", "Close Saved", "1_close", 40., None, None),
    (MenuId::EditorTitleContext, None, "workbench.action.closeEditorsInGroup", "Close All", "1_close", 50., None, None),
    (MenuId::EditorTitleContext, None, "workbench.action.keepEditor", "Keep Open", "3_preview", 10., Some("config.workbench.editor.enablePreview"), Some("!activeEditorIsNotPreview")),
    (MenuId::EditorTitleContext, None, "workbench.action.splitEditor", "Split Right", "5_split", 10., Some("!splitEditorsVertically"), None),
    (MenuId::EditorTitleContext, None, "workbench.action.splitEditor", "Split Down", "5_split", 10., Some("splitEditorsVertically"), None),
    (MenuId::EditorTitleContext, Some(MenuId::EditorSplitMoveSubmenu), "", "Split & Move", "5_split", 15., None, None),
    (MenuId::EditorTitleContext, None, "workbench.action.moveEditorToNewWindow", "Move into New Window", "7_new_window", 10., None, None),
    (MenuId::EditorTitleContext, None, "workbench.action.copyEditorToNewWindow", "Copy into New Window", "7_new_window", 20., None, None),
    // debug.contribution.ts: Run or Debug..., a split button (`isSplitButton: { togglePrimaryAction: true }`).
    (MenuId::EditorTitle, Some(MenuId::EditorTitleRun), "", "Run or Debug...", "navigation", -1., None, None),
    // editor.contribution.ts: the editor title's `...` (its groups but `navigation`). Lock Group is a title icon in an
    // editor window and Maximize Group needs several groups.
    (MenuId::EditorTitle, Some(MenuId::DiffEditorViewSubmenu), "", "Diff View", "1_diff", 10., Some("isInDiffEditor && !isSessionsWindow"), None),
    // multiDiffEditor/browser/actions.ts: Files View & Position, the file list's sides.
    (MenuId::EditorTitle, Some(MenuId::MultiDiffEditorFilesViewAndPosition), "", "Files View & Position", "z_files", 0., Some("activeEditor == 'multiDiffEditor' && multiDiffEditorFileListAvailable && !isSessionsWindow"), None),
    (MenuId::EditorTitle, None, "workbench.action.showEditorsInGroup", "Show Opened Editors", "3_open", 10., Some("!editorPartModal"), None),
    (MenuId::EditorTitle, None, "workbench.action.closeEditorsInGroup", "Close All", "5_close", 10., Some("!editorPartModal"), None),
    (MenuId::EditorTitle, None, "workbench.action.closeUnmodifiedEditors", "Close Saved", "5_close", 20., Some("!editorPartModal"), None),
    (MenuId::EditorTitle, None, "workbench.action.toggleMaximizeEditorGroup", "Maximize Group", "8_group_operations", 5., Some("!editorPartMaximizedEditorGroup && editorPartMultipleEditorGroups"), None),
    (MenuId::EditorTitle, None, "workbench.action.toggleMaximizeEditorGroup", "Unmaximize Group", "8_group_operations", 5., Some("editorPartMaximizedEditorGroup"), None),
    (MenuId::EditorTitle, None, "workbench.action.configureEditor", "Configure Editors", "9_configure", 10., Some("!editorPartModal"), None),
    // codeCoverageDecorations.ts: GoToNextMissedCoverageLine and GoToPreviousMissedCoverageLine.
    (MenuId::EditorTitle, None, "testing.coverage.goToNextMissedLine", "Go to Next Uncovered Line", "coverage", 2., Some("testing.hasCoverageInFile"), Some("testing.hasCoverageInFile")),
    (MenuId::EditorTitle, None, "testing.coverage.goToPreviousMissedLine", "Go to Previous Uncovered Line", "coverage", 3., Some("testing.hasCoverageInFile"), Some("testing.hasCoverageInFile")),
    // fileActions.contribution.ts and editor.contribution.ts: the empty editor group's context menu.
    (MenuId::EmptyEditorGroupContext, None, "workbench.action.files.newUntitledFile", "New Text File", "1_file", 10., None, None),
    (MenuId::EmptyEditorGroupContext, None, "workbench.action.quickOpen", "Open File...", "1_file", 20., None, None),
    // terminalMenus.ts.
    (MenuId::EmptyEditorGroupContext, None, "workbench.action.createTerminalEditorSameGroup", "New Terminal", "1_zzz_file", 30., Some("terminalProcessSupported"), None),
    (MenuId::EditorTitleContext, None, "workbench.action.terminal.moveToTerminalPanel", "Move Terminal into Panel", "2_files", 0., Some("resourceScheme == 'vscode-terminal' && !layoutMode"), None),
    (MenuId::EditorTitleContext, None, "workbench.action.terminal.rename", "Rename...", "2_files", 0., Some("resourceScheme == 'vscode-terminal'"), None),
    (MenuId::EditorTitleContext, None, "workbench.action.terminal.changeColor", "Change Color...", "2_files", 0., Some("resourceScheme == 'vscode-terminal'"), None),
    (MenuId::EditorTitleContext, None, "workbench.action.terminal.changeIcon", "Change Icon...", "2_files", 0., Some("resourceScheme == 'vscode-terminal'"), None),
    (MenuId::EditorTitleContext, None, "workbench.action.terminal.sizeToContentWidth", "Toggle Size to Content Width", "2_files", 0., Some("resourceScheme == 'vscode-terminal'"), None),
    (MenuId::EmptyEditorGroupContext, None, "workbench.action.splitEditorUp", "Split Up", "2_split", 10., None, None),
    (MenuId::EmptyEditorGroupContext, None, "workbench.action.splitEditorDown", "Split Down", "2_split", 20., None, None),
    (MenuId::EmptyEditorGroupContext, None, "workbench.action.splitEditorLeft", "Split Left", "2_split", 30., None, None),
    (MenuId::EmptyEditorGroupContext, None, "workbench.action.splitEditorRight", "Split Right", "2_split", 40., None, None),
    (MenuId::EmptyEditorGroupContext, None, "workbench.action.newEmptyEditorWindow", "New Window", "3_window", 10., None, None),
    (MenuId::EmptyEditorGroupContext, None, "workbench.action.closeGroup", "Close", "5_close", 10., Some("multipleEditorGroups"), None),
    // fileActions.contribution.ts, terminalMenus.ts and editor.contribution.ts: the tab bar's context menu.
    (MenuId::EditorTabsBarContext, None, "workbench.action.files.newUntitledFile", "New Text File", "1_file", 10., None, None),
    (MenuId::EditorTabsBarContext, None, "workbench.action.quickOpen", "Open File...", "1_file", 20., None, None),
    (MenuId::EditorTabsBarContext, None, "workbench.action.createTerminalEditorSameGroup", "New Terminal", "1_zzz_file", 30., Some("terminalProcessSupported"), None),
    (MenuId::EditorTabsBarContext, None, "workbench.action.splitEditorUp", "Split Up", "2_split", 10., None, None),
    (MenuId::EditorTabsBarContext, None, "workbench.action.splitEditorDown", "Split Down", "2_split", 20., None, None),
    (MenuId::EditorTabsBarContext, None, "workbench.action.splitEditorLeft", "Split Left", "2_split", 30., None, None),
    (MenuId::EditorTabsBarContext, None, "workbench.action.splitEditorRight", "Split Right", "2_split", 40., None, None),
    (MenuId::EditorTabsBarContext, None, "workbench.action.moveEditorGroupToNewWindow", "Move into New Window", "3_window", 10., None, None),
    (MenuId::EditorTabsBarContext, None, "workbench.action.copyEditorGroupToNewWindow", "Copy into New Window", "3_window", 20., None, None),
    (MenuId::EditorTabsBarContext, Some(MenuId::EditorTabsBarShowTabsSubmenu), "", "Tab Bar", "4_config", 10., Some("!inZenMode"), None),
    (MenuId::EditorTabsBarContext, Some(MenuId::EditorTabsBarShowTabsZenModeSubmenu), "", "Tab Bar", "4_config", 10., Some("inZenMode"), None),
    (MenuId::EditorTabsBarContext, Some(MenuId::EditorActionsPositionSubmenu), "", "Editor Actions Position", "4_config", 20., None, None),
    (MenuId::EditorTabsBarContext, None, "workbench.action.configureEditorTabs", "Configure Tabs", "9_configure", 10., None, None),
    (MenuId::EditorSplitMoveSubmenu, None, "workbench.action.splitEditorUp", "Split Up", "1_split", 10., None, None),
    (MenuId::EditorSplitMoveSubmenu, None, "workbench.action.splitEditorDown", "Split Down", "1_split", 20., None, None),
    (MenuId::EditorSplitMoveSubmenu, None, "workbench.action.splitEditorLeft", "Split Left", "1_split", 30., None, None),
    (MenuId::EditorSplitMoveSubmenu, None, "workbench.action.splitEditorRight", "Split Right", "1_split", 40., None, None),
    (MenuId::EditorSplitMoveSubmenu, None, "workbench.action.moveEditorToAboveGroup", "Move Above", "2_move", 10., None, None),
    (MenuId::EditorSplitMoveSubmenu, None, "workbench.action.moveEditorToBelowGroup", "Move Below", "2_move", 20., None, None),
    (MenuId::EditorSplitMoveSubmenu, None, "workbench.action.moveEditorToLeftGroup", "Move Left", "2_move", 30., None, None),
    (MenuId::EditorSplitMoveSubmenu, None, "workbench.action.moveEditorToRightGroup", "Move Right", "2_move", 40., None, None),
    // fileActions.contribution.ts `appendEditorTitleContextMenuItem`.
    (MenuId::EditorTitleContext, None, "workbench.action.files.save", "Save", "1_close_save", 10., Some("activeEditorIsDirty"), None),
    (MenuId::EditorTitleContext, None, "workbench.action.files.saveAs", "Save As...", "1_close_save", 20., Some("activeEditorIsDirty"), Some("!multipleEditorsSelectedInGroup")),
    (MenuId::EditorTitleContext, None, "revealInExplorer", "Reveal in Explorer View", "2_files", 1., Some("isFileSystemResource"), Some("!multipleEditorsSelectedInGroup")),
    (MenuId::EditorTitleContext, None, "workbench.action.reopenWithEditor", "Reopen Editor With...", "1_open", 10., Some("activeEditorAvailableEditorIds"), None),
    (MenuId::EditorTitleContext, None, "breadcrumbs.copyPath", "Copy Breadcrumbs Path", "1_cutcopypaste", 100., Some("breadcrumbsPossible && breadcrumbsHasSymbols"), None),
    (MenuId::EditorTitleContext, None, "workbench.action.pinEditor", "Pin", "3_preview", 20., Some("!activeEditorIsPinned"), None),
    (MenuId::EditorTitleContext, None, "workbench.action.unpinEditor", "Unpin", "3_preview", 20., Some("activeEditorIsPinned"), None),
    // fileActions.contribution.ts and electron-browser/fileActions.contribution.ts `appendEditorTitleContextMenuItem`.
    (MenuId::EditorTitleContext, None, "copyFilePath", "Copy Path", "1_cutcopypaste", 0., Some("isFileSystemResource"), None),
    (MenuId::EditorTitleContext, None, "copyRelativeFilePath", "Copy Relative Path", "1_cutcopypaste", 0., Some("isFileSystemResource"), None),
    (MenuId::EditorTitleContext, None, "revealFileInOS", "Reveal in Finder", "2_files", 0., Some("resourceScheme == 'file' || resourceScheme == 'vscode-userdata'"), Some("!multipleEditorsSelectedInGroup")),
    // fileActions.contribution.ts: MenuId.OpenEditorsContext.
    (MenuId::OpenEditorsContext, None, "explorer.openToSide", "Open to the Side", "navigation", 10., Some("isFileSystemResource || resourceScheme == 'untitled'"), None),
    (MenuId::OpenEditorsContext, None, "revealFileInOS", "Reveal in Finder", "navigation", 20., Some("resourceScheme == 'file' || resourceScheme == 'vscode-userdata'"), None),
    (MenuId::OpenEditorsContext, None, "workbench.action.reopenWithEditor", "Reopen Editor With...", "1_open", 10., Some("activeEditorAvailableEditorIds && !groupFocusedInOpenEditors"), None),
    (MenuId::OpenEditorsContext, None, "copyFilePath", "Copy Path", "1_cutcopypaste", 10., Some("isFileSystemResource"), None),
    (MenuId::OpenEditorsContext, None, "copyRelativeFilePath", "Copy Relative Path", "1_cutcopypaste", 20., Some("isFileSystemResource"), None),
    (MenuId::OpenEditorsContext, None, "workbench.action.files.save", "Save", "2_save", 10., Some("resourceScheme == 'untitled' || !groupFocusedInOpenEditors && !readonlyEditorFocusedInOpenEditors && !autoSaveAfterShortDelayContext"), Some("dirtyEditorFocusedInOpenEditors")),
    (MenuId::OpenEditorsContext, None, "workbench.action.files.revert", "Revert File", "2_save", 20., Some("!groupFocusedInOpenEditors && !readonlyEditorFocusedInOpenEditors && resourceScheme != 'untitled' && !autoSaveAfterShortDelayContext"), Some("dirtyEditorFocusedInOpenEditors")),
    (MenuId::OpenEditorsContext, None, "workbench.files.action.saveAllInGroup", "Save All", "2_save", 30., Some("groupFocusedInOpenEditors"), Some("dirtyWorkingCopies")),
    (MenuId::OpenEditorsContext, None, "workbench.files.action.compareWithSaved", "Compare with Saved", "3_compare", 10., Some("isFileSystemResource && !autoSaveAfterShortDelayContext && !listDoubleSelection"), Some("dirtyEditorFocusedInOpenEditors")),
    (MenuId::OpenEditorsContext, None, "compareFiles", "Compare with Selected", "3_compare", 20., Some("hasResource && resourceSelectedForCompare && (isFileSystemResource || resourceScheme == 'untitled') && !listDoubleSelection"), None),
    (MenuId::OpenEditorsContext, None, "selectForCompare", "Select for Compare", "3_compare", 30., Some("hasResource && (isFileSystemResource || resourceScheme == 'untitled') && !listDoubleSelection"), None),
    (MenuId::OpenEditorsContext, None, "compareSelected", "Compare Selected", "3_compare", 30., Some("hasResource && listDoubleSelection && openEditorsSelectedFileOrUntitled"), None),
    (MenuId::OpenEditorsContext, None, "workbench.action.closeActiveEditor", "Close", "4_close", 10., Some("!groupFocusedInOpenEditors"), None),
    (MenuId::OpenEditorsContext, None, "workbench.action.closeOtherEditors", "Close Others", "4_close", 20., Some("!groupFocusedInOpenEditors"), None),
    (MenuId::OpenEditorsContext, None, "workbench.action.closeUnmodifiedEditors", "Close Saved", "4_close", 30., None, None),
    (MenuId::OpenEditorsContext, None, "workbench.action.closeEditorsInGroup", "Close All", "4_close", 40., None, None),
    // fileActions.contribution.ts, the ExplorerContext items of the commands the port has.
    (MenuId::ExplorerContext, None, "explorer.openToSide", "Open to the Side", "navigation", 10., Some("!explorerResourceIsFolder && hasResource"), None),
    (MenuId::ExplorerContext, None, "explorer.openWith", "Open With...", "navigation", 20., Some("!explorerResourceIsFolder && explorerResourceAvailableEditorIds"), None),
    (MenuId::ExplorerContext, None, "explorer.newFile", "New File...", "navigation", 4., Some("explorerResourceIsFolder"), Some("!explorerResourceReadonly")),
    (MenuId::ExplorerContext, None, "explorer.newFolder", "New Folder...", "navigation", 6., Some("explorerResourceIsFolder"), Some("!explorerResourceReadonly")),
    (MenuId::ExplorerContext, None, "addRootFolder", "Add Folder to Workspace...", "2_workspace", 10., Some("explorerResourceIsRoot && (enterMultiRootWorkspaceSupport || workbenchState == 'workspace')"), None),
    // preferences.contribution.ts.
    (MenuId::ExplorerContext, None, "_workbench.action.openFolderSettings", "Open Folder Settings", "2_workspace", 20., Some("explorerResourceIsRoot && explorerResourceIsFolder"), None),
    (MenuId::ExplorerContext, None, "removeRootFolder", "Remove Folder from Workspace", "2_workspace", 30., Some("explorerResourceIsRoot && explorerResourceIsFolder && workspaceFolderCount != '0' && (enterMultiRootWorkspaceSupport || workbenchState == 'workspace')"), None),
    (MenuId::ExplorerContext, None, "compareFiles", "Compare with Selected", "3_compare", 20., Some("!explorerResourceIsFolder && hasResource && resourceSelectedForCompare && !listDoubleSelection"), None),
    (MenuId::ExplorerContext, None, "selectForCompare", "Select for Compare", "3_compare", 30., Some("!explorerResourceIsFolder && hasResource && !listDoubleSelection"), None),
    (MenuId::ExplorerContext, None, "compareSelected", "Compare Selected", "3_compare", 30., Some("!explorerResourceIsFolder && hasResource && listDoubleSelection"), None),
    // timeline.contribution.ts; the port's resource keys name `resourceSet` `hasResource`.
    (MenuId::ExplorerContext, None, "files.openTimeline", "Open Timeline", "4_timeline", 1., Some("hasResource && timelineHasProvider"), None),
    (MenuId::ExplorerContext, None, "revealFileInOS", "Reveal in Finder", "navigation", 20., Some("resourceScheme == 'file' || resourceScheme == 'vscode-userdata'"), None),
    // imageCarousel.contribution.ts `OpenImagesInCarouselFromExplorerAction`.
    (MenuId::ExplorerContext, None, "workbench.action.openImagesInCarousel", "Open in Images Preview", "navigation", 25., Some("config.imageCarousel.explorerContextMenu.enabled && (explorerResourceIsFolder || resourceExtname =~ /^\\.(png|jpg|jpeg|jpe|gif|webp|svg|bmp|ico|mp4|webm|mov)$/i)"), None),
    // externalTerminal.contribution.ts; the port has no remote, so the `vscode-remote` alternative is left out.
    (MenuId::ExplorerContext, None, "openInIntegratedTerminal", "Open in Integrated Terminal", "navigation", 30., Some("resourceScheme == 'file' && (config.terminal.explorerKind == 'integrated' || config.terminal.explorerKind == 'both')"), None),
    (MenuId::ExplorerContext, None, "openInTerminal", "Open in External Terminal", "navigation", 31., Some("resourceScheme == 'file' && (config.terminal.explorerKind == 'external' || config.terminal.explorerKind == 'both')"), None),
    // searchActionsFind.ts.
    (MenuId::ExplorerContext, None, "filesExplorer.findInFolder", "Find in Folder...", "4_search", 10., Some("explorerResourceIsFolder"), None),
    (MenuId::ExplorerContext, None, "filesExplorer.cut", "Cut", "5_cutcopypaste", 8., Some("!explorerResourceIsRoot && !explorerResourceReadonly"), None),
    (MenuId::ExplorerContext, None, "filesExplorer.copy", "Copy", "5_cutcopypaste", 10., Some("!explorerResourceIsRoot"), None),
    (MenuId::ExplorerContext, None, "filesExplorer.paste", "Paste", "5_cutcopypaste", 20., Some("explorerResourceIsFolder"), Some("!explorerResourceReadonly && fileCopied")),
    (MenuId::ExplorerContext, None, "copyFilePath", "Copy Path", "6_copypath", 10., Some("isFileSystemResource"), None),
    (MenuId::ExplorerContext, None, "copyRelativeFilePath", "Copy Relative Path", "6_copypath", 20., Some("isFileSystemResource"), None),
    (MenuId::ExplorerContext, None, "renameFile", "Rename...", "7_modification", 10., Some("!explorerResourceIsRoot"), Some("!explorerResourceReadonly")),
    (MenuId::ExplorerContext, None, "moveFileToTrash", "Delete", "7_modification", 20., Some("!explorerResourceIsRoot && explorerResourceMoveableToTrash"), None),
    (MenuId::ExplorerContext, None, "deleteFile", "Delete Permanently", "7_modification", 20., Some("!explorerResourceIsRoot && !explorerResourceMoveableToTrash"), None),
    // searchActionsRemoveReplace.ts, searchActionsFind.ts and searchActionsCopy.ts: the SearchContext items.
    (MenuId::SearchContext, None, "search.action.replace", "Replace", "search", 1., Some("replaceActive && matchFocus && isEditableItem"), None),
    (MenuId::SearchContext, None, "search.action.replaceAllInFile", "Replace All", "search", 1., Some("replaceActive && fileMatchFocus && isEditableItem"), None),
    (MenuId::SearchContext, None, "search.action.replaceAllInFolder", "Replace All", "search", 1., Some("replaceActive && folderMatchFocus && isEditableItem"), None),
    (MenuId::SearchContext, None, "search.action.remove", "Dismiss", "search", 2., None, None),
    (MenuId::SearchContext, None, "search.action.restrictSearchToFolder", "Restrict Search to Folder", "search", 3., Some("folderMatchWithResourceFocus"), None),
    (MenuId::SearchContext, None, "search.action.expandRecursively", "Expand Recursively", "search", 4., Some("folderMatchFocus && hasSearchResult"), None),
    (MenuId::SearchContext, None, "search.action.excludeFromSearch", "Exclude Folder from Search", "search", 4., Some("folderMatchWithResourceFocus"), None),
    (MenuId::SearchContext, None, "search.action.excludeFileTypeFromSearch", "Exclude File Type from Search", "search", 5., Some("fileMatchFocus"), None),
    (MenuId::SearchContext, None, "search.action.includeFileTypeInSearch", "Include File Type from Search", "search", 6., Some("fileMatchFocus"), None),
    (MenuId::SearchContext, None, "search.action.copyMatch", "Copy", "search_2", 1., Some("fileMatchOrMatchFocus"), None),
    (MenuId::SearchContext, None, "search.action.copyPath", "Copy Path", "search_2", 2., Some("fileMatchOrFolderMatchWithResourceFocus"), None),
    (MenuId::SearchContext, None, "search.action.copyAll", "Copy All", "search_2", 3., Some("hasSearchResult"), None),
    (MenuId::SearchContext, None, "search.action.revealInSideBar", "Reveal in Explorer View", "search_3", 1., Some("fileMatchFocus && hasSearchResult"), None),
    // editActions.ts and cellOutputActions.ts; "Open in Output Preview" needs `notebook.output.openInPreviewEditor.enabled`,
    // a setting no build registers, and "Add Cell Output to Chat" needs chat.
    (MenuId::NotebookOutputToolbar, None, "notebook.cell.clearOutputs", "Clear Cell Outputs", "", 0., Some("notebookCellHasOutputs && notebookEditable && notebookCellEditable && notebookCellIsFirstOutput && config.notebook.consolidatedOutputButton"), None),
    (MenuId::NotebookOutputToolbar, None, "notebook.cellOuput.showEmptyOutputs", "Show Empty Outputs", "", 0., Some("notebookCellHasOutputs && notebookCellHasHiddenOutputs"), None),
    (MenuId::NotebookOutputToolbar, None, "notebook.cellOutput.copy", "Copy Cell Output", "", 0., Some("notebookCellHasOutputs"), None),
    (MenuId::NotebookOutputToolbar, None, "notebook.cellOutput.saveImage", "Save Image", "", 0., Some("notebookCellOutputMimetype =~ /^image\\//"), None),
    // The cell toolbar: sectionActions.ts, editActions.ts, executeActions.ts (`executeCondition`) and cellCommands.ts
    // in `CellToolbarOrder`; editActions.ts `DeleteCellAction` in NotebookCellDelete.
    (MenuId::NotebookCellTitle, None, "notebook.section.runCells", "Run Cells In Section", "inline/cell", 0., Some("notebookCellType == 'markup'"), None),
    (MenuId::NotebookCellTitle, None, "notebook.cell.edit", "Edit Cell", "inline/cell", 1., Some("notebookEditable && notebookCellType == 'markup' && !notebookCellMarkdownEditMode && notebookCellEditable"), None),
    (MenuId::NotebookCellTitle, None, "notebook.cell.executeCellsAbove", "Execute Above Cells", "inline/cell", 2., Some("notebookCellType == 'code' && (notebookKernelCount > 0 || notebookKernelSourceCount > 0 || notebookMissingKernelExtension) && config.notebook.consolidatedRunButton == false"), None),
    (MenuId::NotebookCellTitle, None, "notebook.cell.executeCellAndBelow", "Execute Cell and Below", "inline/cell", 3., Some("notebookCellType == 'code' && (notebookKernelCount > 0 || notebookKernelSourceCount > 0 || notebookMissingKernelExtension) && config.notebook.consolidatedRunButton == false"), None),
    (MenuId::NotebookCellTitle, None, "notebook.cell.quitEdit", "Stop Editing Cell", "inline/cell", 4., Some("notebookCellType == 'markup' && notebookCellMarkdownEditMode && notebookCellEditable"), None),
    (MenuId::NotebookCellTitle, None, "notebook.cell.split", "Split Cell", "inline/cell", 5., Some("notebookEditable && notebookCellEditable && !notebookCellInputIsCollapsed"), None),
    (MenuId::NotebookCellTitle, None, "notebook.cell.clearOutputs", "Clear Cell Outputs", "inline/output", 6., Some("notebookCellType == 'code' && (notebookKernelCount > 0 || notebookKernelSourceCount > 0) && notebookCellHasOutputs && notebookEditable && notebookCellEditable && !config.notebook.consolidatedOutputButton"), None),
    (MenuId::NotebookCellDelete, None, "notebook.cell.delete", "Delete Cell", "inline/cell", 0., Some("notebookEditable"), None),
    (MenuId::NotebookCellExecute, None, "notebook.cell.executeCellsAbove", "Execute Above Cells", "", 0., Some("notebookCellType == 'code' && (notebookKernelCount > 0 || notebookKernelSourceCount > 0 || notebookMissingKernelExtension) && config.notebook.consolidatedRunButton == true"), None),
    (MenuId::NotebookCellExecute, None, "notebook.cell.executeCellAndBelow", "Execute Cell and Below", "", 0., Some("notebookCellType == 'code' && (notebookKernelCount > 0 || notebookKernelSourceCount > 0 || notebookMissingKernelExtension) && config.notebook.consolidatedRunButton == true"), None),
    (MenuId::InteractiveCellDelete, None, "notebook.cell.delete", "Delete Cell", "inline/cell", 0., None, None),
    // The cell toolbar's `...`: notebookClipboard.ts, coreActions.ts, cellCommands.ts and layoutActions.ts in
    // `CellOverflowToolbarGroups`; Show Cell Line Numbers is added in `workbench_menus` for its check.
    (MenuId::NotebookCellTitle, None, "notebook.cell.cut", "Cut Cell", "1_copy", 1., Some("notebookEditorFocused && notebookEditable && notebookCellEditable"), None),
    (MenuId::NotebookCellTitle, None, "notebook.cell.copy", "Copy Cell", "1_copy", 2., Some("notebookEditorFocused"), None),
    (MenuId::NotebookCellTitle, None, "notebook.cell.paste", "Paste Cell", "1_copy", 3., Some("notebookEditorFocused && notebookEditable"), None),
    (MenuId::NotebookCellTitle, Some(MenuId::NotebookCellInsert), "", "Insert Cell", "2_insert", 0., Some("notebookEditable"), None),
    (MenuId::NotebookCellTitle, None, "notebook.cell.changeToCode", "Change Cell to Code", "3_edit", 0., Some("notebookEditorFocused && notebookEditable && notebookCellEditable && notebookCellType == 'markup'"), Some("activeEditor == 'workbench.editor.notebook' && notebookCellType == 'markup'")),
    (MenuId::NotebookCellTitle, None, "notebook.cell.changeToMarkdown", "Change Cell to Markdown", "3_edit", 0., Some("notebookEditorFocused && notebookEditable && notebookCellEditable && notebookCellType == 'code'"), Some("activeEditor == 'workbench.editor.notebook' && notebookCellType == 'code'")),
    (MenuId::NotebookCellTitle, None, "notebook.cell.joinAbove", "Join With Previous Cell", "3_edit", 10., Some("notebookEditorFocused && notebookEditable"), None),
    (MenuId::NotebookCellTitle, None, "notebook.cell.joinBelow", "Join With Next Cell", "3_edit", 11., Some("notebookEditorFocused && notebookEditable"), None),
    (MenuId::NotebookCellTitle, None, "notebook.cell.joinSelected", "Join Selected Cells", "3_edit", 12., Some("notebookEditorFocused && notebookEditable"), None),
    (MenuId::NotebookCellTitle, None, "notebook.cell.copyDown", "Copy Cell Down", "3_edit", 13., Some("notebookEditorFocused && notebookEditable && notebookCellEditable"), None),
    (MenuId::NotebookCellTitle, None, "notebook.cell.moveUp", "Move Cell Up", "3_edit", 14., Some("config.notebook.dragAndDropEnabled == false"), None),
    (MenuId::NotebookCellTitle, None, "notebook.cell.moveDown", "Move Cell Down", "3_edit", 14., Some("config.notebook.dragAndDropEnabled == false"), None),
    (MenuId::NotebookCellTitle, Some(MenuId::EditorContextShare), "", "Share", "4_share", 0., None, None),
    (MenuId::NotebookCellTitle, None, "notebook.toggleCellToolbarPosition", "Toggle Cell Toolbar Position", "View", 1., None, None),
    // insertCellActions.ts.
    (MenuId::NotebookCellInsert, None, "notebook.cell.insertCodeCellAbove", "Insert Code Cell Above", "", 0., None, None),
    (MenuId::NotebookCellInsert, None, "notebook.cell.insertCodeCellBelow", "Insert Code Cell Below", "", 1., None, None),
    (MenuId::NotebookCellInsert, None, "notebook.cell.insertMarkdownCellAbove", "Insert Markdown Cell Above", "", 2., None, None),
    (MenuId::NotebookCellInsert, None, "notebook.cell.insertMarkdownCellBelow", "Insert Markdown Cell Below", "", 3., None, None),
    // layoutActions.ts: the notebook toolbar's `...`; Breadcrumbs and Line Numbers are added in `workbench_menus`.
    (MenuId::NotebookToolbar, None, "workbench.notebook.layout.configure", "Customize Notebook Layout", "notebookLayout", 1., Some("config.notebook.globalToolbar == true"), None),
    // mergeEditor commands.ts `ResetToBaseAndAutoMergeCommand`.
    (MenuId::MergeInputResultToolbar, None, "mergeEditor.resetResultToBaseAndAutoMerge", "Reset Result", "primary", 0., None, Some("isMergeEditor")),
    // inlineCompletions/browser/controller/commands.ts: EditorAction menu items take the precondition as their `when`.
    (MenuId::InlineSuggestionToolbar, None, "editor.action.inlineSuggest.commit", "Accept", "primary", 2., Some("inlineSuggestionVisible || inlineEditIsVisible"), Some("inlineSuggestionVisible || inlineEditIsVisible")),
    (MenuId::InlineSuggestionToolbar, None, "editor.action.inlineSuggest.acceptNextWord", "Accept Word", "primary", 2., Some("!editorReadonly && inlineSuggestionVisible"), Some("!editorReadonly && inlineSuggestionVisible")),
    (MenuId::InlineSuggestionToolbar, None, "editor.action.inlineSuggest.acceptNextLine", "Accept Line", "secondary", 2., Some("!editorReadonly && inlineSuggestionVisible"), Some("!editorReadonly && inlineSuggestionVisible")),
    // notificationsCommands.ts: the title bar bell.
    (MenuId::TitleBar, None, "notifications.toggleList", "Toggle Notifications", "navigation", 10000., Some("config.workbench.notifications.position == 'top-right' && config.workbench.notifications.showInTitleBar == true"), None),
];

/// windowActions.ts, layoutActions.ts, auxiliaryBarActions.ts, panelActions.ts, activitybarPart.ts, toggleMinimap.ts, stickyScrollActions.ts and
/// toggleRenderControlCharacter.ts: the Appearance items the port has, checked by their `toggled`.
type ToggleRow = (MenuId, &'static str, &'static str, &'static str, f64, &'static str, &'static str);
const APPEARANCE_TOGGLES: [ToggleRow; 34] = [
    (MenuId::MenubarAppearanceMenu, "workbench.action.toggleZenMode", "Zen Mode", "1_toggle_view", 2., "!isSessionsWindow", "inZenMode"),
    (MenuId::MenubarAppearanceMenu, "workbench.action.toggleCenteredLayout", "&&Centered Layout", "1_toggle_view", 3., "!isSessionsWindow", "isCenteredLayout"),
    (MenuId::MenubarAppearanceMenu, "workbench.action.toggleStatusbarVisibility", "S&&tatus Bar", "2_workbench_layout", 3., "!isSessionsWindow", "config.workbench.statusBar.visible == true"),
    (MenuId::PanelPositionMenu, "workbench.action.positionPanelTop", "Top", "", 5., "", "panelPosition == 'top'"),
    (MenuId::PanelPositionMenu, "workbench.action.positionPanelLeft", "Left", "", 6., "", "panelPosition == 'left'"),
    (MenuId::PanelPositionMenu, "workbench.action.positionPanelRight", "Right", "", 7., "", "panelPosition == 'right'"),
    (MenuId::PanelPositionMenu, "workbench.action.positionPanelBottom", "Bottom", "", 8., "", "panelPosition == 'bottom'"),
    (MenuId::PanelAlignmentMenu, "workbench.action.alignPanelLeft", "Left", "", 5., "!isSessionsWindow", "panelAlignment == 'left'"),
    (MenuId::PanelAlignmentMenu, "workbench.action.alignPanelRight", "Right", "", 5., "!isSessionsWindow", "panelAlignment == 'right'"),
    (MenuId::PanelAlignmentMenu, "workbench.action.alignPanelCenter", "Center", "", 5., "", "panelAlignment == 'center'"),
    (MenuId::PanelAlignmentMenu, "workbench.action.alignPanelJustify", "Justify", "", 5., "", "panelAlignment == 'justify'"),
    (MenuId::MenubarAppearanceMenu, "workbench.action.toggleFullScreen", "&&Full Screen", "1_toggle_view", 1., "", "isFullscreen"),
    (MenuId::MenubarAppearanceMenu, "workbench.action.toggleSidebarVisibility", "&&Primary Side Bar", "2_workbench_layout", 1., "!isSessionsWindow", "sideBarVisible"),
    (MenuId::MenubarAppearanceMenu, "workbench.action.toggleAuxiliaryBar", "&&Secondary Side Bar", "2_workbench_layout", 2., "!isSessionsWindow", "secondarySideBarVisible"),
    (MenuId::MenubarAppearanceMenu, "workbench.action.togglePanel", "&&Panel", "2_workbench_layout", 5., "", "panelVisible"),
    // layoutDensityActions.ts
    (MenuId::LayoutDensityMenu, "workbench.action.setLayoutDensity.default", "Default", "", 1., "", "config.window.density.layout == 'default'"),
    (MenuId::LayoutDensityMenu, "workbench.action.setLayoutDensity.compact", "Compact", "", 2., "", "config.window.density.layout == 'compact'"),
    (MenuId::ActivityBarPositionMenu, "workbench.action.activityBarLocation.default", "&&Default", "", 1., "", "config.workbench.activityBar.location == 'default'"),
    (MenuId::ActivityBarPositionMenu, "workbench.action.activityBarLocation.top", "&&Top", "", 2., "", "config.workbench.activityBar.location == 'top'"),
    (MenuId::ActivityBarPositionMenu, "workbench.action.activityBarLocation.bottom", "&&Bottom", "", 3., "", "config.workbench.activityBar.location == 'bottom'"),
    (MenuId::ActivityBarPositionMenu, "workbench.action.activityBarLocation.hide", "&&Hidden", "", 4., "", "config.workbench.activityBar.location == 'hidden'"),
    (MenuId::MenubarAppearanceMenu, "editor.action.toggleMinimap", "&&Minimap", "4_editor", 1., "", "config.editor.minimap.enabled"),
    (MenuId::MenubarAppearanceMenu, "breadcrumbs.toggle", "&&Breadcrumbs", "4_editor", 2., "", "config.breadcrumbs.enabled"),
    (MenuId::MenubarAppearanceMenu, "editor.action.toggleStickyScroll", "&&Sticky Scroll", "4_editor", 3., "", "config.editor.stickyScroll.enabled"),
    (MenuId::MenubarAppearanceMenu, "editor.action.toggleRenderControlCharacter", "Render &&Control Characters", "4_editor", 5., "", "config.editor.renderControlCharacters"),
    // editor.contribution.ts: the Tab Bar and Editor Actions Position submenus.
    (MenuId::EditorTabsBarShowTabsSubmenu, "workbench.action.showMultipleEditorTabs", "Multiple Tabs", "1_config", 10., "", "config.workbench.editor.showTabs == 'multiple'"),
    (MenuId::EditorTabsBarShowTabsSubmenu, "workbench.action.showEditorTab", "Single Tab", "1_config", 20., "", "config.workbench.editor.showTabs == 'single'"),
    (MenuId::EditorTabsBarShowTabsSubmenu, "workbench.action.hideEditorTabs", "Hidden", "1_config", 30., "", "config.workbench.editor.showTabs == 'none'"),
    (MenuId::EditorTabsBarShowTabsZenModeSubmenu, "workbench.action.zenShowMultipleEditorTabs", "Multiple Tabs", "1_config", 10., "", "config.zenMode.showTabs == 'multiple'"),
    (MenuId::EditorTabsBarShowTabsZenModeSubmenu, "workbench.action.zenShowEditorTab", "Single Tab", "1_config", 20., "", "config.zenMode.showTabs == 'single'"),
    (MenuId::EditorTabsBarShowTabsZenModeSubmenu, "workbench.action.zenHideEditorTabs", "Hidden", "1_config", 30., "", "config.zenMode.showTabs == 'none'"),
    (MenuId::EditorActionsPositionSubmenu, "workbench.action.editorActionsDefault", "Tab Bar", "1_config", 10., "config.workbench.editor.showTabs != 'none'", "config.workbench.editor.editorActionsLocation == 'default'"),
    (
        MenuId::EditorActionsPositionSubmenu,
        "workbench.action.editorActionsTitleBar",
        "Title Bar",
        "1_config",
        20.,
        "",
        "config.workbench.editor.editorActionsLocation == 'titleBar' || config.workbench.editor.showTabs == 'none' && config.workbench.editor.editorActionsLocation == 'default'",
    ),
    (MenuId::EditorActionsPositionSubmenu, "workbench.action.hideEditorActions", "Hidden", "1_config", 30., "", "config.workbench.editor.editorActionsLocation == 'hidden'"),
];

/// themes.contribution.ts: `ThemesSubMenu` items.
const THEMES_SUBMENU: [(&str, &str, f64); 3] = [("workbench.action.selectTheme", "Color Theme", 1.), ("workbench.action.selectIconTheme", "File Icon Theme", 2.), ("workbench.action.selectProductIconTheme", "Product Icon Theme", 3.)];

/// titlebarActions.ts `ToggleTitleBarConfigAction`s of the title bar parts the port draws: setting, title, order,
/// `when`. Notifications and Integrated Browser toggle parts the port has not; Editor Actions is `EDITOR_ACTIONS_TOGGLE`.
/// titlebarActions.ts `ToggleEditorActions`.
pub const EDITOR_ACTIONS_TOGGLE: &str = "toggle.workbench.editor.editorActionsLocation";
pub const ALWAYS_SHOW_INLINE_TOOLBAR: &str = "editor.action.inlineSuggest.toggleAlwaysShowToolbar";
pub const TITLE_BAR_TOGGLES: [(&str, &str, f64, &str); 3] = [
    ("window.commandCenter", "Command Center", 1., "!isCompactTitleBar"),
    ("workbench.navigationControl.enabled", "Navigation Controls", 2., "!isCompactTitleBar && config.window.commandCenter"),
    ("workbench.layoutControl.enabled", "Layout Controls", 4., ""),
];

/// `MenuRegistry` with the workbench's items.
pub fn workbench_menus() -> Vec<MenuItem> {
    let mut items = Vec::new();
    for (menu, submenu, id, title, group, order, when, precondition) in WORKBENCH_MENUS.iter().copied() {
        let entry = match submenu {
            Some(submenu) => Entry::Submenu { submenu, toggled: None },
            None => {
                // The Delete item runs Delete Permanently with Alt held.
                let alt = match (menu, id) {
                    (_, "moveFileToTrash") => Some(Alt { id: "deleteFile".into(), title: "Delete Permanently".into(), precondition: None }),
                    (MenuId::DebugToolBar, "workbench.action.debug.stop") => Some(Alt { id: "workbench.action.debug.disconnect".into(), title: "Disconnect".into(), precondition: Expr::deserialize("!focusedSessionIsAttach && terminateDebuggeeSupported") }),
                    (MenuId::DebugToolBar, "workbench.action.debug.disconnect") => Some(Alt { id: "workbench.action.debug.stop".into(), title: "Stop".into(), precondition: Expr::deserialize("focusedSessionIsAttach && terminateDebuggeeSupported") }),
                    _ => None,
                };
                Entry::Command { id: id.to_string(), precondition: precondition.and_then(Expr::deserialize), toggled: None, alt }
            }
        };
        items.push(MenuItem { menu, entry, title: title.to_string(), group: group.to_string(), order, when: when.and_then(Expr::deserialize) });
    }
    // fileActions.contribution.ts: checked unless `files.autoSave` is `off`.
    let entry = Entry::Command { id: "workbench.action.toggleAutoSave".into(), precondition: None, toggled: Toggled::when(Expr::deserialize("config.files.autoSave != 'off'")), alt: None };
    items.push(MenuItem { menu: MenuId::MenubarFileMenu, entry, title: "A&&uto Save".into(), group: "5_autosave".into(), order: 1., when: None });
    // update.ts `UpdateContribution`: Show Update Release Notes on a stable build only.
    if crate::product::is_stable() {
        let entry = Entry::Command { id: "update.showUpdateReleaseNotes".into(), precondition: None, toggled: None, alt: None };
        let when = Expr::deserialize("updateState == 'ready' && majorMinorUpdateAvailable");
        items.push(MenuItem { menu: MenuId::GlobalActivity, entry, title: "Show Update Release Notes".into(), group: "7_update".into(), order: 1., when });
    }
    // extensions.contribution.ts: Download VSIX comes first on a stable build, Download Pre-Release VSIX elsewhere.
    let stable = crate::product::is_stable();
    let downloads = [
        ("workbench.extensions.action.download", "Download VSIX", if stable { 0. } else { 1. }, "!extensionDisallowInstall && isGalleryExtension"),
        ("workbench.extensions.action.downloadPreRelease", "Download Pre-Release VSIX", if stable { 1. } else { 0. }, "!extensionDisallowInstall && isGalleryExtension && extensionHasPreReleaseVersion"),
    ];
    for (id, title, order, when) in downloads {
        let entry = Entry::Command { id: id.into(), precondition: None, toggled: None, alt: None };
        items.push(MenuItem { menu: MenuId::ExtensionContext, entry, title: title.into(), group: String::new(), order, when: Expr::deserialize(when) });
    }
    let entry = Entry::Command { id: "workbench.extensions.action.toggleApplyToAllProfiles".into(), precondition: None, toggled: Toggled::when(Expr::deserialize("isApplicationScopedExtension")), alt: None };
    let when = Expr::deserialize("extensionStatus == 'installed' && !isDefaultApplicationScopedExtension && !isBuiltinExtension && isWorkspaceScopedExtension == false");
    items.push(MenuItem { menu: MenuId::ExtensionContext, entry, title: "Apply Extension to all Profiles".into(), group: "2_configure".into(), order: 3., when });
    // stickyScrollActions.ts and breadcrumbsControl.ts: the toggles' checked titles, the only ones the menu shows while it is open.
    for (id, setting, title) in [("breadcrumbs.toggle", "breadcrumbs.enabled", "Breadcrumbs"), ("editor.action.toggleStickyScroll", "editor.stickyScroll.enabled", "Sticky Scroll")] {
        let entry = Entry::Command { id: id.into(), precondition: None, toggled: Toggled::when(Expr::deserialize(&format!("config.{setting} == true"))), alt: None };
        items.push(MenuItem { menu: MenuId::StickyScrollContext, entry, title: title.into(), group: String::new(), order: 0., when: None });
    }
    // editor.contribution.ts: the toggles of the editor title's `...` and of the empty group's context menu.
    let toggles = [
        (MenuId::EditorTitle, "workbench.action.toggleKeepEditors", "Enable Preview Editors", "7_settings", 10., "config.workbench.editor.enablePreview", "!editorPartModal"),
        (MenuId::EditorTitle, "workbench.action.toggleEditorGroupLock", "Lock Group", "8_group_operations", 10., "activeEditorGroupLocked", "!isAuxiliaryWindow && !editorPartModal"),
        (MenuId::EmptyEditorGroupContext, "workbench.action.toggleEditorGroupLock", "Lock Group", "4_lock", 10., "activeEditorGroupLocked", "!isAuxiliaryWindow"),
        // codeCoverageDecorations.ts ToggleCoverageToolbar.
        (MenuId::EditorTitle, "testing.coverageToggleToolbar", "Show Test Coverage Toolbar", "coverage", 1., "testing.coverageToolbarEnabled", "testing.hasCoverageInFile"),
        (MenuId::StickyScrollContext, "testing.coverageToggleToolbar", "Show Test Coverage Toolbar", "", 0., "testing.coverageToolbarEnabled", "testing.isTestCoverageOpen"),
    ];
    for (menu, id, title, group, order, toggled, when) in toggles {
        let entry = Entry::Command { id: id.into(), precondition: None, toggled: Toggled::when(Some(Expr::has(toggled))), alt: None };
        items.push(MenuItem { menu, entry, title: title.into(), group: group.into(), order, when: Expr::deserialize(when) });
    }
    // codeCoverageDecorations.ts ToggleInlineCoverage and FilterCoverageToTestInEditor: editor title icons while the
    // coverage toolbar, which holds them otherwise, is off.
    let coverage_title_actions = [
        ("testing.toggleInlineCoverage", "Toggle Inline Coverage", "testing.inlineCoverageEnabled", Some("Hide Inline Coverage"), None, "testing.hasInlineCoverageDetails && testing.coverageToolbarEnabled != true"),
        ("testing.coverageFilterToTestInEditor", "Filter Coverage to Test", "testing.isCoverageFilteredToTest", None, Some("filter-filled"), "testing.hasCoverageInFile && testing.coverageToolbarEnabled != true && testing.hasPerTestCoverage && activeEditor == 'workbench.editors.files.textFileEditor'"),
    ];
    for (id, title, toggled, toggled_title, toggled_icon, when) in coverage_title_actions {
        let toggled = Toggled { condition: Expr::has(toggled), title: toggled_title.map(Into::into), icon: toggled_icon.map(Into::into) };
        let entry = Entry::Command { id: id.into(), precondition: None, toggled: Some(toggled), alt: None };
        items.push(MenuItem { menu: MenuId::EditorTitle, entry, title: title.into(), group: "navigation".into(), order: 0., when: Expr::deserialize(when) });
    }
    // inlineCompletions/browser/controller/commands.ts ToggleAlwaysShowInlineSuggestionToolbar.
    let toggled = Toggled::when(Expr::deserialize("config.editor.inlineSuggest.showToolbar == 'always'"));
    let entry = Entry::Command { id: ALWAYS_SHOW_INLINE_TOOLBAR.into(), precondition: None, toggled, alt: None };
    items.push(MenuItem { menu: MenuId::InlineSuggestionToolbar, entry, title: "Always Show Toolbar".into(), group: "secondary".into(), order: 10., when: None });
    // editor.contribution.ts: Diff View's modes, checked by the diff settings; Automatic names the mode it renders.
    let side_by_side = "config.diffEditor.renderSideBySide == true";
    let diff_modes = [
        ("diffEditor.setViewMode.inline", "Inline", 1., "config.diffEditor.renderSideBySide == false".to_string(), None),
        ("diffEditor.setViewMode.sideBySide", "Side by Side", 2., format!("{side_by_side} && config.diffEditor.useInlineViewWhenSpaceIsLimited == false"), None),
        ("diffEditor.setViewMode.automatic", "Automatic (Currently Side by Side)", 3., format!("{side_by_side} && config.diffEditor.useInlineViewWhenSpaceIsLimited == true"), Some("diffEditorAutomaticRenderSideBySide")),
        ("diffEditor.setViewMode.automatic", "Automatic (Currently Inline)", 3., format!("{side_by_side} && config.diffEditor.useInlineViewWhenSpaceIsLimited == true"), Some("!diffEditorAutomaticRenderSideBySide")),
    ];
    for (id, title, order, toggled, when) in diff_modes {
        let entry = Entry::Command { id: id.into(), precondition: None, toggled: Toggled::when(Expr::deserialize(&toggled)), alt: None };
        items.push(MenuItem { menu: MenuId::DiffEditorViewSubmenu, entry, title: title.into(), group: "1_view".into(), order, when: when.and_then(Expr::deserialize) });
    }
    // multiDiffEditor/browser/actions.ts `SetFileListPositionAction` and `SetFileListViewModeAction`, checked by the
    // list's position and view mode.
    let file_list = Expr::deserialize("activeEditor == 'multiDiffEditor' && multiDiffEditorFileListAvailable");
    for (id, title, position, order) in [("multiDiffEditor.positionFileListLeft", "On the Left", "left", 1.), ("multiDiffEditor.positionFileListRight", "On the Right", "right", 2.)] {
        let toggled = Toggled::when(Expr::deserialize(&format!("multiDiffEditorFileListPosition == '{position}'")));
        let entry = Entry::Command { id: id.into(), precondition: file_list.clone(), toggled, alt: None };
        items.push(MenuItem { menu: MenuId::MultiDiffEditorFilesViewAndPosition, entry, title: title.into(), group: "2_position".into(), order, when: file_list.clone() });
    }
    for (id, title, mode, order) in [("multiDiffEditor.viewFileListAsList", "View as List", "list", 1.), ("multiDiffEditor.viewFileListAsTree", "View as Tree", "tree", 2.)] {
        let toggled = Toggled::when(Expr::deserialize(&format!("multiDiffEditorFileListViewMode == '{mode}'")));
        let entry = Entry::Command { id: id.into(), precondition: file_list.clone(), toggled, alt: None };
        items.push(MenuItem { menu: MenuId::MultiDiffEditorFilesViewAndPosition, entry, title: title.into(), group: "1_view".into(), order, when: file_list.clone() });
    }
    // terminal.stickyScroll.contribution.ts: Toggle Sticky Scroll, checked by its setting.
    let entry = Entry::Command { id: "workbench.action.terminal.toggleStickyScroll".into(), precondition: None, toggled: Toggled::when(Expr::deserialize("config.terminal.integrated.stickyScroll.enabled == true")), alt: None };
    items.push(MenuItem { menu: MenuId::TerminalStickyScrollContext, entry, title: "Sticky Scroll".into(), group: String::new(), order: 0., when: None });
    // layoutActions.ts: the notebook editor title's Customize Notebook... gear and its submenu, with the toggles'
    // short titles (toolbar dropdowns render `shortTitle`). Not ported: Toggle Cell Toolbar Position (the cell
    // toolbar is always on the right, `notebook.cellToolbarLocation` is not read).
    let notebook = Expr::deserialize("activeEditor == 'workbench.editor.notebook'");
    let entry = Entry::Submenu { submenu: MenuId::NotebookEditorLayoutConfigure, toggled: None };
    items.push(MenuItem { menu: MenuId::EditorTitle, entry, title: "Customize Notebook...".into(), group: "navigation".into(), order: -1., when: notebook.clone() });
    let entry = Entry::Command { id: "workbench.notebook.layout.configure.editorTitle".into(), precondition: None, toggled: None, alt: None };
    items.push(MenuItem { menu: MenuId::NotebookEditorLayoutConfigure, entry, title: "Customize Notebook Layout".into(), group: "notebookLayout".into(), order: 1., when: notebook.clone() });
    let toggles = [
        ("notebook.toggleLineNumbersFromEditorTitle", "Line Numbers", "config.notebook.lineNumbers != 'off'", Some("notebookEditorFocused"), 1., notebook.clone()),
        ("breadcrumbs.toggleFromEditorTitle", "Breadcrumbs", "config.breadcrumbs.enabled == true", None, 2., None),
    ];
    for (id, title, checked, precondition, order, when) in toggles {
        let toggled = Toggled::when(Expr::deserialize(checked));
        let entry = Entry::Command { id: id.into(), precondition: precondition.and_then(Expr::deserialize), toggled, alt: None };
        items.push(MenuItem { menu: MenuId::NotebookEditorLayoutConfigure, entry, title: title.into(), group: "notebookLayoutDetails".into(), order, when });
    }
    let entry = Entry::Command { id: "notebook.toggleCellToolbarPositionFromEditorTitle".into(), precondition: None, toggled: None, alt: None };
    items.push(MenuItem { menu: MenuId::NotebookEditorLayoutConfigure, entry, title: "Toggle Cell Toolbar Position".into(), group: "notebookLayoutDetails".into(), order: 3., when: None });
    // cellEditorOptions.ts `ToggleActiveLineNumberAction`, checked by the cell's own setting, else the notebook's.
    let toggled = Toggled::when(Expr::deserialize("notebookCellLineNumbers == 'on' || notebookCellLineNumbers == 'inherit' && config.notebook.lineNumbers == 'on'"));
    let entry = Entry::Command { id: "notebook.cell.toggleLineNumbers".into(), precondition: notebook.clone(), toggled, alt: None };
    items.push(MenuItem { menu: MenuId::NotebookCellTitle, entry, title: "Show Cell Line Numbers".into(), group: "View".into(), order: 1., when: None });
    // breadcrumbsControl.ts and cellEditorOptions.ts in the notebook toolbar's `...`, titled as the toolbar renders
    // them (Line Numbers' `shortTitle`).
    let global_toolbar = Expr::deserialize("config.notebook.globalToolbar == true");
    let toolbar_toggles = [
        ("breadcrumbs.toggle", "Breadcrumbs", "config.breadcrumbs.enabled == true", None, None),
        ("notebook.toggleLineNumbers", "Line Numbers", "config.notebook.lineNumbers != 'off'", Expr::deserialize("notebookEditorFocused"), global_toolbar),
    ];
    for (id, title, checked, precondition, when) in toolbar_toggles {
        let entry = Entry::Command { id: id.into(), precondition, toggled: Toggled::when(Expr::deserialize(checked)), alt: None };
        items.push(MenuItem { menu: MenuId::NotebookToolbar, entry, title: title.into(), group: "notebookLayout".into(), order: 2., when });
    }
    // toggleWordWrap.ts: checked while the active editor wraps, enabled while it can toggle.
    let entry = Entry::Command { id: "editor.action.toggleWordWrap".into(), precondition: Some(Expr::has("canToggleWordWrap")), toggled: Toggled::when(Some(Expr::has("editorWordWrap"))), alt: None };
    items.push(MenuItem { menu: MenuId::MenubarViewMenu, entry, title: "&&Word Wrap".into(), group: "6_editor".into(), order: 1., when: None });
    // toggleWordWrap.ts: the editor title action of a file dominated by long lines.
    for (title, when) in [("Disable wrapping for this file", "isDominatedByLongLines && isWordWrapMinified"), ("Enable wrapping for this file", "!inDiffEditor && isDominatedByLongLines && !isWordWrapMinified")] {
        let entry = Entry::Command { id: "editor.action.toggleWordWrap".into(), precondition: None, toggled: None, alt: None };
        items.push(MenuItem { menu: MenuId::EditorTitle, entry, title: title.into(), group: "navigation".into(), order: 1., when: Expr::deserialize(when) });
    }
    // fileActions.contribution.ts `appendSaveConflictEditorTitleAction`: the conflict editor's accept and revert.
    for (id, title, order) in [("workbench.files.action.acceptLocalChanges", "Use your changes and overwrite file contents", -10.), ("workbench.files.action.revertLocalChanges", "Discard your changes and revert to file contents", -9.)] {
        let entry = Entry::Command { id: id.into(), precondition: None, toggled: None, alt: None };
        items.push(MenuItem { menu: MenuId::EditorTitle, entry, title: title.into(), group: "navigation".into(), order, when: Expr::deserialize("saveConflictResolutionContext") });
    }
    // localHistoryCommands.ts: Restore Contents on the editor of a local history entry.
    let entry = Entry::Command { id: "workbench.action.localHistory.restoreViaEditor".into(), precondition: None, toggled: None, alt: None };
    items.push(MenuItem { menu: MenuId::EditorTitle, entry, title: "Restore Contents".into(), group: "navigation".into(), order: -10., when: Expr::deserialize("resourceScheme == 'vscode-local-history'") });
    // toggleColumnSelection.ts: checked while `config.editor.columnSelection` is true.
    let entry = Entry::Command { id: "editor.action.toggleColumnSelection".into(), precondition: None, toggled: Toggled::when(Some(Expr::has("config.editor.columnSelection"))), alt: None };
    items.push(MenuItem { menu: MenuId::MenubarSelectionMenu, entry, title: "Column &&Selection Mode".into(), group: "4_config".into(), order: 2., when: None });
    // toggleMultiCursorModifier.ts: the item names the modifier the toggle switches to.
    for (title, current) in [("Switch to Alt+Click for Multi-Cursor", "ctrlCmd"), ("Switch to Cmd+Click for Multi-Cursor", "altKey")] {
        let entry = Entry::Command { id: "workbench.action.toggleMultiCursorModifier".into(), precondition: None, toggled: None, alt: None };
        let when = Expr::deserialize(&format!("multiCursorModifier == '{current}'"));
        items.push(MenuItem { menu: MenuId::MenubarSelectionMenu, entry, title: title.into(), group: "4_config".into(), order: 1., when });
    }
    // The Appearance items with their check: menu, command, title, group, order, `when`, `toggled`.
    for (menu, id, title, group, order, when, toggled) in APPEARANCE_TOGGLES {
        let entry = Entry::Command { id: id.into(), precondition: None, toggled: Toggled::when(Expr::deserialize(toggled)), alt: None };
        items.push(MenuItem { menu, entry, title: title.into(), group: group.into(), order, when: Expr::deserialize(when) });
    }
    for (id, title, order) in THEMES_SUBMENU {
        let entry = Entry::Command { id: id.to_string(), precondition: None, toggled: None, alt: None };
        items.push(MenuItem { menu: MenuId::ThemesSubMenu, entry, title: title.to_string(), group: String::new(), order, when: None });
    }
    for (setting, title, order, when) in TITLE_BAR_TOGGLES {
        for menu in [MenuId::TitleBarContext, MenuId::TitleBarTitleContext] {
            let toggled = Toggled::when(Some(Expr::has(&format!("config.{setting}"))));
            let entry = Entry::Command { id: format!("toggle.{setting}"), precondition: None, toggled, alt: None };
            items.push(MenuItem { menu, entry, title: title.to_string(), group: "2_config".into(), order, when: Expr::deserialize(when) });
        }
    }
    for menu in [MenuId::TitleBarContext, MenuId::TitleBarTitleContext] {
        let toggled = Toggled::when(Expr::deserialize("config.workbench.editor.editorActionsLocation != 'hidden'"));
        let entry = Entry::Command { id: EDITOR_ACTIONS_TOGGLE.into(), precondition: None, toggled, alt: None };
        let when = Expr::deserialize("config.workbench.editor.showTabs == 'none' || config.workbench.editor.editorActionsLocation != 'default'");
        items.push(MenuItem { menu, entry, title: "Editor Actions".into(), group: "2_config".into(), order: 3., when });
    }
    items.extend(crate::workbench::scm_actions::menu_items());
    items
}

/// menusExtensionPoint.ts `apiMenus`: the `contributes.menus` keys of the menus the port shows. `commandPalette`
/// is read by `command_palette::menu`.
const API_MENUS: &[(&str, MenuId)] = &[
    ("file/newFile", MenuId::NewFile),
    ("editor/context", MenuId::EditorContext),
    ("explorer/context", MenuId::ExplorerContext),
    ("editor/title/context", MenuId::EditorTitleContext),
    ("editor/lineNumber/context", MenuId::EditorLineNumberContext),
    ("scm/title", MenuId::ScmTitle),
    ("scm/resourceGroup/context", MenuId::ScmResourceGroupContext),
    ("scm/resourceState/context", MenuId::ScmResourceStateContext),
    ("scm/resourceFolder/context", MenuId::ScmResourceFolderContext),
    ("scm/inputBox", MenuId::ScmInputBox),
    ("scm/change/title", MenuId::ScmChangeContext),
    ("diffEditor/gutter/hunk", MenuId::DiffEditorHunkToolbar),
    ("diffEditor/gutter/selection", MenuId::DiffEditorSelectionToolbar),
    ("multiDiffEditor/content", MenuId::MultiDiffEditorContent),
    ("multiDiffEditor/resource/title", MenuId::MultiDiffEditorFileToolbar),
    ("editor/title", MenuId::EditorTitle),
    ("editor/title/run", MenuId::EditorTitleRun),
    ("interactive/toolbar", MenuId::InteractiveToolbar),
    ("notebook/toolbar", MenuId::NotebookToolbar),
    ("notebook/cell/title", MenuId::NotebookCellTitle),
    ("notebook/cell/execute", MenuId::NotebookCellExecute),
    ("notebook/kernelSource", MenuId::NotebookKernelSource),
    ("notebook/variables/context", MenuId::NotebookVariablesContext),
    ("interactive/cell/title", MenuId::InteractiveCellTitle),
    ("scm/sourceControl", MenuId::ScmSourceControl),
    ("scm/repositories/title", MenuId::ScmSourceControlTitle),
    ("scm/repository", MenuId::ScmSourceControlInline),
    ("scm/artifactGroup/context", MenuId::ScmArtifactGroupContext),
    ("scm/artifact/context", MenuId::ScmArtifactContext),
    ("scm/history/title", MenuId::ScmHistoryTitle),
    ("scm/historyItem/context", MenuId::ScmHistoryItemContext),
    ("scm/historyItemRef/context", MenuId::ScmHistoryItemRefContext),
    ("timeline/title", MenuId::TimelineTitle),
    ("timeline/item/context", MenuId::TimelineItemContext),
    ("testing/item/context", MenuId::TestItem),
    ("testing/profiles/context", MenuId::TestProfilesContext),
    ("testing/item/gutter", MenuId::TestItemGutter),
    ("testing/item/result", MenuId::TestPeekElement),
    ("testing/message/context", MenuId::TestMessageContext),
    ("testing/message/content", MenuId::TestMessageContent),
    ("debug/callstack/context", MenuId::DebugCallStackContext),
    ("debug/variables/context", MenuId::DebugVariablesContext),
    ("debug/watch/context", MenuId::DebugWatchContext),
    ("debug/toolBar", MenuId::DebugToolBar),
    ("debug/createConfiguration", MenuId::DebugCreateConfiguration),
    ("view/title", MenuId::ViewTitle),
    ("viewContainer/title", MenuId::ViewContainerTitle),
    ("extension/context", MenuId::ExtensionContext),
    ("view/item/context", MenuId::ViewItemContext),
    ("editor/context/copy", MenuId::EditorContextCopy),
    ("editor/context/share", MenuId::EditorContextShare),
    ("explorer/context/share", MenuId::ExplorerContextShare),
    ("editor/title/context/share", MenuId::EditorTitleContextShare),
    ("file/share", MenuId::MenubarShare),
    ("menuBar/edit/copy", MenuId::MenubarCopy),
    ("editor/content", MenuId::EditorContent),
    ("webview/context", MenuId::WebviewContext),
    ("comments/commentThread/title", MenuId::CommentThreadTitle),
    ("comments/commentThread/context", MenuId::CommentThreadActions),
    ("comments/commentThread/additionalActions", MenuId::CommentThreadAdditionalActions),
    ("comments/comment/title", MenuId::CommentTitle),
    ("comments/comment/context", MenuId::CommentActions),
    ("commentsView/commentThread/context", MenuId::CommentsViewThreadActions),
    ("comments/comment/editorActions", MenuId::CommentEditorActions),
    ("comments/commentThread/title/context", MenuId::CommentThreadTitleContext),
    ("comments/commentThread/comment/context", MenuId::CommentThreadCommentContext),
    ("mergeEditor/result/title", MenuId::MergeInputResultToolbar),
    ("titleBar", MenuId::TitleBar),
    ("modalEditor/editorTitle", MenuId::ModalEditorEditorTitle),
    ("editor/inlineCompletions/actions", MenuId::InlineCompletionsActions),
    ("terminal/context", MenuId::TerminalInstanceContext),
    ("terminal/title/context", MenuId::TerminalTabContext),
];

/// The `icon` of each `contributes.commands` entry with one: a `$(codicon)` name, or the light and dark image paths.
pub fn command_icons(extensions: &[ScannedExtension]) -> std::collections::HashMap<String, CommandIcon> {
    let mut icons = crate::workbench::scm_actions::command_icons();
    // toggleWordWrap.ts: the editor title items' `Codicon.wordWrap`.
    icons.insert("editor.action.toggleWordWrap".to_string(), CommandIcon::Codicon("word-wrap".into()));
    // debugIcons.ts `debugInspectMemory`.
    icons.insert("workbench.debug.viewlet.action.viewMemory".to_string(), CommandIcon::Codicon("debug-inspect-memory".into()));
    // localHistory.ts `LOCAL_HISTORY_ICON_RESTORE`.
    icons.insert("workbench.action.localHistory.restoreViaEditor".to_string(), CommandIcon::Codicon("check".into()));
    icons.insert("workbench.files.action.acceptLocalChanges".to_string(), CommandIcon::Codicon("check".into()));
    icons.insert("workbench.files.action.revertLocalChanges".to_string(), CommandIcon::Codicon("discard".into()));
    // testing icons.ts: a test row's inline actions and the call stack's; callStackWidget.ts `Codicon.goToFile`.
    for (id, icon) in [("testing.toggleInlineCoverage", "coverage"), ("testing.coverageFilterToTestInEditor", "filter"), ("testing.run", "run"), ("testing.debug", "debug-alt-small"), ("testing.coverage", "run-coverage"), ("testing.callStack.run", "run"), ("testing.callStack.debug", "debug-alt-small"), ("callStackWidget.goToFile", "go-to-file")] {
        icons.insert(id.to_string(), CommandIcon::Codicon(icon.into()));
    }
    // notebookIcons.ts: the cell toolbar's buttons.
    let notebook_icons = [
        ("notebook.section.runCells", "play"),
        ("notebook.cell.edit", "pencil"),
        ("notebook.cell.executeCellsAbove", "run-above"),
        ("notebook.cell.executeCellAndBelow", "run-below"),
        ("notebook.cell.quitEdit", "check"),
        ("notebook.cell.split", "split-vertical"),
        ("notebook.cell.clearOutputs", "clear-all"),
        ("notebook.cell.delete", "trash"),
        ("notebook.cell.moveUp", "arrow-up"),
        ("notebook.cell.moveDown", "arrow-down"),
    ];
    for (id, icon) in notebook_icons {
        icons.insert(id.to_string(), CommandIcon::Codicon(icon.into()));
    }
    for extension in extensions {
        let commands = match &extension.description["contributes"]["commands"] {
            Value::Array(commands) => commands.iter().collect(),
            command @ Value::Object(_) => vec![command],
            _ => Vec::new(),
        };
        for command in commands {
            let Some(id) = command["command"].as_str() else { continue };
            let Some(icon) = contributed_icon(extension, &command["icon"]) else { continue };
            icons.insert(id.to_string(), icon);
        }
    }
    icons
}

/// menusExtensionPoint.ts: a contributed submenu's `icon`, which its menu items show in toolbars.
pub fn submenu_icons(extensions: &[ScannedExtension]) -> std::collections::HashMap<MenuId, CommandIcon> {
    contributed_submenus(extensions).into_iter().filter_map(|(_, submenu, _, icon)| Some((submenu, icon?))).collect()
}

/// A contributed command's or submenu's `icon`: `$(codicon)`, a path for both themes, or `{ light, dark }` paths.
fn contributed_icon(extension: &ScannedExtension, icon: &Value) -> Option<CommandIcon> {
    match icon {
        Value::String(icon) => match icon.strip_prefix("$(").and_then(|icon| icon.strip_suffix(')')) {
            Some(codicon) => Some(CommandIcon::Codicon(codicon.to_string())),
            None => Some(CommandIcon::Image(extension.location.join(icon), extension.location.join(icon))),
        },
        Value::Object(paths) => {
            let path = |key: &str| extension.location.join(paths.get(key).and_then(Value::as_str).unwrap_or_default());
            Some(CommandIcon::Image(path("light"), path("dark")))
        }
        _ => None,
    }
}

/// A command's icon in a toolbar (`ICommandAction.icon`).
#[derive(Clone, Debug, PartialEq)]
pub enum CommandIcon {
    Codicon(String),
    Image(std::path::PathBuf, std::path::PathBuf),
}

/// menusExtensionPoint.ts, the `submenus` and `menus` handlers: every extension's `contributes.menus` items of the
/// port's menus and of contributed submenus, with their command's title and enablement from `contributes.commands`.
/// An item of a command or submenu nobody contributes is skipped, as is a menu whose items are not all valid.
pub fn extension_menus(extensions: &[ScannedExtension]) -> Vec<MenuItem> {
    let commands: Vec<_> = extensions.iter().flat_map(crate::command_palette::contributed_commands).collect();
    // MenuRegistry.addCommand: the last registration of an id wins.
    let find_command = |id: &str| commands.iter().rev().find(|command| command.id == id);
    let submenus = contributed_submenus(extensions);
    let mut items = Vec::new();
    let mut submenu_items: Vec<(MenuId, MenuId)> = Vec::new();
    for extension in extensions {
        let Some(menus) = extension.description["contributes"]["menus"].as_object() else { continue };
        let message = |severity, text: String| crate::perf::extension_point_message(&extension.id, severity, text);
        for (key, entries) in menus {
            let Some(entries) = entries.as_array() else {
                message(Severity::Error, "submenu items must be an array".into());
                continue;
            };
            if let Some(reject) = entries.iter().find_map(menu_item_reject) {
                message(Severity::Error, reject);
                continue;
            }
            let api_menu = API_MENUS.iter().find(|(api_key, _)| api_key == key).map(|(_, menu)| *menu);
            // menusExtensionPoint.ts: the `proposed` menus need their API proposal.
            let proposal = match key.as_str() {
                "editor/content" | "multiDiffEditor/content" => Some("contribEditorContentMenu"),
                "debug/createConfiguration" => Some("contribDebugCreateConfiguration"),
                "commentsView/commentThread/context" => Some("contribCommentsViewThreadMenus"),
                "comments/comment/editorActions" => Some("contribCommentEditorActionsMenu"),
                "comments/commentThread/additionalActions" => Some("contribCommentThreadAdditionalMenu"),
                "comments/commentThread/title/context" | "comments/commentThread/comment/context" => Some("contribCommentPeekContext"),
                "mergeEditor/result/title" => Some("contribMergeEditorMenus"),
                "titleBar" => Some("contribTitleBar"),
                "editor/inlineCompletions/actions" => Some("inlineCompletionsAdditions"),
                "diffEditor/gutter/selection" => Some("contribDiffEditorGutterToolBarMenus"),
                "scm/historyItemRef/context" => Some("contribSourceControlHistoryItemMenu"),
                "viewContainer/title" => Some("contribViewContainerTitle"),
                "notebook/kernelSource" => Some("notebookKernelSource"),
                _ => None,
            };
            if let Some(proposal) = proposal.filter(|proposal| !extension.description["enabledApiProposals"].as_array().is_some_and(|proposals| proposals.iter().any(|enabled| enabled == proposal))) {
                message(Severity::Error, format!("{key} is a proposed menu identifier. It requires 'package.json#enabledApiProposals: [\"{proposal}\"]' and is only available when running out of dev or with the following command line switch: --enable-proposed-api {}", extension.id));
                continue;
            }
            let Some(menu) = api_menu.or_else(|| submenus.iter().find(|(id, ..)| id == key).map(|(_, menu, ..)| *menu)) else { continue };
            for entry in entries {
                let (entry_value, title) = match entry["command"].as_str() {
                    Some(id) => {
                        let Some(command) = find_command(id) else { continue };
                        let alt = entry["alt"].as_str().and_then(find_command).map(|alt| Alt { id: alt.id.clone(), title: alt.title.clone(), precondition: alt.precondition.clone() });
                        if entry["alt"] == id {
                            message(Severity::Info, "Menu item references the same command as default and alt-command".into());
                        }
                        (Entry::Command { id: command.id.clone(), precondition: command.precondition.clone(), toggled: None, alt }, command.title.clone())
                    }
                    None => {
                        if ["file/newFile", "comments/commentThread/context", "comments/comment/context"].contains(&key.as_str()) {
                            message(Severity::Error, "Menu item references a submenu for a menu which doesn't have submenu support.".into());
                            continue;
                        }
                        let submenu_id = entry["submenu"].as_str().expect("checked by menu_item_reject");
                        let Some((_, submenu, label, _)) = submenus.iter().find(|(id, ..)| id == submenu_id) else {
                            message(Severity::Error, format!("Menu item references a submenu `{submenu_id}` which is not defined in the 'submenus' section."));
                            continue;
                        };
                        if submenu_items.contains(&(menu, *submenu)) {
                            message(Severity::Warning, format!("The `{submenu_id}` submenu was already contributed to the `{key}` menu."));
                            continue;
                        }
                        submenu_items.push((menu, *submenu));
                        (Entry::Submenu { submenu: *submenu, toggled: None }, label.clone())
                    }
                };
                let (group, order) = group_and_order(entry["group"].as_str().unwrap_or_default());
                if menu == MenuId::ViewContainerTitle && !entry["when"].as_str().is_some_and(|when| when.contains("viewContainer == workbench.view.debug")) {
                    message(Severity::Error, "The `viewContainer/title` menu contribution must check `viewContainer == workbench.view.debug` in its \"when\" clause.".into());
                    continue;
                }
                let when = entry["when"].as_str().and_then(Expr::deserialize);
                items.push(MenuItem { menu, entry: entry_value, title, group, order, when });
            }
        }
    }
    items
}

/// `contributes.submenus`: id, menu id, label and icon; the first registration of an id wins.
fn contributed_submenus(extensions: &[ScannedExtension]) -> Vec<(String, MenuId, String, Option<CommandIcon>)> {
    let mut submenus: Vec<(String, MenuId, String, Option<CommandIcon>)> = Vec::new();
    for extension in extensions {
        let message = |severity, text: String| crate::perf::extension_point_message(&extension.id, severity, text);
        for submenu in extension.description["contributes"]["submenus"].as_array().into_iter().flatten() {
            if matches!(submenu, Value::Bool(_) | Value::Number(_) | Value::String(_)) {
                message(Severity::Error, "submenu items must be an object".into());
                continue;
            }
            let Some(id) = submenu["id"].as_str() else {
                message(Severity::Error, "property `id` is mandatory and must be of type `string`".into());
                continue;
            };
            let Some(label) = submenu["label"].as_str() else {
                message(Severity::Error, "property `label` is mandatory and must be of type `string`".into());
                continue;
            };
            if id.is_empty() {
                message(Severity::Warning, "`` is not a valid submenu identifier".into());
                continue;
            }
            if submenus.iter().any(|(known, ..)| known == id) {
                message(Severity::Info, format!("The `{id}` submenu was already previously registered."));
                continue;
            }
            if label.is_empty() {
                message(Severity::Warning, "`` is not a valid submenu label".into());
                continue;
            }
            submenus.push((id.to_string(), MenuId::Api(submenus.len()), label.to_string(), contributed_icon(extension, &submenu["icon"])));
        }
    }
    submenus
}

/// `schema.isValidMenuItem` and `isValidSubmenuItem`: why the item is rejected. `command` or `submenu` is a
/// string; `alt`, `when` and `group` are falsy or strings.
fn menu_item_reject(item: &Value) -> Option<String> {
    let (required, optional) = match item["command"].is_string() {
        true => ("command", &["alt", "when", "group"][..]),
        false => ("submenu", &["when", "group"][..]),
    };
    if !item[required].is_string() {
        return Some(format!("property `{required}` is mandatory and must be of type `string`"));
    }
    let wrong = optional.iter().find(|key| crate::contextkey::truthy(item.get(**key)) && !item[**key].is_string())?;
    Some(format!("property `{wrong}` can be omitted or must be of type `string`"))
}

/// `group@order`: the order after the last `@` (0 when it is not a number), the group alone otherwise.
fn group_and_order(group: &str) -> (String, f64) {
    match group.rfind('@') {
        Some(index) if index > 0 => (group[..index].to_string(), group[index + 1..].trim().parse().ok().filter(|order: &f64| !order.is_nan()).unwrap_or(0.)),
        _ => (group.to_string(), 0.),
    }
}

/// `getFlatContextMenuActions(menu.getActions())`: the items of `menu` whose `when` holds, in groups joined by
/// separators. A submenu without actions is left out.
pub fn menu_actions(registry: &[MenuItem], menu: MenuId, context: &dyn Context) -> Vec<MenuAction> {
    menu_group_actions(registry, menu, context, |_| true)
}

/// `menu_actions` of the groups `keep` takes, as `getActionBarActions` splits a toolbar's buttons from its `...`.
pub fn menu_group_actions(registry: &[MenuItem], menu: MenuId, context: &dyn Context, keep: impl Fn(&str) -> bool) -> Vec<MenuAction> {
    let holds = |expr: &Option<Expr>| expr.as_ref().is_none_or(|expr| expr.evaluate(context));
    let mut items: Vec<&MenuItem> = registry.iter().filter(|item| item.menu == menu && keep(&item.group) && holds(&item.when)).collect();
    items.sort_by(|a, b| compare_menu_items(a, b));
    // The main menu's titles name its menus: electron-main/menubar.ts labels them with its own `localize` calls.
    let localize = |title: String| match menu {
        MenuId::MenubarMainMenu => title,
        _ => crate::nls::localize_in(&format!("{menu:?}"), &title).into_owned(),
    };
    let mut actions = Vec::new();
    let mut group: Option<&str> = None;
    for item in items {
        let action = match &item.entry {
            Entry::Command { id, precondition, toggled, alt } => {
                let toggled = toggled.as_ref().filter(|toggled| toggled.condition.evaluate(context));
                let title = toggled.and_then(|toggled| toggled.title.clone()).unwrap_or_else(|| item.title.clone());
                let alt = alt.as_ref().filter(|alt| holds(&alt.precondition)).map(|alt| (alt.id.clone(), alt.title.clone()));
                MenuAction::Command { id: id.clone(), title: localize(title), enabled: holds(precondition), checked: toggled.is_some(), alt }
            }
            Entry::Submenu { submenu, toggled } => {
                let submenu_actions = menu_actions(registry, *submenu, context);
                if submenu_actions.is_empty() {
                    continue;
                }
                let checked = toggled.as_ref().is_some_and(|toggled| toggled.evaluate(context));
                MenuAction::Submenu { title: localize(item.title.clone()), actions: submenu_actions, checked }
            }
        };
        if group.is_some_and(|group| group != item.group) {
            actions.push(MenuAction::Separator);
        }
        group = Some(&item.group);
        actions.push(action);
    }
    actions
}

/// `MenuInfo.compareMenuItems`: groups by name with `navigation` first and no group last, then order, then title.
pub fn compare_menu_items(a: &MenuItem, b: &MenuItem) -> Ordering {
    if a.group != b.group {
        match (a.group.as_str(), b.group.as_str()) {
            ("", _) => return Ordering::Greater,
            (_, "") => return Ordering::Less,
            ("navigation", _) => return Ordering::Less,
            (_, "navigation") => return Ordering::Greater,
            (a, b) => match locale_compare(a, b) {
                Ordering::Equal => {}
                order => return order,
            },
        }
    }
    a.order.total_cmp(&b.order).then_with(|| locale_compare(&a.title, &b.title))
}

/// labels.ts `mnemonicMenuLabel` on macOS: mnemonics are dropped.
pub fn mnemonic_menu_label(label: &str) -> String {
    static MNEMONIC: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"\(&&\w\)|&&").expect("valid pattern"));
    MNEMONIC.replace_all(label, "").into_owned()
}