Skip to content

Commit a610bd6

Browse files
Use scope tests plugin
1 parent 9a8acc9 commit a610bd6

File tree

7 files changed

+45
-36747
lines changed

7 files changed

+45
-36747
lines changed

packages/cursorless-org-docs/docusaurus.config.mts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ const config: Config = {
146146
},
147147
],
148148
],
149-
plugins: ["./src/plugins/tailwind-plugin.js"],
149+
plugins: [
150+
"./src/plugins/tailwind-plugin.ts",
151+
"./src/plugins/scope-tests-plugin.ts",
152+
],
150153

151154
themeConfig: {
152155
navbar: {

packages/cursorless-org-docs/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
"write-heading-ids": "docusaurus write-heading-ids",
4343
"compile": "tsc --build",
4444
"watch": "tsc --build --watch",
45-
"prepare-assets": "my-ts-node src/scripts/prepare-assets.ts",
4645
"clean": "pnpm clear && rm -rf ./out tsconfig.tsbuildinfo ./dist ./build"
4746
},
4847
"dependencies": {

packages/cursorless-org-docs/src/docs/user/languages/components/ScopeVisualizer.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ import {
66
type ScopeSupportFacetInfo,
77
} from "@cursorless/common";
88
import React, { useState } from "react";
9-
import scopeTestsJson from "../../../../../static/scopeTests.json";
109
import { Code, type Highlight } from "./Code";
1110
import "./ScopeVisualizer.css";
12-
import type { Fixture, ScopeTestsJson } from "./types";
11+
import type { Fixture, ScopeTests } from "./types";
1312
import { getFacetInfo, prettifyFacet, prettifyScopeType } from "./util";
14-
15-
const scopeTests = scopeTestsJson as ScopeTestsJson;
13+
import { usePluginData } from "@docusaurus/useGlobalData";
1614

1715
type RangeType = "content" | "removal";
1816

@@ -33,7 +31,8 @@ interface Props {
3331
}
3432

3533
export function ScopeVisualizer({ languageId }: Props) {
36-
const [scopes] = useState(getScopeFixtures(languageId));
34+
const scopeTests = usePluginData("scope-tests-plugin") as ScopeTests;
35+
const [scopes] = useState(getScopeFixtures(scopeTests, languageId));
3736
const [rangeType, setRangeType] = useState<RangeType>("content");
3837
const [renderWhitespace, setRenderWhitespace] = useState(false);
3938

@@ -198,7 +197,7 @@ function getOverlap(a: Range, b: Range): Range | null {
198197
: null;
199198
}
200199

201-
function getScopeFixtures(languageId: string): Scope[] {
200+
function getScopeFixtures(scopeTests: ScopeTests, languageId: string): Scope[] {
202201
const languageIds = new Set<string>(
203202
scopeTests.imports[languageId] ?? [languageId],
204203
);

packages/cursorless-org-docs/src/docs/user/languages/components/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {
33
PlaintextScopeSupportFacet,
44
} from "@cursorless/common";
55

6-
export interface ScopeTestsJson {
6+
export interface ScopeTests {
77
imports: Record<string, string[]>;
88
fixtures: Fixture[];
99
}

packages/cursorless-org-docs/src/scripts/prepare-assets.ts renamed to packages/cursorless-org-docs/src/plugins/scope-tests-plugin.ts

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,54 @@ import {
44
getScopeTestPaths,
55
type ScopeTestPath,
66
} from "@cursorless/node-common";
7+
import { LoadContext, Plugin } from "@docusaurus/types";
78
import * as fs from "node:fs";
89
import * as path from "node:path";
910
import type {
1011
Fixture,
1112
Scope,
12-
ScopeTestsJson,
13+
ScopeTests,
1314
Target,
1415
} from "../docs/user/languages/components/types";
1516

16-
const fixtures: Fixture[] = [];
17+
export default function prepareAssetsPlugin(
18+
context: LoadContext,
19+
options: {},
20+
): Plugin<ScopeTests> {
21+
let data: ScopeTests;
1722

18-
const importedLanguages = getScopeTestLanguagesRecursively();
23+
return {
24+
name: "scope-tests-plugin",
1925

20-
for (const test of getScopeTestPaths()) {
21-
const fixture = parseTest(test);
22-
if (fixture != null) {
23-
fixtures.push(fixture);
24-
}
26+
loadContent(): ScopeTests {
27+
const repoRoot = path.join(__dirname, "../../../..");
28+
process.env.CURSORLESS_REPO_ROOT = repoRoot;
29+
return prepareAssets();
30+
},
31+
32+
async contentLoaded({ content, actions }) {
33+
actions.setGlobalData(content);
34+
},
35+
};
2536
}
2637

27-
const result: ScopeTestsJson = {
28-
imports: importedLanguages,
29-
fixtures,
30-
};
38+
function prepareAssets(): ScopeTests {
39+
const fixtures: Fixture[] = [];
3140

32-
saveJson(result);
41+
const importedLanguages = getScopeTestLanguagesRecursively();
42+
43+
for (const test of getScopeTestPaths()) {
44+
const fixture = parseTest(test);
45+
if (fixture != null) {
46+
fixtures.push(fixture);
47+
}
48+
}
49+
50+
return {
51+
imports: importedLanguages,
52+
fixtures,
53+
};
54+
}
3355

3456
function parseTest(test: ScopeTestPath) {
3557
const fixture = fs
@@ -171,13 +193,3 @@ function parseLine(line: string) {
171193

172194
return { scopeIndex, targetIndex, type, value };
173195
}
174-
175-
function saveJson(result: ScopeTestsJson) {
176-
const assetPath = path.join(
177-
getPackagePath("cursorless-org-docs"),
178-
"static",
179-
"scopeTests.json",
180-
);
181-
const content = JSON.stringify(result, null, 2) + "\n";
182-
fs.writeFileSync(assetPath, content, "utf8");
183-
}

0 commit comments

Comments
 (0)