Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/markdown-language-features/src/commandManager.ts
3292 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as vscode from 'vscode';
7
8
export interface Command {
9
readonly id: string;
10
11
execute(...args: any[]): void;
12
}
13
14
export class CommandManager {
15
private readonly _commands = new Map<string, vscode.Disposable>();
16
17
public dispose() {
18
for (const registration of this._commands.values()) {
19
registration.dispose();
20
}
21
this._commands.clear();
22
}
23
24
public register<T extends Command>(command: T): vscode.Disposable {
25
this._registerCommand(command.id, command.execute, command);
26
return new vscode.Disposable(() => {
27
this._commands.delete(command.id);
28
});
29
}
30
31
private _registerCommand(id: string, impl: (...args: any[]) => void, thisArg?: any) {
32
if (this._commands.has(id)) {
33
return;
34
}
35
36
this._commands.set(id, vscode.commands.registerCommand(id, impl, thisArg));
37
}
38
}
39
40