@macroforge/mcp-server 0.1.17
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/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/docs-loader.d.ts +30 -0
- package/dist/tools/docs-loader.d.ts.map +1 -0
- package/dist/tools/docs-loader.js +112 -0
- package/dist/tools/docs-loader.js.map +1 -0
- package/dist/tools/index.d.ts +6 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +348 -0
- package/dist/tools/index.js.map +1 -0
- package/docs/api/api-overview.md +75 -0
- package/docs/api/expand-sync.md +121 -0
- package/docs/api/native-plugin.md +106 -0
- package/docs/api/position-mapper.md +127 -0
- package/docs/api/transform-sync.md +98 -0
- package/docs/builtin-macros/clone.md +180 -0
- package/docs/builtin-macros/debug.md +222 -0
- package/docs/builtin-macros/default.md +192 -0
- package/docs/builtin-macros/deserialize.md +662 -0
- package/docs/builtin-macros/hash.md +205 -0
- package/docs/builtin-macros/macros-overview.md +169 -0
- package/docs/builtin-macros/ord.md +258 -0
- package/docs/builtin-macros/partial-eq.md +306 -0
- package/docs/builtin-macros/partial-ord.md +268 -0
- package/docs/builtin-macros/serialize.md +321 -0
- package/docs/concepts/architecture.md +139 -0
- package/docs/concepts/derive-system.md +173 -0
- package/docs/concepts/how-macros-work.md +124 -0
- package/docs/custom-macros/custom-overview.md +84 -0
- package/docs/custom-macros/rust-setup.md +146 -0
- package/docs/custom-macros/ts-macro-derive.md +307 -0
- package/docs/custom-macros/ts-quote.md +696 -0
- package/docs/getting-started/first-macro.md +120 -0
- package/docs/getting-started/installation.md +110 -0
- package/docs/integration/cli.md +207 -0
- package/docs/integration/configuration.md +116 -0
- package/docs/integration/integration-overview.md +51 -0
- package/docs/integration/typescript-plugin.md +96 -0
- package/docs/integration/vite-plugin.md +126 -0
- package/docs/language-servers/ls-overview.md +47 -0
- package/docs/language-servers/svelte-ls.md +80 -0
- package/docs/language-servers/zed-extensions.md +84 -0
- package/docs/sections.json +258 -0
- package/package.json +48 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Your First Macro
|
|
2
|
+
|
|
3
|
+
*Let's create a class that uses Macroforge's derive macros to automatically generate useful methods.*
|
|
4
|
+
|
|
5
|
+
## Creating a Class with Derive Macros
|
|
6
|
+
|
|
7
|
+
Start by creating a simple `User` class. We'll use the `@derive` decorator to automatically generate methods.
|
|
8
|
+
|
|
9
|
+
`user.ts`
|
|
10
|
+
```typescript
|
|
11
|
+
import { Debug, Clone, Eq } from "macroforge";
|
|
12
|
+
|
|
13
|
+
/** @derive(Debug, Clone, Eq) */
|
|
14
|
+
export class User {
|
|
15
|
+
name: string;
|
|
16
|
+
age: number;
|
|
17
|
+
email: string;
|
|
18
|
+
|
|
19
|
+
constructor(name: string, age: number, email: string) {
|
|
20
|
+
this.name = name;
|
|
21
|
+
this.age = age;
|
|
22
|
+
this.email = email;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## What Gets Generated
|
|
28
|
+
|
|
29
|
+
After macro expansion, your class will have these methods:
|
|
30
|
+
|
|
31
|
+
`user.ts (expanded)`
|
|
32
|
+
```typescript
|
|
33
|
+
export class User {
|
|
34
|
+
name: string;
|
|
35
|
+
age: number;
|
|
36
|
+
email: string;
|
|
37
|
+
|
|
38
|
+
constructor(name: string, age: number, email: string) {
|
|
39
|
+
this.name = name;
|
|
40
|
+
this.age = age;
|
|
41
|
+
this.email = email;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Generated by Debug
|
|
45
|
+
toString(): string {
|
|
46
|
+
return \`User { name: \${this.name}, age: \${this.age}, email: \${this.email} }\`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Generated by Clone
|
|
50
|
+
clone(): User {
|
|
51
|
+
return new User(this.name, this.age, this.email);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Generated by Eq
|
|
55
|
+
equals(other: User): boolean {
|
|
56
|
+
return this.name === other.name
|
|
57
|
+
&& this.age === other.age
|
|
58
|
+
&& this.email === other.email;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Using the Generated Methods
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
const user = new User("Alice", 30, "alice@example.com");
|
|
67
|
+
|
|
68
|
+
// Debug: toString()
|
|
69
|
+
console.log(user.toString());
|
|
70
|
+
// Output: User { name: Alice, age: 30, email: alice@example.com }
|
|
71
|
+
|
|
72
|
+
// Clone: clone()
|
|
73
|
+
const copy = user.clone();
|
|
74
|
+
console.log(copy.name); // "Alice"
|
|
75
|
+
|
|
76
|
+
// Eq: equals()
|
|
77
|
+
console.log(user.equals(copy)); // true
|
|
78
|
+
|
|
79
|
+
const different = new User("Bob", 25, "bob@example.com");
|
|
80
|
+
console.log(user.equals(different)); // false
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Customizing Behavior
|
|
84
|
+
|
|
85
|
+
You can customize how macros work using field-level decorators. For example, with the Debug macro:
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
/** @derive(Debug) */
|
|
89
|
+
export class User {
|
|
90
|
+
/** @debug({ rename: "userId" }) */
|
|
91
|
+
id: number;
|
|
92
|
+
|
|
93
|
+
name: string;
|
|
94
|
+
|
|
95
|
+
/** @debug({ skip: true }) */
|
|
96
|
+
password: string;
|
|
97
|
+
|
|
98
|
+
constructor(id: number, name: string, password: string) {
|
|
99
|
+
this.id = id;
|
|
100
|
+
this.name = name;
|
|
101
|
+
this.password = password;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const user = new User(42, "Alice", "secret123");
|
|
106
|
+
console.log(user.toString());
|
|
107
|
+
// Output: User { userId: 42, name: Alice }
|
|
108
|
+
// Note: 'id' is renamed to 'userId', 'password' is skipped
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
>
|
|
112
|
+
> Field-level decorators let you control exactly how each field is handled by the macro.
|
|
113
|
+
|
|
114
|
+
## Next Steps
|
|
115
|
+
|
|
116
|
+
- [Learn how macros work under the hood]({base}/docs/concepts)
|
|
117
|
+
|
|
118
|
+
- [Explore all Debug options]({base}/docs/builtin-macros/debug)
|
|
119
|
+
|
|
120
|
+
- [Create your own custom macros]({base}/docs/custom-macros)
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Installation
|
|
2
|
+
|
|
3
|
+
*Get started with Macroforge in just a few minutes. Install the package and configure your project to start using TypeScript macros.*
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- Node.js 18.0 or later
|
|
8
|
+
|
|
9
|
+
- TypeScript 5.0 or later
|
|
10
|
+
|
|
11
|
+
## Install the Package
|
|
12
|
+
|
|
13
|
+
Install Macroforge using your preferred package manager:
|
|
14
|
+
|
|
15
|
+
`npm`
|
|
16
|
+
```bash
|
|
17
|
+
npm install macroforge
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`bun`
|
|
21
|
+
```bash
|
|
22
|
+
bun add macroforge
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`pnpm`
|
|
26
|
+
```bash
|
|
27
|
+
pnpm add macroforge
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
> **Note:**
|
|
31
|
+
> Macroforge includes pre-built native binaries for macOS (x64, arm64), Linux (x64, arm64), and Windows (x64, arm64).
|
|
32
|
+
|
|
33
|
+
## Basic Usage
|
|
34
|
+
|
|
35
|
+
The simplest way to use Macroforge is with the built-in derive macros. Add a `@derive` comment decorator to your class:
|
|
36
|
+
|
|
37
|
+
`user.ts`
|
|
38
|
+
```typescript
|
|
39
|
+
import { Debug, Clone, Eq } from "macroforge";
|
|
40
|
+
|
|
41
|
+
/** @derive(Debug, Clone, Eq) */
|
|
42
|
+
class User {
|
|
43
|
+
name: string;
|
|
44
|
+
age: number;
|
|
45
|
+
|
|
46
|
+
constructor(name: string, age: number) {
|
|
47
|
+
this.name = name;
|
|
48
|
+
this.age = age;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// After macro expansion, User has:
|
|
53
|
+
// - toString(): string (from Debug)
|
|
54
|
+
// - clone(): User (from Clone)
|
|
55
|
+
// - equals(other: User): boolean (from Eq)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## IDE Integration
|
|
59
|
+
|
|
60
|
+
For the best development experience, add the TypeScript plugin to your `tsconfig.json`:
|
|
61
|
+
|
|
62
|
+
`tsconfig.json`
|
|
63
|
+
```json
|
|
64
|
+
{
|
|
65
|
+
"compilerOptions": {
|
|
66
|
+
"plugins": [
|
|
67
|
+
{
|
|
68
|
+
"name": "@macroforge/typescript-plugin"
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
This enables features like:
|
|
76
|
+
|
|
77
|
+
- Accurate error positions in your source code
|
|
78
|
+
|
|
79
|
+
- Autocompletion for generated methods
|
|
80
|
+
|
|
81
|
+
- Type checking for expanded code
|
|
82
|
+
|
|
83
|
+
## Build Integration (Vite)
|
|
84
|
+
|
|
85
|
+
If you're using Vite, add the plugin to your config for automatic macro expansion during build:
|
|
86
|
+
|
|
87
|
+
`vite.config.ts`
|
|
88
|
+
```typescript
|
|
89
|
+
import macroforge from "@macroforge/vite-plugin";
|
|
90
|
+
import { defineConfig } from "vite";
|
|
91
|
+
|
|
92
|
+
export default defineConfig({
|
|
93
|
+
plugins: [
|
|
94
|
+
macroforge({
|
|
95
|
+
generateTypes: true,
|
|
96
|
+
typesOutputDir: ".macroforge/types"
|
|
97
|
+
})
|
|
98
|
+
]
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Next Steps
|
|
103
|
+
|
|
104
|
+
Now that you have Macroforge installed, learn how to use it:
|
|
105
|
+
|
|
106
|
+
- [Create your first macro]({base}/docs/getting-started/first-macro)
|
|
107
|
+
|
|
108
|
+
- [Understand how macros work]({base}/docs/concepts)
|
|
109
|
+
|
|
110
|
+
- [Explore built-in macros]({base}/docs/builtin-macros)
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# Command Line Interface
|
|
2
|
+
|
|
3
|
+
*The `macroforge` CLI provides commands for expanding macros and running type checks with macro support.*
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
The CLI is a Rust binary. You can install it using Cargo:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
cargo install macroforge_ts
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or build from source:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
git clone https://github.com/rymskip/macroforge-ts.git
|
|
17
|
+
cd macroforge-ts/crates
|
|
18
|
+
cargo build --release --bin macroforge
|
|
19
|
+
|
|
20
|
+
# The binary is at target/release/macroforge
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Commands
|
|
24
|
+
|
|
25
|
+
### macroforge expand
|
|
26
|
+
|
|
27
|
+
Expands macros in a TypeScript file and outputs the transformed code.
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
macroforge expand <input> [options]
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
#### Arguments
|
|
34
|
+
|
|
35
|
+
| `<input>`
|
|
36
|
+
| Path to the TypeScript or TSX file to expand
|
|
37
|
+
|
|
38
|
+
#### Options
|
|
39
|
+
|
|
40
|
+
| `--out <path>`
|
|
41
|
+
| Write the expanded JavaScript/TypeScript to a file
|
|
42
|
+
|
|
43
|
+
| `--types-out <path>`
|
|
44
|
+
| Write the generated `.d.ts` declarations to a file
|
|
45
|
+
|
|
46
|
+
| `--print`
|
|
47
|
+
| Print output to stdout even when `--out` is specified
|
|
48
|
+
|
|
49
|
+
| `--builtin-only`
|
|
50
|
+
| Use only built-in Rust macros (faster, but no external macro support)
|
|
51
|
+
|
|
52
|
+
#### Examples
|
|
53
|
+
|
|
54
|
+
Expand a file and print to stdout:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
macroforge expand src/user.ts
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Expand and write to a file:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
macroforge expand src/user.ts --out dist/user.js
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Expand with both runtime output and type declarations:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
macroforge expand src/user.ts --out dist/user.js --types-out dist/user.d.ts
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Use fast built-in macros only (no external macro support):
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
macroforge expand src/user.ts --builtin-only
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
>
|
|
79
|
+
> By default, the CLI uses Node.js for full macro support (including external macros). It must be run from your project's root directory where `macroforge` and any external macro packages are installed in `node_modules`.
|
|
80
|
+
|
|
81
|
+
### macroforge tsc
|
|
82
|
+
|
|
83
|
+
Runs TypeScript type checking with macro expansion. This wraps `tsc --noEmit` and expands macros before type checking, so your generated methods are properly type-checked.
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
macroforge tsc [options]
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
#### Options
|
|
90
|
+
|
|
91
|
+
| `-p, --project <path>`
|
|
92
|
+
| Path to `tsconfig.json` (defaults to `tsconfig.json` in current directory)
|
|
93
|
+
|
|
94
|
+
#### Examples
|
|
95
|
+
|
|
96
|
+
Type check with default tsconfig.json:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
macroforge tsc
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Type check with a specific config:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
macroforge tsc -p tsconfig.build.json
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Output Format
|
|
109
|
+
|
|
110
|
+
### Expanded Code
|
|
111
|
+
|
|
112
|
+
When expanding a file like this:
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
/** @derive(Debug) */
|
|
116
|
+
class User {
|
|
117
|
+
name: string;
|
|
118
|
+
age: number;
|
|
119
|
+
|
|
120
|
+
constructor(name: string, age: number) {
|
|
121
|
+
this.name = name;
|
|
122
|
+
this.age = age;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
The CLI outputs the expanded code with the generated methods:
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
class User {
|
|
131
|
+
name: string;
|
|
132
|
+
age: number;
|
|
133
|
+
|
|
134
|
+
constructor(name: string, age: number) {
|
|
135
|
+
this.name = name;
|
|
136
|
+
this.age = age;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
[Symbol.for("nodejs.util.inspect.custom")](): string {
|
|
140
|
+
return \`User { name: \${this.name}, age: \${this.age} }\`;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Diagnostics
|
|
146
|
+
|
|
147
|
+
Errors and warnings are printed to stderr in a readable format:
|
|
148
|
+
|
|
149
|
+
```text
|
|
150
|
+
[macroforge] error at src/user.ts:5:1: Unknown derive macro: InvalidMacro
|
|
151
|
+
[macroforge] warning at src/user.ts:10:3: Field 'unused' is never used
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Use Cases
|
|
155
|
+
|
|
156
|
+
### CI/CD Type Checking
|
|
157
|
+
|
|
158
|
+
Use `macroforge tsc` in your CI pipeline to type-check with macro expansion:
|
|
159
|
+
|
|
160
|
+
```json
|
|
161
|
+
# package.json
|
|
162
|
+
{
|
|
163
|
+
"scripts": {
|
|
164
|
+
"typecheck": "macroforge tsc"
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Debugging Macro Output
|
|
170
|
+
|
|
171
|
+
Use `macroforge expand` to inspect what code your macros generate:
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
macroforge expand src/models/user.ts | less
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Build Pipeline
|
|
178
|
+
|
|
179
|
+
Generate expanded files as part of a custom build:
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
#!/bin/bash
|
|
183
|
+
for file in src/**/*.ts; do
|
|
184
|
+
outfile="dist/$(basename "$file" .ts).js"
|
|
185
|
+
macroforge expand "$file" --out "$outfile"
|
|
186
|
+
done
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Built-in vs Full Mode
|
|
190
|
+
|
|
191
|
+
By default, the CLI uses Node.js for full macro support including external macros. Use `--builtin-only` for faster expansion when you only need built-in macros:
|
|
192
|
+
|
|
193
|
+
| Built-in macros
|
|
194
|
+
| Yes
|
|
195
|
+
| Yes
|
|
196
|
+
|
|
197
|
+
| External macros
|
|
198
|
+
| Yes
|
|
199
|
+
| No
|
|
200
|
+
|
|
201
|
+
| Performance
|
|
202
|
+
| Standard
|
|
203
|
+
| Faster
|
|
204
|
+
|
|
205
|
+
| Dependencies
|
|
206
|
+
| Requires `macroforge` in node_modules
|
|
207
|
+
| None
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# Configuration
|
|
2
|
+
|
|
3
|
+
*Macroforge can be configured with a `macroforge.json` file in your project root.*
|
|
4
|
+
|
|
5
|
+
## Configuration File
|
|
6
|
+
|
|
7
|
+
Create a `macroforge.json` file:
|
|
8
|
+
|
|
9
|
+
`macroforge.json`
|
|
10
|
+
```json
|
|
11
|
+
{
|
|
12
|
+
"allowNativeMacros": true,
|
|
13
|
+
"macroPackages": [],
|
|
14
|
+
"keepDecorators": false,
|
|
15
|
+
"limits": {
|
|
16
|
+
"maxExecutionTimeMs": 5000,
|
|
17
|
+
"maxMemoryBytes": 104857600,
|
|
18
|
+
"maxOutputSize": 10485760,
|
|
19
|
+
"maxDiagnostics": 100
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Options Reference
|
|
25
|
+
|
|
26
|
+
### allowNativeMacros
|
|
27
|
+
|
|
28
|
+
| Type
|
|
29
|
+
| `boolean`
|
|
30
|
+
|
|
31
|
+
| Default
|
|
32
|
+
| `true`
|
|
33
|
+
|
|
34
|
+
Enable or disable native (Rust) macro packages. Set to `false` to only allow built-in macros.
|
|
35
|
+
|
|
36
|
+
### macroPackages
|
|
37
|
+
|
|
38
|
+
| Type
|
|
39
|
+
| `string[]`
|
|
40
|
+
|
|
41
|
+
| Default
|
|
42
|
+
| `[]`
|
|
43
|
+
|
|
44
|
+
List of npm packages that provide macros. Macroforge will look for macros in these packages.
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"macroPackages": [
|
|
49
|
+
"@my-org/custom-macros",
|
|
50
|
+
"community-macros"
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### keepDecorators
|
|
56
|
+
|
|
57
|
+
| Type
|
|
58
|
+
| `boolean`
|
|
59
|
+
|
|
60
|
+
| Default
|
|
61
|
+
| `false`
|
|
62
|
+
|
|
63
|
+
Keep `@derive` decorators in the output. Useful for debugging.
|
|
64
|
+
|
|
65
|
+
### limits
|
|
66
|
+
|
|
67
|
+
Configure resource limits for macro expansion:
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"limits": {
|
|
72
|
+
// Maximum time for a single macro expansion (ms)
|
|
73
|
+
"maxExecutionTimeMs": 5000,
|
|
74
|
+
|
|
75
|
+
// Maximum memory usage (bytes)
|
|
76
|
+
"maxMemoryBytes": 104857600, // 100MB
|
|
77
|
+
|
|
78
|
+
// Maximum size of generated code (bytes)
|
|
79
|
+
"maxOutputSize": 10485760, // 10MB
|
|
80
|
+
|
|
81
|
+
// Maximum number of diagnostics per file
|
|
82
|
+
"maxDiagnostics": 100
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Macro Runtime Overrides
|
|
88
|
+
|
|
89
|
+
Override settings for specific macros:
|
|
90
|
+
|
|
91
|
+
```json
|
|
92
|
+
{
|
|
93
|
+
"macroRuntimeOverrides": {
|
|
94
|
+
"@my-org/macros": {
|
|
95
|
+
"maxExecutionTimeMs": 10000
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
> **Warning:**
|
|
102
|
+
> Be careful when increasing limits, as this could allow malicious macros to consume excessive resources.
|
|
103
|
+
|
|
104
|
+
## Environment Variables
|
|
105
|
+
|
|
106
|
+
Some settings can be overridden with environment variables:
|
|
107
|
+
|
|
108
|
+
| `MACROFORGE_DEBUG`
|
|
109
|
+
| Enable debug logging
|
|
110
|
+
|
|
111
|
+
| `MACROFORGE_LOG_FILE`
|
|
112
|
+
| Write logs to a file
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
MACROFORGE_DEBUG=1 npm run dev
|
|
116
|
+
```
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Integration
|
|
2
|
+
|
|
3
|
+
*Macroforge integrates with your development workflow through IDE plugins and build tool integration.*
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
| TypeScript Plugin
|
|
8
|
+
| IDE support (errors, completions)
|
|
9
|
+
| `@macroforge/typescript-plugin`
|
|
10
|
+
|
|
11
|
+
| Vite Plugin
|
|
12
|
+
| Build-time macro expansion
|
|
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
|
|
24
|
+
# Install both plugins
|
|
25
|
+
npm install -D @macroforge/typescript-plugin @macroforge/vite-plugin
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## How They Work Together
|
|
29
|
+
|
|
30
|
+
```text
|
|
31
|
+
┌────────────────────────────────────────────────────────┐
|
|
32
|
+
│ Development Flow │
|
|
33
|
+
├────────────────────────────────────────────────────────┤
|
|
34
|
+
│ │
|
|
35
|
+
│ Your Code ──► TypeScript Plugin ──► IDE Feedback │
|
|
36
|
+
│ │ │
|
|
37
|
+
│ │ │
|
|
38
|
+
│ └──────► Vite Plugin ────────► Dev Server │
|
|
39
|
+
│ │ │
|
|
40
|
+
│ └─────────────► Production Build │
|
|
41
|
+
│ │
|
|
42
|
+
└────────────────────────────────────────────────────────┘
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Detailed Guides
|
|
46
|
+
|
|
47
|
+
- [TypeScript Plugin setup]({base}/docs/integration/typescript-plugin)
|
|
48
|
+
|
|
49
|
+
- [Vite Plugin configuration]({base}/docs/integration/vite-plugin)
|
|
50
|
+
|
|
51
|
+
- [Configuration options]({base}/docs/integration/configuration)
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# TypeScript Plugin
|
|
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
|
+
npm install -D @macroforge/typescript-plugin
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Configuration
|
|
12
|
+
|
|
13
|
+
Add the plugin to your `tsconfig.json`:
|
|
14
|
+
|
|
15
|
+
`tsconfig.json`
|
|
16
|
+
```json
|
|
17
|
+
{
|
|
18
|
+
"compilerOptions": {
|
|
19
|
+
"plugins": [
|
|
20
|
+
{
|
|
21
|
+
"name": "@macroforge/typescript-plugin"
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## VS Code Setup
|
|
29
|
+
|
|
30
|
+
VS Code uses its own TypeScript version by default. To use the workspace version (which includes plugins):
|
|
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
|
|
43
|
+
{
|
|
44
|
+
"typescript.tsdk": "node_modules/typescript/lib"
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Features
|
|
49
|
+
|
|
50
|
+
### Error Reporting
|
|
51
|
+
|
|
52
|
+
Errors in macro-generated code are reported at the `@derive` decorator position:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
/** @derive(Debug) */ // <- Errors appear here
|
|
56
|
+
class User {
|
|
57
|
+
name: string;
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Completions
|
|
62
|
+
|
|
63
|
+
The plugin provides completions for generated methods:
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
const user = new User("Alice");
|
|
67
|
+
user.to // Suggests: toString(), toJSON(), etc.
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Type Information
|
|
71
|
+
|
|
72
|
+
Hover over generated methods to see their types:
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
// Hover over 'clone' shows:
|
|
76
|
+
// (method) User.clone(): User
|
|
77
|
+
const copy = user.clone();
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Troubleshooting
|
|
81
|
+
|
|
82
|
+
### Plugin Not Loading
|
|
83
|
+
|
|
84
|
+
1. Ensure you're using the workspace TypeScript version
|
|
85
|
+
|
|
86
|
+
2. Restart the TypeScript server (Command Palette → "TypeScript: Restart TS Server")
|
|
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)
|