-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
147 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/cursorless-vscode/src/keyboard/KeyboardCommandTypeHelpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { KeyboardCommandHandler } from "./KeyboardCommandHandler"; | ||
|
||
/** | ||
* Maps from the name of a method in KeyboardCommandHandler to the type of its | ||
* argument. | ||
*/ | ||
export type KeyboardCommandArgTypes = { | ||
[K in keyof KeyboardCommandHandler]: KeyboardCommandHandler[K] extends ( | ||
arg: infer T, | ||
) => void | ||
? T | ||
: never; | ||
}; | ||
|
||
export type KeyboardCommandTypeMap = { | ||
[K in keyof KeyboardCommandHandler]: { | ||
type: K; | ||
arg: KeyboardCommandArgTypes[K]; | ||
}; | ||
}; | ||
|
||
export type KeyboardCommand<T extends keyof KeyboardCommandHandler> = { | ||
type: T; | ||
arg: KeyboardCommandArgTypes[T]; | ||
}; | ||
|
||
// Ensure that all methods in KeyboardCommandHandler take an object as their | ||
// first argument, and return void or Promise<void>. Note that the first check | ||
// may look backwards, because the arg type is contravariant, so the 'extends' | ||
// needs to be flipped. | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
function assertExtends<A extends B, B>() {} | ||
assertExtends< | ||
Record<keyof KeyboardCommandArgTypes, (arg?: object) => never>, | ||
Pick<KeyboardCommandHandler, keyof KeyboardCommandArgTypes> | ||
>; | ||
assertExtends< | ||
Pick<KeyboardCommandHandler, keyof KeyboardCommandArgTypes>, | ||
Record<keyof KeyboardCommandArgTypes, (arg: never) => void | Promise<void>> | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 11 additions & 7 deletions
18
packages/cursorless-vscode/src/keyboard/grammar/MyPostProcess.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters