@macroforge/mcp-server 0.1.33 → 0.1.35
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 +68 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +46 -1
- package/dist/index.js.map +1 -1
- package/dist/tools/docs-loader.d.ts +133 -5
- package/dist/tools/docs-loader.d.ts.map +1 -1
- package/dist/tools/docs-loader.js +131 -15
- package/dist/tools/docs-loader.js.map +1 -1
- package/dist/tools/index.d.ts +48 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +163 -14
- package/dist/tools/index.js.map +1 -1
- package/docs/api/api-overview.md +24 -46
- package/docs/api/expand-sync.md +24 -51
- package/docs/api/native-plugin.md +24 -56
- package/docs/api/position-mapper.md +34 -76
- package/docs/api/transform-sync.md +27 -59
- package/docs/builtin-macros/clone.md +45 -104
- package/docs/builtin-macros/debug.md +33 -104
- package/docs/builtin-macros/default.md +78 -114
- package/docs/builtin-macros/deserialize.md +93 -273
- package/docs/builtin-macros/hash.md +58 -100
- package/docs/builtin-macros/macros-overview.md +42 -103
- package/docs/builtin-macros/ord.md +65 -133
- package/docs/builtin-macros/partial-eq.md +53 -179
- package/docs/builtin-macros/partial-ord.md +67 -159
- package/docs/builtin-macros/serialize.md +64 -194
- package/docs/concepts/architecture.md +40 -99
- package/docs/concepts/derive-system.md +129 -125
- package/docs/concepts/how-macros-work.md +52 -84
- package/docs/custom-macros/custom-overview.md +17 -39
- package/docs/custom-macros/rust-setup.md +22 -55
- package/docs/custom-macros/ts-macro-derive.md +43 -107
- package/docs/custom-macros/ts-quote.md +177 -507
- package/docs/getting-started/first-macro.md +108 -33
- package/docs/getting-started/installation.md +32 -73
- package/docs/integration/cli.md +70 -156
- package/docs/integration/configuration.md +32 -75
- package/docs/integration/integration-overview.md +16 -55
- package/docs/integration/mcp-server.md +30 -69
- package/docs/integration/svelte-preprocessor.md +60 -83
- package/docs/integration/typescript-plugin.md +32 -74
- package/docs/integration/vite-plugin.md +30 -79
- package/docs/language-servers/ls-overview.md +22 -46
- package/docs/language-servers/svelte.md +30 -69
- package/docs/language-servers/zed.md +34 -72
- package/docs/roadmap/roadmap.md +54 -130
- package/docs/sections.json +3 -262
- package/package.json +2 -2
|
@@ -1,58 +1,19 @@
|
|
|
1
1
|
# Integration
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
| `@macroforge/vite-plugin`
|
|
14
|
-
|
|
15
|
-
## Recommended Setup
|
|
16
|
-
|
|
17
|
-
For the best development experience, use both integrations:
|
|
18
|
-
|
|
19
|
-
1. **TypeScript Plugin**: Provides real-time feedback in your IDE
|
|
20
|
-
|
|
21
|
-
2. **Vite Plugin**: Expands macros during development and production builds
|
|
22
|
-
|
|
23
|
-
```bash
|
|
2
|
+
*Macroforge integrates with your development workflow through IDE plugins and build tool integration.*
|
|
3
|
+
## Overview
|
|
4
|
+
| Integration | Purpose | Package |
|
|
5
|
+
| --- | --- | --- |
|
|
6
|
+
| TypeScript Plugin | IDE support (errors, completions) | `@macroforge/typescript-plugin` |
|
|
7
|
+
| Vite Plugin | Build-time macro expansion | `@macroforge/vite-plugin` |
|
|
8
|
+
## Recommended Setup
|
|
9
|
+
For the best development experience, use both integrations:
|
|
10
|
+
1. **TypeScript Plugin**: Provides real-time feedback in your IDE
|
|
11
|
+
2. **Vite Plugin**: Expands macros during development and production builds
|
|
12
|
+
```
|
|
24
13
|
# Install both plugins
|
|
25
14
|
npm install -D @macroforge/typescript-plugin @macroforge/vite-plugin
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
source="Your Code"
|
|
32
|
-
sourceDesc="TypeScript with @derive decorators"
|
|
33
|
-
branches={[
|
|
34
|
-
{
|
|
35
|
-
plugin: 'TypeScript Plugin',
|
|
36
|
-
pluginDesc: 'Language service integration',
|
|
37
|
-
outputs: [
|
|
38
|
-
{ label: 'IDE Feedback', desc: 'Errors & completions' }
|
|
39
|
-
]
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
plugin: 'Vite Plugin',
|
|
43
|
-
pluginDesc: 'Build-time transformation',
|
|
44
|
-
outputs: [
|
|
45
|
-
{ label: 'Dev Server', desc: 'Hot reload' },
|
|
46
|
-
{ label: 'Production Build', desc: 'Optimized output' }
|
|
47
|
-
]
|
|
48
|
-
}
|
|
49
|
-
]}
|
|
50
|
-
/>
|
|
51
|
-
|
|
52
|
-
## Detailed Guides
|
|
53
|
-
|
|
54
|
-
- [TypeScript Plugin setup]({base}/docs/integration/typescript-plugin)
|
|
55
|
-
|
|
56
|
-
- [Vite Plugin configuration]({base}/docs/integration/vite-plugin)
|
|
57
|
-
|
|
58
|
-
- [Configuration options]({base}/docs/integration/configuration)
|
|
15
|
+
``` ## How They Work Together
|
|
16
|
+
<div class="flex justify-center"><div class="border-2 border-primary bg-primary/10 rounded-lg px-6 py-3 text-center"><div class="font-semibold text-primary">Your Code TypeScript with @derive decorators <div class="absolute top-0 h-px bg-border" style="width: 50%; left: 25%;"> <div class="flex flex-col items-center"> <div class="border border-border bg-card rounded-lg px-4 py-3 text-center w-full mt-1"><div class="font-medium text-foreground">TypeScript Plugin Language service integration <div class="border border-success/30 bg-success/10 rounded-md px-3 py-2 text-center"><div class="text-sm font-medium text-success-foreground">IDE Feedback Errors & completions <div class="border border-border bg-card rounded-lg px-4 py-3 text-center w-full mt-1"><div class="font-medium text-foreground">Vite Plugin Build-time transformation <div class="border border-success/30 bg-success/10 rounded-md px-3 py-2 text-center"><div class="text-sm font-medium text-success-foreground">Dev Server Hot reload<div class="text-sm font-medium text-success-foreground">Production Build Optimized output ## Detailed Guides
|
|
17
|
+
- [TypeScript Plugin setup](../docs/integration/typescript-plugin)
|
|
18
|
+
- [Vite Plugin configuration](../docs/integration/vite-plugin)
|
|
19
|
+
- [Configuration options](../docs/integration/configuration)
|
|
@@ -1,31 +1,17 @@
|
|
|
1
1
|
# MCP Server
|
|
2
|
-
|
|
3
|
-
|
|
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
|
|
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 [`@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`:
|
|
4
|
+
```
|
|
8
5
|
npx -y @macroforge/mcp-server
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
## Claude Code
|
|
14
|
-
|
|
15
|
-
To include the local MCP version in Claude Code, simply run the following command:
|
|
16
|
-
|
|
17
|
-
```bash
|
|
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
|
+
```
|
|
18
10
|
claude mcp add -t stdio -s [scope] macroforge -- npx -y @macroforge/mcp-server
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
## Claude Desktop
|
|
24
|
-
|
|
25
|
-
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:
|
|
26
|
-
|
|
27
|
-
`claude_desktop_config.json`
|
|
28
|
-
```json
|
|
11
|
+
``` The `[scope]` must be `user`, `project` or `local`.
|
|
12
|
+
## Claude Desktop
|
|
13
|
+
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:
|
|
14
|
+
```
|
|
29
15
|
{
|
|
30
16
|
"mcpServers": {
|
|
31
17
|
"macroforge": {
|
|
@@ -34,51 +20,26 @@ In the Settings > Developer section, click on Edit Config. It will open the fold
|
|
|
34
20
|
}
|
|
35
21
|
}
|
|
36
22
|
}
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
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):
|
|
42
|
-
|
|
43
|
-
`config.toml`
|
|
44
|
-
```toml
|
|
23
|
+
``` ## Codex CLI
|
|
24
|
+
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):
|
|
25
|
+
```
|
|
45
26
|
[mcp_servers.macroforge]
|
|
46
27
|
command = "npx"
|
|
47
28
|
args = ["-y", "@macroforge/mcp-server"]
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
To include the local MCP version in Gemini CLI, simply run the following command:
|
|
53
|
-
|
|
54
|
-
```bash
|
|
29
|
+
``` ## Gemini CLI
|
|
30
|
+
To include the local MCP version in Gemini CLI, simply run the following command:
|
|
31
|
+
```
|
|
55
32
|
gemini mcp add -t stdio -s [scope] macroforge npx -y @macroforge/mcp-server
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
| Lists all available Macroforge documentation sections
|
|
70
|
-
|
|
71
|
-
| `get-documentation`
|
|
72
|
-
| Retrieves full documentation for one or more sections
|
|
73
|
-
|
|
74
|
-
| `macroforge-autofixer`
|
|
75
|
-
| Validates code with `@derive` decorators and returns diagnostics
|
|
76
|
-
|
|
77
|
-
| `expand-code`
|
|
78
|
-
| Expands macros and returns the transformed TypeScript code
|
|
79
|
-
|
|
80
|
-
| `get-macro-info`
|
|
81
|
-
| Retrieves documentation for macros and field decorators
|
|
82
|
-
|
|
83
|
-
>
|
|
84
|
-
> 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`.
|
|
33
|
+
``` The `[scope]` must be `user`, `project` or `local`.
|
|
34
|
+
## Other Clients
|
|
35
|
+
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.
|
|
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.
|
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
# Svelte Preprocessor
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
2
|
+
*The Svelte preprocessor expands Macroforge macros in `<script>` blocks before Svelte compilation, enabling seamless macro usage in Svelte components.*
|
|
3
|
+
## Installation
|
|
4
|
+
```
|
|
8
5
|
npm install -D @macroforge/svelte-preprocessor
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Add the preprocessor to your `svelte.config.js`:
|
|
14
|
-
|
|
15
|
-
`svelte.config.js`
|
|
16
|
-
```javascript
|
|
6
|
+
``` ## Configuration
|
|
7
|
+
Add the preprocessor to your `svelte.config.js`:
|
|
8
|
+
```
|
|
17
9
|
import adapter from '@sveltejs/adapter-auto';
|
|
18
10
|
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
|
19
11
|
import { macroforgePreprocess } from '@macroforge/svelte-preprocessor';
|
|
@@ -31,24 +23,29 @@ const config = {
|
|
|
31
23
|
};
|
|
32
24
|
|
|
33
25
|
export default config;
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
>
|
|
38
|
-
|
|
39
|
-
|
|
26
|
+
``` **Warning Always place `macroforgePreprocess()` **before** other preprocessors like `vitePreprocess()`. This ensures macros are expanded before TypeScript compilation. ## Usage
|
|
27
|
+
Use `@derive` decorators directly in your Svelte component scripts:
|
|
28
|
+
```
|
|
29
|
+
**<script lang="ts">
|
|
30
|
+
/** @derive(Debug, Clone) */
|
|
31
|
+
class User {
|
|
32
|
+
name: string;
|
|
33
|
+
email: string;
|
|
34
|
+
|
|
35
|
+
constructor(name: string, email: string) {
|
|
36
|
+
this.name = name;
|
|
37
|
+
this.email = email;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
let user = new User("Alice", "alice@example.com");
|
|
42
|
+
console.log(user.toString()); // Generated by Debug macro
|
|
43
|
+
</script>
|
|
42
44
|
|
|
43
|
-
`UserCard.svelte`
|
|
44
|
-
```svelte
|
|
45
45
|
User: {user.name}
|
|
46
46
|
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Options
|
|
50
|
-
|
|
51
|
-
```typescript
|
|
47
|
+
``` ## Options
|
|
48
|
+
```
|
|
52
49
|
macroforgePreprocess({
|
|
53
50
|
// Keep @derive decorators in output (for debugging)
|
|
54
51
|
keepDecorators: false,
|
|
@@ -56,41 +53,20 @@ macroforgePreprocess({
|
|
|
56
53
|
// Process JavaScript files (not just TypeScript)
|
|
57
54
|
processJavaScript: false
|
|
58
55
|
})
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
| `
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
## How It Works
|
|
74
|
-
|
|
75
|
-
The preprocessor:
|
|
76
|
-
|
|
77
|
-
1. Intercepts `<script lang="ts">` blocks in `.svelte` files
|
|
78
|
-
|
|
79
|
-
2. Checks for `@derive` decorators (skips files without them)
|
|
80
|
-
|
|
81
|
-
3. Expands macros using the native Macroforge binary
|
|
82
|
-
|
|
83
|
-
4. Returns the transformed code for Svelte compilation
|
|
84
|
-
|
|
85
|
-
>
|
|
86
|
-
> Files without `@derive` decorators are passed through unchanged with zero overhead.
|
|
87
|
-
|
|
88
|
-
## SvelteKit Integration
|
|
89
|
-
|
|
90
|
-
For SvelteKit projects, you can use both the preprocessor (for `.svelte` files) and the Vite plugin (for standalone `.ts` files):
|
|
91
|
-
|
|
92
|
-
`svelte.config.js`
|
|
93
|
-
```javascript
|
|
56
|
+
``` ### Option Reference
|
|
57
|
+
| Option | Type | Default | Description |
|
|
58
|
+
| --- | --- | --- | --- |
|
|
59
|
+
| `keepDecorators` | `boolean` | `false` | Keep decorators in output |
|
|
60
|
+
| `processJavaScript` | `boolean` | `false` | Process `<script>` blocks without `lang="ts"` |
|
|
61
|
+
## How It Works
|
|
62
|
+
The preprocessor:
|
|
63
|
+
1. Intercepts `<script lang="ts">` blocks in `.svelte` files
|
|
64
|
+
2. Checks for `@derive` decorators (skips files without them)
|
|
65
|
+
3. Expands macros using the native Macroforge binary
|
|
66
|
+
4. Returns the transformed code for Svelte compilation
|
|
67
|
+
**Tip Files without `@derive` decorators are passed through unchanged with zero overhead. ## SvelteKit Integration
|
|
68
|
+
For SvelteKit projects, you can use both the preprocessor (for `.svelte` files) and the Vite plugin (for standalone `.ts` files):
|
|
69
|
+
```
|
|
94
70
|
// svelte.config.js
|
|
95
71
|
import { macroforgePreprocess } from '@macroforge/svelte-preprocessor';
|
|
96
72
|
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
|
@@ -101,10 +77,7 @@ export default {
|
|
|
101
77
|
vitePreprocess()
|
|
102
78
|
]
|
|
103
79
|
};
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
`vite.config.ts`
|
|
107
|
-
```typescript
|
|
80
|
+
``` ```
|
|
108
81
|
// vite.config.ts
|
|
109
82
|
import macroforge from '@macroforge/vite-plugin';
|
|
110
83
|
import { sveltekit } from '@sveltejs/kit/vite';
|
|
@@ -116,14 +89,9 @@ export default defineConfig({
|
|
|
116
89
|
sveltekit()
|
|
117
90
|
]
|
|
118
91
|
});
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
The preprocessor works seamlessly with Vitest for testing Svelte components:
|
|
124
|
-
|
|
125
|
-
`vitest.config.ts`
|
|
126
|
-
```typescript
|
|
92
|
+
``` ## Using with Vitest
|
|
93
|
+
The preprocessor works seamlessly with Vitest for testing Svelte components:
|
|
94
|
+
```
|
|
127
95
|
// vitest.config.ts
|
|
128
96
|
import { defineConfig } from 'vitest/config';
|
|
129
97
|
import { sveltekit } from '@sveltejs/kit/vite';
|
|
@@ -141,12 +109,21 @@ export default defineConfig({
|
|
|
141
109
|
include: ['src/**/*.{test,spec}.{js,ts}']
|
|
142
110
|
}
|
|
143
111
|
});
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
112
|
+
``` ## Svelte 5 Runes Compatibility
|
|
113
|
+
The preprocessor is fully compatible with Svelte 5 runes (`$state`, `$derived`, `$props`, etc.). Files using runes but without `@derive` decorators are skipped entirely.
|
|
114
|
+
```
|
|
115
|
+
**<script lang="ts">
|
|
116
|
+
// Runes work normally
|
|
117
|
+
let count = $state(0);
|
|
118
|
+
let doubled = $derived(count * 2);
|
|
119
|
+
|
|
120
|
+
// Macros expand correctly
|
|
121
|
+
/** @derive(Debug) */
|
|
122
|
+
class Counter {
|
|
123
|
+
value: number;
|
|
124
|
+
constructor(value: number) {
|
|
125
|
+
this.value = value;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
</script>
|
|
152
129
|
```
|
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
# TypeScript Plugin
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
2
|
+
*The TypeScript plugin provides IDE integration for Macroforge, including error reporting, completions, and type checking for generated code.*
|
|
3
|
+
## Installation
|
|
4
|
+
```
|
|
8
5
|
npm install -D @macroforge/typescript-plugin
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Add the plugin to your `tsconfig.json`:
|
|
14
|
-
|
|
15
|
-
`tsconfig.json`
|
|
16
|
-
```json
|
|
6
|
+
``` ## Configuration
|
|
7
|
+
Add the plugin to your `tsconfig.json`:
|
|
8
|
+
```
|
|
17
9
|
{
|
|
18
10
|
"compilerOptions": {
|
|
19
11
|
"plugins": [
|
|
@@ -23,74 +15,40 @@ Add the plugin to your `tsconfig.json`:
|
|
|
23
15
|
]
|
|
24
16
|
}
|
|
25
17
|
}
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
1. Open the Command Palette (`Cmd/Ctrl + Shift + P`)
|
|
33
|
-
|
|
34
|
-
2. Search for "TypeScript: Select TypeScript Version"
|
|
35
|
-
|
|
36
|
-
3. Choose "Use Workspace Version"
|
|
37
|
-
|
|
38
|
-
>
|
|
39
|
-
> Add this setting to your `.vscode/settings.json` to make it permanent:
|
|
40
|
-
|
|
41
|
-
`.vscode/settings.json`
|
|
42
|
-
```json
|
|
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 (`Cmd/Ctrl + Shift + P`)
|
|
21
|
+
2. Search for "TypeScript: Select TypeScript Version"
|
|
22
|
+
3. Choose "Use Workspace Version"
|
|
23
|
+
**Tip Add this setting to your `.vscode/settings.json` to make it permanent: ```
|
|
43
24
|
{
|
|
44
25
|
"typescript.tsdk": "node_modules/typescript/lib"
|
|
45
26
|
}
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
Errors in macro-generated code are reported at the `@derive` decorator position:
|
|
53
|
-
|
|
54
|
-
```typescript
|
|
55
|
-
/** @derive(Debug) */ // <- Errors appear here
|
|
27
|
+
``` ## Features
|
|
28
|
+
### Error Reporting
|
|
29
|
+
Errors in macro-generated code are reported at the `@derive` decorator position:
|
|
30
|
+
```
|
|
31
|
+
/** @derive(Debug) */ // **<- Errors appear here
|
|
56
32
|
class User {
|
|
57
33
|
name: string;
|
|
58
34
|
}
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
The plugin provides completions for generated methods:
|
|
64
|
-
|
|
65
|
-
```typescript
|
|
35
|
+
``` ### Completions
|
|
36
|
+
The plugin provides completions for generated methods:
|
|
37
|
+
```
|
|
66
38
|
const user = new User("Alice");
|
|
67
39
|
user.to // Suggests: toString(), toJSON(), etc.
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
Hover over generated methods to see their types:
|
|
73
|
-
|
|
74
|
-
```typescript
|
|
40
|
+
``` ### Type Information
|
|
41
|
+
Hover over generated methods to see their types:
|
|
42
|
+
```
|
|
75
43
|
// Hover over 'clone' shows:
|
|
76
44
|
// (method) User.clone(): User
|
|
77
45
|
const copy = user.clone();
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
2.
|
|
87
|
-
|
|
88
|
-
3. Check that the plugin is listed in `tsconfig.json`
|
|
89
|
-
|
|
90
|
-
### Errors Not Showing
|
|
91
|
-
|
|
92
|
-
If errors from macros aren't appearing:
|
|
93
|
-
|
|
94
|
-
1. Make sure the Vite plugin is also installed (for source file watching)
|
|
95
|
-
|
|
96
|
-
2. Check that your file is saved (plugins process on save)
|
|
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 `tsconfig.json`
|
|
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)
|
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
# Vite Plugin
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
2
|
+
*The Vite plugin provides build-time macro expansion, transforming your code during development and production builds.*
|
|
3
|
+
## Installation
|
|
4
|
+
```
|
|
8
5
|
npm install -D @macroforge/vite-plugin
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Add the plugin to your `vite.config.ts`:
|
|
14
|
-
|
|
15
|
-
`vite.config.ts`
|
|
16
|
-
```typescript
|
|
6
|
+
``` ## Configuration
|
|
7
|
+
Add the plugin to your `vite.config.ts`:
|
|
8
|
+
```
|
|
17
9
|
import macroforge from "@macroforge/vite-plugin";
|
|
18
10
|
import { defineConfig } from "vite";
|
|
19
11
|
|
|
@@ -22,11 +14,8 @@ export default defineConfig({
|
|
|
22
14
|
macroforge()
|
|
23
15
|
]
|
|
24
16
|
});
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## Options
|
|
28
|
-
|
|
29
|
-
```typescript
|
|
17
|
+
``` ## Options
|
|
18
|
+
```
|
|
30
19
|
macroforge({
|
|
31
20
|
// Generate .d.ts files for expanded code
|
|
32
21
|
generateTypes: true,
|
|
@@ -44,36 +33,16 @@ macroforge({
|
|
|
44
33
|
include: ["**/*.ts", "**/*.tsx"],
|
|
45
34
|
exclude: ["node_modules/**"]
|
|
46
35
|
})
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
| `
|
|
52
|
-
| `boolean`
|
|
53
|
-
| `
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
| `string`
|
|
58
|
-
| `.macroforge/types`
|
|
59
|
-
| Where to write type files
|
|
60
|
-
|
|
61
|
-
| `emitMetadata`
|
|
62
|
-
| `boolean`
|
|
63
|
-
| `false`
|
|
64
|
-
| Emit macro metadata files
|
|
65
|
-
|
|
66
|
-
| `keepDecorators`
|
|
67
|
-
| `boolean`
|
|
68
|
-
| `false`
|
|
69
|
-
| Keep decorators in output
|
|
70
|
-
|
|
71
|
-
## Framework Integration
|
|
72
|
-
|
|
73
|
-
### React (Vite)
|
|
74
|
-
|
|
75
|
-
`vite.config.ts`
|
|
76
|
-
```typescript
|
|
36
|
+
``` ### Option Reference
|
|
37
|
+
| Option | Type | Default | Description |
|
|
38
|
+
| --- | --- | --- | --- |
|
|
39
|
+
| `generateTypes` | `boolean` | `true` | Generate .d.ts files |
|
|
40
|
+
| `typesOutputDir` | `string` | `.macroforge/types` | Where to write type files |
|
|
41
|
+
| `emitMetadata` | `boolean` | `false` | Emit macro metadata files |
|
|
42
|
+
| `keepDecorators` | `boolean` | `false` | Keep decorators in output |
|
|
43
|
+
## Framework Integration
|
|
44
|
+
### React (Vite)
|
|
45
|
+
```
|
|
77
46
|
import macroforge from "@macroforge/vite-plugin";
|
|
78
47
|
import react from "@vitejs/plugin-react";
|
|
79
48
|
import { defineConfig } from "vite";
|
|
@@ -84,12 +53,8 @@ export default defineConfig({
|
|
|
84
53
|
react()
|
|
85
54
|
]
|
|
86
55
|
});
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
### SvelteKit
|
|
90
|
-
|
|
91
|
-
`vite.config.ts`
|
|
92
|
-
```typescript
|
|
56
|
+
``` ### SvelteKit
|
|
57
|
+
```
|
|
93
58
|
import macroforge from "@macroforge/vite-plugin";
|
|
94
59
|
import { sveltekit } from "@sveltejs/kit/vite";
|
|
95
60
|
import { defineConfig } from "vite";
|
|
@@ -100,27 +65,13 @@ export default defineConfig({
|
|
|
100
65
|
sveltekit()
|
|
101
66
|
]
|
|
102
67
|
});
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
##
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
-
|
|
113
|
-
|
|
114
|
-
- Expands macros on save
|
|
115
|
-
|
|
116
|
-
- Provides HMR support for expanded code
|
|
117
|
-
|
|
118
|
-
## Production Build
|
|
119
|
-
|
|
120
|
-
During production builds, the plugin:
|
|
121
|
-
|
|
122
|
-
- Expands all macros in the source files
|
|
123
|
-
|
|
124
|
-
- Generates type declaration files
|
|
125
|
-
|
|
126
|
-
- Strips `@derive` decorators from output
|
|
68
|
+
``` > **Note:** Always place the Macroforge plugin before other framework plugins to ensure macros are expanded first. ## Development Server
|
|
69
|
+
During development, the plugin:
|
|
70
|
+
- Watches for file changes
|
|
71
|
+
- Expands macros on save
|
|
72
|
+
- Provides HMR support for expanded code
|
|
73
|
+
## Production Build
|
|
74
|
+
During production builds, the plugin:
|
|
75
|
+
- Expands all macros in the source files
|
|
76
|
+
- Generates type declaration files
|
|
77
|
+
- Strips `@derive` decorators from output
|