Path: blob/main/extensions/markdown-language-features/src/commandManager.ts
3292 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import * as vscode from 'vscode';67export interface Command {8readonly id: string;910execute(...args: any[]): void;11}1213export class CommandManager {14private readonly _commands = new Map<string, vscode.Disposable>();1516public dispose() {17for (const registration of this._commands.values()) {18registration.dispose();19}20this._commands.clear();21}2223public register<T extends Command>(command: T): vscode.Disposable {24this._registerCommand(command.id, command.execute, command);25return new vscode.Disposable(() => {26this._commands.delete(command.id);27});28}2930private _registerCommand(id: string, impl: (...args: any[]) => void, thisArg?: any) {31if (this._commands.has(id)) {32return;33}3435this._commands.set(id, vscode.commands.registerCommand(id, impl, thisArg));36}37}383940