Skip to content

Commit 940c367

Browse files
committed
docs(affine-vscode): align adapter docs with --vscode-extension (issue #105)
The README and mod.js still described the pre-#105 manual hookup and referred to the hook as `_extraImports`. The codegen shim uses `extraImports` and #105 now emits the wiring inline. - Document `--vscode-extension` (and the adapter / no-lc sub-flags) as the recommended path; keep a corrected manual fallback. - Fix the hook name `_extraImports` -> `extraImports`. - Fix the manual example's third argument: the adapter expects the .cjs shim module (it reads `_registerHandle` / `_instance` off it), not a `() => instance` thunk or a bare WebAssembly.Instance. https://claude.ai/code/session_01FkzAgzpZFSGxzorVNZ9FUF
1 parent d5024a6 commit 940c367

2 files changed

Lines changed: 37 additions & 21 deletions

File tree

packages/affine-vscode/README.adoc

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,41 @@ deliverable.
88

99
== Usage
1010

11-
In your AffineScript-authored VS Code extension's CJS entry point, after
12-
loading the `.cjs` produced by `affinescript compile extension.affine
13-
-o extension.cjs`, plug this adapter into the Wasm imports:
11+
=== Recommended: `--vscode-extension` (issue #105)
12+
13+
Compile with the `--vscode-extension` flag and the generated `.cjs` is
14+
directly loadable as the extension's `main` — the adapter wiring is
15+
emitted inline, so there is no hand-written entry point to maintain:
16+
17+
[source,sh]
18+
----
19+
affinescript compile src/extension.affine -o out/extension.cjs --vscode-extension
20+
----
21+
22+
Point your extension's `package.json` `main` at the unmodified
23+
`out/extension.cjs` and list `@hyperpolymath/affine-vscode` in
24+
`dependencies`. Sub-flags: `--vscode-extension-adapter <specifier>`
25+
overrides the adapter `require()` target; `--vscode-extension-no-lc`
26+
omits the `vscode-languageclient/node` dependency.
27+
28+
=== Manual wiring (fallback)
29+
30+
If you cannot use the flag, set the shim's `extraImports` hook before the
31+
first `activate`/`deactivate` call so the extern fns resolve to live
32+
vscode APIs. Pass the shim module itself as the third argument — the
33+
adapter reads its handle table and `_instance` lazily:
1434

1535
[source,javascript]
1636
----
1737
const vscode = require("vscode");
1838
const lc = require("vscode-languageclient/node");
1939
const makeBindings = require("@hyperpolymath/affine-vscode");
2040
21-
// The Node-CJS shim emitted by affinescript's compile -o *.cjs path lazily
22-
// instantiates the wasm. Patch its `_extraImports()` hook before the first
23-
// activate/deactivate call so the extern fns resolve to live vscode APIs.
24-
25-
let instance;
26-
const adapter = require("./extension.cjs");
27-
const original = adapter._extraImports || (() => ({}));
28-
adapter._extraImports = () => makeBindings(vscode, lc, () => instance);
41+
const shim = require("./extension.cjs");
42+
shim.extraImports = () => makeBindings(vscode, lc, shim);
2943
30-
// (Real wiring belongs in the codegen — Phase 3 will replace this manual
31-
// hookup with auto-generated glue once `extension.affine` is the source of
32-
// truth for the extension entry point.)
44+
exports.activate = shim.activate;
45+
exports.deactivate = shim.deactivate;
3346
----
3447

3548
== Surface

packages/affine-vscode/mod.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@
33
//
44
// affine-vscode: JS-side adapter for stdlib/Vscode.affine + stdlib/VscodeLanguageClient.affine.
55
//
6-
// Issue #35 Phase 2 deliverable. Plug this into your Node-CJS extension's
7-
// `_extraImports()` so each `extern fn` declared in the bindings resolves
8-
// to the right vscode API call.
6+
// Issue #35 Phase 2 deliverable. Resolves each `extern fn` declared in the
7+
// bindings to the right vscode API call.
98
//
10-
// Usage from a hand-written .cjs (until Phase 3 automates the wiring):
9+
// Preferred wiring (issue #105): compile with `--vscode-extension` and the
10+
// generated .cjs installs `exports.extraImports` calling this adapter
11+
// automatically — no hand-written entry point.
1112
//
12-
// const vscodeBindings = require("@hyperpolymath/affine-vscode")(
13+
// Manual wiring (fallback), from a hand-written .cjs:
14+
//
15+
// const shim = require("./extension.cjs");
16+
// shim.extraImports = () => require("@hyperpolymath/affine-vscode")(
1317
// require("vscode"),
1418
// require("vscode-languageclient/node"),
15-
// instance, // WebAssembly.Instance, set after instantiate
19+
// shim, // the .cjs shim module (hostShim)
1620
// );
17-
// // Pass vscodeBindings into the Wasm imports map under "env".
1821
//
1922
// The adapter maintains a per-process JS-side handle table keyed by Int
2023
// so opaque handles passed across the FFI boundary survive round-trips.

0 commit comments

Comments
 (0)