@nova-energy/openamx 0.12.0 → 0.14.0
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/README.md +39 -9
- package/dist/cli.js +5 -5
- package/dist/editor/completion.js +104 -2
- package/dist/editor/highlighting.js +27 -1
- package/dist/editor/refactoring.js +4 -1
- package/dist/editor/sourceRanges.js +2 -1
- package/dist/editor/symbols.js +104 -45
- package/dist/formatter/formatAmx.js +83 -7
- package/dist/parser/parseExpression.js +68 -3
- package/dist/parser/parseStatements.js +147 -0
- package/dist/renderer/diagramBrowserEntry.js +255 -0
- package/dist/renderer/diagramBrowserRuntime.js +2 -0
- package/dist/renderer/diagramHtml.js +47 -0
- package/dist/renderer/narrativeModel.js +36 -11
- package/dist/renderer/renderHtml.js +95 -41
- package/dist/renderer/reportDocx.js +38 -16
- package/dist/renderer/reportPdf.js +122 -35
- package/dist/renderer/reportPreparation.js +97 -23
- package/dist/renderer/reportSequence.js +29 -0
- package/dist/renderer/staticDiagram.js +94 -0
- package/dist/runtime/diagramModel.js +455 -0
- package/dist/runtime/environment.js +6 -0
- package/dist/runtime/evaluateExpression.js +78 -2
- package/dist/runtime/moduleLoader.js +60 -2
- package/dist/runtime/standardLibrary.js +208 -1
- package/dist/runtime/valueSerialization.js +12 -0
- package/dist/typechecker/checkDocument.js +242 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -178,9 +178,19 @@ Other [examples](examples/) show calculations, tables and charts, typed JSON/CSV
|
|
|
178
178
|
inputs, local modules, and JSON/CSV outputs. The Asset Management schemas are
|
|
179
179
|
opt-in examples, not domain-certified standards.
|
|
180
180
|
|
|
181
|
-
The [V0.
|
|
182
|
-
|
|
181
|
+
The [V0.14 language specification](docs/language-spec-v0.14.md) documents the
|
|
182
|
+
runtime type-checking, mathematical, text, and numeric-formatting additions.
|
|
183
|
+
Try the [runtime type checks](examples/v0.14-runtime-type-checks.amx),
|
|
184
|
+
[math and Measurements](examples/v0.14-math-and-measurements.amx), and
|
|
185
|
+
[text and formatting](examples/v0.14-text-and-formatting.amx) examples.
|
|
186
|
+
V0.14 integrated acceptance, release, and publication are tracked separately;
|
|
187
|
+
this documentation does not claim them. The [V0.12 language specification](docs/language-spec-v0.12.md)
|
|
188
|
+
documents its additive language contract. Try the [record inheritance and enums](examples/v0.12-records-and-enums.amx)
|
|
183
189
|
and [braced conditional](examples/v0.12-braced-if.amx) examples. The
|
|
190
|
+
[V0.13 diagram specification](docs/language-spec-v0.13.md) records the approved
|
|
191
|
+
diagram syntax and its implementation limits. Try the
|
|
192
|
+
[crank-slider](examples/v0.13-crank-slider.amx) and
|
|
193
|
+
[battery-resistor](examples/v0.13-battery-resistor.amx) examples.
|
|
184
194
|
[V0.9 language specification](docs/language-spec-v0.9.md) and [V0.9 migration guide](docs/migrating-to-v0.9.md)
|
|
185
195
|
remain historical references for the earlier language contract and its approved compatibility changes. Earlier specifications describe
|
|
186
196
|
the language's evolution: [V0.5](docs/language-spec-v0.5.md),
|
|
@@ -363,13 +373,33 @@ tables, code, rules, and visible source line breaks; authored raw HTML remains
|
|
|
363
373
|
inert text. Narrative images must be project-contained PNG or JPEG files with
|
|
364
374
|
nonempty alternative text, no more than 4 MiB and 4,000,000 decoded pixels per
|
|
365
375
|
image. They are sanitized and embedded, so reports do not fetch remote images.
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
376
|
+
Image width is optional in Report Settings at either project-default or
|
|
377
|
+
current-document scope. Enter a fixed width such as `640px` or a content-width
|
|
378
|
+
percentage such as `75%`; for example, `.openamx/project.json` may contain
|
|
379
|
+
`"report": { "imageWidth": "75%" }`, while document front matter may contain
|
|
380
|
+
`report: { imageWidth: 640px }`. Images keep their aspect ratio; widths are
|
|
381
|
+
clamped to the available report/page bounds. Fixed CSS pixels map to 0.75 PDF
|
|
382
|
+
points. With no width setting, the existing fit-to-bounds sizing is used.
|
|
383
|
+
Report Settings can also select a project-contained `.css` stylesheet at
|
|
384
|
+
project-default or current-document scope. Its contents are embedded in live
|
|
385
|
+
preview and standalone HTML exports, so those HTML files retain the styling
|
|
386
|
+
without loading the original CSS file; stylesheet changes do not affect PDF or
|
|
387
|
+
DOCX output.
|
|
388
|
+
CSS files are editable project tabs in the desktop explorer. Use **New CSS** to
|
|
389
|
+
create a stylesheet, edit it in the source editor, and select it in Report
|
|
390
|
+
Settings. Switching back to an AMX tab previews unsaved CSS edits; HTML export
|
|
391
|
+
also uses the open stylesheet buffer.
|
|
392
|
+
External links are limited to HTTP(S); local companion links in reports are
|
|
393
|
+
limited to PDF, PNG, JPEG, TXT, CSV, and JSON targets contained by the project.
|
|
394
|
+
They are relative to the final report location, and companion files are not
|
|
395
|
+
copied; keep them at the corresponding relative paths when moving a report.
|
|
396
|
+
In the desktop live preview, a Markdown link such as
|
|
397
|
+
`[Related analysis](../other.amx)` opens a visible AMX file in the same project
|
|
398
|
+
in a workbench tab; `../` paths are allowed only while they remain inside the project. These AMX links are not
|
|
399
|
+
navigable in exported reports. Desktop preview routes activated external and
|
|
400
|
+
companion links through host confirmation. Viewer behavior varies: Word for the
|
|
401
|
+
Web rewrote tested relative DOCX links as HTTPS targets, so local companion-file
|
|
402
|
+
opening there is not claimed.
|
|
373
403
|
|
|
374
404
|
Run the V0.5 typed example with its local imports, JSON/CSV inputs, table and
|
|
375
405
|
chart. Copy the sample project config into a temporary project because the CLI
|
package/dist/cli.js
CHANGED
|
@@ -80,7 +80,7 @@ cli
|
|
|
80
80
|
.option("--out <path>", "Output PDF or DOCX file path")
|
|
81
81
|
.option("--input <mapping>", "Map a logical input to a data file", { type: [String] })
|
|
82
82
|
.option("--validation <mode>", "Validation mode: aggregate or fail-fast")
|
|
83
|
-
.option("--project-root <path>", "Project root for report metadata and
|
|
83
|
+
.option("--project-root <path>", "Project root for report metadata and assets")
|
|
84
84
|
.action(async (format, input, options) => {
|
|
85
85
|
try {
|
|
86
86
|
const inputMappings = suppliedMappings(options, "input");
|
|
@@ -90,8 +90,8 @@ cli
|
|
|
90
90
|
inputMappings,
|
|
91
91
|
validation: options.validation
|
|
92
92
|
});
|
|
93
|
-
const report = await prepareReport(doc, env, { file: input, projectRoot: options.projectRoot });
|
|
94
|
-
const bytes = await serializeDocxReport(prepareDocxReport(report, {
|
|
93
|
+
const report = await prepareReport(doc, env, { file: input, projectRoot: options.projectRoot, includeStylesheet: false });
|
|
94
|
+
const bytes = await serializeDocxReport(await prepareDocxReport(report, {
|
|
95
95
|
sourceDocumentPath: input,
|
|
96
96
|
destinationPath: destination.path
|
|
97
97
|
}));
|
|
@@ -106,7 +106,7 @@ cli
|
|
|
106
106
|
inputMappings,
|
|
107
107
|
validation: options.validation
|
|
108
108
|
});
|
|
109
|
-
const report = await prepareReport(doc, env, { file: input, projectRoot: options.projectRoot });
|
|
109
|
+
const report = await prepareReport(doc, env, { file: input, projectRoot: options.projectRoot, includeStylesheet: false });
|
|
110
110
|
const bytes = await serializePdfReport(preparePdfReport(report, {
|
|
111
111
|
sourceDocumentPath: input,
|
|
112
112
|
destinationPath: destination.path
|
|
@@ -130,7 +130,7 @@ cli
|
|
|
130
130
|
.option("--input <mapping>", "Map a logical input to a data file", { type: [String] })
|
|
131
131
|
.option("--output <mapping>", "Write an exported value to a JSON or CSV file", { type: [String] })
|
|
132
132
|
.option("--validation <mode>", "Validation mode: aggregate or fail-fast")
|
|
133
|
-
.option("--project-root <path>", "Project root for report metadata and
|
|
133
|
+
.option("--project-root <path>", "Project root for report metadata and assets")
|
|
134
134
|
.action(async (input, options) => {
|
|
135
135
|
try {
|
|
136
136
|
const outPath = options.out || input.replace(/\.amx$/, ".html");
|
|
@@ -9,8 +9,24 @@ const v04Keywords = ["table", "chart", "show", "title", "description", "column",
|
|
|
9
9
|
const v09ListKeywords = ["add", "remove", "at"];
|
|
10
10
|
const v09UnitKeywords = ["dimension", "unit"];
|
|
11
11
|
const v12Keywords = ["enum", "extends", "override"];
|
|
12
|
+
const v13Keywords = ["diagram"];
|
|
13
|
+
const v14Keywords = ["is"];
|
|
12
14
|
const standardFunctions = ["sum", "min", "max", "mean", "round", "abs", "sqrt", "pow"];
|
|
15
|
+
const v14Functions = [
|
|
16
|
+
"sin", "cos", "tan", "asin", "acos", "atan", "sinh", "cosh", "tanh", "asinh", "acosh", "atanh", "ln", "log", "exp",
|
|
17
|
+
"len", "trim", "left", "right", "format"
|
|
18
|
+
];
|
|
19
|
+
const standardConstants = ["PI", "E"];
|
|
13
20
|
const primitiveTypes = ["Number", "String", "Boolean", "DateTime"];
|
|
21
|
+
const diagramProperties = ["title", "description", "width", "height"];
|
|
22
|
+
const diagramElements = ["line", "rectangle", "circle", "text"];
|
|
23
|
+
const elementProperties = {
|
|
24
|
+
line: ["x1", "y1", "x2", "y2", "stroke", "lineWidth", "arrow"],
|
|
25
|
+
rectangle: ["x", "y", "width", "height", "stroke", "fill", "lineWidth"],
|
|
26
|
+
circle: ["cx", "cy", "r", "stroke", "fill", "lineWidth"],
|
|
27
|
+
text: ["x", "y", "value", "fill"]
|
|
28
|
+
};
|
|
29
|
+
const arrowValues = ['"none"', '"start"', '"end"', '"both"'];
|
|
14
30
|
function cursorInsideOpenAmxFence(text, cursorOffset) {
|
|
15
31
|
const frontMatter = parseFrontMatter(text);
|
|
16
32
|
if (frontMatter.error)
|
|
@@ -111,6 +127,85 @@ function statementEndOffset(text, statement) {
|
|
|
111
127
|
}
|
|
112
128
|
return text.length;
|
|
113
129
|
}
|
|
130
|
+
function blockBounds(text, source) {
|
|
131
|
+
const start = sourceOffset(text, source);
|
|
132
|
+
if (start === undefined)
|
|
133
|
+
return undefined;
|
|
134
|
+
let open = -1;
|
|
135
|
+
let depth = 0;
|
|
136
|
+
for (let offset = start; offset < text.length; offset++) {
|
|
137
|
+
if (text[offset] === '"' || text[offset] === "'") {
|
|
138
|
+
const end = findStringLiteralEnd(text, offset);
|
|
139
|
+
if (end === undefined)
|
|
140
|
+
return open < 0 ? undefined : { open, close: text.length };
|
|
141
|
+
offset = end;
|
|
142
|
+
}
|
|
143
|
+
else if (text[offset] === "{") {
|
|
144
|
+
if (open < 0)
|
|
145
|
+
open = offset;
|
|
146
|
+
depth++;
|
|
147
|
+
}
|
|
148
|
+
else if (text[offset] === "}" && open >= 0 && --depth === 0)
|
|
149
|
+
return { open, close: offset };
|
|
150
|
+
}
|
|
151
|
+
return open < 0 ? undefined : { open, close: text.length };
|
|
152
|
+
}
|
|
153
|
+
function diagramAt(text, parsed, cursorOffset) {
|
|
154
|
+
for (const diagram of statementsOf(parsed).filter((statement) => statement.type === "diagramDeclaration")) {
|
|
155
|
+
const bounds = blockBounds(text, diagram.source);
|
|
156
|
+
if (!bounds || cursorOffset <= bounds.open || cursorOffset > bounds.close)
|
|
157
|
+
continue;
|
|
158
|
+
const element = diagram.elements.find(candidate => {
|
|
159
|
+
const elementBounds = blockBounds(text, candidate.source);
|
|
160
|
+
return !!elementBounds && cursorOffset > elementBounds.open && cursorOffset <= elementBounds.close;
|
|
161
|
+
});
|
|
162
|
+
return { diagram, element };
|
|
163
|
+
}
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
function diagramCompletionFacts(text, contextText, cursorOffset, parsed, visible) {
|
|
167
|
+
const active = diagramAt(text, parsed, cursorOffset);
|
|
168
|
+
if (!active)
|
|
169
|
+
return undefined;
|
|
170
|
+
const contextCursor = Math.max(0, Math.min(cursorOffset, contextText.length));
|
|
171
|
+
const lineStart = contextText.lastIndexOf("\n", Math.max(0, contextCursor - 1)) + 1;
|
|
172
|
+
const prefix = contextText.slice(lineStart, contextCursor);
|
|
173
|
+
const propertyValue = prefix.match(/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*:\s*/);
|
|
174
|
+
if (propertyValue) {
|
|
175
|
+
if (active.element?.primitive === "line" && propertyValue[1] === "arrow") {
|
|
176
|
+
return arrowValues.map(label => ({ label, kind: "keyword" }));
|
|
177
|
+
}
|
|
178
|
+
const variables = new Set(visible.variables);
|
|
179
|
+
if (active.element && active.diagram.times.length === 1)
|
|
180
|
+
variables.add(active.diagram.times[0].name);
|
|
181
|
+
const fieldReceiver = prefix.match(/\b([A-Za-z][A-Za-z0-9_]*)\.\w*$/)?.[1];
|
|
182
|
+
const fields = fieldReceiver
|
|
183
|
+
? visible.enums.get(fieldReceiver)?.members.map(member => member.name)
|
|
184
|
+
?? visible.recordTypes.get(fieldReceiver)?.fields.map(field => field.name) ?? []
|
|
185
|
+
: [];
|
|
186
|
+
return [
|
|
187
|
+
...standardFunctions.map(label => ({ label, kind: "function" })),
|
|
188
|
+
...[...visible.functions].map(label => ({ label, kind: "function" })),
|
|
189
|
+
...[...visible.types].map(label => ({ label, kind: "class" })),
|
|
190
|
+
...[...variables].map(label => ({ label, kind: "variable" })),
|
|
191
|
+
...[...visible.views].map(label => ({ label, kind: "reference" })),
|
|
192
|
+
...fields.map(label => ({ label, kind: "field" }))
|
|
193
|
+
];
|
|
194
|
+
}
|
|
195
|
+
const partialProperty = prefix.match(/^\s*([A-Za-z_][A-Za-z0-9_]*)?$/);
|
|
196
|
+
if (!partialProperty)
|
|
197
|
+
return [];
|
|
198
|
+
const existing = active.element
|
|
199
|
+
? active.element.properties.map(property => property.name)
|
|
200
|
+
: [...active.diagram.properties.map(property => property.name), ...(active.diagram.times.length ? ["time"] : [])];
|
|
201
|
+
const available = active.element
|
|
202
|
+
? elementProperties[active.element.primitive] ?? []
|
|
203
|
+
: [...diagramProperties, "time", ...diagramElements];
|
|
204
|
+
return available.filter(name => !existing.includes(name)).map(label => ({
|
|
205
|
+
label,
|
|
206
|
+
kind: diagramElements.includes(label) || label === "time" ? "keyword" : "field"
|
|
207
|
+
}));
|
|
208
|
+
}
|
|
114
209
|
function loopBounds(text, loop) {
|
|
115
210
|
const start = sourceOffset(text, loop.source);
|
|
116
211
|
if (start === undefined)
|
|
@@ -308,6 +403,9 @@ function visibleSymbols(text, parsed, cursorOffset, analysis) {
|
|
|
308
403
|
collectExpression(expression.left);
|
|
309
404
|
collectExpression(expression.right);
|
|
310
405
|
break;
|
|
406
|
+
case "typeTestExpression":
|
|
407
|
+
collectExpression(expression.value);
|
|
408
|
+
break;
|
|
311
409
|
case "measurementAttachment":
|
|
312
410
|
case "measurementConversion":
|
|
313
411
|
collectExpression(expression.value);
|
|
@@ -383,14 +481,18 @@ export function editorCompletionFacts(text, cursorOffset, parsed, analysis, cont
|
|
|
383
481
|
?? visible.recordTypes.get(fieldReceiver)?.fields.map(field => field.name) ?? []
|
|
384
482
|
: [];
|
|
385
483
|
const facts = [
|
|
386
|
-
...[...v02Keywords, ...v03Keywords, ...v04Keywords, ...v09ListKeywords, ...v09UnitKeywords, ...v12Keywords].map(label => ({ label, kind: "keyword" })),
|
|
387
|
-
...standardFunctions.map(label => ({ label, kind: "function" })),
|
|
484
|
+
...[...v02Keywords, ...v03Keywords, ...v04Keywords, ...v09ListKeywords, ...v09UnitKeywords, ...v12Keywords, ...v13Keywords, ...v14Keywords].map(label => ({ label, kind: "keyword" })),
|
|
485
|
+
...[...standardFunctions, ...v14Functions].map(label => ({ label, kind: "function" })),
|
|
486
|
+
...standardConstants.map(label => ({ label, kind: "variable" })),
|
|
388
487
|
...[...visible.functions].map(label => ({ label, kind: "function" })),
|
|
389
488
|
...[...visible.types].map(label => ({ label, kind: "class" })),
|
|
390
489
|
...[...visible.variables].map(label => ({ label, kind: "variable" })),
|
|
391
490
|
...[...visible.views].map(label => ({ label, kind: "reference" })),
|
|
392
491
|
...fields.map(label => ({ label, kind: "field" }))
|
|
393
492
|
];
|
|
493
|
+
const diagramFacts = diagramCompletionFacts(text, contextText, cursor, parsed, visible);
|
|
494
|
+
if (diagramFacts)
|
|
495
|
+
return diagramFacts;
|
|
394
496
|
return facts;
|
|
395
497
|
}
|
|
396
498
|
export function executableBlockContentStart(text, node) {
|
|
@@ -95,6 +95,11 @@ export function editorHighlightFacts(text, document) {
|
|
|
95
95
|
expression(node.left);
|
|
96
96
|
expression(node.right);
|
|
97
97
|
break;
|
|
98
|
+
case "typeTestExpression":
|
|
99
|
+
expression(node.value);
|
|
100
|
+
add(node.operatorSource, "is", "keyword");
|
|
101
|
+
typeReference(node.target);
|
|
102
|
+
break;
|
|
98
103
|
case "unaryExpression":
|
|
99
104
|
expression(node.argument);
|
|
100
105
|
break;
|
|
@@ -143,7 +148,7 @@ export function editorHighlightFacts(text, document) {
|
|
|
143
148
|
variableDeclaration: "let", typeDeclaration: "type", enumDeclaration: "enum", functionDeclaration: "fn",
|
|
144
149
|
dimensionDeclaration: "dimension", unitDeclaration: "unit",
|
|
145
150
|
inputDeclaration: "input", importDeclaration: "import", tableDeclaration: "table",
|
|
146
|
-
chartDeclaration: "chart", showStatement: "show", forStatement: "for",
|
|
151
|
+
chartDeclaration: "chart", diagramDeclaration: "diagram", showStatement: "show", forStatement: "for",
|
|
147
152
|
assignmentStatement: "", compoundAssignmentStatement: "", bracedIfStatement: "if", returnStatement: "return",
|
|
148
153
|
addStatement: "add", removeStatement: "remove"
|
|
149
154
|
};
|
|
@@ -170,6 +175,27 @@ export function editorHighlightFacts(text, document) {
|
|
|
170
175
|
add(item.source, item.name, "reference");
|
|
171
176
|
if (node.type === "inputDeclaration")
|
|
172
177
|
typeReference(node.annotation);
|
|
178
|
+
if (node.type === "diagramDeclaration") {
|
|
179
|
+
for (const property of node.properties) {
|
|
180
|
+
add(property.nameSource, property.name, "field");
|
|
181
|
+
expression(property.expression);
|
|
182
|
+
}
|
|
183
|
+
for (const time of node.times) {
|
|
184
|
+
add(time.source, "time", "keyword");
|
|
185
|
+
add(time.nameSource, time.name, "declaration");
|
|
186
|
+
expression(time.from);
|
|
187
|
+
expression(time.to);
|
|
188
|
+
expression(time.duration);
|
|
189
|
+
}
|
|
190
|
+
for (const element of node.elements) {
|
|
191
|
+
add(element.source, element.primitive, "keyword");
|
|
192
|
+
add(element.nameSource, element.name, "declaration");
|
|
193
|
+
for (const property of element.properties) {
|
|
194
|
+
add(property.nameSource, property.name, "field");
|
|
195
|
+
expression(property.expression);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
173
199
|
if (node.type === "typeDeclaration") {
|
|
174
200
|
const firstParent = node.parents?.[0];
|
|
175
201
|
const typeOffset = sourceOffset(text, node.source);
|
|
@@ -2,7 +2,10 @@ import { sourceTokenRange } from "./sourceRanges";
|
|
|
2
2
|
const reservedNames = new Set([
|
|
3
3
|
"let", "for", "in", "to", "return", "match", "case", "default", "if", "then", "else", "and", "or", "not", "dimension", "unit", "extends", "override", "enum",
|
|
4
4
|
"true", "false", "null", "type", "fn", "import", "from", "input", "export", "table", "chart", "show",
|
|
5
|
-
"
|
|
5
|
+
"diagram", "time", "line", "rectangle", "circle", "text",
|
|
6
|
+
"title", "description", "column", "category", "x", "y", "width", "height", "duration",
|
|
7
|
+
"x1", "y1", "x2", "y2", "cx", "cy", "r", "stroke", "fill", "lineWidth", "arrow", "value",
|
|
8
|
+
"group", "labels", "series", "as",
|
|
6
9
|
"Number", "String", "Boolean", "DateTime"
|
|
7
10
|
]);
|
|
8
11
|
export function isSafeRenameIdentifier(name) {
|
|
@@ -7,7 +7,8 @@ const declarationKeywords = {
|
|
|
7
7
|
inputDeclaration: "input",
|
|
8
8
|
variableDeclaration: "let",
|
|
9
9
|
tableDeclaration: "table",
|
|
10
|
-
chartDeclaration: "chart"
|
|
10
|
+
chartDeclaration: "chart",
|
|
11
|
+
diagramDeclaration: "diagram"
|
|
11
12
|
};
|
|
12
13
|
export function sourceOffset(text, source) {
|
|
13
14
|
if (!source || !Number.isSafeInteger(source.line) || !Number.isSafeInteger(source.column)
|
package/dist/editor/symbols.js
CHANGED
|
@@ -60,11 +60,13 @@ export function editorSymbolFacts(text, entryFile, entryDocument, analysis, modu
|
|
|
60
60
|
const range = sourceTokenRange(moduleText, member.nameSource, member.name);
|
|
61
61
|
if (!range)
|
|
62
62
|
continue;
|
|
63
|
+
const parent = declaration(moduleText, file, declarationNode)?.target;
|
|
63
64
|
enumMemberTargets.set(`${file}\0${declarationNode.name}\0${member.name}`, {
|
|
64
65
|
...range,
|
|
65
66
|
file,
|
|
66
67
|
name: member.name,
|
|
67
68
|
target: { file, ...range },
|
|
69
|
+
parent,
|
|
68
70
|
declaration: true,
|
|
69
71
|
kind: "enumMember",
|
|
70
72
|
detail: `enum member ${declarationNode.name}.${member.name}`
|
|
@@ -89,56 +91,66 @@ export function editorSymbolFacts(text, entryFile, entryDocument, analysis, modu
|
|
|
89
91
|
if (range)
|
|
90
92
|
result.push({ ...target, ...range, file, declaration: false });
|
|
91
93
|
};
|
|
92
|
-
const
|
|
94
|
+
const typeReference = (reference, scope) => {
|
|
95
|
+
if (reference.type === "namedType" && reference.name)
|
|
96
|
+
add(reference.source, reference.name, scope.get(reference.name));
|
|
97
|
+
else if (reference.element)
|
|
98
|
+
typeReference(reference.element, scope);
|
|
99
|
+
};
|
|
100
|
+
const expression = (node, scope = visible) => {
|
|
93
101
|
if (!analysis && statements.some(statement => statement.type === "importDeclaration"))
|
|
94
102
|
return;
|
|
95
103
|
switch (node.type) {
|
|
96
104
|
case "stringInterpolation":
|
|
97
105
|
node.parts.forEach(part => { if (typeof part !== "string")
|
|
98
|
-
expression(part); });
|
|
106
|
+
expression(part, scope); });
|
|
99
107
|
break;
|
|
100
108
|
case "identifier":
|
|
101
|
-
add(node.source, node.name,
|
|
109
|
+
add(node.source, node.name, scope.get(node.name));
|
|
102
110
|
break;
|
|
103
111
|
case "functionCall":
|
|
104
|
-
add(node.source, node.callee,
|
|
105
|
-
node.arguments.forEach(expression);
|
|
112
|
+
add(node.source, node.callee, scope.get(node.callee));
|
|
113
|
+
node.arguments.forEach(argument => expression(argument, scope));
|
|
106
114
|
break;
|
|
107
115
|
case "recordConstructor":
|
|
108
|
-
add(node.source, node.name,
|
|
109
|
-
node.fields.forEach(field => expression(field.expression));
|
|
116
|
+
add(node.source, node.name, scope.get(node.name));
|
|
117
|
+
node.fields.forEach(field => expression(field.expression, scope));
|
|
110
118
|
break;
|
|
111
119
|
case "binaryExpression":
|
|
112
|
-
expression(node.left);
|
|
113
|
-
expression(node.right);
|
|
120
|
+
expression(node.left, scope);
|
|
121
|
+
expression(node.right, scope);
|
|
122
|
+
break;
|
|
123
|
+
case "typeTestExpression":
|
|
124
|
+
expression(node.value, scope);
|
|
125
|
+
typeReference(node.target, scope);
|
|
114
126
|
break;
|
|
115
127
|
case "measurementAttachment":
|
|
116
128
|
case "measurementConversion":
|
|
117
|
-
add(node.unitSource, node.unit,
|
|
118
|
-
expression(node.value);
|
|
129
|
+
add(node.unitSource, node.unit, scope.get(node.unit));
|
|
130
|
+
expression(node.value, scope);
|
|
119
131
|
break;
|
|
120
132
|
case "unaryExpression":
|
|
121
|
-
expression(node.argument);
|
|
133
|
+
expression(node.argument, scope);
|
|
122
134
|
break;
|
|
123
135
|
case "conditionalExpression":
|
|
124
|
-
expression(node.test);
|
|
125
|
-
expression(node.consequent);
|
|
126
|
-
expression(node.alternate);
|
|
136
|
+
expression(node.test, scope);
|
|
137
|
+
expression(node.consequent, scope);
|
|
138
|
+
expression(node.alternate, scope);
|
|
127
139
|
break;
|
|
128
140
|
case "listLiteral":
|
|
129
|
-
node.elements.forEach(expression);
|
|
141
|
+
node.elements.forEach(element => expression(element, scope));
|
|
130
142
|
break;
|
|
131
143
|
case "rangeExpression":
|
|
132
|
-
expression(node.start);
|
|
133
|
-
expression(node.end);
|
|
144
|
+
expression(node.start, scope);
|
|
145
|
+
expression(node.end, scope);
|
|
134
146
|
break;
|
|
135
147
|
case "matchExpression":
|
|
136
|
-
expression(node.expression);
|
|
137
|
-
node.cases.forEach(arm => expression(arm.expression));
|
|
138
|
-
expression(node.defaultExpression);
|
|
148
|
+
expression(node.expression, scope);
|
|
149
|
+
node.cases.forEach(arm => expression(arm.expression, scope));
|
|
150
|
+
expression(node.defaultExpression, scope);
|
|
139
151
|
break;
|
|
140
152
|
case "fieldAccess": {
|
|
141
|
-
expression(node.receiver);
|
|
153
|
+
expression(node.receiver, scope);
|
|
142
154
|
if (node.receiver.type === "identifier") {
|
|
143
155
|
const visibleEnum = visibleEnums.get(node.receiver.name);
|
|
144
156
|
const member = visibleEnum && enumMemberTargets.get(`${visibleEnum.file}\0${visibleEnum.declaration.name}\0${node.field}`);
|
|
@@ -147,47 +159,47 @@ export function editorSymbolFacts(text, entryFile, entryDocument, analysis, modu
|
|
|
147
159
|
break;
|
|
148
160
|
}
|
|
149
161
|
case "listAccess":
|
|
150
|
-
expression(node.receiver);
|
|
151
|
-
expression(node.index);
|
|
162
|
+
expression(node.receiver, scope);
|
|
163
|
+
expression(node.index, scope);
|
|
152
164
|
break;
|
|
153
165
|
case "forExpression":
|
|
154
|
-
expression(node.iterable);
|
|
155
|
-
node.body.forEach(nestedStatement);
|
|
166
|
+
expression(node.iterable, scope);
|
|
167
|
+
node.body.forEach(statement => nestedStatement(statement, scope));
|
|
156
168
|
break;
|
|
157
169
|
case "bracedIfExpression":
|
|
158
|
-
expression(node.test);
|
|
159
|
-
node.consequent.forEach(nestedStatement);
|
|
160
|
-
node.alternate.forEach(nestedStatement);
|
|
170
|
+
expression(node.test, scope);
|
|
171
|
+
node.consequent.forEach(statement => nestedStatement(statement, scope));
|
|
172
|
+
node.alternate.forEach(statement => nestedStatement(statement, scope));
|
|
161
173
|
break;
|
|
162
174
|
default: break;
|
|
163
175
|
}
|
|
164
176
|
};
|
|
165
|
-
const nestedStatement = (statement) => {
|
|
177
|
+
const nestedStatement = (statement, scope = visible) => {
|
|
166
178
|
if (statement.type === "variableDeclaration")
|
|
167
|
-
expression(statement.expression);
|
|
179
|
+
expression(statement.expression, scope);
|
|
168
180
|
else if (statement.type === "typeDeclaration") {
|
|
169
181
|
for (const parent of statement.parents ?? [])
|
|
170
|
-
add(parent.source, parent.name,
|
|
182
|
+
add(parent.source, parent.name, scope.get(parent.name));
|
|
171
183
|
for (const field of statement.fields)
|
|
172
184
|
if (field.defaultExpression)
|
|
173
|
-
expression(field.defaultExpression);
|
|
185
|
+
expression(field.defaultExpression, scope);
|
|
174
186
|
}
|
|
175
187
|
else if (statement.type === "enumDeclaration") {
|
|
176
188
|
for (const member of statement.members)
|
|
177
189
|
if (member.value)
|
|
178
|
-
expression(member.value);
|
|
190
|
+
expression(member.value, scope);
|
|
179
191
|
}
|
|
180
192
|
else if (statement.type === "forStatement") {
|
|
181
|
-
expression(statement.iterable);
|
|
182
|
-
statement.body.forEach(nestedStatement);
|
|
193
|
+
expression(statement.iterable, scope);
|
|
194
|
+
statement.body.forEach(item => nestedStatement(item, scope));
|
|
183
195
|
}
|
|
184
196
|
else if (statement.type === "bracedIfStatement") {
|
|
185
|
-
expression(statement.test);
|
|
186
|
-
statement.consequent.forEach(nestedStatement);
|
|
187
|
-
statement.alternate?.forEach(nestedStatement);
|
|
197
|
+
expression(statement.test, scope);
|
|
198
|
+
statement.consequent.forEach(item => nestedStatement(item, scope));
|
|
199
|
+
statement.alternate?.forEach(item => nestedStatement(item, scope));
|
|
188
200
|
}
|
|
189
201
|
else if ("expression" in statement && statement.expression)
|
|
190
|
-
expression(statement.expression);
|
|
202
|
+
expression(statement.expression, scope);
|
|
191
203
|
};
|
|
192
204
|
for (const statement of statements) {
|
|
193
205
|
if (statement.type === "importDeclaration") {
|
|
@@ -232,6 +244,52 @@ export function editorSymbolFacts(text, entryFile, entryDocument, analysis, modu
|
|
|
232
244
|
}
|
|
233
245
|
if (statement.type === "variableDeclaration")
|
|
234
246
|
expression(statement.expression);
|
|
247
|
+
if (statement.type === "diagramDeclaration") {
|
|
248
|
+
const diagram = declaration(moduleText, file, statement);
|
|
249
|
+
const diagramParent = !duplicates.has(statement.name) ? diagram?.target : undefined;
|
|
250
|
+
const diagramScope = new Map(visible);
|
|
251
|
+
for (const property of statement.properties)
|
|
252
|
+
expression(property.expression);
|
|
253
|
+
for (const time of statement.times) {
|
|
254
|
+
expression(time.from);
|
|
255
|
+
expression(time.to);
|
|
256
|
+
expression(time.duration);
|
|
257
|
+
const range = sourceTokenRange(moduleText, time.nameSource, time.name);
|
|
258
|
+
if (!range || !diagramParent)
|
|
259
|
+
continue;
|
|
260
|
+
const localTime = {
|
|
261
|
+
...range,
|
|
262
|
+
file,
|
|
263
|
+
name: time.name,
|
|
264
|
+
target: { file, ...range },
|
|
265
|
+
parent: diagramParent,
|
|
266
|
+
declaration: true,
|
|
267
|
+
kind: "diagramTime",
|
|
268
|
+
detail: `time ${time.name}`
|
|
269
|
+
};
|
|
270
|
+
result.push(localTime);
|
|
271
|
+
diagramScope.set(time.name, localTime);
|
|
272
|
+
}
|
|
273
|
+
const elementNames = new Set();
|
|
274
|
+
for (const element of statement.elements) {
|
|
275
|
+
const range = sourceTokenRange(moduleText, element.nameSource, element.name);
|
|
276
|
+
if (range && diagramParent && !elementNames.has(element.name)) {
|
|
277
|
+
elementNames.add(element.name);
|
|
278
|
+
result.push({
|
|
279
|
+
...range,
|
|
280
|
+
file,
|
|
281
|
+
name: element.name,
|
|
282
|
+
target: { file, ...range },
|
|
283
|
+
parent: diagramParent,
|
|
284
|
+
declaration: true,
|
|
285
|
+
kind: "diagramElement",
|
|
286
|
+
detail: `${element.primitive} ${element.name}`
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
for (const property of element.properties)
|
|
290
|
+
expression(property.expression, diagramScope);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
235
293
|
if (statement.type === "typeDeclaration") {
|
|
236
294
|
for (const parent of statement.parents ?? [])
|
|
237
295
|
add(parent.source, parent.name, visible.get(parent.name));
|
|
@@ -277,12 +335,12 @@ export function editorSymbolFacts(text, entryFile, entryDocument, analysis, modu
|
|
|
277
335
|
}
|
|
278
336
|
if (statement.type === "forStatement") {
|
|
279
337
|
expression(statement.iterable);
|
|
280
|
-
statement.body.forEach(nestedStatement);
|
|
338
|
+
statement.body.forEach(item => nestedStatement(item));
|
|
281
339
|
}
|
|
282
340
|
if (statement.type === "bracedIfStatement") {
|
|
283
341
|
expression(statement.test);
|
|
284
|
-
statement.consequent.forEach(nestedStatement);
|
|
285
|
-
statement.alternate?.forEach(nestedStatement);
|
|
342
|
+
statement.consequent.forEach(item => nestedStatement(item));
|
|
343
|
+
statement.alternate?.forEach(item => nestedStatement(item));
|
|
286
344
|
}
|
|
287
345
|
if (statement.type === "functionDeclaration")
|
|
288
346
|
expression(statement.body);
|
|
@@ -293,13 +351,14 @@ export function editorSymbolFacts(text, entryFile, entryDocument, analysis, modu
|
|
|
293
351
|
if (inferred)
|
|
294
352
|
declared.detail = `binding ${statement.name}: ${typeText(inferred)}`;
|
|
295
353
|
}
|
|
296
|
-
|
|
354
|
+
if (statement.type !== "diagramDeclaration")
|
|
355
|
+
visible.set(statement.name, declared);
|
|
297
356
|
result.push(declared);
|
|
298
357
|
if (statement.type === "typeDeclaration")
|
|
299
358
|
for (const field of statement.fields) {
|
|
300
359
|
const range = sourceTokenRange(moduleText, field.source, field.name);
|
|
301
360
|
if (range)
|
|
302
|
-
result.push({ ...range, file, name: field.name, target: { file, ...range }, declaration: true, kind: "field", detail: `field ${field.name}: ${field.annotation.name ?? field.annotation.type}` });
|
|
361
|
+
result.push({ ...range, file, name: field.name, target: { file, ...range }, parent: declared.target, declaration: true, kind: "field", detail: `field ${field.name}: ${field.annotation.name ?? field.annotation.type}` });
|
|
303
362
|
}
|
|
304
363
|
}
|
|
305
364
|
}
|