Skip to content

Commit

Permalink
Add hat snapshot documentation code links (#362)
Browse files Browse the repository at this point in the history
* Add hat snapshot documentation code links

* Fix doc links

* More cleanup

* cleanup
  • Loading branch information
pokey authored Dec 7, 2021
1 parent 0b685a7 commit d855232
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions docs/architecture/hat-snapshots.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

In order to allow long chained command phrases, we take a snapshot of the hat token map at the start of a phrase and continue to use this map during the course of the entire phrase. This way you can be sure that any commands issued during the course of a single phrase that refer to a decorated token will continue to refer to the same logical token no matter what happens in the document during phrase execution. Note that the ranges of tokens will be kept current as the document changes so that they refer to the same logical range, but the same logical token will keep the same key in the hat token map over the course of a phrase.

To make this work, first the voice engine touches a file within the signals subdirectory of the command server communication directory after the phrase has been parsed but right before execution begins. Then cursorless will check the version of the signal file via the command server signal API. If the signal has been emitted since the last time cursorless took a snapshot of the hat token map, it will take a new snapshot and continue to use that snapshot of the hats until the next time the signal is emitted. Note that the signal transmission is asynchronous so cursorless just needs to make sure to check the version of the signal before it either updates or reads the map.
To make this work, first the voice engine [touches](https://github.com/knausj85/knausj_talon/blob/e373780af16256ab8fd5638af32d97fa23c4c0fc/apps/vscode/command_client/command_client.py#L398) a file within the signals subdirectory of the command server communication directory after the phrase has been parsed but right before execution begins. Then cursorless will check the version of the signal file before it [reads](https://github.com/pokey/cursorless-vscode/blob/2a624888369d41b0531e472d001d63d09912c8aa/src/core/HatTokenMap.ts#L88) or [updates](https://github.com/pokey/cursorless-vscode/blob/main/src/core/HatTokenMap.ts#L70) the hat token map via the command server [signal API](https://github.com/pokey/command-server/blob/2b9f9ea2a38b6e95aa60ff9553a804165e527308/src/extension.ts#L29). If the signal has been emitted since the last time cursorless took a snapshot of the hat token map, it will take a new snapshot and continue to use that snapshot of the hats until the next time the signal is emitted. Note that the signal transmission is asynchronous so cursorless just needs to make sure to check the version of the signal before it either updates or reads the map.

![flow diagram](hat-token-map-snapshots.png)
In the diagram below, we document the flow of a couple different cases. Dotted lines represent asynchronous / fire-and-forget communication:

![flow diagram](images/hat-token-map-snapshots.png)

([diagram source](https://swimlanes.io/d/1KkgFFCtj))
Binary file removed docs/architecture/hat-token-map-snapshots.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d855232

Please sign in to comment.