@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,141 +1,168 @@
1
1
  # Your First Macro
2
- *Let's create a class that uses Macroforge's derive macros to automatically generate useful methods.*
3
- ## Creating a Class with Derive Macros
4
- Start by creating a simple <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">User</code> class. We'll use the <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">@derive</code> decorator to automatically generate methods.
5
- <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">
6
- **Before:**
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 &#123;
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) &#123;
18
+ constructor(name: string, age: number, email: string) {
15
19
  this.name = name;
16
20
  this.age = age;
17
21
  this.email = email;
18
- &#125;
19
- &#125;
20
- ``` <div class="flex items-center justify-between gap-2 px-4 py-2 bg-muted rounded-t-lg border border-b-0 border-border">
21
- **After:**
22
+ }
23
+ }
24
+ ```
25
+
26
+ After (Generated)
27
+
22
28
  ```
23
- export class User &#123;
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) &#123;
34
+ constructor(name: string, age: number, email: string) {
29
35
  this.name = name;
30
36
  this.age = age;
31
37
  this.email = email;
32
- &#125;
38
+ }
33
39
 
34
- static toString(value: User): string &#123;
40
+ static toString(value: User): string {
35
41
  return userToString(value);
36
- &#125;
42
+ }
37
43
 
38
- static clone(value: User): User &#123;
44
+ static clone(value: User): User {
39
45
  return userClone(value);
40
- &#125;
46
+ }
41
47
 
42
- static equals(a: User, b: User): boolean &#123;
48
+ static equals(a: User, b: User): boolean {
43
49
  return userEquals(a, b);
44
- &#125;
45
- &#125;
50
+ }
51
+ }
46
52
 
47
- export function userToString(value: User): string &#123;
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 &#123; ' + parts.join(', ') + ' &#125;';
53
- &#125;
58
+ return 'User { ' + parts.join(', ') + ' }';
59
+ }
54
60
 
55
- export function userClone(value: User): User &#123;
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
- &#125;
67
+ }
62
68
 
63
- export function userEquals(a: User, b: User): boolean &#123;
69
+ export function userEquals(a: User, b: User): boolean {
64
70
  if (a === b) return true;
65
- return a.name === b.name &#x26;&#x26; a.age === b.age &#x26;&#x26; a.email === b.email;
66
- &#125;
67
- ``` ## Using the Generated Methods
68
- ```
69
- const&nbsp;user&nbsp;=&nbsp;new&nbsp;User("Alice",&nbsp;30,&nbsp;"alice@example.com");
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
- //&nbsp;Debug:&nbsp;toString()
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
- //&nbsp;Output:&nbsp;User&nbsp;&#123;&nbsp;name:&nbsp;Alice,&nbsp;age:&nbsp;30,&nbsp;email:&nbsp;alice@example.com&nbsp;&#125;
84
+ // OutputUser { nameAliceage30emailalice@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
- //&nbsp;Clone:&nbsp;clone()
76
- const&nbsp;copy&nbsp;=&nbsp;user.clone();
77
- console.log(copy.name);&nbsp;//&nbsp;"Alice"
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
- //&nbsp;Eq:&nbsp;equals()
80
- console.log(user.equals(copy));&nbsp;//&nbsp;true
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&nbsp;different&nbsp;=&nbsp;new&nbsp;User("Bob",&nbsp;25,&nbsp;"bob@example.com");
83
- console.log(user.equals(different));&nbsp;//&nbsp;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 &#123;
91
- /** @debug(&#123; rename: "userId" &#125;) */
105
+ export class User {
106
+ /** @debug({ rename: "userId" }) */
92
107
  id: number;
93
108
 
94
109
  name: string;
95
110
 
96
- /** @debug(&#123; skip: true &#125;) */
111
+ /** @debug({ skip: true }) */
97
112
  password: string;
98
113
 
99
- constructor(id: number, name: string, password: string) &#123;
114
+ constructor(id: number, name: string, password: string) {
100
115
  this.id = id;
101
116
  this.name = name;
102
117
  this.password = password;
103
- &#125;
104
- &#125;
105
- ``` <div class="flex items-center justify-between gap-2 px-4 py-2 bg-muted rounded-t-lg border border-b-0 border-border">
106
- **After:**
118
+ }
119
+ }
120
+ ```
121
+
122
+ After (Generated)
123
+
107
124
  ```
108
- export class User &#123;
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) &#123;
132
+ constructor(id: number, name: string, password: string) {
116
133
  this.id = id;
117
134
  this.name = name;
118
135
  this.password = password;
119
- &#125;
136
+ }
120
137
 
121
- static toString(value: User): string &#123;
138
+ static toString(value: User): string {
122
139
  return userToString(value);
123
- &#125;
124
- &#125;
140
+ }
141
+ }
125
142
 
