@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.
- package/LICENSE +22 -0
- package/docs/BOOK.md +165 -0
- package/docs/api/api-overview.md +67 -48
- package/docs/api/expand-sync.md +88 -53
- package/docs/api/native-plugin.md +121 -71
- package/docs/api/position-mapper.md +115 -55
- package/docs/api/transform-sync.md +86 -60
- package/docs/builtin-macros/clone.md +0 -20
- package/docs/builtin-macros/debug.md +0 -23
- package/docs/builtin-macros/default.md +1 -40
- package/docs/builtin-macros/deserialize/example.md +8 -1416
- package/docs/builtin-macros/deserialize.md +8 -1416
- package/docs/builtin-macros/hash.md +0 -42
- package/docs/builtin-macros/macros-overview/detailed-documentation.md +13 -0
- package/docs/builtin-macros/macros-overview/enum-support.md +30 -0
- package/docs/builtin-macros/macros-overview/interface-support.md +28 -0
- package/docs/builtin-macros/macros-overview/overview.md +36 -0
- package/docs/builtin-macros/macros-overview/type-alias-support.md +62 -0
- package/docs/builtin-macros/macros-overview.md +171 -130
- package/docs/builtin-macros/ord.md +0 -25
- package/docs/builtin-macros/partial-eq.md +0 -84
- package/docs/builtin-macros/partial-ord.md +2 -32
- package/docs/builtin-macros/serialize.md +2 -62
- package/docs/concepts/architecture.md +125 -48
- package/docs/concepts/derive-system/built-in-vs-custom-macros.md +13 -0
- package/docs/concepts/derive-system/overview.md +200 -0
- package/docs/concepts/derive-system.md +157 -104
- package/docs/concepts/how-macros-work.md +98 -47
- package/docs/custom-macros/custom-overview.md +79 -57
- package/docs/custom-macros/rust-setup.md +138 -99
- package/docs/custom-macros/ts-macro-derive/accessing-field-data.md +40 -31
- package/docs/custom-macros/ts-macro-derive/adding-imports.md +14 -11
- package/docs/custom-macros/ts-macro-derive/attribute-options.md +20 -25
- package/docs/custom-macros/ts-macro-derive/complete-example.md +40 -38
- package/docs/custom-macros/ts-macro-derive/deriveinput-structure.md +49 -47
- package/docs/custom-macros/ts-macro-derive/function-signature.md +12 -0
- package/docs/custom-macros/ts-macro-derive/overview.md +9 -7
- package/docs/custom-macros/ts-macro-derive/parsing-input.md +20 -18
- package/docs/custom-macros/ts-macro-derive/returning-errors.md +15 -13
- package/docs/custom-macros/ts-macro-derive.md +322 -228
- package/docs/custom-macros/ts-quote/backtick-template-literals.md +19 -7
- package/docs/custom-macros/ts-quote/comments-and.md +56 -22
- package/docs/custom-macros/ts-quote/complete-example-json-derive-macro.md +89 -98
- package/docs/custom-macros/ts-quote/conditionals-ifif.md +35 -29
- package/docs/custom-macros/ts-quote/identifier-concatenation-content.md +30 -22
- package/docs/custom-macros/ts-quote/iteration-for.md +48 -40
- package/docs/custom-macros/ts-quote/local-constants-let.md +23 -21
- package/docs/custom-macros/ts-quote/match-expressions-match.md +46 -38
- package/docs/custom-macros/ts-quote/overview.md +5 -10
- package/docs/custom-macros/ts-quote/pattern-matching-iflet.md +39 -0
- package/docs/custom-macros/ts-quote/quick-reference.md +50 -129
- package/docs/custom-macros/ts-quote/side-effects-do.md +13 -78
- package/docs/custom-macros/ts-quote/string-interpolation-textexpr.md +36 -0
- package/docs/custom-macros/ts-quote/tsstream-injection-typescript.md +43 -35
- package/docs/custom-macros/ts-quote/while-loops-while.md +31 -23
- package/docs/custom-macros/ts-quote.md +800 -520
- package/docs/getting-started/first-macro.md +98 -71
- package/docs/getting-started/installation.md +109 -65
- package/docs/integration/cli.md +214 -105
- package/docs/integration/configuration.md +115 -72
- package/docs/integration/integration-overview.md +55 -18
- package/docs/integration/mcp-server.md +84 -43
- package/docs/integration/svelte-preprocessor.md +183 -126
- package/docs/integration/typescript-plugin.md +101 -53
- package/docs/integration/vite-plugin.md +116 -76
- package/docs/language-servers/ls-overview.md +37 -21
- package/docs/language-servers/svelte.md +69 -38
- package/docs/language-servers/zed.md +81 -44
- package/docs/roadmap/roadmap.md +75 -53
- package/docs/sections.json +1 -242
- package/package.json +27 -28
|
@@ -1,141 +1,168 @@
|
|
|
1
1
|
# Your First Macro
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
+
Before (Your Code)
|
|
10
|
+
|
|
7
11
|
```
|
|
8
12
|
/** @derive(Debug, Clone, PartialEq) */
|
|
9
|
-
export class User
|
|
13
|
+
export class User {
|
|
10
14
|
name: string;
|
|
11
15
|
age: number;
|
|
12
16
|
email: string;
|
|
13
17
|
|
|
14
|
-
constructor(name: string, age: number, email: string)
|
|
18
|
+
constructor(name: string, age: number, email: string) {
|
|
15
19
|
this.name = name;
|
|
16
20
|
this.age = age;
|
|
17
21
|
this.email = email;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
After (Generated)
|
|
27
|
+
|
|
22
28
|
```
|
|
23
|
-
export class User
|
|
29
|
+
export class User {
|
|
24
30
|
name: string;
|
|
25
31
|
age: number;
|
|
26
32
|
email: string;
|
|
27
33
|
|
|
28
|
-
constructor(name: string, age: number, email: string)
|
|
34
|
+
constructor(name: string, age: number, email: string) {
|
|
29
35
|
this.name = name;
|
|
30
36
|
this.age = age;
|
|
31
37
|
this.email = email;
|
|
32
|
-
|
|
38
|
+
}
|
|
33
39
|
|
|
34
|
-
static toString(value: User): string
|
|
40
|
+
static toString(value: User): string {
|
|
35
41
|
return userToString(value);
|
|
36
|
-
|
|
42
|
+
}
|
|
37
43
|
|
|
38
|
-
static clone(value: User): User
|
|
44
|
+
static clone(value: User): User {
|
|
39
45
|
return userClone(value);
|
|
40
|
-
|
|
46
|
+
}
|
|
41
47
|
|
|
42
|
-
static equals(a: User, b: User): boolean
|
|
48
|
+
static equals(a: User, b: User): boolean {
|
|
43
49
|
return userEquals(a, b);
|
|
44
|
-
|
|
45
|
-
|
|
50
|
+
}
|
|
51
|
+
}
|
|
46
52
|
|
|
47
|
-
export function userToString(value: User): string
|
|
53
|
+
export function userToString(value: User): string {
|
|
48
54
|
const parts: string[] = [];
|
|
49
55
|
parts.push('name: ' + value.name);
|
|
50
56
|
parts.push('age: ' + value.age);
|
|
51
57
|
parts.push('email: ' + value.email);
|
|
52
|
-
return 'User
|
|
53
|
-
|
|
58
|
+
return 'User { ' + parts.join(', ') + ' }';
|
|
59
|
+
}
|
|
54
60
|
|
|
55
|
-
export function userClone(value: User): User
|
|
61
|
+
export function userClone(value: User): User {
|
|
56
62
|
const cloned = Object.create(Object.getPrototypeOf(value));
|
|
57
63
|
cloned.name = value.name;
|
|
58
64
|
cloned.age = value.age;
|
|
59
65
|
cloned.email = value.email;
|
|
60
66
|
return cloned;
|
|
61
|
-
|
|
67
|
+
}
|
|
62
68
|
|
|
63
|
-
export function userEquals(a: User, b: User): boolean
|
|
69
|
+
export function userEquals(a: User, b: User): boolean {
|
|
64
70
|
if (a === b) return true;
|
|
65
|
-
return a.name === b.name
|
|
66
|
-
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
return a.name === b.name && a.age === b.age && a.email === b.email;
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Using the Generated Methods
|
|
70
76
|
|
|
71
|
-
|
|
77
|
+
TypeScript
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
const user = new User("Alice", 30, "alice@example.com");
|
|
81
|
+
|
|
82
|
+
// Debug: toString()
|
|
72
83
|
console.log(user.toString());
|
|
73
|
-
|
|
84
|
+
// Output: User { name: Alice, age: 30, email: alice@example.com }
|
|
85
|
+
|
|
86
|
+
// Clone: clone()
|
|
87
|
+
const copy = user.clone();
|
|
88
|
+
console.log(copy.name); // "Alice"
|
|
89
|
+
|
|
90
|
+
// Eq: equals()
|
|
91
|
+
console.log(user.equals(copy)); // true
|
|
74
92
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
93
|
+
const different = new User("Bob", 25, "bob@example.com");
|
|
94
|
+
console.log(user.equals(different)); // false
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Customizing Behavior
|
|
78
98
|
|
|
79
|
-
|
|
80
|
-
|
|
99
|
+
You can customize how macros work using field-level decorators. For example, with the Debug macro:
|
|
100
|
+
|
|
101
|
+
Before (Your Code)
|
|
81
102
|
|
|
82
|
-
const different = new User("Bob", 25, "bob@example.com");
|
|
83
|
-
console.log(user.equals(different)); // false
|
|
84
|
-
``` ## Customizing Behavior
|
|
85
|
-
You can customize how macros work using field-level decorators. For example, with the Debug macro:
|
|
86
|
-
<div><div class="flex items-center justify-between gap-2 px-4 py-2 bg-muted rounded-t-lg border border-b-0 border-border">
|
|
87
|
-
**Before:**
|
|
88
103
|
```
|
|
89
104
|
/** @derive(Debug) */
|
|
90
|
-
export class User
|
|
91
|
-
/** @debug(
|
|
105
|
+
export class User {
|
|
106
|
+
/** @debug({ rename: "userId" }) */
|
|
92
107
|
id: number;
|
|
93
108
|
|
|
94
109
|
name: string;
|
|
95
110
|
|
|
96
|
-
/** @debug(
|
|
111
|
+
/** @debug({ skip: true }) */
|
|
97
112
|
password: string;
|
|
98
113
|
|
|
99
|
-
constructor(id: number, name: string, password: string)
|
|
114
|
+
constructor(id: number, name: string, password: string) {
|
|
100
115
|
this.id = id;
|
|
101
116
|
this.name = name;
|
|
102
117
|
this.password = password;
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
```
|
|
106
|
-
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
After (Generated)
|
|
123
|
+
|
|
107
124
|
```
|
|
108
|
-
export class User
|
|
125
|
+
export class User {
|
|
109
126
|
id: number;
|
|
110
127
|
|
|
111
128
|
name: string;
|
|
112
129
|
|
|
113
130
|
password: string;
|
|
114
131
|
|
|
115
|
-
constructor(id: number, name: string, password: string)
|
|
132
|
+
constructor(id: number, name: string, password: string) {
|
|
116
133
|
this.id = id;
|
|
117
134
|
this.name = name;
|
|
118
135
|
this.password = password;
|
|
119
|
-
|
|
136
|
+
}
|
|
120
137
|
|
|
121
|
-
static toString(value: User): string
|
|
138
|
+
static toString(value: User): string {
|
|
122
139
|
return userToString(value);
|
|
123
|
-
|
|
124
|
-
|
|
140
|
+
}
|
|
141
|
+
}
|
|
125
142
|
|
|
126
|
-
export function userToString(value: User): string
|
|
143
|
+
export function userToString(value: User): string {
|
|
127
144
|
const parts: string[] = [];
|
|
128
145
|
parts.push('userId: ' + value.id);
|
|
129
146
|
parts.push('name: ' + value.name);
|
|
130
|
-
return 'User
|
|
131
|
-
|
|
132
|
-
```
|
|
133
|
-
|
|
147
|
+
return 'User { ' + parts.join(', ') + ' }';
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
TypeScript
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
const user = new User(42, "Alice", "secret123");
|
|
134
155
|
console.log(user.toString());
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
156
|
+
// Output: User { userId: 42, name: Alice }
|
|
157
|
+
// Note: 'id' is renamed to 'userId', 'password' is skipped
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Field-level decorators
|
|
161
|
+
|
|
162
|
+
Field-level decorators let you control exactly how each field is handled by the macro.
|
|
163
|
+
|
|
164
|
+
## Next Steps
|
|
165
|
+
|
|
166
|
+
* [Learn how macros work under the hood](../../docs/concepts)
|
|
167
|
+
* [Explore all Debug options](../../docs/builtin-macros/debug)
|
|
168
|
+
* [Create your own custom macros](../../docs/custom-macros)
|
|
@@ -1,66 +1,110 @@
|
|
|
1
1
|
# Installation
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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 24.0 or later
|
|
8
|
+
* TypeScript 5.9 or later
|
|
9
|
+
|
|
10
|
+
## Install the Package
|
|
11
|
+
|
|
12
|
+
Install Macroforge using your preferred package manager:
|
|
13
|
+
|
|
14
|
+
npm
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
npm install macroforge
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
bun
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
bun add macroforge
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
pnpm
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
pnpm add macroforge
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Info
|
|
33
|
+
|
|
34
|
+
Macroforge includes pre-built native binaries for macOS (x64, arm64), Linux (x64, arm64), and Windows (x64, arm64).
|
|
35
|
+
|
|
36
|
+
## Basic Usage
|
|
37
|
+
|
|
38
|
+
The simplest way to use Macroforge is with the built-in derive macros. Add a `@derive` comment decorator to your class:
|
|
39
|
+
|
|
40
|
+
user.ts
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
/** @derive(Debug, Clone, PartialEq) */
|
|
44
|
+
class User {
|
|
45
|
+
name: string;
|
|
46
|
+
age: number;
|
|
47
|
+
|
|
48
|
+
constructor(name: string, age: number) {
|
|
49
|
+
this.name = name;
|
|
50
|
+
this.age = age;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// After macro expansion, User has:
|
|
55
|
+
// - toString(): string (from Debug)
|
|
56
|
+
// - clone(): User (from Clone)
|
|
57
|
+
// - equals(other: unknown): boolean (from PartialEq)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## IDE Integration
|
|
61
|
+
|
|
62
|
+
For the best development experience, add the TypeScript plugin to your `tsconfig.json`:
|
|
63
|
+
|
|
64
|
+
tsconfig.json
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
{
|
|
68
|
+
"compilerOptions": {
|
|
69
|
+
"plugins": [
|
|
70
|
+
{
|
|
71
|
+
"name": "@macroforge/typescript-plugin"
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
This enables features like:
|
|
79
|
+
|
|
80
|
+
* Accurate error positions in your source code
|
|
81
|
+
* Autocompletion for generated methods
|
|
82
|
+
* Type checking for expanded code
|
|
83
|
+
|
|
84
|
+
## Build Integration (Vite)
|
|
85
|
+
|
|
86
|
+
If you're using Vite, add the plugin to your config for automatic macro expansion during build:
|
|
87
|
+
|
|
88
|
+
vite.config.ts
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
import macroforge from "@macroforge/vite-plugin";
|
|
92
|
+
import { defineConfig } from "vite";
|
|
93
|
+
|
|
94
|
+
export default defineConfig({
|
|
95
|
+
plugins: [
|
|
96
|
+
macroforge({
|
|
97
|
+
generateTypes: true,
|
|
98
|
+
typesOutputDir: ".macroforge/types"
|
|
99
|
+
})
|
|
100
|
+
]
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Next Steps
|
|
105
|
+
|
|
106
|
+
Now that you have Macroforge installed, learn how to use it:
|
|
107
|
+
|
|
108
|
+
* [Create your first macro](../docs/getting-started/first-macro)
|
|
109
|
+
* [Understand how macros work](../docs/concepts)
|
|
110
|
+
* [Explore built-in macros](../docs/builtin-macros)
|