Skip to content

Commit 80172d9

Browse files
Extract cheatsheet into separate package (#2482)
## 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
1 parent 9f70536 commit 80172d9

File tree

11 files changed

+92
-19
lines changed

11 files changed

+92
-19
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "@cursorless/cursorless-cheatsheet",
3+
"version": "0.1.0",
4+
"description": "Cursorless cheatsheet implementation",
5+
"type": "module",
6+
"main": "./out/index.js",
7+
"types": "./out/index.d.ts",
8+
"scripts": {
9+
"compile:tsc": "tsc --build",
10+
"compile:esbuild": "esbuild ./src/index.ts --sourcemap --format=esm --bundle --packages=external --outfile=./out/index.js",
11+
"compile": "pnpm compile:tsc && pnpm compile:esbuild",
12+
"watch:tsc": "pnpm compile:tsc --watch",
13+
"watch:esbuild": "pnpm compile:esbuild --watch",
14+
"watch": "pnpm run --filter @cursorless/cursorless-cheatsheet --parallel '/^watch:.*/'",
15+
"clean": "rm -rf ./out tsconfig.tsbuildinfo ./dist ./build"
16+
},
17+
"keywords": [],
18+
"author": "",
19+
"license": "MIT",
20+
"exports": {
21+
".": {
22+
"cursorless:bundler": "./src/index.ts",
23+
"default": "./out/index.js"
24+
}
25+
},
26+
"dependencies": {
27+
"@cursorless/common": "workspace:*",
28+
"immer": "^10.0.4",
29+
"lodash-es": "^4.17.21",
30+
"node-html-parser": "^6.1.12"
31+
},
32+
"devDependencies": {
33+
"@types/lodash-es": "4.17.0"
34+
}
35+
}

packages/cursorless-engine/src/core/Cheatsheet.ts renamed to packages/cursorless-cheatsheet/src/Cheatsheet.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
import { getCursorlessRepoRoot, type IDE } from "@cursorless/common";
12
import { readFile, writeFile } from "fs/promises";
2-
import { parse } from "node-html-parser";
3-
import { sortBy } from "lodash-es";
4-
import { ide } from "../singletons/ide.singleton";
5-
import path from "path";
6-
import { getCursorlessRepoRoot } from "@cursorless/common";
73
import { produce } from "immer";
4+
import { sortBy } from "lodash-es";
5+
import { parse } from "node-html-parser";
6+
import * as path from "path";
87

98
/**
109
* The argument expected by the cheatsheet command.
@@ -27,16 +26,15 @@ interface CheatSheetCommandArg {
2726
outputPath: string;
2827
}
2928

30-
export async function showCheatsheet({
31-
version,
32-
spokenFormInfo,
33-
outputPath,
34-
}: CheatSheetCommandArg) {
29+
export async function showCheatsheet(
30+
ide: IDE,
31+
{ version, spokenFormInfo, outputPath }: CheatSheetCommandArg,
32+
) {
3533
if (version !== 0) {
3634
throw new Error(`Unsupported cheatsheet api version: ${version}`);
3735
}
3836

39-
const cheatsheetPath = path.join(ide().assetsRoot, "cheatsheet.html");
37+
const cheatsheetPath = path.join(ide.assetsRoot, "cheatsheet.html");
4038

4139
const cheatsheetContent = (await readFile(cheatsheetPath)).toString();
4240

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./Cheatsheet";
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"outDir": "out",
5+
"rootDir": "src"
6+
},
7+
"include": ["src/**/*.ts", "src/**/*.json", "../../typings/**/*.d.ts"],
8+
"references": [
9+
{
10+
"path": "../common"
11+
}
12+
]
13+
}

packages/cursorless-engine/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"lodash-es": "^4.17.21",
3030
"moo": "0.5.2",
3131
"nearley": "2.20.1",
32-
"node-html-parser": "^6.1.12",
3332
"sbd": "^1.0.19",
3433
"uuid": "^9.0.1",
3534
"zod": "3.22.4"

packages/cursorless-engine/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export * from "./testUtil/plainObjectToTarget";
2-
export * from "./core/Cheatsheet";
32
export * from "./testUtil/takeSnapshot";
43
export * from "./testCaseRecorder/TestCaseRecorder";
54
export * from "./core/StoredTargets";

packages/cursorless-vscode/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,7 @@
12401240
},
12411241
"dependencies": {
12421242
"@cursorless/common": "workspace:*",
1243+
"@cursorless/cursorless-cheatsheet": "workspace:*",
12431244
"@cursorless/cursorless-engine": "workspace:*",
12441245
"@cursorless/file-system-common": "workspace:*",
12451246
"@cursorless/vscode-common": "workspace:*",

packages/cursorless-vscode/src/registerCommands.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import {
44
isTesting,
55
type CommandHistoryStorage,
66
} from "@cursorless/common";
7+
import {
8+
showCheatsheet,
9+
updateDefaults,
10+
} from "@cursorless/cursorless-cheatsheet";
711
import {
812
CommandApi,
913
StoredTargetMap,
1014
TestCaseRecorder,
1115
analyzeCommandHistory,
12-
showCheatsheet,
13-
updateDefaults,
1416
type ScopeTestRecorder,
1517
} from "@cursorless/cursorless-engine";
1618
import * as vscode from "vscode";
@@ -57,7 +59,7 @@ export function registerCommands(
5759
},
5860

5961
// Cheatsheet commands
60-
["cursorless.showCheatsheet"]: showCheatsheet,
62+
["cursorless.showCheatsheet"]: (arg) => showCheatsheet(vscodeIde, arg),
6163
["cursorless.internal.updateCheatsheetDefaults"]: updateDefaults,
6264

6365
// Testcase recorder commands

packages/cursorless-vscode/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
{
1111
"path": "../common"
1212
},
13+
{
14+
"path": "../cursorless-cheatsheet"
15+
},
1316
{
1417
"path": "../cursorless-engine"
1518
},

pnpm-lock.yaml

Lines changed: 22 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)