Skip to content

Commit 57ff467

Browse files
committed
More PR feedback
1 parent 99a7427 commit 57ff467

File tree

8 files changed

+41
-17
lines changed

8 files changed

+41
-17
lines changed

packages/common/src/ide/types/FileSystem.types.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,15 @@ export interface FileSystem {
1010
* @returns A disposable to cancel the watcher
1111
*/
1212
watchDir(path: string, onDidChange: PathChangeListener): Disposable;
13+
14+
/**
15+
* The path to the directory that Cursorless talon uses to share its state
16+
* with the Cursorless engine.
17+
*/
18+
readonly cursorlessDir: string;
19+
20+
/**
21+
* The path to the spoken forms JSON file.
22+
*/
23+
readonly cursorlessTalonStateJsonPath: string;
1324
}

packages/cursorless-engine/src/api/CursorlessEngineApi.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export interface CursorlessEngine {
1212
storedTargets: StoredTargetMap;
1313
hatTokenMap: HatTokenMap;
1414
snippets: Snippets;
15-
spokenFormsJsonPath: string;
1615
injectIde: (ide: IDE | undefined) => void;
1716
runIntegrationTests: () => Promise<void>;
1817
}

packages/cursorless-engine/src/cursorlessEngine.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ export function createCursorlessEngine(
9999
storedTargets,
100100
hatTokenMap,
101101
snippets,
102-
spokenFormsJsonPath: talonSpokenForms.spokenFormsPath,
103102
injectIde,
104103
runIntegrationTests: () =>
105104
runIntegrationTests(treeSitter, languageDefinitions),

packages/cursorless-engine/src/generateSpokenForm/CustomSpokenFormGeneratorImpl.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,7 @@ export class CustomSpokenFormGeneratorImpl
5555
return this.customSpokenForms.needsInitialTalonUpdate;
5656
}
5757

58-
dispose = this.disposer.dispose;
58+
dispose() {
59+
this.disposer.dispose();
60+
}
5961
}

packages/cursorless-engine/src/nodeCommon/TalonSpokenFormsJsonReader.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import { Disposer, FileSystem, Notifier, isTesting } from "@cursorless/common";
2-
import * as crypto from "crypto";
1+
import { Disposer, FileSystem, Notifier } from "@cursorless/common";
32
import { mkdir, readFile } from "fs/promises";
4-
import * as os from "os";
53

64
import * as path from "path";
75
import {
@@ -20,20 +18,16 @@ const LATEST_SPOKEN_FORMS_JSON_VERSION = 0;
2018
export class TalonSpokenFormsJsonReader implements TalonSpokenForms {
2119
private disposer = new Disposer();
2220
private notifier = new Notifier();
23-
public readonly spokenFormsPath;
21+
private cursorlessTalonStateJsonPath;
2422

2523
constructor(private fileSystem: FileSystem) {
26-
const cursorlessDir = isTesting()
27-
? path.join(os.tmpdir(), crypto.randomBytes(16).toString("hex"))
28-
: path.join(os.homedir(), ".cursorless");
29-
30-
this.spokenFormsPath = path.join(cursorlessDir, "state.json");
24+
this.cursorlessTalonStateJsonPath = fileSystem.cursorlessTalonStateJsonPath;
3125

3226
this.init();
3327
}
3428

3529
private async init() {
36-
const parentDir = path.dirname(this.spokenFormsPath);
30+
const parentDir = path.dirname(this.cursorlessTalonStateJsonPath);
3731
await mkdir(parentDir, { recursive: true });
3832
this.disposer.push(
3933
this.fileSystem.watchDir(parentDir, () =>
@@ -52,11 +46,13 @@ export class TalonSpokenFormsJsonReader implements TalonSpokenForms {
5246
async getSpokenFormEntries(): Promise<SpokenFormEntry[]> {
5347
let payload: TalonSpokenFormsPayload;
5448
try {
55-
payload = JSON.parse(await readFile(this.spokenFormsPath, "utf-8"));
49+
payload = JSON.parse(
50+
await readFile(this.cursorlessTalonStateJsonPath, "utf-8"),
51+
);
5652
} catch (err) {
5753
if ((err as any)?.code === "ENOENT") {
5854
throw new NeedsInitialTalonUpdateError(
59-
`Custom spoken forms file not found at ${this.spokenFormsPath}. Using default spoken forms.`,
55+
`Custom spoken forms file not found at ${this.cursorlessTalonStateJsonPath}. Using default spoken forms.`,
6056
);
6157
}
6258

packages/cursorless-engine/src/spokenForms/CustomSpokenForms.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ export class CustomSpokenForms {
125125
}));
126126
}
127127

128-
dispose = this.disposer.dispose;
128+
dispose() {
129+
this.disposer.dispose();
130+
}
129131
}
130132

131133
function updateEntriesForType<T extends SpokenFormType>(

packages/cursorless-vscode/src/extension.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,15 @@ async function createVscodeIde(context: vscode.ExtensionContext) {
139139
);
140140
await hats.init();
141141

142-
return { vscodeIDE, hats, fileSystem: new VscodeFileSystem() };
142+
// FIXME: Inject this from test harness. Would need to arrange to delay
143+
// extension initialization, probably by returning a function from extension
144+
// init that has parameters consisting of test configuration, and have that
145+
// function do the actual initialization.
146+
const cursorlessDir = isTesting()
147+
? path.join(os.tmpdir(), crypto.randomBytes(16).toString("hex"))
148+
: path.join(os.homedir(), ".cursorless");
149+
150+
return { vscodeIDE, hats, fileSystem: new VscodeFileSystem(cursorlessDir) };
143151
}
144152

145153
function createTreeSitter(parseTreeApi: ParseTreeApi): TreeSitter {

packages/cursorless-vscode/src/ide/vscode/VscodeFileSystem.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { Disposable, FileSystem, PathChangeListener } from "@cursorless/common";
22
import { RelativePattern, workspace } from "vscode";
3+
import * as path from "path";
34

45
export class VscodeFileSystem implements FileSystem {
6+
constructor(public cursorlessDir: string) {}
7+
8+
public get cursorlessTalonStateJsonPath() {
9+
return path.join(this.cursorlessDir, "state.json");
10+
}
11+
512
watchDir(path: string, onDidChange: PathChangeListener): Disposable {
613
// FIXME: Support globs?
714
const watcher = workspace.createFileSystemWatcher(

0 commit comments

Comments
 (0)