@gdscript-analyzer/wasm 0.1.0 → 0.2.1

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 ADDED
@@ -0,0 +1,99 @@
1
+ # @gdscript-analyzer/wasm
2
+
3
+ **Browser/WebAssembly binding for [gdscript-analyzer](https://github.com/yanivkalfa/gdscript-analyzer) — a fast, embeddable GDScript (Godot 4.x) static-analysis library. "Roslyn for Godot."**
4
+
5
+ [![npm](https://img.shields.io/npm/v/@gdscript-analyzer/wasm?logo=npm)](https://www.npmjs.com/package/@gdscript-analyzer/wasm)
6
+ [![License: MIT OR Apache-2.0](https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-blue.svg)](https://github.com/yanivkalfa/gdscript-analyzer#license)
7
+
8
+ Run a full GDScript analyzer **entirely in the browser** — no server, no Godot,
9
+ no network: diagnostics, type-aware hover, completion, symbols, and navigation.
10
+ This is the `wasm-bindgen` (`--target web`, ESM) build; for Node use the native
11
+ [`@gdscript-analyzer/core`](https://www.npmjs.com/package/@gdscript-analyzer/core).
12
+
13
+ **▶︎ See it running:** [the playground](https://yanivkalfa.github.io/gdscript-analyzer/playground/).
14
+
15
+ ```sh
16
+ npm i @gdscript-analyzer/wasm
17
+ ```
18
+
19
+ ---
20
+
21
+ ## Quick start
22
+
23
+ ```js
24
+ import init, { Analyzer } from "@gdscript-analyzer/wasm";
25
+
26
+ await init(); // instantiate the .wasm (required, once)
27
+ const az = new Analyzer();
28
+
29
+ const uri = "inmemory://main.gd";
30
+ az.openDocument(uri, "extends Node\nfunc _ready():\n\tvar x = 5 / 2\n", null);
31
+
32
+ console.log(JSON.parse(az.diagnostics(uri))); // → INTEGER_DIVISION warning
33
+ ```
34
+
35
+ Bundlers and native ESM both work. With Vite/webpack, `import init` resolves the
36
+ `.wasm` automatically; for a no-bundler setup, serve the package and
37
+ `import init from "/node_modules/@gdscript-analyzer/wasm/gdscript.js"`.
38
+
39
+ ---
40
+
41
+ ## Engine-class completion (optional)
42
+
43
+ Parse + type diagnostics work out of the box. To get completion/hover for **Godot
44
+ engine classes** (`Node`, `Button`, …), load the engine model once — a binary
45
+ blob you host alongside your app:
46
+
47
+ ```js
48
+ const bytes = new Uint8Array(await (await fetch("/data/extension_api.bin")).arrayBuffer());
49
+ az.loadEngineApi(bytes); // → true on success
50
+ ```
51
+
52
+ The blob is the analyzer's compiled Godot 4.x API model. The
53
+ [playground](https://yanivkalfa.github.io/gdscript-analyzer/playground/) ships one
54
+ at `playground/data/extension_api.bin` you can copy, or generate it from the repo.
55
+
56
+ ---
57
+
58
+ ## API
59
+
60
+ Same URI-keyed session model as the native package. Construct once, push
61
+ documents, query by **UTF-8 byte offset**; data queries return a **JSON string**.
62
+
63
+ ```js
64
+ az.openDocument(uri, text, resPath); // resPath ("res://…") enables cross-file resolution
65
+ az.changeDocument(uri, newText);
66
+ az.closeDocument(uri);
67
+ az.setProjectConfig(projectGodotText); // enables [autoload] resolution
68
+ az.loadEngineApi(bytes); // optional engine model
69
+
70
+ JSON.parse(az.diagnostics(uri));
71
+ JSON.parse(az.documentSymbols(uri));
72
+ JSON.parse(az.completions(uri, byteOffset));
73
+ const hover = az.hover(uri, byteOffset); // string | null
74
+ JSON.parse(az.gotoDefinition(uri, byteOffset));
75
+ JSON.parse(az.inlayHints(uri));
76
+ JSON.parse(az.foldingRanges(uri));
77
+ ```
78
+
79
+ ### Positions (byte offsets)
80
+
81
+ The analyzer speaks **UTF-8 byte offsets**; the browser's strings/editors are
82
+ UTF-16. Convert at the boundary — the
83
+ [playground source](https://github.com/yanivkalfa/gdscript-analyzer/blob/master/playground/index.html)
84
+ has a complete, copy-pasteable `utf16 ⇄ byte` helper plus an editor wiring you can
85
+ lift directly.
86
+
87
+ ```js
88
+ const enc = new TextEncoder();
89
+ const byteOffset = enc.encode(text.slice(0, utf16Index)).length;
90
+ ```
91
+
92
+ ---
93
+
94
+ ## Links
95
+
96
+ - **Repository & docs:** https://github.com/yanivkalfa/gdscript-analyzer
97
+ - **Playground (live demo + reference integration):** https://yanivkalfa.github.io/gdscript-analyzer/playground/
98
+ - **Native (Node) package:** [`@gdscript-analyzer/core`](https://www.npmjs.com/package/@gdscript-analyzer/core)
99
+ - **License:** MIT OR Apache-2.0
Binary file
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "@gdscript-analyzer/wasm",
3
3
  "type": "module",
4
- "description": "wasm-bindgen browser binding (documented fallback to the napi-rs wasm target) for gdscript-analyzer.",
5
- "version": "0.1.0",
4
+ "collaborators": [
5
+ "Yaniv Kalfa <yanivkalfa@gmail.com>"
6
+ ],
7
+ "description": "Run a full GDScript (Godot 4.x) static analyzer in the browser — diagnostics, type-aware hover, completion, symbols, navigation. The wasm-bindgen binding of gdscript-analyzer (Roslyn for Godot).",
8
+ "version": "0.2.1",
6
9
  "license": "MIT OR Apache-2.0",
7
10
  "repository": {
8
11
  "type": "git",
@@ -14,10 +17,18 @@
14
17
  "gdscript_wasm.d.ts"
15
18
  ],
16
19
  "main": "gdscript_wasm.js",
20
+ "homepage": "https://github.com/yanivkalfa/gdscript-analyzer",
17
21
  "types": "gdscript_wasm.d.ts",
18
22
  "sideEffects": [
19
23
  "./snippets/*"
20
24
  ],
25
+ "keywords": [
26
+ "gdscript",
27
+ "godot",
28
+ "analyzer",
29
+ "lsp",
30
+ "language-server"
31
+ ],
21
32
  "publishConfig": {
22
33
  "access": "public",
23
34
  "provenance": true