Skip to content

Commit

Permalink
Remove node references from Talon spoken form reader
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasArvidsson committed Jul 9, 2024
1 parent 0a70357 commit 6efad17
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
12 changes: 12 additions & 0 deletions packages/common/src/ide/types/FileSystem.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,23 @@ export interface FileSystem {
*/
watchDir(path: string, onDidChange: PathChangeListener): Disposable;

/**
* Reads a file from the file system.
* @param path The path to the file to read.
* @returns The contents of the file, decoded as UTF-8.
*/
readFile(path: string): Promise<string>;

/**
* The path to the Cursorless talon state JSON file.
*/
readonly cursorlessTalonStateJsonPath: string;

/**
* The path to the directory containing the Cursorless talon state JSON file.
*/
readonly cursorlessTalonStateJsonDirPath: string;

/**
* The path to the Cursorless command history directory.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { Disposable, FileSystem, Notifier } from "@cursorless/common";
import { readFile } from "fs/promises";

import * as path from "path";
import {
NeedsInitialTalonUpdateError,
SpokenFormEntry,
TalonSpokenForms,
} from "../scopeProviders/TalonSpokenForms";
} from "./scopeProviders/TalonSpokenForms";

interface TalonSpokenFormsPayload {
version: number;
Expand All @@ -21,7 +18,7 @@ export class TalonSpokenFormsJsonReader implements TalonSpokenForms {

constructor(private fileSystem: FileSystem) {
this.disposable = this.fileSystem.watchDir(
path.dirname(this.fileSystem.cursorlessTalonStateJsonPath),
this.fileSystem.cursorlessTalonStateJsonDirPath,
() => this.notifier.notifyListeners(),
);
}
Expand All @@ -37,7 +34,9 @@ export class TalonSpokenFormsJsonReader implements TalonSpokenForms {
let payload: TalonSpokenFormsPayload;
try {
payload = JSON.parse(
await readFile(this.fileSystem.cursorlessTalonStateJsonPath, "utf-8"),
await this.fileSystem.readFile(
this.fileSystem.cursorlessTalonStateJsonPath,
),
);
} catch (err) {
if (isErrnoException(err) && err.code === "ENOENT") {
Expand Down
2 changes: 1 addition & 1 deletion packages/cursorless-engine/src/cursorlessEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { StoredTargetMap } from "./core/StoredTargets";
import { RangeUpdater } from "./core/updateSelections/RangeUpdater";
import { CustomSpokenFormGeneratorImpl } from "./generateSpokenForm/CustomSpokenFormGeneratorImpl";
import { LanguageDefinitions } from "./languages/LanguageDefinitions";
import { TalonSpokenFormsJsonReader } from "./nodeCommon/TalonSpokenFormsJsonReader";
import { TalonSpokenFormsJsonReader } from "./TalonSpokenFormsJsonReader";
import { ModifierStageFactoryImpl } from "./processTargets/ModifierStageFactoryImpl";
import { ScopeHandlerFactoryImpl } from "./processTargets/modifiers/scopeHandlers";
import { runCommand } from "./runCommand";
Expand Down
3 changes: 0 additions & 3 deletions packages/cursorless-engine/src/nodeCommon/README.md

This file was deleted.

12 changes: 11 additions & 1 deletion packages/cursorless-vscode/src/ide/vscode/VscodeFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import {
PathChangeListener,
RunMode,
} from "@cursorless/common";
import * as fs from "fs/promises";
import { isAbsolute, join } from "path";
import * as vscode from "vscode";

export class VscodeFileSystem implements FileSystem {
public readonly cursorlessTalonStateJsonPath: string;
readonly cursorlessTalonStateJsonDirPath: string;
public readonly cursorlessCommandHistoryDirPath: string;

private decoder = new TextDecoder("utf-8");
Expand All @@ -18,7 +20,11 @@ export class VscodeFileSystem implements FileSystem {
private readonly runMode: RunMode,
private readonly cursorlessDir: string,
) {
this.cursorlessTalonStateJsonPath = join(this.cursorlessDir, "state.json");
this.cursorlessTalonStateJsonDirPath = this.cursorlessDir;
this.cursorlessTalonStateJsonPath = join(
this.cursorlessTalonStateJsonDirPath,
"state.json",
);
this.cursorlessCommandHistoryDirPath = join(
this.cursorlessDir,
"commandHistory",
Expand Down Expand Up @@ -90,4 +96,8 @@ export class VscodeFileSystem implements FileSystem {

return watcher;
}

public readFile(path: string): Promise<string> {
return fs.readFile(path, "utf-8");
}
}

0 comments on commit 6efad17

Please sign in to comment.