-
-
Notifications
You must be signed in to change notification settings - Fork 85
Allow spoken forms generator to use custom #1947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pokey
merged 16 commits into
main
from
pokey/allow-spoken-forms-generator-to-use-custom
Oct 23, 2023
Merged
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ffbd0b1
Allow spoken forms generator to use custom
pokey 77e28dd
Fix tests
pokey 605b6fa
Update unit tests
pokey 1a31ee7
Don't test spoken forms for secret scopes
pokey 78beb77
Doc string
pokey 0bca581
More doc strings
pokey 12347ed
More doc string
pokey c017178
Tweaks
pokey f74032c
Rename file
pokey 1ae0d45
Strengthen types
pokey 95df930
Doc strings
pokey 61a2da6
tweaks
pokey 46b82dc
Tweaks
pokey c81fe64
tweaks
pokey fd64a8f
Cleanup
pokey ecafb63
comment
pokey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,47 @@ | ||
/** | ||
* The spoken form of a command, scope type, etc, that can be spoken | ||
* using a given set of custom or default spoken forms. | ||
*/ | ||
export interface SpokenFormSuccess { | ||
type: "success"; | ||
|
||
/** | ||
* The spoken forms for this entity. These could either be a user's custom | ||
* spoken forms, if we have access to them, or the default spoken forms, if we | ||
* don't, or if we're testing. There will often only be a single entry in this | ||
* array, but there can be multiple if the user has used the `|` syntax in their | ||
* spoken form csv's to define aliases for a single spoken form. | ||
*/ | ||
spokenForms: string[]; | ||
} | ||
|
||
/** | ||
* An error spoken form, which indicates that the given entity (command, scope | ||
* type, etc) cannot be spoken, and the reason why. | ||
*/ | ||
export interface SpokenFormError { | ||
type: "error"; | ||
|
||
/** | ||
* The reason why the entity cannot be spoken. | ||
*/ | ||
reason: string; | ||
|
||
/** | ||
* If `true`, indicates that the entity wasn't found in the user's Talon spoken | ||
* forms json, and so they need to update their cursorless-talon to get the | ||
* given entity. | ||
*/ | ||
requiresTalonUpdate: boolean; | ||
|
||
/** | ||
* If `true`, indicates that the entity is only for internal experimentation, | ||
* and should not be exposed to users except within a targeted working group. | ||
*/ | ||
isPrivate: boolean; | ||
} | ||
|
||
/** | ||
* A spoken form, which can either be a success or an error. | ||
*/ | ||
export type SpokenForm = SpokenFormSuccess | SpokenFormError; |
This file contains hidden or 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,17 @@ | ||
/** | ||
* Converts a camelCase string to a string with spaces between each word, and | ||
* all words in lowercase. | ||
* | ||
* Example: `camelCaseToAllDown("fooBarBaz")` returns `"foo bar baz"`. | ||
* | ||
* @param input A camelCase string | ||
* @returns The same string, but with spaces between each word, and all words | ||
* in lowercase | ||
*/ | ||
export function camelCaseToAllDown(input: string): string { | ||
return input | ||
.replace(/([A-Z])/g, " $1") | ||
.split(" ") | ||
.map((word) => word.toLowerCase()) | ||
.join(" "); | ||
} |
6 changes: 5 additions & 1 deletion
6
packages/cursorless-engine/src/generateSpokenForm/NoSpokenFormError.ts
This file contains hidden or 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 |
---|---|---|
@@ -1,5 +1,9 @@ | ||
export class NoSpokenFormError extends Error { | ||
constructor(public reason: string) { | ||
constructor( | ||
public reason: string, | ||
public requiresTalonUpdate: boolean = false, | ||
public isPrivate: boolean = false, | ||
) { | ||
super(`No spoken form for: ${reason}`); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
packages/cursorless-engine/src/generateSpokenForm/SpokenFormComponent.ts
This file contains hidden or 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 { SpokenFormMapEntry } from "../spokenForms/SpokenFormMap"; | ||
import { | ||
SpokenFormMapKeyTypes, | ||
SpokenFormType, | ||
} from "../spokenForms/SpokenFormType"; | ||
|
||
/** | ||
* A component of a spoken form used internally during spoken form generation. | ||
* This is a recursive type, so it can contain other spoken form components. | ||
* During the final step of spoken form generation, it is flattened. | ||
* | ||
* FIXME: In the future, we want to replace `string` with something like | ||
* `LiteralSpokenFormComponent` and `SpokenFormComponent[]` with something like | ||
* `SequenceSpokenFormComponent`. We'd also like to avoid throwing | ||
* `NoSpokenFormError` and instead return a `SpokenFormComponent` that | ||
* represents an error. This would allow us to localize errors and still render | ||
* the remainder of the spoken form component. | ||
*/ | ||
export type SpokenFormComponent = | ||
| CustomizableSpokenFormComponent | ||
| string | ||
| SpokenFormComponent[]; | ||
|
||
export interface CustomizableSpokenFormComponentForType< | ||
T extends SpokenFormType, | ||
> { | ||
type: "customizable"; | ||
spokenForms: SpokenFormMapEntry; | ||
spokenFormType: T; | ||
id: SpokenFormMapKeyTypes[T]; | ||
} | ||
|
||
/** | ||
* A customizable spoken form component. This is a spoken form component that | ||
* can be customized by the user. It is used internally during spoken form | ||
* generation. | ||
*/ | ||
export type CustomizableSpokenFormComponent = { | ||
[K in SpokenFormType]: CustomizableSpokenFormComponentForType<K>; | ||
}[SpokenFormType]; |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.