@macroforge/mcp-server 0.1.40 → 0.1.49

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 +65 -46
  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 +114 -54
  7. package/docs/api/transform-sync.md +85 -59
  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 +11 -43
  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 +171 -97
  28. package/docs/concepts/how-macros-work.md +89 -37
  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 +799 -519
  57. package/docs/getting-started/first-macro.md +61 -32
  58. package/docs/getting-started/installation.md +109 -66
  59. package/docs/integration/cli.md +212 -103
  60. package/docs/integration/configuration.md +114 -71
  61. package/docs/integration/integration-overview.md +54 -17
  62. package/docs/integration/mcp-server.md +83 -42
  63. package/docs/integration/svelte-preprocessor.md +183 -126
  64. package/docs/integration/typescript-plugin.md +101 -54
  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 -39
  68. package/docs/language-servers/zed.md +81 -45
  69. package/docs/roadmap/roadmap.md +75 -53
  70. package/docs/sections.json +333 -44
  71. package/package.json +27 -28
@@ -1,54 +1,110 @@
1
1
  # PositionMapper
2
- *Bidirectional position mapper for translating between original and expanded source positions. This mapper enables IDE features like error reporting, go-to-definition, and hover to work correctly with macro-expanded code by translating positions between the original source (what the user wrote) and the expanded source (what the compiler sees).*
3
- ## Getting a Mapper
4
- ```
5
- import { NativePlugin, PositionMapper } from "macroforge";
6
2
 
7
- const plugin = new NativePlugin();
8
- const result = plugin.processFile("user.ts", code, { version: "1" });
9
-
10
- // Get the mapper for this file
11
- const mapper = plugin.getMapper("user.ts");
12
- if (mapper) {
13
- // Use the mapper...
14
- }
15
- ``` ## Methods
16
- ### isEmpty()
17
- Check if the mapper has any mappings:
18
- ```
19
- isEmpty(): boolean
20
- ``` ### originalToExpanded()
21
- Map a position from original to expanded code:
22
- ```
23
- originalToExpanded(pos: number): number
24
- ``` ### expandedToOriginal()
25
- Map a position from expanded to original code:
26
- ```
27
- expandedToOriginal(pos: number): number | null
28
- ``` Returns `null` if the position is in generated code.
29
- ### isInGenerated()
30
- Check if a position is in macro-generated code:
31
- ```
32
- isInGenerated(pos: number): boolean
33
- ``` ### generatedBy()
34
- Get the name of the macro that generated code at a position:
35
- ```
36
- generatedBy(pos: number): string | null
37
- ``` ### mapSpanToOriginal()
38
- Map a span (range) from expanded to original code:
39
- ```
40
- mapSpanToOriginal(start: number, length: number): SpanResult | null
41
-
42
- interface SpanResult {
43
- start: number;
44
- length: number;
45
- }
46
- ``` ### mapSpanToExpanded()
47
- Map a span from original to expanded code:
48
- ```
49
- mapSpanToExpanded(start: number, length: number): SpanResult
50
- ``` ## Example: Error Position Mapping
51
- ```
3
+ macroforge v0.1.43
4
+
5
+ Bidirectional position mapper for translating between original and expanded source positions. This mapper enables IDE features like error reporting, go-to-definition, and hover to work correctly with macro-expanded code by translating positions between the original source (what the user wrote) and the expanded source (what the compiler sees).
6
+
7
+ ## Getting a Mapper
8
+
9
+ TypeScript
10
+
11
+ ```
12
+ import { NativePlugin, PositionMapper } from "macroforge";
13
+
14
+ const plugin = new NativePlugin();
15
+ const result = plugin.processFile("user.ts", code, { version: "1" });
16
+
17
+ // Get the mapper for this file
18
+ const mapper = plugin.getMapper("user.ts");
19
+ if (mapper) {
20
+   // Use the mapper...
21
+ }
22
+ ```
23
+
24
+ ## Methods
25
+
26
+ ### isEmpty()
27
+
28
+ Check if the mapper has any mappings:
29
+
30
+ TypeScript
31
+
32
+ ```
33
+ isEmpty(): boolean
34
+ ```
35
+
36
+ ### originalToExpanded()
37
+
38
+ Map a position from original to expanded code:
39
+
40
+ TypeScript
41
+
42
+ ```
43
+ originalToExpanded(pos: number): number
44
+ ```
45
+
46
+ ### expandedToOriginal()
47
+
48
+ Map a position from expanded to original code:
49
+
50
+ TypeScript
51
+
52
+ ```
53
+ expandedToOriginal(pos: number): number | null
54
+ ```
55
+
56
+ Returns `null` if the position is in generated code.
57
+
58
+ ### isInGenerated()
59
+
60
+ Check if a position is in macro-generated code:
61
+
62
+ TypeScript
63
+
64
+ ```
65
+ isInGenerated(pos: number): boolean
66
+ ```
67
+
68
+ ### generatedBy()
69
+
70
+ Get the name of the macro that generated code at a position:
71
+
72
+ TypeScript
73
+
74
+ ```
75
+ generatedBy(pos: number): string | null
76
+ ```
77
+
78
+ ### mapSpanToOriginal()
79
+
80
+ Map a span (range) from expanded to original code:
81
+
82
+ TypeScript
83
+
84
+ ```
85
+ mapSpanToOriginal(start: number, length: number): SpanResult | null
86
+
87
+ interface SpanResult {
88
+   start: number;
89
+   length: number;
90
+ }
91
+ ```
92
+
93
+ ### mapSpanToExpanded()
94
+
95
+ Map a span from original to expanded code:
96
+
97
+ TypeScript
98
+
99
+ ```
100
+ mapSpanToExpanded(start: number, length: number): SpanResult
101
+ ```
102
+
103
+ ## Example: Error Position Mapping
104
+
105
+ TypeScript
106
+
107
+ ```
52
108
  import { NativePlugin } from "macroforge";
