@fossil-lang/wasm 0.3.0-alpha.8 → 0.3.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  JS/TS wrapper around the `fossil-wasm` Rust crate's wasm-bindgen artefacts. Provides:
4
4
 
5
+ - `openProgram(uri, { host, text })` — one program open for an editor, and the
6
+ call a host with an editor makes. See below.
5
7
  - `initFossilWasm()` — boots the module (memoised). Its `.wasm` ships in this
6
8
  package and the host's bundler emits it as an asset; the host copies nothing.
7
9
  - `tokenize(text)` — calls the Rust lexer, returns `TokenRow[]`. The Rust lexer
@@ -11,6 +13,29 @@ JS/TS wrapper around the `fossil-wasm` Rust crate's wasm-bindgen artefacts. Prov
11
13
  itself is native-only (stdio over crossbeam), so the browser gets this
12
14
  equivalent dispatch surface over the same `fossil-ide` functions.
13
15
 
16
+ ## One program in one editor: `openProgram`
17
+
18
+ ```typescript
19
+ import { openProgram } from '@fossil-lang/wasm';
20
+ import { fossil } from '@fossil-lang/codemirror-fossil';
21
+
22
+ const program = await openProgram('job.fossil', { host, text }); // host: SourceHost
23
+ const extensions = fossil({ ...program, onNavigate });
24
+
25
+ program.registerDescriptor(descriptor); // a host-introspected source, before a check
26
+ const sources = await program.sources(text); // what introspection DESCRIBEs
27
+ ```
28
+
29
+ It boots the module, opens `uri` in its own workspace, and reads the documents
30
+ the text names through `host`. The answer carries `fossil()`'s option names —
31
+ `uri`, `tokenize`, `tokenKinds`, `check`, `hover`, `complete`, `definition` —
32
+ and every one that answers about the program takes the text and pushes it
33
+ first, comparing against what it last pushed so the common case costs a string
34
+ comparison. `check` and `sources` also run `resolveDocuments`, which reads
35
+ nothing when nothing is missing. That is the whole protocol an editor host used
36
+ to write by hand; `workspace` is the `FossilPlayground` underneath, for a
37
+ question this surface does not ask, and `close()` frees it.
38
+
14
39
  ## Documents and sources: fossil resolves, the host reads
15
40
 
16
41
  A program names shape documents (`io.shex("@vocab/person.shex")`) and data
package/dist/index.d.ts CHANGED
@@ -7,6 +7,9 @@
7
7
  * - {@link tokenize} — calls the Rust lexer, returns TokenRow[].
8
8
  * - {@link tokenKinds} — the legend for TokenRow.kind: variant names by index.
9
9
  * - {@link semanticLegend} — returns the LSP SemanticTokensLegend.
10
+ * - {@link openProgram} — one program open for an editor: the workspace, the push-before-ask
11
+ * discipline and the document resolution a host would otherwise write, shaped to spread into
12
+ * `@fossil-lang/codemirror-fossil`'s `fossil()`. What a host with one editor calls.
10
13
  * - {@link FossilPlayground} — Workspace API class: open / update / close,
11
14
  * `check`, the three position queries (`hover`, `completions`,
12
15
  * `gotoDefinition`) an editor draws its IDE surface from, and the documents
@@ -15,15 +18,18 @@
15
18
  *
16
19
  * Consumer pattern (wasm-bindgen --target web):
17
20
  *
18
- * import { initFossilWasm, tokenize } from '@fossil-lang/wasm';
21
+ * import { openProgram } from '@fossil-lang/wasm';
22
+ * import { fossil } from '@fossil-lang/codemirror-fossil';
19
23
  *
20
- * await initFossilWasm();
21
- * const tokens = tokenize('User := io.csv("data/people.csv")');
24
+ * const program = await openProgram('job.fossil', { host, text });
25
+ * const extensions = fossil({ ...program, onNavigate });
22
26
  */
23
27
  export { initFossilWasm } from './load.js';
24
28
  export type { InitInput } from './load.js';
