@macroforge/mcp-server 0.1.42 → 0.1.50

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.
Files changed (71) hide show
  1. package/LICENSE +22 -0
  2. package/docs/BOOK.md +165 -0
  3. package/docs/api/api-overview.md +67 -48
  4. package/docs/api/expand-sync.md +88 -53
  5. package/docs/api/native-plugin.md +121 -71
  6. package/docs/api/position-mapper.md +115 -55
  7. package/docs/api/transform-sync.md +86 -60
  8. package/docs/builtin-macros/clone.md +0 -20
  9. package/docs/builtin-macros/debug.md +0 -23
  10. package/docs/builtin-macros/default.md +1 -40
  11. package/docs/builtin-macros/deserialize/example.md +8 -1416
  12. package/docs/builtin-macros/deserialize.md +8 -1416
  13. package/docs/builtin-macros/hash.md +0 -42
  14. package/docs/builtin-macros/macros-overview/detailed-documentation.md +13 -0
  15. package/docs/builtin-macros/macros-overview/enum-support.md +30 -0
  16. package/docs/builtin-macros/macros-overview/interface-support.md +28 -0
  17. package/docs/builtin-macros/macros-overview/overview.md +36 -0
  18. package/docs/builtin-macros/macros-overview/type-alias-support.md +62 -0
  19. package/docs/builtin-macros/macros-overview.md +171 -130
  20. package/docs/builtin-macros/ord.md +0 -25
  21. package/docs/builtin-macros/partial-eq.md +0 -84
  22. package/docs/builtin-macros/partial-ord.md +2 -32
  23. package/docs/builtin-macros/serialize.md +2 -62
  24. package/docs/concepts/architecture.md +125 -48
  25. package/docs/concepts/derive-system/built-in-vs-custom-macros.md +13 -0
  26. package/docs/concepts/derive-system/overview.md +200 -0
  27. package/docs/concepts/derive-system.md +157 -104
  28. package/docs/concepts/how-macros-work.md +98 -47
  29. package/docs/custom-macros/custom-overview.md +79 -57
  30. package/docs/custom-macros/rust-setup.md +138 -99
  31. package/docs/custom-macros/ts-macro-derive/accessing-field-data.md +40 -31
  32. package/docs/custom-macros/ts-macro-derive/adding-imports.md +14 -11
  33. package/docs/custom-macros/ts-macro-derive/attribute-options.md +20 -25
  34. package/docs/custom-macros/ts-macro-derive/complete-example.md +40 -38
  35. package/docs/custom-macros/ts-macro-derive/deriveinput-structure.md +49 -47
  36. package/docs/custom-macros/ts-macro-derive/function-signature.md +12 -0
  37. package/docs/custom-macros/ts-macro-derive/overview.md +9 -7
  38. package/docs/custom-macros/ts-macro-derive/parsing-input.md +20 -18
  39. package/docs/custom-macros/ts-macro-derive/returning-errors.md +15 -13
  40. package/docs/custom-macros/ts-macro-derive.md +322 -228
  41. package/docs/custom-macros/ts-quote/backtick-template-literals.md +19 -7
  42. package/docs/custom-macros/ts-quote/comments-and.md +56 -22
  43. package/docs/custom-macros/ts-quote/complete-example-json-derive-macro.md +89 -98
  44. package/docs/custom-macros/ts-quote/conditionals-ifif.md +35 -29
  45. package/docs/custom-macros/ts-quote/identifier-concatenation-content.md +30 -22
  46. package/docs/custom-macros/ts-quote/iteration-for.md +48 -40
  47. package/docs/custom-macros/ts-quote/local-constants-let.md +23 -21
  48. package/docs/custom-macros/ts-quote/match-expressions-match.md +46 -38
  49. package/docs/custom-macros/ts-quote/overview.md +5 -10
  50. package/docs/custom-macros/ts-quote/pattern-matching-iflet.md +39 -0
  51. package/docs/custom-macros/ts-quote/quick-reference.md +50 -129
  52. package/docs/custom-macros/ts-quote/side-effects-do.md +13 -78
  53. package/docs/custom-macros/ts-quote/string-interpolation-textexpr.md +36 -0
  54. package/docs/custom-macros/ts-quote/tsstream-injection-typescript.md +43 -35
  55. package/docs/custom-macros/ts-quote/while-loops-while.md +31 -23
  56. package/docs/custom-macros/ts-quote.md +800 -520
  57. package/docs/getting-started/first-macro.md +98 -71
  58. package/docs/getting-started/installation.md +109 -65
  59. package/docs/integration/cli.md +214 -105
  60. package/docs/integration/configuration.md +115 -72
  61. package/docs/integration/integration-overview.md +55 -18
  62. package/docs/integration/mcp-server.md +84 -43
  63. package/docs/integration/svelte-preprocessor.md +183 -126
  64. package/docs/integration/typescript-plugin.md +101 -53
  65. package/docs/integration/vite-plugin.md +116 -76
  66. package/docs/language-servers/ls-overview.md +37 -21
  67. package/docs/language-servers/svelte.md +69 -38
  68. package/docs/language-servers/zed.md +81 -44
  69. package/docs/roadmap/roadmap.md +75 -53
  70. package/docs/sections.json +1 -242
  71. package/package.json +27 -28
