diff --git a/extensions/typescript/src/utils/commandManager.ts b/extensions/typescript/src/utils/commandManager.ts index 1a5b2ced886..153358e3db2 100644 --- a/extensions/typescript/src/utils/commandManager.ts +++ b/extensions/typescript/src/utils/commandManager.ts @@ -12,19 +12,21 @@ export interface Command { } export class CommandManager { - private readonly commands: vscode.Disposable[] = []; + private readonly commands = new Map(); public dispose() { - while (this.commands.length) { - const obj = this.commands.pop(); - if (obj) { - obj.dispose(); - } + for (const registration of this.commands) { + registration[1].dispose(); } + this.commands.clear(); } public registerCommand(id: string, impl: (...args: any[]) => void, thisArg?: any) { - this.commands.push(vscode.commands.registerCommand(id, impl, thisArg)); + if (this.commands.has(id)) { + return; + } + + this.commands.set(id, vscode.commands.registerCommand(id, impl, thisArg)); } public register(command: Command) {