Skip to content

Commit b708cc4

Browse files
Remove node process from hat token map (#2501)
Since we're using a threshold of sixty seconds I don't think we need nanosecond precision. Instead of finding a polyfill for bigint I just switch to date.now which gives us the time in milliseconds. ## 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 --------- Co-authored-by: Pokey Rule <[email protected]>
1 parent bb988f3 commit b708cc4

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

packages/cursorless-engine/src/core/HatTokenMapImpl.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import {
55
ReadOnlyHatMap,
66
TokenHat,
77
} from "@cursorless/common";
8-
import { hrtime } from "process";
98
import { ide } from "../singletons/ide.singleton";
10-
import { abs } from "../util/bigint";
119
import { Debug } from "./Debug";
1210
import { HatAllocator } from "./HatAllocator";
1311
import { IndividualHatMap } from "./IndividualHatMap";
@@ -16,7 +14,7 @@ import { RangeUpdater } from "./updateSelections/RangeUpdater";
1614
/**
1715
* Maximum age for the pre-phrase snapshot before we consider it to be stale
1816
*/
19-
const PRE_PHRASE_SNAPSHOT_MAX_AGE_NS = BigInt(6e10); // 60 seconds
17+
const PRE_PHRASE_SNAPSHOT_MAX_AGE_MS = 60000; // 60 seconds
2018

2119
/**
2220
* Maps from (hatStyle, character) pairs to tokens
@@ -34,7 +32,7 @@ export class HatTokenMapImpl implements HatTokenMap {
3432
* hat with the same color and shape will refer to the same logical range.
3533
*/
3634
private prePhraseMapSnapshot?: IndividualHatMap;
37-
private prePhraseMapsSnapshotTimestamp: bigint | null = null;
35+
private prePhraseMapsSnapshotTimestamp: number | null = null;
3836

3937
private lastSignalVersion: string | null = null;
4038
private hatAllocator: HatAllocator;
@@ -106,8 +104,8 @@ export class HatTokenMapImpl implements HatTokenMap {
106104
}
107105

108106
if (
109-
abs(hrtime.bigint() - this.prePhraseMapsSnapshotTimestamp!) >
110-
PRE_PHRASE_SNAPSHOT_MAX_AGE_NS
107+
performance.now() - this.prePhraseMapsSnapshotTimestamp! >
108+
PRE_PHRASE_SNAPSHOT_MAX_AGE_MS
111109
) {
112110
console.error(
113111
"Navigation map pre-phrase snapshot requested, but snapshot is more than a minute old",
@@ -149,6 +147,6 @@ export class HatTokenMapImpl implements HatTokenMap {
149147
}
150148

151149
this.prePhraseMapSnapshot = this.activeMap.clone();
152-
this.prePhraseMapsSnapshotTimestamp = hrtime.bigint();
150+
this.prePhraseMapsSnapshotTimestamp = performance.now();
153151
}
154152
}

packages/cursorless-engine/src/util/bigint.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)