@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.
- package/LICENSE +22 -0
- package/docs/BOOK.md +165 -0
- package/docs/api/api-overview.md +65 -46
- package/docs/api/expand-sync.md +88 -53
- package/docs/api/native-plugin.md +121 -71
- package/docs/api/position-mapper.md +114 -54
- package/docs/api/transform-sync.md +85 -59
- 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 +11 -43
- 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 +171 -97
- package/docs/concepts/how-macros-work.md +89 -37
- 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 +799 -519
- package/docs/getting-started/first-macro.md +61 -32
- package/docs/getting-started/installation.md +109 -66
- package/docs/integration/cli.md +212 -103
- package/docs/integration/configuration.md +114 -71
- package/docs/integration/integration-overview.md +54 -17
- package/docs/integration/mcp-server.md +83 -42
- package/docs/integration/svelte-preprocessor.md +183 -126
- package/docs/integration/typescript-plugin.md +101 -54
- package/docs/integration/vite-plugin.md +116 -76
- package/docs/language-servers/ls-overview.md +37 -21
- package/docs/language-servers/svelte.md +69 -39
- package/docs/language-servers/zed.md +81 -45
- package/docs/roadmap/roadmap.md +75 -53
- package/docs/sections.json +333 -44
- 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
|
-
|
|
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
|
-
|
|
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
|
-
```
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
68
|
+
const result = transformSync(sourceCode, "user.ts");
|
|
48
69
|
|
|
49
70
|
console.log(result.code);
|
|
50
71
|
|
|
51
|
-
if
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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;
|
|
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:
|