You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .github/copilot-instructions.md
+17-4Lines changed: 17 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,41 +7,54 @@ Big picture architecture
7
7
- Validation: `src/validator.ts` calls `validateWitSyntaxDetailedFromWasm` from `src/wasmUtils.ts`, parses errors with `src/errorParser.ts`, and writes VS Code diagnostics. Prefer Problems pane over popups.
8
8
- WASM integration: `src/wasmUtils.ts` lazy-loads local package `wit-bindgen-wasm` and initializes its wasm binary. Primary APIs: `getWitBindgenVersionFromWasm`, `validateWitSyntaxDetailedFromWasm`, `generateBindingsFromWasm` (returns JSON map of files with latin1-encoded content).
- Rust subproject: `wit-bindgen-wasm/` builds a wasm-pack package consumed at runtime (`wit_bindgen_wasm_bg.wasm`).
10
+
- Rust subproject: `wit-bindgen-wasm/` builds a wasm-pack package consumed at runtime (`wit_bindgen_wasm_bg.wasm`). Uses `wit-parser` 0.241, `wit-component` 0.241, and `wasmparser` 0.241.
11
11
12
12
Build and dev workflows
13
13
- One-time setup (requires Rust + cargo): `npm run setup-wasm` (installs wasm-pack 0.13.1 and wasm32 target).
14
14
- Dev watch: `npm run dev` (parallel: `gen-watch` for d.ts, `build-extension-watch` for esbuild).
15
15
- Full build: `npm run build` (build wasm via wasm-pack, then bundle the extension with esbuild).
16
+
- Build WASM only: `npm run build-wasm` (dev) or `npm run build-wasm-prod` (release).
16
17
- Pack/install locally: `npm run package` then `npm run install-extension` (uses `vsce` and `code --install-extension`).
17
18
- Tests: `npm test` runs lint, prettier check, build, package, grammar tests, and unit tests. Quick loops: `npm run test-unit` or `npm run test-grammar`. Update grammar snapshots: `npm run update-snapshot`.
19
+
- Verify WASM build: `npm run verify-wasm` checks that the built WASM file exists and is valid.
- Plugins auto-discover and copy dynamic WASM references and worker JS to `dist/`. `src/wasmUtils.ts` first looks for `dist/wit_bindgen_wasm_bg.wasm` and falls back to module default init. If you introduce new wasm or worker assets referenced via `new URL('file.ext', import.meta.url)`, the plugin will attempt to copy them.
22
24
23
25
Runtime behaviors and contracts
24
26
- Extract WIT from components: command `wit-idl.extractWit` shells out to `wasm-tools component wit <file.wasm>`; ensure `wasm-tools` is on PATH. Enablement uses a context key set when active editor is a `.wasm` with component version 0x0A.
25
-
- Binding generation: `generateBindingsFromWasm` returns a JSON map of filename -> content (latin1). When writing to disk, create buffers via `Buffer.from(content, 'latin1')`. See usage in `src/extension.ts`.
27
+
- Extract Core WASM: command `wit-idl.extractCoreWasm` uses `wasm-tools component wit <file.wasm> --raw` to extract the core module.
28
+
- Binding generation: `generateBindingsFromWasm` returns a JSON map of filename -> content (latin1). When writing to disk, create buffers via `Buffer.from(content, 'latin1')`. See usage in `src/extension.ts`. Supports Rust, C, C#, Go, and MoonBit.
26
29
- Diagnostics: use `WitSyntaxValidator.createDiagnosticFromError` and keep `diagnostic.source` consistent (`wit-syntax` or `wit-bindgen`). Workspace validation streams progress via `withProgress` and writes a dedicated output channel.
30
+
- Format Document: command `wit-idl.formatDocument` formats WIT files using the WASM module's formatting capability.
27
31
28
32
Coding conventions specific to this repo
29
33
- ESM TypeScript: use explicit `.js` extensions in relative imports (e.g., `import { X } from './validator.js'`). Keep explicit param/return types; avoid `any`.
30
34
- File layout: implementation in `src/`, tests in `tests/` (Vitest), grammar tests under `tests/grammar/**`. Type declarations generated to `types/` by `npm run gen-types`.
31
35
- VS Code contributions: update `package.json` for languages, grammars, snippets, menus, keybindings, and new commands. Match command IDs with registrations in `extension.ts`.
36
+
- Use 4 spaces for indentation. Follow ESLint and Prettier rules.
37
+
38
+
wit-parser API changes (v0.239.0+, currently using 0.241)
39
+
-`resolve.select_world(package_id, world_name)` now expects first argument as a slice: `resolve.select_world(&[package_id], world_name)`.
40
+
- When calling `select_world`, always wrap package IDs in a slice: `&[pkg_id]`.
41
+
- This applies to all direct uses of `wit_parser::Resolve::select_world` in the Rust codebase.
42
+
- The project is currently using wit-parser 0.241, which maintains this API contract.
32
43
33
44
Adding a feature safely
34
45
- Register a command in `package.json` and implement it in `src/extension.ts`; push to `context.subscriptions`.
35
46
- If it relies on `wit-bindgen-wasm`, add a thin wrapper in `src/wasmUtils.ts` and write unit tests in `tests/` (Vitest). Use Problems pane diagnostics over modal errors.
36
47
- If you need WIT extraction or inspection, prefer `wasm-tools` CLI calls (as in `extractWitWithWasmTools`).
37
48
38
49
Common pitfalls and fixes
39
-
- “Failed to initialize WIT bindgen WASM module”: ensure `npm run build` copied `wit_bindgen_wasm_bg.wasm` to `dist/` or run `npm run setup-wasm && npm run build-wasm`.
40
-
- “wasm-tools not found” when extracting WIT: install wasm-tools and ensure PATH is set for the VS Code environment.
50
+
- "Failed to initialize WIT bindgen WASM module": ensure `npm run build` copied `wit_bindgen_wasm_bg.wasm` to `dist/` or run `npm run setup-wasm && npm run build-wasm`. Verify with `npm run verify-wasm`.
51
+
- "wasm-tools not found" when extracting WIT: install wasm-tools and ensure PATH is set for the VS Code environment.
52
+
-`select_world` signature errors: ensure you're wrapping package IDs in a slice `&[pkg_id]` when calling `resolve.select_world()`.
0 commit comments