-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial attempt to at snapshots * Switch to unnamed snapshots * A kind of workign attempt * A kind of workign attempt * Use command server signal API * More error robustness * Working version * Have navigation map return snapshot * Attempt at big refactor * Fixes to get it running * Rename * Bind function * Remove unnecessary field * Add docstring * snapshot => prePhraseSnapshot * Clean yaml * Do disposal in hat allocator * navigationMap => hatTokenMap * Add tests * Make isTesting into function * Set testing env var * Try to change env var * Initial cleanup work for edits outside viewport * More cleanup * Fix yarn lockfile * Fix yarn * refactoring * Fixes; add tests * File rename * Finish merging * Some cleanup * Create command runner class * Working backwards compatible command runner * More backward compatibility fixes * Rejects stale snapshots * Add link * A bunch of refactoring * Test fixes * Revert change * Improved canonicalization * Add comment * Fix ci * Rollback decoration test change * Attempt to fix decorations * Normalize hat enablement during testing * Fix recorded tests * Fix tests * Cleanup test recording * Add docs * Fix creating nested recorded test directories * Cleanup test case bulk transformer * More transform script fixes * More transform stuff * Upgrade a test
- Loading branch information
Showing
862 changed files
with
4,494 additions
and
3,827 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
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,7 @@ | ||
# Hat snapshots | ||
|
||
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. | ||
|
||
![flow diagram](hat-token-map-snapshots.png) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import * as vscode from "vscode"; | ||
import { addDecorationsToEditors } from "../util/addDecorationsToEditor"; | ||
import { DECORATION_DEBOUNCE_DELAY } from "../core/constants"; | ||
import { Graph } from "../typings/Types"; | ||
import { Disposable } from "vscode"; | ||
import { IndividualHatMap } from "./IndividualHatMap"; | ||
|
||
interface Context { | ||
getActiveMap(): Promise<IndividualHatMap>; | ||
} | ||
|
||
export class HatAllocator { | ||
private timeoutHandle: NodeJS.Timeout | null = null; | ||
private isActive: boolean; | ||
private disposables: Disposable[] = []; | ||
private disposalFunctions: (() => void)[] = []; | ||
|
||
constructor(private graph: Graph, private context: Context) { | ||
graph.extensionContext.subscriptions.push(this); | ||
|
||
this.isActive = vscode.workspace | ||
.getConfiguration("cursorless") | ||
.get<boolean>("showOnStart")!; | ||
|
||
this.addDecorationsDebounced = this.addDecorationsDebounced.bind(this); | ||
this.toggleDecorations = this.toggleDecorations.bind(this); | ||
this.clearEditorDecorations = this.clearEditorDecorations.bind(this); | ||
|
||
this.disposalFunctions.push( | ||
graph.decorations.registerDecorationChangeListener( | ||
this.addDecorationsDebounced | ||
) | ||
); | ||
|
||
this.disposables.push( | ||
vscode.commands.registerCommand( | ||
"cursorless.toggleDecorations", | ||
this.toggleDecorations | ||
), | ||
|
||
vscode.window.onDidChangeTextEditorVisibleRanges( | ||
this.addDecorationsDebounced | ||
), | ||
vscode.window.onDidChangeActiveTextEditor(this.addDecorationsDebounced), | ||
vscode.window.onDidChangeVisibleTextEditors(this.addDecorationsDebounced), | ||
vscode.window.onDidChangeTextEditorSelection( | ||
this.addDecorationsDebounced | ||
), | ||
vscode.workspace.onDidChangeTextDocument(this.addDecorationsDebounced) | ||
); | ||
} | ||
|
||
private clearEditorDecorations(editor: vscode.TextEditor) { | ||
this.graph.decorations.decorations.forEach(({ decoration }) => { | ||
editor.setDecorations(decoration, []); | ||
}); | ||
} | ||
|
||
async addDecorations() { | ||
const activeMap = await this.context.getActiveMap(); | ||
|
||
if (this.isActive) { | ||
addDecorationsToEditors(activeMap, this.graph.decorations); | ||
} else { | ||
vscode.window.visibleTextEditors.forEach(this.clearEditorDecorations); | ||
activeMap.clear(); | ||
} | ||
} | ||
|
||
addDecorationsDebounced() { | ||
if (this.timeoutHandle != null) { | ||
clearTimeout(this.timeoutHandle); | ||
} | ||
|
||
this.timeoutHandle = setTimeout(() => { | ||
this.addDecorations(); | ||
|
||
this.timeoutHandle = null; | ||
}, DECORATION_DEBOUNCE_DELAY); | ||
} | ||
|
||
private toggleDecorations() { | ||
this.isActive = !this.isActive; | ||
this.addDecorationsDebounced(); | ||
} | ||
|
||
dispose() { | ||
this.disposables.forEach(({ dispose }) => dispose()); | ||
this.disposalFunctions.forEach((dispose) => dispose()); | ||
|
||
if (this.timeoutHandle != null) { | ||
clearTimeout(this.timeoutHandle); | ||
} | ||
} | ||
} |
Oops, something went wrong.