-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathregisterCommands.ts
More file actions
98 lines (84 loc) · 3.25 KB
/
registerCommands.ts
File metadata and controls
98 lines (84 loc) · 3.25 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import {
CURSORLESS_COMMAND_ID,
CursorlessCommandId,
isTesting,
} from "@cursorless/common";
import {
CommandApi,
TestCaseRecorder,
showCheatsheet,
updateDefaults,
} from "@cursorless/cursorless-engine";
import * as vscode from "vscode";
import { showDocumentation, showQuickPick } from "./commands";
import { VscodeIDE } from "./ide/vscode/VscodeIDE";
import { VscodeHats } from "./ide/vscode/hats/VscodeHats";
import { KeyboardCommands } from "./keyboard/KeyboardCommands";
import { ScopeVisualizer } from "./ScopeVisualizerCommandApi";
export function registerCommands(
extensionContext: vscode.ExtensionContext,
vscodeIde: VscodeIDE,
commandApi: CommandApi,
testCaseRecorder: TestCaseRecorder,
scopeVisualizer: ScopeVisualizer,
keyboardCommands: KeyboardCommands,
hats: VscodeHats,
): void {
const commands: Record<CursorlessCommandId, (...args: any[]) => any> = {
// The core Cursorless command
[CURSORLESS_COMMAND_ID]: async (...args: unknown[]) => {
try {
return await commandApi.runCommandSafe(...args);
} catch (e) {
if (!isTesting()) {
const err = e as Error;
console.error(err.stack);
vscodeIde.handleCommandError(err);
}
throw e;
}
},
// Cheatsheet commands
["cursorless.showCheatsheet"]: showCheatsheet,
["cursorless.internal.updateCheatsheetDefaults"]: updateDefaults,
// Testcase recorder commands
["cursorless.recordTestCase"]: testCaseRecorder.toggle,
["cursorless.recordOneTestCaseThenPause"]:
testCaseRecorder.recordOneThenPause,
["cursorless.pauseRecording"]: testCaseRecorder.pause,
["cursorless.resumeRecording"]: testCaseRecorder.resume,
["cursorless.takeSnapshot"]: testCaseRecorder.takeSnapshot,
// Other commands
["cursorless.showQuickPick"]: showQuickPick,
["cursorless.showDocumentation"]: showDocumentation,
// Hats
["cursorless.toggleDecorations"]: hats.toggle,
["cursorless.recomputeDecorationStyles"]: hats.recomputeDecorationStyles,
// Scope visualizer
["cursorless.showScopeVisualizer"]: scopeVisualizer.start,
["cursorless.hideScopeVisualizer"]: scopeVisualizer.stop,
// General keyboard commands
["cursorless.keyboard.escape"]:
keyboardCommands.keyboardHandler.cancelActiveListener,
// Targeted keyboard commands
["cursorless.keyboard.targeted.targetHat"]:
keyboardCommands.targeted.targetDecoratedMark,
["cursorless.keyboard.targeted.targetScope"]:
keyboardCommands.targeted.targetScopeType,
["cursorless.keyboard.targeted.targetSelection"]:
keyboardCommands.targeted.targetSelection,
["cursorless.keyboard.targeted.clearTarget"]:
keyboardCommands.targeted.clearTarget,
["cursorless.keyboard.targeted.runActionOnTarget"]:
keyboardCommands.targeted.performActionOnTarget,
// Modal keyboard commands
["cursorless.keyboard.modal.modeOn"]: keyboardCommands.modal.modeOn,
["cursorless.keyboard.modal.modeOff"]: keyboardCommands.modal.modeOff,
["cursorless.keyboard.modal.modeToggle"]: keyboardCommands.modal.modeToggle,
};
extensionContext.subscriptions.push(
...Object.entries(commands).map(([commandId, callback]) =>
vscode.commands.registerCommand(commandId, callback),
),
);
}