@nova-energy/openamx 0.11.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 +42 -10
- package/dist/cli.js +5 -5
- package/dist/editor/completion.js +199 -6
- package/dist/editor/highlighting.js +63 -4
- package/dist/editor/moduleAnalysis.js +8 -2
- package/dist/editor/refactoring.js +5 -2
- package/dist/editor/sourceRanges.js +3 -1
- package/dist/editor/symbols.js +195 -30
- package/dist/formatter/formatAmx.js +83 -7
- package/dist/parser/parseExpression.js +82 -3
- package/dist/parser/parseIf.js +180 -0
- package/dist/parser/parseStatements.js +232 -7
- 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 +8 -0
- package/dist/runtime/evaluateExpression.js +194 -10
- package/dist/runtime/inputData.js +20 -18
- package/dist/runtime/moduleLoader.js +76 -4
- package/dist/runtime/outputData.js +18 -12
- package/dist/runtime/standardLibrary.js +208 -1
- package/dist/runtime/valueSerialization.js +12 -0
- package/dist/typechecker/checkDocument.js +496 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -178,9 +178,21 @@ 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
|
-
|
|
183
|
-
|
|
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)
|
|
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.
|
|
194
|
+
[V0.9 language specification](docs/language-spec-v0.9.md) and [V0.9 migration guide](docs/migrating-to-v0.9.md)
|
|
195
|
+
remain historical references for the earlier language contract and its approved compatibility changes. Earlier specifications describe
|
|
184
196
|
the language's evolution: [V0.5](docs/language-spec-v0.5.md),
|
|
185
197
|
[V0.2](docs/language-spec-v0.2.md),
|
|
186
198
|
[V0.3](docs/language-spec-v0.3.md), and [V0.4](docs/language-spec-v0.4.md).
|
|
@@ -361,13 +373,33 @@ tables, code, rules, and visible source line breaks; authored raw HTML remains
|
|
|
361
373
|
inert text. Narrative images must be project-contained PNG or JPEG files with
|
|
362
374
|
nonempty alternative text, no more than 4 MiB and 4,000,000 decoded pixels per
|
|
363
375
|
image. They are sanitized and embedded, so reports do not fetch remote images.
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
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.
|
|
371
403
|
|
|
372
404
|
Run the V0.5 typed example with its local imports, JSON/CSV inputs, table and
|
|
373
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");
|
|
@@ -8,8 +8,25 @@ const v03Keywords = ["null", "type", "fn", "import", "from", "input", "export"];
|
|
|
8
8
|
const v04Keywords = ["table", "chart", "show", "title", "description", "column", "category", "x", "y", "group", "labels", "series", "as"];
|
|
9
9
|
const v09ListKeywords = ["add", "remove", "at"];
|
|
10
10
|
const v09UnitKeywords = ["dimension", "unit"];
|
|
11
|
+
const v12Keywords = ["enum", "extends", "override"];
|
|
12
|
+
const v13Keywords = ["diagram"];
|
|
13
|
+
const v14Keywords = ["is"];
|
|
11
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"];
|
|
12
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"'];
|
|
13
30
|
function cursorInsideOpenAmxFence(text, cursorOffset) {
|
|
14
31
|
const frontMatter = parseFrontMatter(text);
|
|
15
32
|
if (frontMatter.error)
|
|
@@ -110,6 +127,85 @@ function statementEndOffset(text, statement) {
|
|
|
110
127
|
}
|
|
111
128
|
return text.length;
|
|
112
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
|
+
}
|
|
113
209
|
function loopBounds(text, loop) {
|
|
114
210
|
const start = sourceOffset(text, loop.source);
|
|
115
211
|
if (start === undefined)
|
|
@@ -129,19 +225,82 @@ function loopBounds(text, loop) {
|
|
|
129
225
|
if (end === undefined)
|
|
130
226
|
return undefined;
|
|
131
227
|
offset = end;
|
|
132
|
-
continue;
|
|
133
228
|
}
|
|
134
|
-
if (character === "{")
|
|
229
|
+
else if (character === "{")
|
|
135
230
|
depth++;
|
|
136
231
|
else if (character === "}" && --depth === 0)
|
|
137
232
|
return { open, close: offset };
|
|
138
233
|
}
|
|
139
234
|
return undefined;
|
|
140
235
|
}
|
|
236
|
+
function ifBranchBounds(text, node, alternate) {
|
|
237
|
+
const start = sourceOffset(text, node.source);
|
|
238
|
+
if (start === undefined)
|
|
239
|
+
return undefined;
|
|
240
|
+
const findOpen = (from) => {
|
|
241
|
+
let brackets = 0;
|
|
242
|
+
for (let offset = from; offset < text.length; offset++) {
|
|
243
|
+
const character = text[offset];
|
|
244
|
+
if (character === '"' || character === "'") {
|
|
245
|
+
const end = findStringLiteralEnd(text, offset);
|
|
246
|
+
if (end === undefined)
|
|
247
|
+
return undefined;
|
|
248
|
+
offset = end;
|
|
249
|
+
}
|
|
250
|
+
else if (character === "(" || character === "[")
|
|
251
|
+
brackets++;
|
|
252
|
+
else if (character === ")" || character === "]")
|
|
253
|
+
brackets--;
|
|
254
|
+
else if (character === "{" && brackets === 0)
|
|
255
|
+
return offset;
|
|
256
|
+
}
|
|
257
|
+
return undefined;
|
|
258
|
+
};
|
|
259
|
+
const findClose = (open) => {
|
|
260
|
+
let depth = 0;
|
|
261
|
+
for (let offset = open; offset < text.length; offset++) {
|
|
262
|
+
const character = text[offset];
|
|
263
|
+
if (character === '"' || character === "'") {
|
|
264
|
+
const end = findStringLiteralEnd(text, offset);
|
|
265
|
+
if (end === undefined)
|
|
266
|
+
return undefined;
|
|
267
|
+
offset = end;
|
|
268
|
+
}
|
|
269
|
+
else if (character === "{")
|
|
270
|
+
depth++;
|
|
271
|
+
else if (character === "}" && --depth === 0)
|
|
272
|
+
return offset;
|
|
273
|
+
}
|
|
274
|
+
return undefined;
|
|
275
|
+
};
|
|
276
|
+
const firstOpen = findOpen(start + 2);
|
|
277
|
+
if (firstOpen === undefined)
|
|
278
|
+
return undefined;
|
|
279
|
+
const firstClose = findClose(firstOpen);
|
|
280
|
+
if (firstClose === undefined)
|
|
281
|
+
return undefined;
|
|
282
|
+
if (!alternate)
|
|
283
|
+
return { open: firstOpen, close: firstClose };
|
|
284
|
+
let cursor = firstClose + 1;
|
|
285
|
+
while (/\s/.test(text[cursor] ?? ""))
|
|
286
|
+
cursor++;
|
|
287
|
+
if (!text.startsWith("else", cursor))
|
|
288
|
+
return undefined;
|
|
289
|
+
const secondOpen = findOpen(cursor + 4);
|
|
290
|
+
if (secondOpen === undefined)
|
|
291
|
+
return undefined;
|
|
292
|
+
const secondClose = findClose(secondOpen);
|
|
293
|
+
return secondClose === undefined ? undefined : { open: secondOpen, close: secondClose };
|
|
294
|
+
}
|
|
295
|
+
function insideIfBranch(text, node, cursorOffset, alternate) {
|
|
296
|
+
const bounds = ifBranchBounds(text, node, alternate);
|
|
297
|
+
return !!bounds && cursorOffset > bounds.open && cursorOffset < bounds.close;
|
|
298
|
+
}
|
|
141
299
|
function visibleSymbols(text, parsed, cursorOffset, analysis) {
|
|
142
300
|
const variables = new Set();
|
|
143
301
|
const functions = new Set();
|
|
144
302
|
const types = new Set(primitiveTypes);
|
|
303
|
+
const enums = new Map();
|
|
145
304
|
const views = new Set();
|
|
146
305
|
const recordTypes = new Map();
|
|
147
306
|
const localTypeDeclarations = new Map();
|
|
@@ -175,6 +334,12 @@ function visibleSymbols(text, parsed, cursorOffset, analysis) {
|
|
|
175
334
|
localTypeDeclarations.set(statement.name, statement);
|
|
176
335
|
}
|
|
177
336
|
}
|
|
337
|
+
else if (statement.type === "enumDeclaration") {
|
|
338
|
+
if (statementEndOffset(text, statement) <= cursorOffset) {
|
|
339
|
+
types.add(statement.name);
|
|
340
|
+
enums.set(statement.name, statement);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
178
343
|
else if (statement.type === "functionDeclaration") {
|
|
179
344
|
if (statementEndOffset(text, statement) <= cursorOffset)
|
|
180
345
|
functions.add(statement.name);
|
|
@@ -188,6 +353,10 @@ function visibleSymbols(text, parsed, cursorOffset, analysis) {
|
|
|
188
353
|
for (const item of statement.names) {
|
|
189
354
|
if (analysis?.importedTypes.has(item.name))
|
|
190
355
|
types.add(item.name);
|
|
356
|
+
if (analysis?.importedEnums.has(item.name)) {
|
|
357
|
+
types.add(item.name);
|
|
358
|
+
enums.set(item.name, analysis.importedEnums.get(item.name));
|
|
359
|
+
}
|
|
191
360
|
if (analysis?.importedFunctions.has(item.name))
|
|
192
361
|
functions.add(item.name);
|
|
193
362
|
if (analysis?.importedBindings.has(item.name)) {
|
|
@@ -201,6 +370,13 @@ function visibleSymbols(text, parsed, cursorOffset, analysis) {
|
|
|
201
370
|
}
|
|
202
371
|
else if (statement.type === "forStatement")
|
|
203
372
|
collectLoop(statement);
|
|
373
|
+
else if (statement.type === "bracedIfStatement") {
|
|
374
|
+
collectExpression(statement.test);
|
|
375
|
+
if (insideIfBranch(text, statement, cursorOffset, false))
|
|
376
|
+
collectStatements(statement.consequent);
|
|
377
|
+
if (statement.alternate && insideIfBranch(text, statement, cursorOffset, true))
|
|
378
|
+
collectStatements(statement.alternate);
|
|
379
|
+
}
|
|
204
380
|
else if (statement.type === "assignmentStatement" || statement.type === "compoundAssignmentStatement")
|
|
205
381
|
collectExpression(statement.expression);
|
|
206
382
|
else if ("expression" in statement && statement.expression)
|
|
@@ -227,6 +403,9 @@ function visibleSymbols(text, parsed, cursorOffset, analysis) {
|
|
|
227
403
|
collectExpression(expression.left);
|
|
228
404
|
collectExpression(expression.right);
|
|
229
405
|
break;
|
|
406
|
+
case "typeTestExpression":
|
|
407
|
+
collectExpression(expression.value);
|
|
408
|
+
break;
|
|
230
409
|
case "measurementAttachment":
|
|
231
410
|
case "measurementConversion":
|
|
232
411
|
collectExpression(expression.value);
|
|
@@ -239,6 +418,13 @@ function visibleSymbols(text, parsed, cursorOffset, analysis) {
|
|
|
239
418
|
collectExpression(expression.consequent);
|
|
240
419
|
collectExpression(expression.alternate);
|
|
241
420
|
break;
|
|
421
|
+
case "bracedIfExpression":
|
|
422
|
+
collectExpression(expression.test);
|
|
423
|
+
if (insideIfBranch(text, expression, cursorOffset, false))
|
|
424
|
+
collectStatements(expression.consequent);
|
|
425
|
+
if (insideIfBranch(text, expression, cursorOffset, true))
|
|
426
|
+
collectStatements(expression.alternate);
|
|
427
|
+
break;
|
|
242
428
|
case "matchExpression":
|
|
243
429
|
collectMatch(expression);
|
|
244
430
|
break;
|
|
@@ -280,7 +466,7 @@ function visibleSymbols(text, parsed, cursorOffset, analysis) {
|
|
|
280
466
|
for (const [name, declaration] of analysis.importedTypes)
|
|
281
467
|
if (types.has(name))
|
|
282
468
|
localTypeDeclarations.set(name, declaration);
|
|
283
|
-
return { variables, functions, types, views, recordTypes };
|
|
469
|
+
return { variables, functions, types, enums, views, recordTypes };
|
|
284
470
|
}
|
|
285
471
|
/** Return only candidates proven visible before the cursor in the parsed source order. */
|
|
286
472
|
export function editorCompletionFacts(text, cursorOffset, parsed, analysis, contextText = text) {
|
|
@@ -290,16 +476,23 @@ export function editorCompletionFacts(text, cursorOffset, parsed, analysis, cont
|
|
|
290
476
|
const lineStart = contextText.lastIndexOf("\n", Math.max(0, contextCursor - 1)) + 1;
|
|
291
477
|
const prefix = contextText.slice(lineStart, contextCursor);
|
|
292
478
|
const fieldReceiver = prefix.match(/\b([A-Za-z][A-Za-z0-9_]*)\.\w*$/)?.[1];
|
|
293
|
-
const fields = fieldReceiver
|
|
479
|
+
const fields = fieldReceiver
|
|
480
|
+
? visible.enums.get(fieldReceiver)?.members.map(member => member.name)
|
|
481
|
+
?? visible.recordTypes.get(fieldReceiver)?.fields.map(field => field.name) ?? []
|
|
482
|
+
: [];
|
|
294
483
|
const facts = [
|
|
295
|
-
...[...v02Keywords, ...v03Keywords, ...v04Keywords, ...v09ListKeywords, ...v09UnitKeywords].map(label => ({ label, kind: "keyword" })),
|
|
296
|
-
...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" })),
|
|
297
487
|
...[...visible.functions].map(label => ({ label, kind: "function" })),
|
|
298
488
|
...[...visible.types].map(label => ({ label, kind: "class" })),
|
|
299
489
|
...[...visible.variables].map(label => ({ label, kind: "variable" })),
|
|
300
490
|
...[...visible.views].map(label => ({ label, kind: "reference" })),
|
|
301
491
|
...fields.map(label => ({ label, kind: "field" }))
|
|
302
492
|
];
|
|
493
|
+
const diagramFacts = diagramCompletionFacts(text, contextText, cursor, parsed, visible);
|
|
494
|
+
if (diagramFacts)
|
|
495
|
+
return diagramFacts;
|
|
303
496
|
return facts;
|
|
304
497
|
}
|
|
305
498
|
export function executableBlockContentStart(text, node) {
|
|
@@ -3,6 +3,10 @@ import { findStringLiteralEnd } from "../parser/stringScanner";
|
|
|
3
3
|
function statementsOf(document) {
|
|
4
4
|
return document.nodes.flatMap(node => node.type === "executableCodeBlock" ? node.statements : []);
|
|
5
5
|
}
|
|
6
|
+
function sourceLocationAtOffset(text, offset) {
|
|
7
|
+
const before = text.slice(0, offset).split(/\r?\n/);
|
|
8
|
+
return { line: before.length, column: before.at(-1).length + 1 };
|
|
9
|
+
}
|
|
6
10
|
/** Return parser-proven tokens only; narrative and ordinary fences never enter the AST statement walk. */
|
|
7
11
|
export function editorHighlightFacts(text, document) {
|
|
8
12
|
const facts = [];
|
|
@@ -91,6 +95,11 @@ export function editorHighlightFacts(text, document) {
|
|
|
91
95
|
expression(node.left);
|
|
92
96
|
expression(node.right);
|
|
93
97
|
break;
|
|
98
|
+
case "typeTestExpression":
|
|
99
|
+
expression(node.value);
|
|
100
|
+
add(node.operatorSource, "is", "keyword");
|
|
101
|
+
typeReference(node.target);
|
|
102
|
+
break;
|
|
94
103
|
case "unaryExpression":
|
|
95
104
|
expression(node.argument);
|
|
96
105
|
break;
|
|
@@ -99,6 +108,12 @@ export function editorHighlightFacts(text, document) {
|
|
|
99
108
|
expression(node.consequent);
|
|
100
109
|
expression(node.alternate);
|
|
101
110
|
break;
|
|
111
|
+
case "bracedIfExpression":
|
|
112
|
+
add(node.source, "if", "keyword");
|
|
113
|
+
expression(node.test);
|
|
114
|
+
node.consequent.forEach(statement);
|
|
115
|
+
node.alternate.forEach(statement);
|
|
116
|
+
break;
|
|
102
117
|
case "forExpression":
|
|
103
118
|
expression(node.iterable);
|
|
104
119
|
node.body.forEach(statement);
|
|
@@ -130,11 +145,11 @@ export function editorHighlightFacts(text, document) {
|
|
|
130
145
|
};
|
|
131
146
|
const statement = (node) => {
|
|
132
147
|
const keyword = {
|
|
133
|
-
variableDeclaration: "let", typeDeclaration: "type", functionDeclaration: "fn",
|
|
148
|
+
variableDeclaration: "let", typeDeclaration: "type", enumDeclaration: "enum", functionDeclaration: "fn",
|
|
134
149
|
dimensionDeclaration: "dimension", unitDeclaration: "unit",
|
|
135
150
|
inputDeclaration: "input", importDeclaration: "import", tableDeclaration: "table",
|
|
136
|
-
chartDeclaration: "chart", showStatement: "show", forStatement: "for",
|
|
137
|
-
assignmentStatement: "", compoundAssignmentStatement: "",
|
|
151
|
+
chartDeclaration: "chart", diagramDeclaration: "diagram", showStatement: "show", forStatement: "for",
|
|
152
|
+
assignmentStatement: "", compoundAssignmentStatement: "", bracedIfStatement: "if", returnStatement: "return",
|
|
138
153
|
addStatement: "add", removeStatement: "remove"
|
|
139
154
|
};
|
|
140
155
|
const word = keyword[node.type];
|
|
@@ -160,11 +175,48 @@ export function editorHighlightFacts(text, document) {
|
|
|
160
175
|
add(item.source, item.name, "reference");
|
|
161
176
|
if (node.type === "inputDeclaration")
|
|
162
177
|
typeReference(node.annotation);
|
|
163
|
-
if (node.type === "
|
|
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
|
+
}
|
|
199
|
+
if (node.type === "typeDeclaration") {
|
|
200
|
+
const firstParent = node.parents?.[0];
|
|
201
|
+
const typeOffset = sourceOffset(text, node.source);
|
|
202
|
+
const parentOffset = sourceOffset(text, firstParent?.source);
|
|
203
|
+
if (typeOffset !== undefined && parentOffset !== undefined) {
|
|
204
|
+
const extendsOffset = text.slice(typeOffset, parentOffset).indexOf("extends");
|
|
205
|
+
if (extendsOffset >= 0)
|
|
206
|
+
add(sourceLocationAtOffset(text, typeOffset + extendsOffset), "extends", "keyword");
|
|
207
|
+
}
|
|
208
|
+
for (const parent of node.parents ?? [])
|
|
209
|
+
add(parent.source, parent.name, "type");
|
|
164
210
|
for (const field of node.fields) {
|
|
211
|
+
if (field.override)
|
|
212
|
+
add(field.overrideSource, "override", "keyword");
|
|
165
213
|
add(field.source, field.name, "field");
|
|
166
214
|
typeReference(field.annotation);
|
|
167
215
|
}
|
|
216
|
+
}
|
|
217
|
+
if (node.type === "enumDeclaration")
|
|
218
|
+
for (const member of node.members)
|
|
219
|
+
add(member.nameSource, member.name, "declaration");
|
|
168
220
|
if (node.type === "variableDeclaration") {
|
|
169
221
|
typeReference(node.annotation);
|
|
170
222
|
expression(node.expression);
|
|
@@ -196,6 +248,13 @@ export function editorHighlightFacts(text, document) {
|
|
|
196
248
|
expression(node.iterable);
|
|
197
249
|
node.body.forEach(statement);
|
|
198
250
|
}
|
|
251
|
+
else if (node.type === "bracedIfStatement") {
|
|
252
|
+
expression(node.test);
|
|
253
|
+
node.consequent.forEach(statement);
|
|
254
|
+
node.alternate?.forEach(statement);
|
|
255
|
+
}
|
|
256
|
+
else if (node.type === "returnStatement")
|
|
257
|
+
expression(node.expression);
|
|
199
258
|
else if ("expression" in node && node.expression)
|
|
200
259
|
expression(node.expression);
|
|
201
260
|
};
|
|
@@ -57,6 +57,7 @@ export function analyzeEditorModules(text, entryFile, resolveModule) {
|
|
|
57
57
|
return {
|
|
58
58
|
document: entryDocument,
|
|
59
59
|
importedTypes: new Map(),
|
|
60
|
+
importedEnums: new Map(),
|
|
60
61
|
importedFunctions: new Map(),
|
|
61
62
|
importedBindings: new Map(),
|
|
62
63
|
importedDimensions: new Map(),
|
|
@@ -96,12 +97,13 @@ export function analyzeEditorModules(text, entryFile, resolveModule) {
|
|
|
96
97
|
moduleIssue("AMX3005", "Inputs may only be declared in the entry module", file, input.source);
|
|
97
98
|
}
|
|
98
99
|
const imports = statements.filter((statement) => statement.type === "importDeclaration");
|
|
99
|
-
const localNames = new Set(statements.flatMap(statement => statement.type === "typeDeclaration" || statement.type === "functionDeclaration"
|
|
100
|
+
const localNames = new Set(statements.flatMap(statement => statement.type === "typeDeclaration" || statement.type === "enumDeclaration" || statement.type === "functionDeclaration"
|
|
100
101
|
|| statement.type === "variableDeclaration" || statement.type === "inputDeclaration"
|
|
101
102
|
|| statement.type === "tableDeclaration" || statement.type === "chartDeclaration"
|
|
102
103
|
|| statement.type === "dimensionDeclaration" || statement.type === "unitDeclaration" ? [statement.name] : []));
|
|
103
104
|
const localDimensionUnitNames = new Set(statements.flatMap(statement => statement.type === "dimensionDeclaration" || statement.type === "unitDeclaration" ? [statement.name] : []));
|
|
104
105
|
const importedTypes = new Map();
|
|
106
|
+
const importedEnums = new Map();
|
|
105
107
|
const importedFunctions = new Map();
|
|
106
108
|
const importedBindings = new Map();
|
|
107
109
|
const importedDimensions = new Map();
|
|
@@ -154,6 +156,8 @@ export function analyzeEditorModules(text, entryFile, resolveModule) {
|
|
|
154
156
|
}
|
|
155
157
|
if (dependency.checkResult.exportedTypes.has(importedName.name))
|
|
156
158
|
importedTypes.set(importedName.name, dependency.checkResult.exportedTypes.get(importedName.name));
|
|
159
|
+
else if (dependency.checkResult.exportedEnums.has(importedName.name))
|
|
160
|
+
importedEnums.set(importedName.name, dependency.checkResult.exportedEnums.get(importedName.name));
|
|
157
161
|
else if (dependency.checkResult.exportedFunctions.has(importedName.name))
|
|
158
162
|
importedFunctions.set(importedName.name, dependency.checkResult.exportedFunctions.get(importedName.name));
|
|
159
163
|
else if (dependency.checkResult.exportedBindings.has(importedName.name))
|
|
@@ -175,6 +179,7 @@ export function analyzeEditorModules(text, entryFile, resolveModule) {
|
|
|
175
179
|
try {
|
|
176
180
|
checkResult = checkDocument(document, file, {
|
|
177
181
|
types: importedTypes,
|
|
182
|
+
enums: importedEnums,
|
|
178
183
|
functions: importedFunctions,
|
|
179
184
|
bindings: importedBindings,
|
|
180
185
|
dimensions: importedDimensions,
|
|
@@ -188,7 +193,7 @@ export function analyzeEditorModules(text, entryFile, resolveModule) {
|
|
|
188
193
|
throw locatedError(error, file);
|
|
189
194
|
}
|
|
190
195
|
visiting.pop();
|
|
191
|
-
const record = { file, document, checkResult, importedTypes, importedFunctions, importedBindings, importedDimensions, importedUnits, importTargets };
|
|
196
|
+
const record = { file, document, checkResult, importedTypes, importedEnums, importedFunctions, importedBindings, importedDimensions, importedUnits, importTargets };
|
|
192
197
|
records.set(file, record);
|
|
193
198
|
return record;
|
|
194
199
|
};
|
|
@@ -196,6 +201,7 @@ export function analyzeEditorModules(text, entryFile, resolveModule) {
|
|
|
196
201
|
return {
|
|
197
202
|
document: result.document,
|
|
198
203
|
importedTypes: result.importedTypes,
|
|
204
|
+
importedEnums: result.importedEnums,
|
|
199
205
|
importedFunctions: result.importedFunctions,
|
|
200
206
|
importedBindings: result.importedBindings,
|
|
201
207
|
importedDimensions: result.importedDimensions,
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { sourceTokenRange } from "./sourceRanges";
|
|
2
2
|
const reservedNames = new Set([
|
|
3
|
-
"let", "for", "in", "to", "return", "match", "case", "default", "if", "then", "else", "and", "or", "not", "dimension", "unit",
|
|
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) {
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
const declarationKeywords = {
|
|
2
2
|
typeDeclaration: "type",
|
|
3
|
+
enumDeclaration: "enum",
|
|
3
4
|
dimensionDeclaration: "dimension",
|
|
4
5
|
unitDeclaration: "unit",
|
|
5
6
|
functionDeclaration: "fn",
|
|
6
7
|
inputDeclaration: "input",
|
|
7
8
|
variableDeclaration: "let",
|
|
8
9
|
tableDeclaration: "table",
|
|
9
|
-
chartDeclaration: "chart"
|
|
10
|
+
chartDeclaration: "chart",
|
|
11
|
+
diagramDeclaration: "diagram"
|
|
10
12
|
};
|
|
11
13
|
export function sourceOffset(text, source) {
|
|
12
14
|
if (!source || !Number.isSafeInteger(source.line) || !Number.isSafeInteger(source.column)
|