25
29
  export { start_lsp_worker, tokenize, tokenKinds, semanticLegend, FossilPlayground, refs, providers, } from './client.js';
26
30
  export type { FileHandle } from './client.js';
31
+ export { openProgram } from './program.js';
32
+ export type { FossilProgram, OpenProgramOptions } from './program.js';
27
33
  /** One external reference a program makes — the typed lineage returned by
28
34
  * {@link refs}. Mirrors `fossil_lineage::SourceRefInfo` (the SAME struct the
29
35
  * native `fossil refs` emits). `connection` is the `@conn` alias the reference
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAQH,OAAO,EAAE,cAA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W,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,iBAAiB,CAAC;CAC9B;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;;;OAKG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ,2EAA2E;IAC3E,OAAO,EAAE,kBAAkB,EAAE,CAAC;IAC9B;;;;;;OAMG;IACH,eAAe,EAAE,MAAM,CAAC;CACzB;AAKD,YAAY,EACV,QAAQ,EACR,oBAAoB,EACpB,UAAU,EACV,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,aAAa,GACd,MAAM,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -7,6 +7,9 @@
7
7
  * - {@link tokenize} — calls the Rust lexer, returns TokenRow[].
8
8
  * - {@link tokenKinds} — the legend for TokenRow.kind: variant names by index.
9
9
  * - {@link semanticLegend} — returns the LSP SemanticTokensLegend.
10
+ * - {@link openProgram} — one program open for an editor: the workspace, the push-before-ask
11
+ * discipline and the document resolution a host would otherwise write, shaped to spread into
12
+ * `@fossil-lang/codemirror-fossil`'s `fossil()`. What a host with one editor calls.
10
13
  * - {@link FossilPlayground} — Workspace API class: open / update / close,
11
14
  * `check`, the three position queries (`hover`, `completions`,
12
15
  * `gotoDefinition`) an editor draws its IDE surface from, and the documents
@@ -15,10 +18,11 @@
15
18
  *
16
19
  * Consumer pattern (wasm-bindgen --target web):
17
20
  *
18
- * import { initFossilWasm, tokenize } from '@fossil-lang/wasm';
21
+ * import { openProgram } from '@fossil-lang/wasm';
22
+ * import { fossil } from '@fossil-lang/codemirror-fossil';
19
23
  *
20
- * await initFossilWasm();
21
- * const tokens = tokenize('User := io.csv("data/people.csv")');
24
+ * const program = await openProgram('job.fossil', { host, text });
25
+ * const extensions = fossil({ ...program, onNavigate });
22
26
  */
23
27
  // The wasm-bindgen glue (`../pkg/fossil_wasm.js`) is imported ONLY from leaf
24
28
  // modules — `load.ts` (init) and `client.ts` (the lexer / LSP / Workspace API) —
@@ -28,4 +32,5 @@
28
32
  // codemirror tokenizer hit on the main thread). This entry only re-exports.
29
33
  export { initFossilWasm } from './load.js';
30
34
  export { start_lsp_worker, tokenize, tokenKinds, semanticLegend, FossilPlayground, refs, providers, } from './client.js';