126
- export function userToString(value: User): string &#123;
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 &#123; ' + parts.join(', ') + ' &#125;';
131
- &#125;
132
- ``` ```
133
- const&nbsp;user&nbsp;=&nbsp;new&nbsp;User(42,&nbsp;"Alice",&nbsp;"secret123");
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
- //&nbsp;Output:&nbsp;User&nbsp;&#123;&nbsp;userId:&nbsp;42,&nbsp;name:&nbsp;Alice&nbsp;&#125;
136
- //&nbsp;Note:&nbsp;'id'&nbsp;is&nbsp;renamed&nbsp;to&nbsp;'userId',&nbsp;'password'&nbsp;is&nbsp;skipped
137
- ``` **Field-level decorators Field-level decorators let you control exactly how each field is handled by the macro. ## Next Steps
138
- - [Learn how macros work under the hood](../../docs/concepts)
139
- - [Explore all Debug options](../../docs/builtin-macros/debug)
140
- - [Create your own custom macros](../../docs/custom-macros)
141
- **
156
+ // OutputUser { userId42nameAlice }
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
- *Get started with Macroforge in just a few minutes. Install the package and configure your project to start using TypeScript macros.*
3
- ## Requirements
4
- - Node.js 24.0 or later
5
- - TypeScript 5.9 or later
6
- ## Install the Package
7
- Install Macroforge using your preferred package manager:
8
- ```
9
- npm&nbsp;install&nbsp;macroforge
10
- ``` ```
11
- bun&nbsp;add&nbsp;macroforge
12
- ``` ```
13
- pnpm&nbsp;add&nbsp;macroforge
14
- ``` **Info Macroforge includes pre-built native binaries for macOS (x64, arm64), Linux (x64, arm64), and Windows (x64, arm64). ## Basic Usage
15
- The simplest way to use Macroforge is with the built-in derive macros. Add a **<code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">@derive</code> comment decorator to your class:
16
- ```
17
- /**&nbsp;@derive(Debug,&nbsp;Clone,&nbsp;PartialEq)&nbsp;*/
18
- class&nbsp;User&nbsp;&#123;
19
- &nbsp;&nbsp;name:&nbsp;string;
20
- &nbsp;&nbsp;age:&nbsp;number;
21
-
22
- &nbsp;&nbsp;constructor(name:&nbsp;string,&nbsp;age:&nbsp;number)&nbsp;&#123;
23
- &nbsp;&nbsp;&nbsp;&nbsp;this.name&nbsp;=&nbsp;name;
24
- &nbsp;&nbsp;&nbsp;&nbsp;this.age&nbsp;=&nbsp;age;
25
- &nbsp;&nbsp;&#125;
26
- &#125;
27
-
28
- //&nbsp;After&nbsp;macro&nbsp;expansion,&nbsp;User&nbsp;has:
29
- //&nbsp;-&nbsp;toString():&nbsp;string&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(from&nbsp;Debug)
30
- //&nbsp;-&nbsp;clone():&nbsp;User&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(from&nbsp;Clone)
31
- //&nbsp;-&nbsp;equals(other:&nbsp;unknown):&nbsp;boolean&nbsp;(from&nbsp;PartialEq)
32
- ``` ## IDE Integration
33
- For the best development experience, add the TypeScript plugin to your <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">tsconfig.json</code>:
34
- ```
35
- &#123;
36
- &nbsp;&nbsp;"compilerOptions":&nbsp;&#123;
37
- &nbsp;&nbsp;&nbsp;&nbsp;"plugins":&nbsp;[
38
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#123;
39
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"name":&nbsp;"@macroforge/typescript-plugin"
40
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
41
- &nbsp;&nbsp;&nbsp;&nbsp;]
42
- &nbsp;&nbsp;&#125;
43
- &#125;
44
- ``` This enables features like:
45
- - Accurate error positions in your source code
46
- - Autocompletion for generated methods
47
- - Type checking for expanded code
48
- ## Build Integration (Vite)
49
- If you're using Vite, add the plugin to your config for automatic macro expansion during build:
50
- ```
51
- import&nbsp;macroforge&nbsp;from&nbsp;"@macroforge/vite-plugin";
52
- import&nbsp;&#123;&nbsp;defineConfig&nbsp;&#125;&nbsp;from&nbsp;"vite";
53
-
54
- export&nbsp;default&nbsp;defineConfig(&#123;
55
- &nbsp;&nbsp;plugins:&nbsp;[
56
- &nbsp;&nbsp;&nbsp;&nbsp;macroforge(&#123;
57
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;generateTypes:&nbsp;true,
58
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typesOutputDir:&nbsp;".macroforge/types"
59
- &nbsp;&nbsp;&nbsp;&nbsp;&#125;)
60
- &nbsp;&nbsp;]
61
- &#125;);
62
- ``` ## Next Steps
63
- Now that you have Macroforge installed, learn how to use it:
64
- - [Create your first macro](../docs/getting-started/first-macro)
65
- - [Understand how macros work](../docs/concepts)
66
- - [Explore built-in macros](../docs/builtin-macros)
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)