forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmockCommandManager.ts
More file actions
39 lines (34 loc) · 1.46 KB
/
mockCommandManager.ts
File metadata and controls
39 lines (34 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { noop } from 'lodash';
import { Disposable, TextEditor, TextEditorEdit } from 'vscode';
import { ICommandManager } from '../../client/common/application/types';
// tslint:disable:no-any no-http-string no-multiline-string max-func-body-length
export class MockCommandManager implements ICommandManager {
private commands: {[key: string]: (...args: any[]) => any} = {};
public registerCommand(command: string, callback: (...args: any[]) => any, thisArg?: any): Disposable {
this.commands[command] = callback;
return {
dispose: () => {
noop();
}
};
}
public registerTextEditorCommand(command: string, callback: (textEditor: TextEditor, edit: TextEditorEdit, ...args: any[]) => void, thisArg?: any): Disposable {
throw new Error('Method not implemented.');
}
public executeCommand<T>(command: string, ...rest: any[]): Thenable<T> {
const func = this.commands[command];
const result = func(...rest);
const tPromise = result as Promise<T>;
if (tPromise) {
return tPromise;
}
return Promise.resolve(result);
}
public getCommands(filterInternal?: boolean): Thenable<string[]> {
const keys = Object.keys(this.commands);
return Promise.resolve(keys);
}
}