提交 6afc2c69 编写于 作者: S Sandeep Somavarapu

Fix #23356

上级 6bee7fc4
......@@ -126,10 +126,15 @@ export interface IMenuService {
export interface IMenuRegistry {
addCommand(userCommand: ICommandAction): boolean;
getCommand(id: string): ICommandAction;
getCommands(): ICommandsMap;
appendMenuItem(menu: MenuId, item: IMenuItem | ISubmenuItem): IDisposable;
getMenuItems(loc: MenuId): (IMenuItem | ISubmenuItem)[];
}
export interface ICommandsMap {
[id: string]: ICommandAction;
}
export const MenuRegistry: IMenuRegistry = new class implements IMenuRegistry {
private _commands: { [id: string]: ICommandAction } = Object.create(null);
......@@ -146,6 +151,10 @@ export const MenuRegistry: IMenuRegistry = new class implements IMenuRegistry {
return this._commands[id];
}
getCommands(): ICommandsMap {
return Object.freeze(this._commands);
}
appendMenuItem({ id }: MenuId, item: IMenuItem | ISubmenuItem): IDisposable {
let array = this._menuItems[id];
if (!array) {
......
......@@ -8,6 +8,7 @@ import { isFalsyOrEmpty } from 'vs/base/common/arrays';
import { ContextKeyExpr, IContext, ContextKeyAndExpr } from 'vs/platform/contextkey/common/contextkey';
import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem';
import { CommandsRegistry, ICommandHandlerDescription } from 'vs/platform/commands/common/commands';
import { MenuRegistry } from 'vs/platform/actions/common/actions';
export interface IResolveResult {
enterChord: boolean;
......@@ -302,21 +303,31 @@ export class KeybindingResolver {
}
public static getAllUnboundCommands(boundCommands: Map<string, boolean>): string[] {
const commands = CommandsRegistry.getCommands();
const unboundCommands: string[] = [];
for (let id in commands) {
if (id[0] === '_' || id.indexOf('vscode.') === 0) { // private command
continue;
const seenMap: Map<string, boolean> = new Map<string, boolean>();
const addCommand = id => {
if (seenMap.has(id)) {
return;
}
if (typeof commands[id].description === 'object'
&& !isFalsyOrEmpty((<ICommandHandlerDescription>commands[id].description).args)) { // command with args
continue;
seenMap.set(id);
if (id[0] === '_' || id.indexOf('vscode.') === 0) { // private command
return;
}
if (boundCommands.get(id) === true) {
continue;
return;
}
const command = CommandsRegistry.getCommand(id);
if (command && typeof command.description === 'object'
&& !isFalsyOrEmpty((<ICommandHandlerDescription>command.description).args)) { // command with args
return;
}
unboundCommands.push(id);
};
for (const id in MenuRegistry.getCommands()) {
addCommand(id);
}
for (const id in CommandsRegistry.getCommands()) {
addCommand(id);
}
return unboundCommands;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册