35
+ export { openProgram } from './program.js';
31
36
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,6EAA6E;AAC7E,iFAAiF;AACjF,iFAAiF;AACjF,2EAA2E;AAC3E,yEAAyE;AACzE,4EAA4E;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAG3C,OAAO,EACL,gBAAgB,EAChB,QAAQ,EACR,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,IAAI,EACJ,SAAS,GACV,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,6EAA6E;AAC7E,iFAAiF;AACjF,iFAAiF;AACjF,2EAA2E;AAC3E,yEAAyE;AACzE,4EAA4E;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAG3C,OAAO,EACL,gBAAgB,EAChB,QAAQ,EACR,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,IAAI,EACJ,SAAS,GACV,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,94 @@
1
+ /**
2
+ * One program, open in a workspace, answering an editor — what every host of the checker wrote by
3
+ * hand before this existed.
4
+ *
5
+ * `FossilPlayground` is the workspace and it is right that it stays general: it holds any number
6
+ * of files and answers about each. What a host with ONE program in ONE editor needs on top of it
7
+ * is always the same protocol, and two copies of it had already diverged in their comments:
8
+ *
9
+ * 1. **Push before you ask.** Four callers at four rates — the debounced linter, hover on pointer
10
+ * rest, completion on nearly every keystroke, goto-def on a key — share one workspace, and all
11
+ * four answer about the text of the last `updateFile`. So every entry point takes the text and
12
+ * pushes it first, and a string comparison against what was last pushed makes that free in the
13
+ * common case. `updateFile` is the one call that bumps the Salsa revision; calling it per
14
+ * mouse-move would invalidate the memoised check the squiggles came from for nothing.
15
+ * 2. **Read what the program names before you check it.** The compiler performs no IO. An edit
16
+ * can name a shape document the workspace has not read, so a check first runs
17
+ * `resolveDocuments` over the host's {@link SourceHost} — which reads nothing when nothing is
18
+ * missing.
19
+ *
20
+ * The result is shaped for `@fossil-lang/codemirror-fossil`'s `fossil()`: `tokenize`,
21
+ * `tokenKinds`, `uri`, `check`, `hover`, `complete` and `definition` are exactly its option
22
+ * names, so a host spreads it and adds what is its own to decide:
23
+ *
24
+ * ```ts
25
+ * const program = await openProgram('job.fossil', { host, text });
26
+ * const extensions = fossil({ ...program, onNavigate });
27
+ * ```
28
+ *
29
+ * One workspace rather than one per rate, for the reason `fossil()`'s own header gives: a second
30
+ * workspace for the position queries would answer from a different revision than the squiggles on
31
+ * screen. The position methods take a SHARED borrow on the Rust side, so they nest inside a live
32
+ * check rather than poisoning it.
33
+ */
34
+ import { type ProgramSource, type SourceHost } from '@fossil-lang/types';
35
+ import { FossilPlayground, tokenize, tokenKinds } from './client.js';
36
+ import type { CheckRow, CompletionRow, DefinitionRow, HoverRow, InferredDescriptorJson } from './index.js';
37
+ import { type InitInput } from './load.js';
38
+ /** What {@link openProgram} takes beside the key. */
39
+ export interface OpenProgramOptions {
40
+ /** The host's one capability: the connection map, and signing what the program names. */
41
+ host: SourceHost;
42
+ /** The buffer's text at open. Defaults to empty; every entry point takes the text anyway. */
43
+ text?: string;
44
+ /** How a signed document is read. Defaults to the global `fetch`. */
45
+ fetch?: typeof fetch;
46
+ /** The module's `.wasm`, for a host with no bundler — see {@link initFossilWasm}. */
47
+ wasm?: InitInput;
48
+ }
49
+ /**
50
+ * A program open in its own workspace. Every member that answers about the program takes the
51
+ * current text, and pushes it first — see the module header for why that repetition is the design.
52
+ */
53
+ export interface FossilProgram {
54
+ /** The key the program is open under — `CheckRow.uri` and `DefinitionRow.uri` carry it. */
55
+ readonly uri: string;
56
+ /** The compiler's lexer, for highlighting. Needs no workspace, and is here so the spread works. */
57
+ readonly tokenize: typeof tokenize;
58
+ /** The legend for a token's `kind`. */
59
+ readonly tokenKinds: typeof tokenKinds;
60
+ /**
61
+ * Push the text, read every document it names that the workspace lacks, and check. No debounce:
62
+ * `fossil()`'s linter waits out its own delay AND waits for this to return before it schedules
63
+ * again, which is what an LSP client does with `didChange`.
64
+ */
65
+ check(text: string): Promise<CheckRow[]>;
66
+ /** The type under the cursor, and the type the target shape demands of it — or `null`. */
67
+ hover(text: string, line: number, character: number): HoverRow | null;
68
+ /** The candidates at the cursor, narrowed by the receiver's type. */
69
+ complete(text: string, line: number, character: number): CompletionRow[];
70
+ /** Where the name under the cursor is defined. Often in the shape document: read `uri`. */
71
+ definition(text: string, line: number, character: number): DefinitionRow[];
72
+ /**
73
+ * The data sources the program reads, as fossil resolved them — what introspection DESCRIBEs.
74
+ * Resolves the documents first, because a source's locator goes through the connection map.
75
+ */
76
+ sources(text: string): Promise<ProgramSource[]>;
77
+ /**
78
+ * A host-introspected input schema, registered under the URI the program wrote. The compiler
79
+ * never introspects a source itself; push this before the check that should see it.
80
+ */
81
+ registerDescriptor(descriptor: InferredDescriptorJson): void;
82
+ /** The workspace underneath, for the rare question this surface does not ask. */
83
+ readonly workspace: FossilPlayground;
84
+ /** Free the workspace. Every member fails after it. */
85
+ close(): void;
86
+ }
87
+ /**
88
+ * Boot the module, open `uri` in a fresh workspace, and read the documents its text names.
89
+ *
90
+ * One call and the answer goes straight into `fossil()`. The boot is memoised, so a second program
91
+ * in the same tab costs a workspace and nothing else.
92
+ */
93
+ export declare function openProgram(uri: string, options: OpenProgramOptions): Promise<FossilProgram>;
94
+ //# sourceM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M,EAAE,SAAS,EAAE,MAAM,GAAG,aAAa,EAAE,CAAC;IACzE,2FAA2F;IAC3F,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,aAAa,EAAE,CAAC;IAC3E;;;OAGG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IAChD;;;OAGG;IACH,kBAAkB,CAAC,UAAU,EAAE,sBAAsB,GAAG,IAAI,CAAC;IAC7D,iFAAiF;IACjF,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAAC;IACrC,uDAAuD;IACvD,KAAK,IAAI,IAAI,CAAC;CACf;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,aAAa,CAAC,CAoDlG"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * One program, open in a workspace, answering an editor — what every host of the checker wrote by
3
+ * hand before this existed.
4
+ *
5
+ * `FossilPlayground` is the workspace and it is right that it stays general: it holds any number
6
+ * of files and answers about each. What a host with ONE program in ONE editor needs on top of it
7
+ * is always the same protocol, and two copies of it had already diverged in their comments:
8
+ *
9
+ * 1. **Push before you ask.** Four callers at four rates — the debounced linter, hover on pointer
10
+ * rest, completion on nearly every keystroke, goto-def on a key — share one workspace, and all
11
+ * four answer about the text of the last `updateFile`. So every entry point takes the text and
12
+ * pushes it first, and a string comparison against what was last pushed makes that free in the
13
+ * common case. `updateFile` is the one call that bumps the Salsa revision; calling it per
14
+ * mouse-move would invalidate the memoised check the squiggles came from for nothing.
15
+ * 2. **Read what the program names before you check it.** The compiler performs no IO. An edit
16
+ * can name a shape document the workspace has not read, so a check first runs
17
+ * `resolveDocuments` over the host's {@link SourceHost} — which reads nothing when nothing is
18
+ * missing.
19
+ *
20
+ * The result is shaped for `@fossil-lang/codemirror-fossil`'s `fossil()`: `tokenize`,
21
+ * `tokenKinds`, `uri`, `check`, `hover`, `complete` and `definition` are exactly its option
22
+ * names, so a host spreads it and adds what is its own to decide:
23
+ *
24
+ * ```ts
25
+ * const program = await openProgram('job.fossil', { host, text });
26
+ * const extensions = fossil({ ...program, onNavigate });
27
+ * ```
28
+ *
29
+ * One workspace rather than one per rate, for the reason `fossil()`'s own header gives: a second
30
+ * workspace for the position queries would answer from a different revision than the squiggles on
31
+ * screen. The position methods take a SHARED borrow on the Rust side, so they nest inside a live
32
+ * check rather than poisoning it.
33
+ */
34
+ import { resolveDocuments } from '@fossil-lang/types';
35
+ import { FossilPlayground, tokenize, tokenKinds } from './client.js';
36
+ import { initFossilWasm } from './load.js';
37
+ /**
38
+ * Boot the module, open `uri` in a fresh workspace, and read the documents its text names.
39
+ *
40
+ * One call and the answer goes straight into `fossil()`. The boot is memoised, so a second program
41
+ * in the same tab costs a workspace and nothing else.
42
+ */
43
+ export async function openProgram(uri, options) {
44
+ const { host, text = '', fetch: fetchImpl = globalThis.fetch, wasm } = options;
45
+ await initFossilWasm(wasm);
46
+ const workspace = new FossilPlayground();
47
+ const handle = workspace.openFile(uri, text);
48
+ let pushed = text;
49
+ const sync = (next) => {
50
+ if (next === pushed)
51
+ return;
52
+ workspace.updateFile(handle, next);
53
+ pushed = next;
54
+ };
55
+ const settle = async (next) => {
56
+ sync(next);
57
+ await resolveDocuments(workspace.workspace(handle), host, fetchImpl);
58
+ };
59
+ await settle(text);
60
+ return {
61
+ uri,
62
+ tokenize,
63
+ tokenKinds,
64
+ async check(next) {
65
+ await settle(next);
66
+ return workspace.check();
67
+ },
68
+ hover(next, line, character) {
69
+ sync(next);
70
+ return workspace.hover(handle, line, character);
71
+ },
72
+ complete(next, line, character) {
73
+ sync(next);
74
+ return workspace.completions(handle, line, character);
75
+ },
76
+ definition(next, line, character) {
77
+ sync(next);
78
+ return workspace.gotoDefinition(handle, line, character);
79
+ },
80
+ async sources(next) {
81
+ await settle(next);
82
+ return workspace.sources(handle);
83
+ },
84
+ registerDescriptor(descriptor) {
85
+ workspace.registerInferredDescriptor(descriptor);
86
+ },
87
+ workspace,
88
+ close() {
89
+ workspace.free();
90
+ },
91
+ };
92
+ }
93
+ //# sourceMappingURL=program.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"program.js","sourceRoot":"","sources":["../src/program.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,OAAO,EAAE,gBAAgB,EAAuC,MAAM,oBAAoB,CAAC;AAE3F,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAQrE,OAAO,EAAE,cAAc,EAAkB,MAAM,WAAW,CAAC;AAqD3D;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,GAAW,EAAE,OAA2B;IACxE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,EAAE,EAAE,KAAK,EAAE,SAAS,GAAG,UAAU,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;IAC/E,MAAM,cAAc,CAAC,IAAI,CAAC,CAAC;IAE3B,MAAM,SAAS,GAAG,IAAI,gBAAgB,EAAE,CAAC;IACzC,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC7C,IAAI,MAAM,GAAG,IAAI,CAAC;IAElB,MAAM,IAAI,GAAG,CAAC,IAAY,EAAQ,EAAE;QAClC,IAAI,IAAI,KAAK,MAAM;YAAE,OAAO;QAC5B,SAAS,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACnC,MAAM,GAAG,IAAI,CAAC;IAChB,CAAC,CAAC;IACF,MAAM,MAAM,GAAG,KAAK,EAAE,IAAY,EAAiB,EAAE;QACnD,IAAI,CAAC,IAAI,CAAC,CAAC;QACX,MAAM,gBAAgB,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,C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0-alpha.9",
4
4
  "description": "JS/TS wrapper around the fossil-wasm wasm-bindgen artifacts (--target web). Exposes initFossilWasm + tokenize + semanticLegend + FossilPlayground class for downstream @fossil-lang/* packages.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -33,7 +33,7 @@
33
33
  ],
34
34
  "sideEffects": false,
35
35
  "dependencies": {
36
- "@fossil-lang/types": "0.3.0-alpha.8"
36
+ "@fossil-lang/types": "0.3.0-alpha.9"
37
37
  },
38
38
  "devDependencies": {
39
39
  "typescript": "^5.6.0",