@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
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 rymskip
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/docs/BOOK.md
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# Macroforge Documentation
|
|
2
|
+
|
|
3
|
+
*TypeScript Macros - Rust-Powered Code Generation*
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
### Getting Started
|
|
10
|
+
- [Installation](#installation)
|
|
11
|
+
- [First Macro](#first-macro)
|
|
12
|
+
|
|
13
|
+
### Core Concepts
|
|
14
|
+
- [How Macros Work](#how-macros-work)
|
|
15
|
+
- [The Derive System](#the-derive-system)
|
|
16
|
+
- [Architecture](#architecture)
|
|
17
|
+
|
|
18
|
+
### Built-in Macros
|
|
19
|
+
- [Overview](#overview)
|
|
20
|
+
- [Debug](#debug)
|
|
21
|
+
- [Clone](#clone)
|
|
22
|
+
- [Default](#default)
|
|
23
|
+
- [Hash](#hash)
|
|
24
|
+
- [Ord](#ord)
|
|
25
|
+
- [PartialEq](#partialeq)
|
|
26
|
+
- [PartialOrd](#partialord)
|
|
27
|
+
- [Serialize](#serialize)
|
|
28
|
+
- [Deserialize](#deserialize)
|
|
29
|
+
|
|
30
|
+
### Custom Macros
|
|
31
|
+
- [Overview](#overview)
|
|
32
|
+
- [Rust Setup](#rust-setup)
|
|
33
|
+
- [ts_macro_derive](#ts-macro-derive)
|
|
34
|
+
- [Template Syntax](#template-syntax)
|
|
35
|
+
|
|
36
|
+
### Integration
|
|
37
|
+
- [Overview](#overview)
|
|
38
|
+
- [CLI](#cli)
|
|
39
|
+
- [TypeScript Plugin](#typescript-plugin)
|
|
40
|
+
- [Vite Plugin](#vite-plugin)
|
|
41
|
+
- [Configuration](#configuration)
|
|
42
|
+
|
|
43
|
+
### Language Servers
|
|
44
|
+
- [Overview](#overview)
|
|
45
|
+
- [Svelte](#svelte)
|
|
46
|
+
- [Zed Extensions](#zed-extensions)
|
|
47
|
+
|
|
48
|
+
### API Reference
|
|
49
|
+
- [Overview](#overview)
|
|
50
|
+
- [expandSync()](#expandsync)
|
|
51
|
+
- [transformSync()](#transformsync)
|
|
52
|
+
- [NativePlugin](#nativeplugin)
|
|
53
|
+
- [PositionMapper](#positionmapper)
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
# Getting Started
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
# Core Concepts
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
# Built-in Macros
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
# Custom Macros
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
# Integration
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
# Language Servers
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
# API Reference
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
---
|
package/docs/api/api-overview.md
CHANGED
|
@@ -1,53 +1,72 @@
|
|
|
1
1
|
# API Reference
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
2
|
+
|
|
3
|
+
macroforge v0.1.43 33 exported items
|
|
4
|
+
|
|
5
|
+
Macroforge provides a programmatic API for expanding macros in TypeScript code.
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
TypeScript
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
import {
|
|
13
|
+
expandSync,
|
|
14
|
+
transformSync,
|
|
15
|
+
checkSyntax,
|
|
16
|
+
parseImportSources,
|
|
17
|
+
NativePlugin,
|
|
18
|
+
PositionMapper
|
|
19
|
+
} from "macroforge";
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Core Functions
|
|
23
|
+
|
|
24
|
+
| Function | Description |
|
|
25
|
+
| ----------------------------------------------- | --------------------------------------- |
|
|
26
|
+
| [`expandSync()`](../docs/api/expand-sync) | Expand macros synchronously |
|
|
17
27
|
| [`transformSync()`](../docs/api/transform-sync) | Transform code with additional metadata |
|
|
18
|
-
| `checkSyntax()`
|
|
19
|
-
| `parseImportSources()`
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
|
28
|
+
| `checkSyntax()` | Validate TypeScript syntax |
|
|
29
|
+
| `parseImportSources()` | Extract import information |
|
|
30
|
+
|
|
31
|
+
## Classes
|
|
32
|
+
|
|
33
|
+
| Class | Description |
|
|
34
|
+
| ----------------------------------------------- | ------------------------------------------------- |
|
|
35
|
+
| [`NativePlugin`](../docs/api/native-plugin) | Stateful plugin with caching |
|
|
24
36
|
| [`PositionMapper`](../docs/api/position-mapper) | Maps positions between original and expanded code |
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
|
|
38
|
+
## Quick Example
|
|
39
|
+
|
|
40
|
+
TypeScript
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
import { expandSync } from "macroforge";
|
|
44
|
+
|
|
45
|
+
const sourceCode = \`
|
|
46
|
+
/** @derive(Debug) */
|
|
47
|
+
class User {
|
|
48
|
+
name: string;
|
|
49
|
+
constructor(name: string) {
|
|
50
|
+
this.name = name;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
37
53
|
\`;
|
|
38
54
|
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
55
|
+
const result = expandSync(sourceCode, "user.ts", {
|
|
56
|
+
keepDecorators: false
|
|
57
|
+
});
|
|
42
58
|
|
|
43
59
|
console.log(result.code);
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
if
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
60
|
+
// Output: class with toString() method generated
|
|
61
|
+
|
|
62
|
+
if (result.diagnostics.length > 0) {
|
|
63
|
+
console.error("Errors:", result.diagnostics);
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Detailed Reference
|
|
68
|
+
|
|
69
|
+
* [`expandSync()`](../docs/api/expand-sync) - Full options and return types
|
|
70
|
+
* [`transformSync()`](../docs/api/transform-sync) - Transform with source maps
|
|
71
|
+
* [`NativePlugin`](../docs/api/native-plugin) - Caching for language servers
|
|
72
|
+
* [`PositionMapper`](../docs/api/position-mapper) - Position mapping utilities
|
package/docs/api/expand-sync.md
CHANGED
|
@@ -1,54 +1,83 @@
|
|
|
1
1
|
# expandSync()
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function
|
|
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
|
-
|
|
2
|
+
|
|
3
|
+
macroforge v0.1.43
|
|
4
|
+
|
|
5
|
+
Synchronously expands macros in TypeScript code. This is the standalone macro expansion function that doesn't use caching. For cached expansion, use \[\`NativePlugin::process\_file\`\] instead.
|
|
6
|
+
|
|
7
|
+
## Signature
|
|
8
|
+
|
|
9
|
+
TypeScript
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
function expandSync(
|
|
13
|
+
code: string,
|
|
14
|
+
filepath: string,
|
|
15
|
+
options?: ExpandOptions
|
|
16
|
+
): ExpandResult
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Parameters
|
|
20
|
+
|
|
21
|
+
| Parameter | Type | Description |
|
|
22
|
+
| ---------- | --------------- | ------------------------------------ |
|
|
23
|
+
| `code` | `string` | TypeScript source code to transform |
|
|
24
|
+
| `filepath` | `string` | File path (used for error reporting) |
|
|
25
|
+
| `options` | `ExpandOptions` | Optional configuration |
|
|
26
|
+
|
|
27
|
+
## ExpandOptions
|
|
28
|
+
|
|
29
|
+
TypeScript
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
interface ExpandOptions {
|
|
33
|
+
// Keep @derive decorators in output (default: false)
|
|
34
|
+
keepDecorators?: boolean;
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## ExpandResult
|
|
39
|
+
|
|
40
|
+
TypeScript
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
interface ExpandResult {
|
|
44
|
+
// Transformed TypeScript code
|
|
45
|
+
code: string;
|
|
46
|
+
|
|
47
|
+
// Generated type declarations (.d.ts content)
|
|
48
|
+
types?: string;
|
|
49
|
+
|
|
50
|
+
// Macro expansion metadata (JSON string)
|
|
51
|
+
metadata?: string;
|
|
52
|
+
|
|
53
|
+
// Warnings and errors from macro expansion
|
|
54
|
+
diagnostics: MacroDiagnostic[];
|
|
55
|
+
|
|
56
|
+
// Position mapping data for source maps
|
|
57
|
+
sourceMapping?: SourceMappingResult;
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## MacroDiagnostic
|
|
62
|
+
|
|
63
|
+
TypeScript
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
interface MacroDiagnostic {
|
|
67
|
+
message: string;
|
|
68
|
+
severity: "error" | "warning" | "info";
|
|
69
|
+
span: {
|
|
70
|
+
start: number;
|
|
71
|
+
end: number;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Example
|
|
77
|
+
|
|
78
|
+
TypeScript
|
|
79
|
+
|
|
80
|
+
```
|
|
52
81
|
import { expandSync } from "macroforge";
|
|
53
82
|
|
|
54
83
|
const sourceCode = `
|
|
@@ -79,9 +108,15 @@ if (result.diagnostics.length > 0) {
|
|
|
79
108
|
console.log(`[${diag.severity}] ${diag.message}`);
|
|
80
109
|
}
|
|
81
110
|
}
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Error Handling
|
|
114
|
+
|
|
115
|
+
Syntax errors and macro errors are returned in the `diagnostics` array, not thrown as exceptions:
|
|
116
|
+
|
|
117
|
+
TypeScript
|
|
118
|
+
|
|
119
|
+
```
|
|
85
120
|
const result = expandSync(invalidCode, "file.ts");
|
|
86
121
|
|
|
87
122
|
for (const diag of result.diagnostics) {
|
|
@@ -1,74 +1,124 @@
|
|
|
1
1
|
# NativePlugin
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
|
|
3
|
+
macroforge v0.1.43
|
|
4
|
+
|
|
5
|
+
The main plugin class for macro expansion with caching support. \`NativePlugin\` is designed to be instantiated once and reused across multiple file processing operations. It maintains a cache of expansion results keyed by filepath and version, enabling efficient incremental processing.
|
|
6
|
+
|
|
7
|
+
## Constructor
|
|
8
|
+
|
|
9
|
+
TypeScript
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
const plugin = new NativePlugin();
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Methods
|
|
16
|
+
|
|
17
|
+
### processFile()
|
|
18
|
+
|
|
19
|
+
Process a file with version-based caching:
|
|
20
|
+
|
|
21
|
+
TypeScript
|
|
22
|
+
|
|
23
|
+
```
|
|
10
24
|
processFile(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
):
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
filepath: string,
|
|
26
|
+
code: string,
|
|
27
|
+
options?: ProcessFileOptions
|
|
28
|
+
): ExpandResult
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
TypeScript
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
interface ProcessFileOptions {
|
|
35
|
+
// Cache key - if unchanged, returns cached result
|
|
36
|
+
version?: string;
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### getMapper()
|
|
41
|
+
|
|
42
|
+
Get the position mapper for a previously processed file:
|
|
43
|
+
|
|
44
|
+
TypeScript
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
getMapper(filepath: string): NativeMapper | null
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### mapDiagnostics()
|
|
51
|
+
|
|
52
|
+
Map diagnostics from expanded positions to original positions:
|
|
53
|
+
|
|
54
|
+
TypeScript
|
|
55
|
+
|
|
56
|
+
```
|
|
27
57
|
mapDiagnostics(
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
58
|
+
filepath: string,
|
|
59
|
+
diagnostics: JsDiagnostic[]
|
|
60
|
+
): JsDiagnostic[]
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### log() / setLogFile()
|
|
64
|
+
|
|
65
|
+
Logging utilities for debugging:
|
|
66
|
+
|
|
67
|
+
TypeScript
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
log(message: string): void
|
|
71
|
+
setLogFile(path: string): void
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Caching Behavior
|
|
75
|
+
|
|
76
|
+
The plugin caches expansion results by file path and version:
|
|
77
|
+
|
|
78
|
+
TypeScript
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
const plugin = new NativePlugin();
|
|
82
|
+
|
|
83
|
+
// First call - performs expansion
|
|
84
|
+
const result1 = plugin.processFile("user.ts", code, { version: "1" });
|
|
85
|
+
|
|
86
|
+
// Same version - returns cached result instantly
|
|
87
|
+
const result2 = plugin.processFile("user.ts", code, { version: "1" });
|
|
88
|
+
|
|
89
|
+
// Different version - re-expands
|
|
90
|
+
const result3 = plugin.processFile("user.ts", newCode, { version: "2" });
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Example: Language Server Integration
|
|
94
|
+
|
|
95
|
+
TypeScript
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
import { NativePlugin } from "macroforge";
|
|
99
|
+
|
|
100
|
+
class MacroforgeLanguageService {
|
|
101
|
+
private plugin = new NativePlugin();
|
|
102
|
+
|
|
103
|
+
processDocument(uri: string, content: string, version: number) {
|
|
104
|
+
// Process with version-based caching
|
|
105
|
+
const result = this.plugin.processFile(uri, content, {
|
|
106
|
+
version: String(version)
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// Get mapper for position translation
|
|
110
|
+
const mapper = this.plugin.getMapper(uri);
|
|
111
|
+
|
|
112
|
+
return { result, mapper };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
getSemanticDiagnostics(uri: string, diagnostics: Diagnostic[]) {
|
|
116
|
+
// Map positions from expanded to original
|
|
117
|
+
return this.plugin.mapDiagnostics(uri, diagnostics);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Thread Safety
|
|
123
|
+
|
|
124
|
+
The `NativePlugin` class is thread-safe and can be used from multiple async contexts. Each file is processed in an isolated thread with its own stack space.
|