-
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor command history to remove node dependencies from engine (#2479)
## 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 <755842+pokey@users.noreply.github.com>
- Loading branch information
1 parent
2caaa66
commit 9f70536
Showing
12 changed files
with
98 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { CommandHistoryEntry } from "../../types/commandHistory"; | ||
|
||
/** | ||
* Used by command history machinery to store entries. | ||
*/ | ||
export interface CommandHistoryStorage { | ||
/** | ||
* Append an entry to a command history file. | ||
* | ||
* @param fileName The name of the file to append the entry to. We usually use | ||
* the a name derived from the current month to do a form of log rotation. | ||
* @param entry The entry to append to the file | ||
*/ | ||
appendEntry(fileName: string, entry: CommandHistoryEntry): Promise<void>; | ||
|
||
/** | ||
* Get all entries from all command history files. | ||
*/ | ||
getEntries(): Promise<CommandHistoryEntry[]>; | ||
} |
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 was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
packages/cursorless-engine/src/generateCommandHistoryEntries.ts
This file was deleted.
Oops, something went wrong.
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
45 changes: 45 additions & 0 deletions
45
packages/file-system-common/src/FileSystemCommandHistoryStorage.ts
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,45 @@ | ||
import type { | ||
CommandHistoryEntry, | ||
CommandHistoryStorage, | ||
} from "@cursorless/common"; | ||
import { glob } from "glob"; | ||
import fs from "node:fs/promises"; | ||
import path from "node:path"; | ||
|
||
export class FileSystemCommandHistoryStorage implements CommandHistoryStorage { | ||
constructor(private dir: string) {} | ||
|
||
async appendEntry( | ||
fileName: string, | ||
entry: CommandHistoryEntry, | ||
): Promise<void> { | ||
const data = JSON.stringify(entry) + "\n"; | ||
const file = path.join(this.dir, fileName); | ||
await fs.mkdir(this.dir, { recursive: true }); | ||
await fs.appendFile(file, data, "utf8"); | ||
} | ||
|
||
async getEntries(): Promise<CommandHistoryEntry[]> { | ||
const files = await glob("*.jsonl", { | ||
cwd: this.dir, | ||
}); | ||
|
||
const entries: CommandHistoryEntry[] = []; | ||
|
||
for (const file of files) { | ||
const filePath = path.join(this.dir, file); | ||
const content = await fs.readFile(filePath, "utf8"); | ||
const lines = content.split("\n"); | ||
|
||
for (const line of lines) { | ||
if (line.length === 0) { | ||
continue; | ||
} | ||
|
||
entries.push(JSON.parse(line)); | ||
} | ||
} | ||
|
||
return entries; | ||
} | ||
} |
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 @@ | ||
export * from "./FileSystemCommandHistoryStorage"; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.