xref: /llvm-project/mlir/utils/vscode/src/command.ts (revision 01652d889cf31708bc7ebbf18ef0a4d925112bc7)
1import * as vscode from 'vscode';
2import {MLIRContext} from './mlirContext';
3
4/**
5 * This class represents a base vscode command. It handles all of the necessary
6 * command registration and disposal boilerplate.
7 */
8export abstract class Command extends vscode.Disposable {
9  private disposable: vscode.Disposable;
10  protected context: MLIRContext;
11
12  constructor(command: string, context: MLIRContext) {
13    super(() => this.dispose());
14    this.disposable =
15        vscode.commands.registerCommand(command, this.execute, this);
16    this.context = context;
17  }
18
19  dispose() { this.disposable && this.disposable.dispose(); }
20
21  /**
22   * The function executed when this command is invoked.
23   */
24  abstract execute(...args: any[]): any;
25}
26