@@ -1,45 +1,86 @@
1
1
  # MCP Server
2
- *The MCP (Model Context Protocol) server enables AI assistants to understand and work with Macroforge macros, providing documentation lookup, code validation, and macro expansion.*
3
- The local (stdio) version of the MCP server is available via the [<code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">@macroforge<span style="--shiki-dark:#F97583;--shiki-light:#D73A49">/<span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">mcp<span style="--shiki-dark:#F97583;--shiki-light:#D73A49">-<span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">server</code>](https://www.npmjs.com/package/@macroforge/mcp-server) npm package. You can either install it globally and then reference it in your configuration or run it with <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">npx</code>:
4
- ```
5
- npx&nbsp;-y&nbsp;@macroforge/mcp-server
6
- ``` Here's how to set it up in some common MCP clients:
7
- ## Claude Code
8
- To include the local MCP version in Claude Code, simply run the following command:
9
- ```
10
- claude&nbsp;mcp&nbsp;add&nbsp;-t&nbsp;stdio&nbsp;-s&nbsp;[scope]&nbsp;macroforge&nbsp;--&nbsp;npx&nbsp;-y&nbsp;@macroforge/mcp-server
11
- ``` The <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">[scope]</code> must be <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">user</code>, <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">project</code> or <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">local</code>.
12
- ## Claude Desktop
13
- In the Settings > Developer section, click on Edit Config. It will open the folder with a <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">claude_desktop_config.json</code> file in it. Edit the file to include the following configuration:
14
- ```
15
- &#123;
16
- &nbsp;&nbsp;&nbsp;&nbsp;"mcpServers":&nbsp;&#123;
17
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"macroforge":&nbsp;&#123;
18
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"command":&nbsp;"npx",
19
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"args":&nbsp;["-y",&nbsp;"@macroforge/mcp-server"]
20
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
21
- &nbsp;&nbsp;&nbsp;&nbsp;&#125;
22
- &#125;
23
- ``` ## Codex CLI
24
- Add the following to your <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#FDAEB7;--shiki-dark-font-style:italic;--shiki-light:#B31D28;--shiki-light-font-style:italic">config.toml</code> (which defaults to <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#FDAEB7;--shiki-dark-font-style:italic;--shiki-light:#B31D28;--shiki-light-font-style:italic">~/.codex/config.toml</code>, but refer to [the configuration documentation](https://github.com/openai/codex/blob/main/docs/config.md) for more advanced setups):
25
- ```
2
+
3
+ The MCP (Model Context Protocol) server enables AI assistants to understand and work with Macroforge macros, providing documentation lookup, code validation, and macro expansion.
4
+
5
+ The local (stdio) version of the MCP server is available via the [`@macroforge/mcp-server`](https://www.npmjs.com/package/@macroforge/mcp-server) npm package. You can either install it globally and then reference it in your configuration or run it with `npx`:
6
+
7
+ Bash
8
+
9
+ ```
10
+ npx -y @macroforge/mcp-server
11
+ ```
12
+
13
+ Here's how to set it up in some common MCP clients:
14
+
15
+ ## Claude Code
16
+
17
+ To include the local MCP version in Claude Code, simply run the following command:
18
+
19
+ Bash
20
+
21
+ ```
22
+ claude mcp add -t stdio -s [scope] macroforge -- npx -y @macroforge/mcp-server
23
+ ```
24
+
25
+ The `[scope]` must be `user`, `project` or `local`.
26
+
27
+ ## Claude Desktop
28
+
29
+ In the Settings > Developer section, click on Edit Config. It will open the folder with a `claude_desktop_config.json` file in it. Edit the file to include the following configuration:
30
+
31
+ claude\_desktop\_config.json
32
+
33
+ ```
34
+ {
35
+     "mcpServers": {
36
+         "macroforge": {
37
+             "command": "npx",
38
+             "args": ["-y", "@macroforge/mcp-server"]
39
+         }
40
+     }
41
+ }
42
+ ```
43
+
44
+ ## Codex CLI
45
+
46
+ Add the following to your `config.toml` (which defaults to `~/.codex/config.toml`, but refer to [the configuration documentation](https://github.com/openai/codex/blob/main/docs/config.md) for more advanced setups):
47
+
48
+ config.toml
49
+
50
+ ```
26
51
  [mcp_servers.macroforge]
27
- command&nbsp;=&nbsp;"npx"
28
- args&nbsp;=&nbsp;["-y",&nbsp;"@macroforge/mcp-server"]
29
- ``` ## Gemini CLI
30
- To include the local MCP version in Gemini CLI, simply run the following command:
31
- ```
32
- gemini&nbsp;mcp&nbsp;add&nbsp;-t&nbsp;stdio&nbsp;-s&nbsp;[scope]&nbsp;macroforge&nbsp;npx&nbsp;-y&nbsp;@macroforge/mcp-server
33
- ``` The <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">[scope]</code> must be <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">user</code>, <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">project</code> or <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">local</code>.
34
- ## Other Clients
35
- If we didn't include the MCP client you are using, refer to their documentation for <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">stdio</code> servers and use <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">npx</code> as the command and <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#F97583;--shiki-light:#D73A49">-<span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">y @macroforge<span style="--shiki-dark:#F97583;--shiki-light:#D73A49">/<span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">mcp<span style="--shiki-dark:#F97583;--shiki-light:#D73A49">-<span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">server</code> as the arguments.
36
- ## Available Tools
37
- The MCP server provides five tools for AI assistants:
38
- | Tool | Description |
39
- | --- | --- |
40
- | list-sections | Lists all available Macroforge documentation sections |
41
- | get-documentation | Retrieves full documentation for one or more sections |
42
- | macroforge-autofixer | Validates code with @derive decorators and returns diagnostics |
43
- | expand-code | Expands macros and returns the transformed TypeScript code |
44
- | get-macro-info | Retrieves documentation for macros and field decorators |
45
- > **Note:** For code validation and expansion features (macroforge-autofixer, expand-code, get-macro-info), the MCP server requires macroforge as a peer dependency. Install it in your project with npm install macroforge.
52
+ command = "npx"
53
+ args = ["-y""@macroforge/mcp-server"]
54
+ ```
55
+
56
+ ## Gemini CLI
57
+
58
+ To include the local MCP version in Gemini CLI, simply run the following command:
59
+
60
+ Bash
61
+
62
+ ```
63
+ gemini mcp add -t stdio -s [scope] macroforge npx -y @macroforge/mcp-server
64
+ ```
65
+
66
+ The `[scope]` must be `user`, `project` or `local`.
67
+
68
+ ## Other Clients
69
+
70
+ If we didn't include the MCP client you are using, refer to their documentation for `stdio` servers and use `npx` as the command and `-y @macroforge/mcp-server` as the arguments.
71
+
72
+ ## Available Tools
73
+
74
+ The MCP server provides five tools for AI assistants:
75
+
76
+ | Tool | Description |
77
+ | ---------------------- | ---------------------------------------------------------------- |
78
+ | `list-sections` | Lists all available Macroforge documentation sections |
79
+ | `get-documentation` | Retrieves full documentation for one or more sections |
80
+ | `macroforge-autofixer` | Validates code with `@derive` decorators and returns diagnostics |
81
+ | `expand-code` | Expands macros and returns the transformed TypeScript code |
82
+ | `get-macro-info` | Retrieves documentation for macros and field decorators |
83
+
84
+ Note
85
+
86
+ For code validation and expansion features (`macroforge-autofixer`, `expand-code`, `get-macro-info`), the MCP server requires `macroforge` as a peer dependency. Install it in your project with `npm install macroforge`.
@@ -1,128 +1,185 @@
1
1
  # Svelte Preprocessor
2
- *The Svelte preprocessor expands Macroforge macros in <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E"><<span style="--shiki-dark:#B392F0;--shiki-light:#6F42C1">script<span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">></code> blocks before Svelte compilation, enabling seamless macro usage in Svelte components.*
3
- ## Installation
4
- ```
5
- npm&nbsp;install&nbsp;-D&nbsp;@macroforge/svelte-preprocessor
6
- ``` ## Configuration
7
- Add the preprocessor to your <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">svelte.config.js</code>:
8
- ```
9
- import&nbsp;adapter&nbsp;from&nbsp;'@sveltejs/adapter-auto';
10
- import&nbsp;&#123;&nbsp;vitePreprocess&nbsp;&#125;&nbsp;from&nbsp;'@sveltejs/vite-plugin-svelte';
11
- import&nbsp;&#123;&nbsp;macroforgePreprocess&nbsp;&#125;&nbsp;from&nbsp;'@macroforge/svelte-preprocessor';
12
-
13
- /**&nbsp;@type&nbsp;&#123;import('@sveltejs/kit').Config&#125;&nbsp;*/
14
- const&nbsp;config&nbsp;=&nbsp;&#123;
15
- &nbsp;&nbsp;preprocess:&nbsp;[
16
- &nbsp;&nbsp;&nbsp;&nbsp;macroforgePreprocess(),&nbsp;&nbsp;//&nbsp;Expand&nbsp;macros&nbsp;FIRST
17
- &nbsp;&nbsp;&nbsp;&nbsp;vitePreprocess()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Then&nbsp;handle&nbsp;TypeScript/CSS
18
- &nbsp;&nbsp;],
19
-
20
- &nbsp;&nbsp;kit:&nbsp;&#123;
21
- &nbsp;&nbsp;&nbsp;&nbsp;adapter:&nbsp;adapter()
22
- &nbsp;&nbsp;&#125;
23
- &#125;;
24
-
25
- export&nbsp;default&nbsp;config;
26
- ``` **Warning Always place **<code class="shiki-inline"><span class="line"><span style="--shiki-dark:#B392F0;--shiki-light:#6F42C1">macroforgePreprocess<span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">()</code> **before** other preprocessors like <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#B392F0;--shiki-light:#6F42C1">vitePreprocess<span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">()</code>. This ensures macros are expanded before TypeScript compilation. ## Usage
27
- Use <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">@derive</code> decorators directly in your Svelte component scripts:
28
- ```
29
- &#x3C;script&nbsp;lang="ts">
30
- &nbsp;&nbsp;/**&nbsp;@derive(Debug,&nbsp;Clone)&nbsp;*/
31
- &nbsp;&nbsp;class&nbsp;User&nbsp;&#123;
32
- &nbsp;&nbsp;&nbsp;&nbsp;name:&nbsp;string;
33
- &nbsp;&nbsp;&nbsp;&nbsp;email:&nbsp;string;
34
-
35
- &nbsp;&nbsp;&nbsp;&nbsp;constructor(name:&nbsp;string,&nbsp;email:&nbsp;string)&nbsp;&#123;
36
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.name&nbsp;=&nbsp;name;
37
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.email&nbsp;=&nbsp;email;
38
- &nbsp;&nbsp;&nbsp;&nbsp;&#125;
39
- &nbsp;&nbsp;&#125;
40
-
41
- &nbsp;&nbsp;let&nbsp;user&nbsp;=&nbsp;new&nbsp;User("Alice",&nbsp;"alice@example.com");
42
- &nbsp;&nbsp;console.log(user.toString());&nbsp;&nbsp;//&nbsp;Generated&nbsp;by&nbsp;Debug&nbsp;macro
43
- &#x3C;/script>
44
-
45
- &#x3C;p>User:&nbsp;&#123;user.name&#125;&#x3C;/p>
46
- ``` ## Options
47
- ```
48
- macroforgePreprocess(&#123;
49
- &nbsp;&nbsp;//&nbsp;Keep&nbsp;@derive&nbsp;decorators&nbsp;in&nbsp;output&nbsp;(for&nbsp;debugging)
50
- &nbsp;&nbsp;keepDecorators:&nbsp;false,
51
-
52
- &nbsp;&nbsp;//&nbsp;Process&nbsp;JavaScript&nbsp;files&nbsp;(not&nbsp;just&nbsp;TypeScript)
53
- &nbsp;&nbsp;processJavaScript:&nbsp;false
54
- &#125;)
55
- ``` ### Option Reference
56
- | Option | Type | Default | Description |
57
- | --- | --- | --- | --- |
58
- | keepDecorators | boolean | false | Keep decorators in output |
59
- | processJavaScript | boolean | false | Process <script> blocks without lang="ts" |
60
- ## How It Works
61
- The preprocessor:
62
- 1. Intercepts <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#F97583;--shiki-light:#D73A49"><<span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">script lang<span style="--shiki-dark:#F97583;--shiki-light:#D73A49">=<span style="--shiki-dark:#9ECBFF;--shiki-light:#032F62">"ts"<span style="--shiki-dark:#F97583;--shiki-light:#D73A49">></code> blocks in <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">.svelte</code> files
63
- 2. Checks for <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">@derive</code> decorators (skips files without them)
64
- 3. Expands macros using the native Macroforge binary
65
- 4. Returns the transformed code for Svelte compilation
66
- **Tip Files without **<code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">@derive</code> decorators are passed through unchanged with zero overhead. ## SvelteKit Integration
67
- For SvelteKit projects, you can use both the preprocessor (for <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">.svelte</code> files) and the Vite plugin (for standalone <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">.ts</code> files):
68
- ```
69
- //&nbsp;svelte.config.js
70
- import&nbsp;&#123;&nbsp;macroforgePreprocess&nbsp;&#125;&nbsp;from&nbsp;'@macroforge/svelte-preprocessor';
71
- import&nbsp;&#123;&nbsp;vitePreprocess&nbsp;&#125;&nbsp;from&nbsp;'@sveltejs/vite-plugin-svelte';
72
-
73
- export&nbsp;default&nbsp;&#123;
74
- &nbsp;&nbsp;preprocess:&nbsp;[
75
- &nbsp;&nbsp;&nbsp;&nbsp;macroforgePreprocess(),
76
- &nbsp;&nbsp;&nbsp;&nbsp;vitePreprocess()
77
- &nbsp;&nbsp;]
78
- &#125;;
79
- ``` ```
80
- //&nbsp;vite.config.ts
81
- import&nbsp;macroforge&nbsp;from&nbsp;'@macroforge/vite-plugin';
82
- import&nbsp;&#123;&nbsp;sveltekit&nbsp;&#125;&nbsp;from&nbsp;'@sveltejs/kit/vite';
83
- import&nbsp;&#123;&nbsp;defineConfig&nbsp;&#125;&nbsp;from&nbsp;'vite';
84
-
85
- export&nbsp;default&nbsp;defineConfig(&#123;
86
- &nbsp;&nbsp;plugins:&nbsp;[
87
- &nbsp;&nbsp;&nbsp;&nbsp;macroforge(),&nbsp;&nbsp;//&nbsp;For&nbsp;.ts&nbsp;files
88
- &nbsp;&nbsp;&nbsp;&nbsp;sveltekit()
89
- &nbsp;&nbsp;]
90
- &#125;);
91
- ``` ## Using with Vitest
92
- The preprocessor works seamlessly with Vitest for testing Svelte components:
93
- ```
94
- //&nbsp;vitest.config.ts
95
- import&nbsp;&#123;&nbsp;defineConfig&nbsp;&#125;&nbsp;from&nbsp;'vitest/config';
96
- import&nbsp;&#123;&nbsp;sveltekit&nbsp;&#125;&nbsp;from&nbsp;'@sveltejs/kit/vite';
97
- import&nbsp;&#123;&nbsp;svelteTesting&nbsp;&#125;&nbsp;from&nbsp;'@testing-library/svelte/vite';
98
- import&nbsp;macroforge&nbsp;from&nbsp;'@macroforge/vite-plugin';
99
-
100
- export&nbsp;default&nbsp;defineConfig(&#123;
101
- &nbsp;&nbsp;plugins:&nbsp;[
102
- &nbsp;&nbsp;&nbsp;&nbsp;macroforge(),
103
- &nbsp;&nbsp;&nbsp;&nbsp;sveltekit(),
104
- &nbsp;&nbsp;&nbsp;&nbsp;svelteTesting()
105
- &nbsp;&nbsp;],
106
- &nbsp;&nbsp;test:&nbsp;&#123;
107
- &nbsp;&nbsp;&nbsp;&nbsp;environment:&nbsp;'jsdom',
108
- &nbsp;&nbsp;&nbsp;&nbsp;include:&nbsp;['src/**/*.&#123;test,spec&#125;.&#123;js,ts&#125;']
109
- &nbsp;&nbsp;&#125;
110
- &#125;);
111
- ``` ## Svelte 5 Runes Compatibility
112
- The preprocessor is fully compatible with Svelte 5 runes (<code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">$state</code>, <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">$derived</code>, <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">$props</code>, etc.). Files using runes but without <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">@derive</code> decorators are skipped entirely.
113
- ```
114
- &#x3C;script&nbsp;lang="ts">
115
- &nbsp;&nbsp;//&nbsp;Runes&nbsp;work&nbsp;normally
116
- &nbsp;&nbsp;let&nbsp;count&nbsp;=&nbsp;$state(0);
117
- &nbsp;&nbsp;let&nbsp;doubled&nbsp;=&nbsp;$derived(count&nbsp;*&nbsp;2);
118
-
119
- &nbsp;&nbsp;//&nbsp;Macros&nbsp;expand&nbsp;correctly
120
- &nbsp;&nbsp;/**&nbsp;@derive(Debug)&nbsp;*/
121
- &nbsp;&nbsp;class&nbsp;Counter&nbsp;&#123;
122
- &nbsp;&nbsp;&nbsp;&nbsp;value:&nbsp;number;
123
- &nbsp;&nbsp;&nbsp;&nbsp;constructor(value:&nbsp;number)&nbsp;&#123;
124
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.value&nbsp;=&nbsp;value;
125
- &nbsp;&nbsp;&nbsp;&nbsp;&#125;
126
- &nbsp;&nbsp;&#125;
127
- &#x3C;/script>
2
+
3
+ The Svelte preprocessor expands Macroforge macros in `<script>` blocks before Svelte compilation, enabling seamless macro usage in Svelte components.
4
+
5
+ ## Installation
6
+
7
+ Bash
8
+
9
+ ```
10
+ npm install -D @macroforge/svelte-preprocessor
11
+ ```
12
+
13
+ ## Configuration
14
+
15
+ Add the preprocessor to your `svelte.config.js`:
16
+
17
+ svelte.config.js
18
+
19
+ ```
20
+ import adapter from '@sveltejs/adapter-auto';
21
+ import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
22
+ import { macroforgePreprocess } from '@macroforge/svelte-preprocessor';
23
+
24
+ /** @type {import('@sveltejs/kit').Config} */
25
+ const config = {
26
+   preprocess: [
27
+     macroforgePreprocess(),  // Expand macros FIRST
28
+     vitePreprocess()          // Then handle TypeScript/CSS
29
+   ],
30
+
31
+   kit: {
32
+     adapter: adapter()
33
+   }
34
+ };
35
+
36
+ export default config;
37
+ ```
38
+
39
+ Warning
40
+
41
+ Always place `macroforgePreprocess()` **before** other preprocessors like `vitePreprocess()`. This ensures macros are expanded before TypeScript compilation.
42
+
43
+ ## Usage
44
+
45
+ Use `@derive` decorators directly in your Svelte component scripts:
46
+
47
+ UserCard.svelte
48
+
49
+ ```
50
+ <script lang="ts">
51
+   /** @derive(Debug, Clone) */
52
+   class User {
53
+     name: string;
54
+     email: string;
55
+
56
+     constructor(name: string, email: string) {
57
+       this.name = name;
58
+       this.email = email;
59
+     }
60
+   }
61
+
62
+   let user = new User("Alice""alice@example.com");
63
+   console.log(user.toString());  // Generated by Debug macro
64
+ </script>
65
+
66
+ <p>User: {user.name}</p>
67
+ ```
68
+
69
+ ## Options
70
+
71
+ TypeScript
72
+
73
+ ```
74
+ macroforgePreprocess({
75
+   // Keep @derive decorators in output (for debugging)
76
+   keepDecorators: false,
77
+
78
+   // Process JavaScript files (not just TypeScript)
79
+   processJavaScript: false
80
+ })
81
+ ```
82
+
83
+ ### Option Reference
84
+
85
+ | Option | Type | Default | Description |
86
+ | ------------------- | --------- | ------- | --------------------------------------------- |
87
+ | `keepDecorators` | `boolean` | `false` | Keep decorators in output |
88
+ | `processJavaScript` | `boolean` | `false` | Process `<script>` blocks without `lang="ts"` |
89
+
90
+ ## How It Works
91
+
92
+ The preprocessor:
93
+
94
+ 1. Intercepts `<script lang="ts">` blocks in `.svelte` files
95
+ 2. Checks for `@derive` decorators (skips files without them)
96
+ 3. Expands macros using the native Macroforge binary
97
+ 4. Returns the transformed code for Svelte compilation
98
+
99
+ Tip
100
+
101
+ Files without `@derive` decorators are passed through unchanged with zero overhead.
102
+
103
+ ## SvelteKit Integration
104
+
105
+ For SvelteKit projects, you can use both the preprocessor (for `.svelte` files) and the Vite plugin (for standalone `.ts` files):
106
+
107
+ svelte.config.js
108
+
109
+ ```
110
+ // svelte.config.js
111
+ import { macroforgePreprocess } from '@macroforge/svelte-preprocessor';
112
+ import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
113
+
114
+ export default {
115
+   preprocess: [
116
+     macroforgePreprocess(),
117
+     vitePreprocess()
118
+   ]
119
+ };
120
+ ```
121
+
122
+ vite.config.ts
123
+
124
+ ```
125
+ // vite.config.ts
126
+ import macroforge from '@macroforge/vite-plugin';
127
+ import { sveltekit } from '@sveltejs/kit/vite';
128
+ import { defineConfig } from 'vite';
129
+
130
+ export default defineConfig({
131
+   plugins: [
132
+     macroforge(),  // For .ts files
133
+     sveltekit()
134
+   ]
135
+ });
136
+ ```
137
+
138
+ ## Using with Vitest
139
+
140
+ The preprocessor works seamlessly with Vitest for testing Svelte components:
141
+
142
+ vitest.config.ts
143
+
144
+ ```
145
+ // vitest.config.ts
146
+ import { defineConfig } from 'vitest/config';
147
+ import { sveltekit } from '@sveltejs/kit/vite';
148
+ import { svelteTesting } from '@testing-library/svelte/vite';
149
+ import macroforge from '@macroforge/vite-plugin';
150
+
151
+ export default defineConfig({
152
+   plugins: [
153
+     macroforge(),
154
+     sveltekit(),
155
+     svelteTesting()
156
+   ],
157
+   test: {
158
+     environment: 'jsdom',
159
+     include: ['src/**/*.{test,spec}.{js,ts}']
160
+   }
161
+ });
162
+ ```
163
+
164
+ ## Svelte 5 Runes Compatibility
165
+
166
+ The preprocessor is fully compatible with Svelte 5 runes (`$state`, `$derived`, `$props`, etc.). Files using runes but without `@derive` decorators are skipped entirely.
167
+
168
+ Svelte
169
+
170
+ ```
171
+ <script lang="ts">
172
+   // Runes work normally
173
+   let count = $state(0);
174
+   let doubled = $derived(count * 2);
175
+
176
+   // Macros expand correctly
177
+   /** @derive(Debug) */
178
+   class Counter {
179
+     value: number;
180
+     constructor(value: number) {
181
+       this.value = value;
182
+     }
183
+   }
184
+ </script>
128
185
  ```
@@ -1,54 +1,102 @@
1
1
  # TypeScript Plugin
2
- *The TypeScript plugin provides IDE integration for Macroforge, including error reporting, completions, and type checking for generated code.*
3
- ## Installation
4
- ```
5
- npm&nbsp;install&nbsp;-D&nbsp;@macroforge/typescript-plugin
6
- ``` ## Configuration
7
- Add the plugin to your <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">tsconfig.json</code>:
8
- ```
9
- &#123;
10
- &nbsp;&nbsp;"compilerOptions":&nbsp;&#123;
11
- &nbsp;&nbsp;&nbsp;&nbsp;"plugins":&nbsp;[
12
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#123;
13
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"name":&nbsp;"@macroforge/typescript-plugin"
14
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
15
- &nbsp;&nbsp;&nbsp;&nbsp;]
16
- &nbsp;&nbsp;&#125;
17
- &#125;
18
- ``` ## VS Code Setup
19
- VS Code uses its own TypeScript version by default. To use the workspace version (which includes plugins):
20
- 1. Open the Command Palette (<code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">Cmd<span style="--shiki-dark:#F97583;--shiki-light:#D73A49">/<span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">Ctrl <span style="--shiki-dark:#F97583;--shiki-light:#D73A49">+<span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E"> Shift <span style="--shiki-dark:#F97583;--shiki-light:#D73A49">+<span style="--shiki-dark:#79B8FF;--shiki-light:#005CC5"> P</code>)
21
- 2. Search for "TypeScript: Select TypeScript Version"
22
- 3. Choose "Use Workspace Version"
23
- **Tip Add this setting to your **<code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">.vscode/settings.json</code> to make it permanent: ```
24
- &#123;
25
- &nbsp;&nbsp;"typescript.tsdk":&nbsp;"node_modules/typescript/lib"
26
- &#125;
27
- ``` ## Features
28
- ### Error Reporting
29
- Errors in macro-generated code are reported at the <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">@derive</code> decorator position:
30
- ```
31
- /**&nbsp;@derive(Debug)&nbsp;*/&nbsp;&nbsp;//&nbsp;&#x3C;-&nbsp;Errors&nbsp;appear&nbsp;here
32
- class&nbsp;User&nbsp;&#123;
33
- &nbsp;&nbsp;name:&nbsp;string;
34
- &#125;
35
- ``` ### Completions
36
- The plugin provides completions for generated methods:
37
- ```
38
- const&nbsp;user&nbsp;=&nbsp;new&nbsp;User("Alice");
39
- user.to&nbsp;&nbsp;//&nbsp;Suggests:&nbsp;toString(),&nbsp;toJSON(),&nbsp;etc.
40
- ``` ### Type Information
41
- Hover over generated methods to see their types:
42
- ```
43
- //&nbsp;Hover&nbsp;over&nbsp;'clone'&nbsp;shows:
44
- //&nbsp;(method)&nbsp;User.clone():&nbsp;User
45
- const&nbsp;copy&nbsp;=&nbsp;user.clone();
46
- ``` ## Troubleshooting
47
- ### Plugin Not Loading
48
- 1. Ensure you're using the workspace TypeScript version
49
- 2. Restart the TypeScript server (Command Palette → "TypeScript: Restart TS Server")
50
- 3. Check that the plugin is listed in <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">tsconfig.json</code>
51
- ### Errors Not Showing
52
- If errors from macros aren't appearing:
53
- 1. Make sure the Vite plugin is also installed (for source file watching)
54
- 2. Check that your file is saved (plugins process on save)
2
+
3
+ The TypeScript plugin provides IDE integration for Macroforge, including error reporting, completions, and type checking for generated code.
4
+
5
+ ## Installation
6
+
7
+ Bash
8
+
9
+ ```
10
+ npm install -D @macroforge/typescript-plugin
11
+ ```
12
+
13
+ ## Configuration
14
+
15
+ Add the plugin to your `tsconfig.json`:
16
+
17
+ tsconfig.json
18
+
19
+ ```
20
+ {
21
+   "compilerOptions": {
22
+     "plugins": [
23
+       {
24
+         "name": "@macroforge/typescript-plugin"
25
+       }
26
+     ]
27
+   }
28
+ }
29
+ ```
30
+
31
+ ## VS Code Setup
32
+
33
+ VS Code uses its own TypeScript version by default. To use the workspace version (which includes plugins):
34
+
35
+ 1. Open the Command Palette (`Cmd/Ctrl + Shift + P`)
36
+ 2. Search for "TypeScript: Select TypeScript Version"
37
+ 3. Choose "Use Workspace Version"
38
+
39
+ Tip
40
+
41
+ Add this setting to your `.vscode/settings.json` to make it permanent:
42
+
43
+ .vscode/settings.json
44
+
45
+ ```
46
+ {
47
+   "typescript.tsdk": "node_modules/typescript/lib"
48
+ }
49
+ ```
50
+
51
+ ## Features
52
+
53
+ ### Error Reporting
54
+
55
+ Errors in macro-generated code are reported at the `@derive` decorator position:
56
+
57
+ TypeScript
58
+
59
+ ```
60
+ /** @derive(Debug) */  // <- Errors appear here
61
+ class User {
62
+   name: string;
63
+ }
64
+ ```
65
+
66
+ ### Completions
67
+
68
+ The plugin provides completions for generated methods:
69
+
70
+ TypeScript
71
+
72
+ ```
73
+ const user = new User("Alice");
74
+ user.to  // Suggests: toString(), toJSON(), etc.
75
+ ```
76
+
77
+ ### Type Information
78
+
79
+ Hover over generated methods to see their types:
80
+
81
+ TypeScript
82
+
83
+ ```
84
+ // Hover over 'clone' shows:
85
+ // (method) User.clone(): User
86
+ const copy = user.clone();
87
+ ```
88
+
89
+ ## Troubleshooting
90
+
91
+ ### Plugin Not Loading
92
+
93
+ 1. Ensure you're using the workspace TypeScript version
94
+ 2. Restart the TypeScript server (Command Palette → "TypeScript: Restart TS Server")
95
+ 3. Check that the plugin is listed in `tsconfig.json`
96
+
97
+ ### Errors Not Showing
98
+
99
+ If errors from macros aren't appearing:
100
+
101
+ 1. Make sure the Vite plugin is also installed (for source file watching)
102
+ 2. Check that your file is saved (plugins process on save)