53
109
 
54
110
  const plugin = new NativePlugin();
@@ -78,8 +134,12 @@ function mapError(filepath: string, expandedPos: number, message: string) {
78
134
 
79
135
  return null;
80
136
  }
81
- ``` ## Performance
82
- Position mapping uses binary search with O(log n) complexity:
83
- - Fast lookups even for large files
84
- - Minimal memory overhead
85
- - Thread-safe access
137
+ ```
138
+
139
+ ## Performance
140
+
141
+ Position mapping uses binary search with O(log n) complexity:
142
+
143
+ * Fast lookups even for large files
144
+ * Minimal memory overhead
145
+ * Thread-safe access
@@ -1,66 +1,92 @@
1
1
  # transformSync()
2
- *Synchronously transforms TypeScript code through the macro expansion system. This is similar to [`expand_sync`] but returns a [`TransformResult`] which includes source map information (when available).*
3
- ## Signature
4
- ```
5
- function transformSync(
6
- code: string,
7
- filepath: string
8
- ): TransformResult
9
- ``` ## Parameters
10
- | Parameter | Type | Description |
11
- | --- | --- | --- |
12
- | `code` | `string` | TypeScript source code to transform |
2
+
3
+ macroforge v0.1.43
4
+
5
+ Synchronously transforms TypeScript code through the macro expansion system. This is similar to \[\`expand\_sync\`\] but returns a \[\`TransformResult\`\] which includes source map information (when available).
6
+
7
+ ## Signature
8
+
9
+ TypeScript
10
+
11
+ ```
12
+ function transformSync(
13
+   code: string,
14
+   filepath: string
15
+ ): TransformResult
16
+ ```
17
+
18
+ ## Parameters
19
+
20
+ | Parameter | Type | Description |
21
+ | ---------- | -------- | ------------------------------------ |
22
+ | `code` | `string` | TypeScript source code to transform |
13
23
  | `filepath` | `string` | File path (used for error reporting) |
14
- ## TransformResult
15
- ```
16
- interface TransformResult {
17
- // Transformed TypeScript code
18
- code: string;
19
-
20
- // Source map (JSON string, not yet implemented)
21
- map?: string;
22
-
23
- // Generated type declarations
24
- types?: string;
25
-
26
- // Macro expansion metadata
27
- metadata?: string;
28
- }
29
- ``` ## Comparison with expandSync()
30
- | Feature | `expandSync` | `transformSync` |
31
- | --- | --- | --- |
32
- | Options | Yes | No |
33
- | Diagnostics | Yes | No |
34
- | Source Mapping | Yes | Limited |
35
- | Use Case | General purpose | Build tools |
36
- ## Example
37
- ```
38
- import { transformSync } from "macroforge";
39
-
40
- const sourceCode = \`
41
- /** @derive(Debug) */
42
- class User {
43
- name: string;
44
- }
24
+
25
+ ## TransformResult
26
+
27
+ TypeScript
28
+
29
+ ```
30
+ interface TransformResult {
31
+   // Transformed TypeScript code
32
+   code: string;
33
+
34
+   // Source map (JSON string, not yet implemented)
35
+   map?: string;
36
+
37
+   // Generated type declarations
38
+   types?: string;
39
+
40
+   // Macro expansion metadata
41
+   metadata?: string;
42
+ }
43
+ ```
44
+
45
+ ## Comparison with expandSync()
46
+
47
+ | Feature | `expandSync` | `transformSync` |
48
+ | -------------- | --------------- | --------------- |
49
+ | Options | Yes | No |
50
+ | Diagnostics | Yes | No |
51
+ | Source Mapping | Yes | Limited |
52
+ | Use Case | General purpose | Build tools |
53
+
54
+ ## Example
55
+
56
+ TypeScript
57
+
58
+ ```
59
+ import { transformSync } from "macroforge";
60
+
61
+ const sourceCode = \`
62
+ /** @derive(Debug) */
63
+ class User {
64
+   name: string;
65
+ }
45
66
  \`;
46
67
 
47
- const result = transformSync(sourceCode, "user.ts");
68
+ const result = transformSync(sourceCode, "user.ts");
48
69
 
49
70
  console.log(result.code);
50
71
 
51
- if (result.types) {
52
- // Write to .d.ts file
53
- fs.writeFileSync("user.d.ts", result.types);
54
- }
55
-
56
- if (result.metadata) {
57
- // Parse and use metadata
58
- const meta = JSON.parse(result.metadata);
59
- console.log("Macros expanded:", meta);
60
- }
61
- ``` ## When to Use
62
- Use `transformSync` when:
63
- - Building custom integrations
64
- - You need raw output without diagnostics
65
- - You're implementing a build tool plugin
66
- Use `expandSync` for most other use cases, as it provides better error handling.
72
+ if (result.types) {
73
+   // Write to .d.ts file
74
+   fs.writeFileSync("user.d.ts", result.types);
75
+ }
76
+
77
+ if (result.metadata) {
78
+   // Parse and use metadata
79
+   const meta = JSON.parse(result.metadata);
80
+   console.log("Macros expanded:", meta);
81
+ }
82
+ ```
83
+
84
+ ## When to Use
85
+
86
+ Use `transformSync` when:
87
+
88
+ * Building custom integrations
89
+ * You need raw output without diagnostics
90
+ * You're implementing a build tool plugin
91
+
92
+ Use `expandSync` for most other use cases, as it provides better error handling.
@@ -53,26 +53,6 @@ export function pointClone(value: Point): Point {
53
53
  }
54
54
  ```
55
55
 
56
- Generated output:
57
-
58
- ```typescript
59
- class Point {
60
- x: number;
61
- y: number;
62
-
63
- static clone(value: Point): Point {
64
- return pointClone(value);
65
- }
66
- }
67
-
68
- export function pointClone(value: Point): Point {
69
- const cloned = Object.create(Object.getPrototypeOf(value));
70
- cloned.x = value.x;
71
- cloned.y = value.y;
72
- return cloned;
73
- }
74
- ```
75
-
76
56
  ## Implementation Notes
77
57
 
78
58
  - **Classes**: Uses `Object.create(Object.getPrototypeOf(value))` to preserve
@@ -59,26 +59,3 @@ export function userToString(value: User): string {
59
59
  return 'User { ' + parts.join(', ') + ' }';
60
60
  }
61
61
  ```
62
-
63
- Generated output:
64
-
65
- ```typescript
66
- class User {
67
- userId: number;
68
-
69
- password: string;
70
-
71
- email: string;
72
-
73
- static toString(value: User): string {
74
- return userToString(value);
75
- }
76
- }
77
-
78
- export function userToString(value: User): string {
79
- const parts: string[] = [];
80
- parts.push('id: ' + value.userId);
81
- parts.push('email: ' + value.email);
82
- return 'User { ' + parts.join(', ') + ' }';
83
- }
84
- ```
@@ -52,7 +52,7 @@ class UserSettings {
52
52
  /** @default(10) */
53
53
  pageSize: number;
54
54
 
55
- notifications: boolean; // Uses type default: false
55
+ notifications: boolean; // Uses type default: false
56
56
  }
57
57
  ```
58
58
 
@@ -74,26 +74,6 @@ class UserSettings {
74
74
  }
75
75
  ```
76
76
 
77
- Generated output:
78
-
79
- ```typescript
80
- class UserSettings {
81
- theme: string;
82
-
83
- pageSize: number;
84
-
85
- notifications: boolean; // Uses type default: false
86
-
87
- static defaultValue(): UserSettings {
88
- const instance = new UserSettings();
89
- instance.theme = 'light';
90
- instance.pageSize = 10;
91
- instance.notifications = false;
92
- return instance;
93
- }
94
- }
95
- ```
96
-
97
77
  ## Enum Defaults
98
78
 
99
79
  For enums, mark one variant with `@default`:
@@ -125,25 +105,6 @@ namespace Status {
125
105
  }
126
106
  ```
127
107
 
128
- Generated output:
129
-
130
- ```typescript
131
- enum Status {
132
- /** @default */
133
- Pending,
134
- Active,
135
- Completed
136
- }
137
-
138
- export function statusDefaultValue(): Status {
139
- return Status.Pending;
140
- }
141
-
142
- namespace Status {
143
- export const defaultValue = statusDefaultValue;
144
- }
145
- ```
146
-
147
108
  ## Error Handling
148
109
 
149
110
  The macro will return an error if: