Make cheat sheet handle missing spoken forms#2760
Conversation
| if "replaceWithTarget" in complex_actions: | ||
| items.append( | ||
| { | ||
| "id": "replaceWithTarget", | ||
| "type": "action", | ||
| "variations": [ | ||
| { | ||
| "spokenForm": f"{complex_actions['replaceWithTarget']} <target> <destination>", | ||
| "description": "Copy <target> to <destination>", | ||
| }, | ||
| { | ||
| "spokenForm": f"{complex_actions['replaceWithTarget']} <target>", | ||
| "description": "Insert copy of <target> at cursor", | ||
| }, | ||
| ], | ||
| } | ||
| ) | ||
|
|
There was a problem hiding this comment.
There's a bit of duplication here and this switches from defining a data structure to a fair bit of imperative code, but I think we could reduce it.
Why not something like a dictionary of tuples (one description and one lambda that generates the spoken form?):
{
"replaceWithTarget": ("Copy <target> to <destination>", lambda value: f"{value} <target> <destination>"),
}Then we could just use a loop to generate all of these and remove some the duplication.
Not sure if you could refer to stuff outside of the scope like swap_connective but I think it's helpful either way, if not that means the more complicated ones will stay as imperative code, which I think itself helps with readability.
There was a problem hiding this comment.
Better like this?
phillco
left a comment
There was a problem hiding this comment.
lgtm let's do the same magic on the others
Today the cheat sheet generation crashes if the user has disabled certain spoken forms Fixes #2647 ## Checklist - [/] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [/] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [/] I have not broken the cheatsheet
Today the cheat sheet generation crashes if the user has disabled certain spoken forms
Fixes #2647
Checklist