langium-tools 0.3.3 → 0.5.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 +57 -34
- package/dist/base/document-issues.js +99 -25
- package/dist/testing/generator-testing.d.ts +6 -0
- package/dist/testing/generator-testing.js +19 -2
- package/dist/testing/matchers.d.ts +34 -38
- package/package.json +13 -6
- package/src/base/document-issues.ts +125 -28
- package/src/testing/generator-testing.ts +20 -2
- package/src/testing/matchers.ts +61 -50
package/README.md
CHANGED
|
@@ -28,12 +28,13 @@
|
|
|
28
28
|
A collection of tools for implementing and testing DSLs with <a href="https://langium.org/"><strong>Langium</strong>!</a>
|
|
29
29
|
<br />
|
|
30
30
|
<br />
|
|
31
|
-
<a href="
|
|
31
|
+
<a href="https://langium-tools.openbrod.org"><strong>Website »</strong></a>
|
|
32
32
|
<br />
|
|
33
|
-
<a href="https://
|
|
33
|
+
<a href="https://langium-tools.openbrod.org/api"><strong>API reference »</strong></a>
|
|
34
|
+
<br />
|
|
35
|
+
<a href="#documentation"><strong>Documentation in this README »</strong></a>
|
|
34
36
|
<br />
|
|
35
37
|
<br />
|
|
36
|
-
|
|
37
38
|
<a href="https://github.com/borisbrodski/langium-tools/issues/new?labels=bug&template=bug-report---.md">Report Bug</a>
|
|
38
39
|
·
|
|
39
40
|
<a href="https://github.com/borisbrodski/langium-tools/issues/new?labels=enhancement&template=feature-request---.md">Request Feature</a>
|
|
@@ -109,7 +110,7 @@ This section should list any major frameworks/libraries used to bootstrap your p
|
|
|
109
110
|
|
|
110
111
|
- Add package to your project
|
|
111
112
|
- Start using one or more features it provides
|
|
112
|
-
-
|
|
113
|
+
- Read the [state machine showcase](https://github.com/borisbrodski/langium-tools-showcases/tree/main/statemachine) for a full language that uses the library
|
|
113
114
|
|
|
114
115
|
### Installation
|
|
115
116
|
|
|
@@ -123,13 +124,35 @@ Add the package to your `package.json`
|
|
|
123
124
|
|
|
124
125
|
### Example project
|
|
125
126
|
|
|
126
|
-
|
|
127
|
+
The [state machine showcase](https://github.com/borisbrodski/langium-tools-showcases/tree/main/statemachine) is the official Langium statemachine. The grammar and the C++ program are the original example. langium-tools replaces the hand-written parts around them. `git diff upstream -- statemachine` in that repository is the extension.
|
|
128
|
+
|
|
129
|
+
Clone it next to this repository. The example depends on `file:../../langium-tools`, and this package exports `dist/`, so build here first:
|
|
130
|
+
|
|
131
|
+
```sh
|
|
132
|
+
git clone https://github.com/borisbrodski/langium-tools.git
|
|
133
|
+
git clone https://github.com/borisbrodski/langium-tools-showcases.git
|
|
134
|
+
cd langium-tools && npm install && npm run build
|
|
135
|
+
cd ../langium-tools-showcases/statemachine && npm install && npm test
|
|
136
|
+
```
|
|
127
137
|
|
|
128
|
-
|
|
138
|
+
What that language uses, and why it is less code:
|
|
139
|
+
|
|
140
|
+
- `getDocumentIssueSummary` is the CLI's only error report. Lexer, parser, and validation errors share one count. Warnings are printed and generation continues. The old loop kept diagnostics of severity 1 and could miss a syntax error.
|
|
141
|
+
- `toHaveNoErrors` ignores warnings. `toHaveNoIssues` does not. A lowercase state name is the test that shows the difference, so a style warning does not have to fail a parse test.
|
|
142
|
+
- `parseWithMarks` and `toHaveDocumentIssues` use `<<{|` … `|}>>` as the expected range. The matcher fails when an issue is missing and when an extra issue appears. Hard-coded ranges such as `[1:19..1:26]` do not.
|
|
143
|
+
- `generate` only calls `createFile`. The CLI writes the directory. Identical bytes keep their modification time. The same path with different text throws before a file is overwritten. The C++ templates themselves are unchanged.
|
|
144
|
+
- `npm test` verifies `generated/` and `generated-metadata.json`. `npm run test:generate` rewrites them. The mode is `GENERATOR_TEST`. The C++ no longer has to be pasted into the test source.
|
|
145
|
+
- `JavaImportManager` turns the events into a Java enum. `useClass('java.util.function.Consumer')` prints `Consumer` and adds the import. A second type with that simple name stays fully qualified. Classes in the current package are not imported.
|
|
146
|
+
|
|
147
|
+
`generateJavaFile` is the one-call wrapper around the import manager. It builds the file with generator nodes from this package's Langium install. A project that also depends on Langium has a second copy, and those nodes print as `[object Object]`. The showcase calls the import manager and `createFile` instead. The note is in `statemachine/src/cli/generator.ts`.
|
|
148
|
+
|
|
149
|
+
`arraySortBy`, `adjustedUnix`, and named generator targets are real features. The state machine does not use them: event order is the language order, the snapshots are `\n`, and the `.cpp` and `.java` share one output directory. Named targets are the next step when those two files must land in different directories.
|
|
129
150
|
|
|
130
151
|
## Documentation
|
|
131
152
|
|
|
132
|
-
|
|
153
|
+
Guides for every part of the library, with examples, are on the website: [langium-tools.openbrod.org](https://langium-tools.openbrod.org). The [showcases](https://langium-tools.openbrod.org/showcases/) page is the index of working languages, starting with the state machine.
|
|
154
|
+
|
|
155
|
+
The generated API reference is [typedoc](https://langium-tools.openbrod.org/api).
|
|
133
156
|
|
|
134
157
|
### Document Issues
|
|
135
158
|
|
|
@@ -234,13 +257,13 @@ The module defines the following enums for issue sources and severities:
|
|
|
234
257
|
|
|
235
258
|
For detailed API documentation, see the Typedoc documentation.
|
|
236
259
|
|
|
237
|
-
- [getDocumentIssueSummary](https://
|
|
238
|
-
- [getDocumentIssues](https://
|
|
239
|
-
- [documentIssueToString](https://
|
|
240
|
-
- [DocumentIssue](https://
|
|
241
|
-
- [DocumentIssueSummary](https://
|
|
242
|
-
- [DocumentIssueSource](https://
|
|
243
|
-
- [DocumentIssueSeverity](https://
|
|
260
|
+
- [getDocumentIssueSummary](https://langium-tools.openbrod.org/api/functions/base.getDocumentIssueSummary.html)
|
|
261
|
+
- [getDocumentIssues](https://langium-tools.openbrod.org/api/functions/base.getDocumentIssues.html)
|
|
262
|
+
- [documentIssueToString](https://langium-tools.openbrod.org/api/functions/base.documentIssueToString.html)
|
|
263
|
+
- [DocumentIssue](https://langium-tools.openbrod.org/api/types/base.DocumentIssue.html)
|
|
264
|
+
- [DocumentIssueSummary](https://langium-tools.openbrod.org/api/types/base.DocumentIssueSummary.html)
|
|
265
|
+
- [DocumentIssueSource](https://langium-tools.openbrod.org/api/enums/base.DocumentIssueSource.html)
|
|
266
|
+
- [DocumentIssueSeverity](https://langium-tools.openbrod.org/api/enums/base.DocumentIssueSeverity.html)
|
|
244
267
|
|
|
245
268
|
#### Notes
|
|
246
269
|
|
|
@@ -379,10 +402,10 @@ await manager.writeToDisk(outputDir: string, target?: string, clean?: boolean);
|
|
|
379
402
|
|
|
380
403
|
For detailed API documentation, see the Typedoc documentation.
|
|
381
404
|
|
|
382
|
-
- [GeneratedContentManager](https://
|
|
383
|
-
- [GeneratorManager](https://
|
|
384
|
-
- [GeneratorTarget](https://
|
|
385
|
-
- [CreateFileOptions](https://
|
|
405
|
+
- [GeneratedContentManager](https://langium-tools.openbrod.org/api/classes/generator.GeneratedContentManager.html)
|
|
406
|
+
- [GeneratorManager](https://langium-tools.openbrod.org/api/interfaces/generator.GeneratorManager.html)
|
|
407
|
+
- [GeneratorTarget](https://langium-tools.openbrod.org/api/interfaces/generator.GeneratorTarget.html)
|
|
408
|
+
- [CreateFileOptions](https://langium-tools.openbrod.org/api/interfaces/generator.CreateFileOptions.html)
|
|
386
409
|
|
|
387
410
|
#### Notes
|
|
388
411
|
|
|
@@ -556,16 +579,16 @@ The generator testing utilities work by:
|
|
|
556
579
|
|
|
557
580
|
#### API Reference
|
|
558
581
|
|
|
559
|
-
For detailed API documentation, see the [Typedoc documentation](https://
|
|
582
|
+
For detailed API documentation, see the [Typedoc documentation](https://langium-tools.openbrod.org/api).
|
|
560
583
|
|
|
561
|
-
- [langiumGeneratorSuite](https://
|
|
562
|
-
- [GeneratorTestOptions](https://
|
|
563
|
-
- [GeneratedContentManager](https://
|
|
584
|
+
- [langiumGeneratorSuite](https://langium-tools.openbrod.org/api/functions/testing.langiumGeneratorSuite.html)
|
|
585
|
+
- [GeneratorTestOptions](https://langium-tools.openbrod.org/api/interfaces/testing.GeneratorTestOptions.html)
|
|
586
|
+
- [GeneratedContentManager](https://langium-tools.openbrod.org/api/classes/generator.GeneratedContentManager.html)
|
|
564
587
|
|
|
565
588
|
#### Notes
|
|
566
589
|
|
|
567
590
|
- **Environment Variable**: The `GENERATOR_TEST` environment variable controls the test mode (`verify` or `generate`).
|
|
568
|
-
- **Testing Framework**: The examples use `vitest`, but the utilities can be used with any testing framework, if you are not using automatic workspace discovery, but rather define one test for one workspace using [langiumGeneratorTest](https://
|
|
591
|
+
- **Testing Framework**: The examples use `vitest`, but the utilities can be used with any testing framework, if you are not using automatic workspace discovery, but rather define one test for one workspace using [langiumGeneratorTest](https://langium-tools.openbrod.org/api/functions/testing.langiumGeneratorTest.html).
|
|
569
592
|
|
|
570
593
|
#### Example Workflow
|
|
571
594
|
|
|
@@ -883,16 +906,16 @@ test("document has no errors, ignoring lexer errors", async () => {
|
|
|
883
906
|
#### API Reference
|
|
884
907
|
|
|
885
908
|
- Matchers:
|
|
886
|
-
- [toHaveNoErrors](https://
|
|
887
|
-
- [toHaveNoIssues](https://
|
|
888
|
-
- [toHaveDocumentIssues](https://
|
|
889
|
-
- [toContainIssue](https://
|
|
909
|
+
- [toHaveNoErrors](https://langium-tools.openbrod.org/api/functions/testing.toHaveNoErrors.html)
|
|
910
|
+
- [toHaveNoIssues](https://langium-tools.openbrod.org/api/functions/testing.toHaveNoIssues.html)
|
|
911
|
+
- [toHaveDocumentIssues](https://langium-tools.openbrod.org/api/functions/testing.toHaveDocumentIssues.html)
|
|
912
|
+
- [toContainIssue](https://langium-tools.openbrod.org/api/functions/testing.toContainIssue.html)
|
|
890
913
|
- Interfaces:
|
|
891
|
-
- [IssueExpectation](https://
|
|
892
|
-
- [IgnoreParameters](https://
|
|
914
|
+
- [IssueExpectation](https://langium-tools.openbrod.org/api/interfaces/testing.IssueExpectation.html)
|
|
915
|
+
- [IgnoreParameters](https://langium-tools.openbrod.org/api/interfaces/testing.IgnoreParameters.html)
|
|
893
916
|
- Enums:
|
|
894
|
-
- [DocumentIssueSeverity](https://
|
|
895
|
-
- [DocumentIssueSource](https://
|
|
917
|
+
- [DocumentIssueSeverity](https://langium-tools.openbrod.org/api/types/base.DocumentIssue.html)
|
|
918
|
+
- [DocumentIssueSource](https://langium-tools.openbrod.org/api/enums/base.DocumentIssueSource.html)
|
|
896
919
|
|
|
897
920
|
#### Notes
|
|
898
921
|
|
|
@@ -903,7 +926,7 @@ test("document has no errors, ignoring lexer errors", async () => {
|
|
|
903
926
|
|
|
904
927
|
In the examples, you might notice the use of a <a href="#adjusted">`adjusted`</a> function to format template strings. This is a utility to clean up multiline strings in tests.
|
|
905
928
|
|
|
906
|
-
See [`adjusted` typedoc](https://
|
|
929
|
+
See [`adjusted` typedoc](https://langium-tools.openbrod.org/api/functions/base.adjusted.html) for more information.
|
|
907
930
|
|
|
908
931
|
#### Conclusion
|
|
909
932
|
|
|
@@ -919,7 +942,7 @@ For more detailed information, refer to the API documentation.
|
|
|
919
942
|
|
|
920
943
|
The adjusted function is a utility for formatting multi-line template strings, ensuring that indentation and line breaks are preserved correctly. This is particularly useful for generating code snippets or structured text where indentation is essential.
|
|
921
944
|
|
|
922
|
-
See [`adjusted` typedoc](https://
|
|
945
|
+
See [`adjusted` typedoc](https://langium-tools.openbrod.org/api/functions/base.adjusted.html) for more information.
|
|
923
946
|
|
|
924
947
|
##### Features
|
|
925
948
|
|
|
@@ -968,7 +991,7 @@ The function returns a formatted string with the following properties:
|
|
|
968
991
|
|
|
969
992
|
##### API Reference
|
|
970
993
|
|
|
971
|
-
- [adjusted](https://
|
|
994
|
+
- [adjusted](https://langium-tools.openbrod.org/api/functions/base.adjusted.html)
|
|
972
995
|
|
|
973
996
|
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
|
974
997
|
|
|
@@ -37,6 +37,79 @@ export var DocumentIssueSeverity;
|
|
|
37
37
|
* @param severity - The `DiagnosticSeverity` to map.
|
|
38
38
|
* @returns The corresponding `DocumentIssueSeverity`.
|
|
39
39
|
*/
|
|
40
|
+
/**
|
|
41
|
+
* LSP 3.18 allows a diagnostic message to be {@link MarkupContent}.
|
|
42
|
+
* Langium still emits plain strings. Keep the public issue message a string.
|
|
43
|
+
*/
|
|
44
|
+
function diagnosticMessage(message) {
|
|
45
|
+
return typeof message === 'string' ? message : message.value;
|
|
46
|
+
}
|
|
47
|
+
/** Codes Langium's `DocumentValidator` stores on copied lexer and parser diagnostics. */
|
|
48
|
+
const LEXING_ERROR = "lexing-error";
|
|
49
|
+
const PARSING_ERROR = "parsing-error";
|
|
50
|
+
function diagnosticCode(diagnostic) {
|
|
51
|
+
const data = diagnostic.data;
|
|
52
|
+
if (typeof data !== "object" || data === null || !("code" in data)) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
const code = data.code;
|
|
56
|
+
return typeof code === "string" ? code : undefined;
|
|
57
|
+
}
|
|
58
|
+
function syntaxSource(diagnostic) {
|
|
59
|
+
const code = diagnosticCode(diagnostic);
|
|
60
|
+
if (code === LEXING_ERROR) {
|
|
61
|
+
return DocumentIssueSource.LEXER;
|
|
62
|
+
}
|
|
63
|
+
if (code === PARSING_ERROR) {
|
|
64
|
+
return DocumentIssueSource.PARSER;
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Langium copies each lexer and parser error into `document.diagnostics` after validation.
|
|
70
|
+
* Prefer that copy: its range has an end position. Keep the offset from `parseResult`.
|
|
71
|
+
* A `parseResult` error with no matching diagnostic is kept as it is.
|
|
72
|
+
*/
|
|
73
|
+
function mergeSyntaxErrors(errors, diagnostics, source, fromParseResult, messageOf) {
|
|
74
|
+
const issues = [];
|
|
75
|
+
const used = new Set();
|
|
76
|
+
for (const error of errors) {
|
|
77
|
+
const message = messageOf(error);
|
|
78
|
+
const match = diagnostics.findIndex((diagnostic, index) => !used.has(index) && diagnosticMessage(diagnostic.message) === message);
|
|
79
|
+
const parsed = fromParseResult(error);
|
|
80
|
+
if (match >= 0) {
|
|
81
|
+
used.add(match);
|
|
82
|
+
const diagnostic = diagnostics[match];
|
|
83
|
+
issues.push({
|
|
84
|
+
source,
|
|
85
|
+
severity: mapSeverity(diagnostic.severity),
|
|
86
|
+
message: diagnosticMessage(diagnostic.message),
|
|
87
|
+
startOffset: parsed.startOffset,
|
|
88
|
+
startLine: diagnostic.range.start.line,
|
|
89
|
+
startColumn: diagnostic.range.start.character,
|
|
90
|
+
endLine: diagnostic.range.end.line,
|
|
91
|
+
endColumn: diagnostic.range.end.character,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
issues.push(parsed);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
diagnostics.forEach((diagnostic, index) => {
|
|
99
|
+
if (!used.has(index)) {
|
|
100
|
+
issues.push({
|
|
101
|
+
source,
|
|
102
|
+
severity: mapSeverity(diagnostic.severity),
|
|
103
|
+
message: diagnosticMessage(diagnostic.message),
|
|
104
|
+
startLine: diagnostic.range.start.line,
|
|
105
|
+
startColumn: diagnostic.range.start.character,
|
|
106
|
+
endLine: diagnostic.range.end.line,
|
|
107
|
+
endColumn: diagnostic.range.end.character,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
return issues;
|
|
112
|
+
}
|
|
40
113
|
function mapSeverity(severity) {
|
|
41
114
|
if (!severity) {
|
|
42
115
|
return DocumentIssueSeverity.UNKNOWN;
|
|
@@ -69,44 +142,43 @@ function mapSeverity(severity) {
|
|
|
69
142
|
export function getDocumentIssues(document, params) {
|
|
70
143
|
var _a;
|
|
71
144
|
const { skipNonErrorDiagnostics = false, skipLexerErrors = false, skipParserErrors = false, skipValidation = false, } = params || {};
|
|
145
|
+
const diagnostics = (_a = document.diagnostics) !== null && _a !== void 0 ? _a : [];
|
|
72
146
|
const issues = [];
|
|
73
147
|
if (!skipLexerErrors) {
|
|
74
|
-
document.parseResult.lexerErrors.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
});
|
|
83
|
-
});
|
|
148
|
+
issues.push(...mergeSyntaxErrors(document.parseResult.lexerErrors, diagnostics.filter((diagnostic) => syntaxSource(diagnostic) === DocumentIssueSource.LEXER), DocumentIssueSource.LEXER, (lexerIssue) => ({
|
|
149
|
+
source: DocumentIssueSource.LEXER,
|
|
150
|
+
message: lexerIssue.message,
|
|
151
|
+
severity: DocumentIssueSeverity.ERROR,
|
|
152
|
+
startOffset: lexerIssue.offset,
|
|
153
|
+
startLine: plus(lexerIssue.line, -1),
|
|
154
|
+
startColumn: plus(lexerIssue.column, -1),
|
|
155
|
+
}), (lexerIssue) => lexerIssue.message));
|
|
84
156
|
}
|
|
85
157
|
if (!skipParserErrors) {
|
|
86
|
-
document.parseResult.parserErrors.
|
|
87
|
-
//
|
|
158
|
+
issues.push(...mergeSyntaxErrors(document.parseResult.parserErrors, diagnostics.filter((diagnostic) => syntaxSource(diagnostic) === DocumentIssueSource.PARSER), DocumentIssueSource.PARSER, (parserError) => {
|
|
159
|
+
// Chevrotain exposes the token before the failure. Inserted EOF tokens use -1
|
|
160
|
+
// for offset, line, and column, which is not a real position.
|
|
88
161
|
const previousToken = parserError === null || parserError === void 0 ? void 0 : parserError.previousToken;
|
|
89
|
-
|
|
162
|
+
return {
|
|
90
163
|
source: DocumentIssueSource.PARSER,
|
|
91
164
|
severity: DocumentIssueSeverity.ERROR,
|
|
92
165
|
message: parserError.message,
|
|
93
166
|
startOffset: firstDefinedNumber(parserError.token.startOffset, previousToken === null || previousToken === void 0 ? void 0 : previousToken.startOffset),
|
|
94
167
|
startLine: plus(firstDefinedNumber(parserError.token.startLine, previousToken === null || previousToken === void 0 ? void 0 : previousToken.startLine), -1),
|
|
95
168
|
startColumn: plus(firstDefinedNumber(parserError.token.startColumn, previousToken === null || previousToken === void 0 ? void 0 : previousToken.startColumn), -1),
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
// endLine: plus(firstDefinedNumber(parserError.token.endLine, previousToken?.endLine), -1),
|
|
99
|
-
// endColumn: plus(firstDefinedNumber(parserError.token.endColumn, previousToken?.endColumn), 1),
|
|
100
|
-
});
|
|
101
|
-
});
|
|
169
|
+
};
|
|
170
|
+
}, (parserError) => parserError.message));
|
|
102
171
|
}
|
|
103
172
|
if (!skipValidation) {
|
|
104
|
-
|
|
173
|
+
diagnostics.forEach((diagnostic) => {
|
|
174
|
+
if (syntaxSource(diagnostic)) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
105
177
|
if (!skipNonErrorDiagnostics || diagnostic.severity === DiagnosticSeverity.Error) {
|
|
106
178
|
issues.push({
|
|
107
179
|
source: DocumentIssueSource.VALIDATION,
|
|
108
180
|
severity: mapSeverity(diagnostic.severity),
|
|
109
|
-
message: diagnostic.message,
|
|
181
|
+
message: diagnosticMessage(diagnostic.message),
|
|
110
182
|
startLine: diagnostic.range.start.line,
|
|
111
183
|
startColumn: diagnostic.range.start.character,
|
|
112
184
|
endLine: diagnostic.range.end.line,
|
|
@@ -280,17 +352,19 @@ function at(issue) {
|
|
|
280
352
|
return result;
|
|
281
353
|
}
|
|
282
354
|
/**
|
|
283
|
-
* Returns the first
|
|
355
|
+
* Returns the first usable source position from two options.
|
|
356
|
+
* `null`, `undefined`, `NaN`, and negative values are skipped. Chevrotain uses `-1`
|
|
357
|
+
* on inserted tokens (typically EOF) when it has no position.
|
|
284
358
|
*
|
|
285
359
|
* @param a - The first number to consider.
|
|
286
360
|
* @param b - The second number to consider.
|
|
287
|
-
* @returns The first
|
|
361
|
+
* @returns The first usable number, or `undefined` if both are unusable.
|
|
288
362
|
*/
|
|
289
363
|
function firstDefinedNumber(a, b) {
|
|
290
|
-
if (a != null && !Number.isNaN(a)) {
|
|
364
|
+
if (a != null && !Number.isNaN(a) && a >= 0) {
|
|
291
365
|
return a;
|
|
292
366
|
}
|
|
293
|
-
if (b != null && !Number.isNaN(b)) {
|
|
367
|
+
if (b != null && !Number.isNaN(b) && b >= 0) {
|
|
294
368
|
return b;
|
|
295
369
|
}
|
|
296
370
|
return undefined;
|
|
@@ -30,6 +30,12 @@ export interface GeneratorTestOptions<SERVICES, SHARED_SERVICES, MODEL extends A
|
|
|
30
30
|
generateForWorkspace?: (service: DslServices<SERVICES, SHARED_SERVICES>, documents: LangiumDocument<AstNode>[], workspaceFolder: WorkspaceFolder, targets?: GeneratorTarget[]) => Promise<GeneratedContentManager>;
|
|
31
31
|
generateForModel?: (services: ExtractServiceType<SERVICES>, document: MODEL, generatorOutput: GeneratorManager) => Promise<void>;
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Vitest title for one workspace.
|
|
35
|
+
* The `(generating)` suffix is only present in generate mode.
|
|
36
|
+
* `GeneratorMode.Generate` is `0`, so the mode must be compared by value.
|
|
37
|
+
*/
|
|
38
|
+
export declare function generatorWorkspaceTestName(testDirName: string, generateMode: GeneratorMode): string;
|
|
33
39
|
/**
|
|
34
40
|
* Run generator snapshot tests for all workspaces (subdirectories of the `testSuiteDir` directory).
|
|
35
41
|
* For each workspace there will be a tests added to vitest suite.
|
|
@@ -13,6 +13,15 @@ export var GeneratorMode;
|
|
|
13
13
|
})(GeneratorMode || (GeneratorMode = {}));
|
|
14
14
|
;
|
|
15
15
|
const globalGenerateMode = process.env.GENERATOR_TEST === "generate" ? GeneratorMode.Generate : GeneratorMode.Verify;
|
|
16
|
+
/**
|
|
17
|
+
* Vitest title for one workspace.
|
|
18
|
+
* The `(generating)` suffix is only present in generate mode.
|
|
19
|
+
* `GeneratorMode.Generate` is `0`, so the mode must be compared by value.
|
|
20
|
+
*/
|
|
21
|
+
export function generatorWorkspaceTestName(testDirName, generateMode) {
|
|
22
|
+
const suffix = generateMode === GeneratorMode.Generate ? ' (generating)' : '';
|
|
23
|
+
return `DSL-Workspace "${testDirName}"${suffix}`;
|
|
24
|
+
}
|
|
16
25
|
/**
|
|
17
26
|
* Run generator snapshot tests for all workspaces (subdirectories of the `testSuiteDir` directory).
|
|
18
27
|
* For each workspace there will be a tests added to vitest suite.
|
|
@@ -27,7 +36,7 @@ export function langiumGeneratorSuite(testSuiteDir, options, targets) {
|
|
|
27
36
|
.filter((dirent) => dirent.isDirectory())
|
|
28
37
|
.forEach((dirent) => {
|
|
29
38
|
const testDirName = dirent.name;
|
|
30
|
-
test(
|
|
39
|
+
test(generatorWorkspaceTestName(testDirName, generateMode), async () => {
|
|
31
40
|
await langiumGeneratorTest(path.join(testSuiteDir, testDirName), options, targets);
|
|
32
41
|
});
|
|
33
42
|
});
|
|
@@ -77,13 +86,21 @@ export async function langiumGeneratorTest(testDir, options, targets) {
|
|
|
77
86
|
if (generateMode === GeneratorMode.Generate) {
|
|
78
87
|
cleanDir(outputDir);
|
|
79
88
|
for (const { dir, metadataFile, target } of dirsAndTargets) {
|
|
89
|
+
// An empty target has nothing to commit. Git does not keep the empty directory.
|
|
90
|
+
if (generatedContentManager.getGeneratedContent(target.name).size === 0) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
80
93
|
await generatedContentManager.writeToDisk(dir, target.name);
|
|
81
94
|
writeMetaData(generatedContentManager, metadataFile, target.name);
|
|
82
95
|
}
|
|
83
96
|
}
|
|
84
97
|
else {
|
|
85
98
|
for (const { dir, metadataFile, target } of dirsAndTargets) {
|
|
86
|
-
|
|
99
|
+
const generatedContent = generatedContentManager.getGeneratedContent(target.name);
|
|
100
|
+
if (generatedContent.size === 0 && !fs.existsSync(dir) && !fs.existsSync(metadataFile)) {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
verifyFiles(generatedContent, dir, target.name);
|
|
87
104
|
verifyMetaData(generatedContentManager, metadataFile, target.name);
|
|
88
105
|
}
|
|
89
106
|
}
|
|
@@ -166,44 +166,40 @@ export declare function toContainIssue(document: LangiumDocument | ParsedDocumen
|
|
|
166
166
|
message: () => string;
|
|
167
167
|
};
|
|
168
168
|
/**
|
|
169
|
-
*
|
|
169
|
+
* Vitest builds `expect()` from Chai's `Assertion` in every supported line.
|
|
170
|
+
* Vitest's own `Assertion` is `Assertion<T>` before version 5 and `Assertion<R, T>` from 5 on.
|
|
171
|
+
* Those two declarations cannot be merged, so the matchers are added here instead.
|
|
170
172
|
*/
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
*/
|
|
203
|
-
declare module 'vitest' {
|
|
204
|
-
interface Assertion<T> extends LangiumMatchers<T> {
|
|
205
|
-
}
|
|
206
|
-
interface AsymmetricMatchersContaining<R = unknown> extends LangiumMatchers<R> {
|
|
173
|
+
declare global {
|
|
174
|
+
namespace Chai {
|
|
175
|
+
interface Assertion {
|
|
176
|
+
/**
|
|
177
|
+
* Asserts that a document has no errors after parsing.
|
|
178
|
+
* Non-error diagnostics (warnings, hints) are ignored by default.
|
|
179
|
+
*
|
|
180
|
+
* @param parameters - Optional parameters to customize which errors to ignore.
|
|
181
|
+
*/
|
|
182
|
+
toHaveNoErrors(parameters?: IgnoreParameters): void;
|
|
183
|
+
/**
|
|
184
|
+
* Asserts that a document has no issues after parsing.
|
|
185
|
+
*
|
|
186
|
+
* @param parameters - Optional parameters to customize which issues to ignore.
|
|
187
|
+
*/
|
|
188
|
+
toHaveNoIssues(parameters?: IgnoreParameters): void;
|
|
189
|
+
/**
|
|
190
|
+
* Asserts that a parsed document has specific issues at specified markers.
|
|
191
|
+
*
|
|
192
|
+
* @param expectedIssues - An array of expected issues.
|
|
193
|
+
* @param parameters - Optional parameters to customize which issues to ignore.
|
|
194
|
+
*/
|
|
195
|
+
toHaveDocumentIssues(expectedIssues: Array<IssueExpectation>, parameters?: IgnoreParameters): void;
|
|
196
|
+
/**
|
|
197
|
+
* Asserts that a document contains a specific issue.
|
|
198
|
+
*
|
|
199
|
+
* @param expectedIssue - The expected issue to look for.
|
|
200
|
+
* @param parameters - Optional parameters to customize which issues to ignore.
|
|
201
|
+
*/
|
|
202
|
+
toContainIssue(expectedIssue: IssueExpectation, parameters?: IgnoreParameters): void;
|
|
203
|
+
}
|
|
207
204
|
}
|
|
208
205
|
}
|
|
209
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langium-tools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "A set of tools for Langium",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -28,14 +28,18 @@
|
|
|
28
28
|
],
|
|
29
29
|
"author": "Boris Brodski",
|
|
30
30
|
"license": "MIT",
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": "^22.22.2 || ^24.15.0 || >=26",
|
|
33
|
+
"npm": ">=10.2.3"
|
|
34
|
+
},
|
|
31
35
|
"dependencies": {
|
|
32
36
|
"@types/node": "^22.0.0",
|
|
33
37
|
"change-case": "^5.4.4",
|
|
34
38
|
"escape-string-regexp": "^5.0.0",
|
|
35
|
-
"langium": "^
|
|
39
|
+
"langium": "^4.4.2"
|
|
36
40
|
},
|
|
37
41
|
"peerDependencies": {
|
|
38
|
-
"vitest": "
|
|
42
|
+
"vitest": "^2.1.9 || ^3.2.6 || >=4.1.0"
|
|
39
43
|
},
|
|
40
44
|
"devDependencies": {
|
|
41
45
|
"@eslint/js": "^9.8.0",
|
|
@@ -43,9 +47,9 @@
|
|
|
43
47
|
"typedoc": "^0.27.0",
|
|
44
48
|
"typedoc-plugin-extras": "^4.0.0",
|
|
45
49
|
"typedoc-plugin-markdown": "^3.0.0",
|
|
46
|
-
"typescript": "
|
|
50
|
+
"typescript": "~5.8.3",
|
|
47
51
|
"typescript-eslint": "^7.18.0",
|
|
48
|
-
"vitest": "
|
|
52
|
+
"vitest": "^5.1.1"
|
|
49
53
|
},
|
|
50
54
|
"overrides": {
|
|
51
55
|
"eslint": "^9.8.0"
|
|
@@ -56,5 +60,8 @@
|
|
|
56
60
|
"*.config.*",
|
|
57
61
|
"package-lock.json",
|
|
58
62
|
"*.json"
|
|
59
|
-
]
|
|
63
|
+
],
|
|
64
|
+
"volta": {
|
|
65
|
+
"node": "22.22.2"
|
|
66
|
+
}
|
|
60
67
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./string.js";
|
|
2
2
|
import { LangiumDocument } from "langium";
|
|
3
|
-
import { DiagnosticSeverity } from "vscode-languageserver";
|
|
3
|
+
import { Diagnostic, DiagnosticSeverity, MarkupContent } from "vscode-languageserver";
|
|
4
4
|
import type { IToken } from 'chevrotain';
|
|
5
5
|
import { EOL } from "node:os";
|
|
6
6
|
|
|
@@ -131,6 +131,91 @@ export interface GetDocumentIssuesParams {
|
|
|
131
131
|
* @param severity - The `DiagnosticSeverity` to map.
|
|
132
132
|
* @returns The corresponding `DocumentIssueSeverity`.
|
|
133
133
|
*/
|
|
134
|
+
/**
|
|
135
|
+
* LSP 3.18 allows a diagnostic message to be {@link MarkupContent}.
|
|
136
|
+
* Langium still emits plain strings. Keep the public issue message a string.
|
|
137
|
+
*/
|
|
138
|
+
function diagnosticMessage(message: string | MarkupContent): string {
|
|
139
|
+
return typeof message === 'string' ? message : message.value;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Codes Langium's `DocumentValidator` stores on copied lexer and parser diagnostics. */
|
|
143
|
+
const LEXING_ERROR = "lexing-error";
|
|
144
|
+
const PARSING_ERROR = "parsing-error";
|
|
145
|
+
|
|
146
|
+
function diagnosticCode(diagnostic: Diagnostic): string | undefined {
|
|
147
|
+
const data = diagnostic.data;
|
|
148
|
+
if (typeof data !== "object" || data === null || !("code" in data)) {
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
const code = (data as { code?: unknown }).code;
|
|
152
|
+
return typeof code === "string" ? code : undefined;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function syntaxSource(diagnostic: Diagnostic): DocumentIssueSource.LEXER | DocumentIssueSource.PARSER | undefined {
|
|
156
|
+
const code = diagnosticCode(diagnostic);
|
|
157
|
+
if (code === LEXING_ERROR) {
|
|
158
|
+
return DocumentIssueSource.LEXER;
|
|
159
|
+
}
|
|
160
|
+
if (code === PARSING_ERROR) {
|
|
161
|
+
return DocumentIssueSource.PARSER;
|
|
162
|
+
}
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Langium copies each lexer and parser error into `document.diagnostics` after validation.
|
|
168
|
+
* Prefer that copy: its range has an end position. Keep the offset from `parseResult`.
|
|
169
|
+
* A `parseResult` error with no matching diagnostic is kept as it is.
|
|
170
|
+
*/
|
|
171
|
+
function mergeSyntaxErrors<T>(
|
|
172
|
+
errors: readonly T[],
|
|
173
|
+
diagnostics: readonly Diagnostic[],
|
|
174
|
+
source: DocumentIssueSource,
|
|
175
|
+
fromParseResult: (error: T) => DocumentIssue,
|
|
176
|
+
messageOf: (error: T) => string,
|
|
177
|
+
): DocumentIssue[] {
|
|
178
|
+
const issues: DocumentIssue[] = [];
|
|
179
|
+
const used = new Set<number>();
|
|
180
|
+
for (const error of errors) {
|
|
181
|
+
const message = messageOf(error);
|
|
182
|
+
const match = diagnostics.findIndex((diagnostic, index) =>
|
|
183
|
+
!used.has(index) && diagnosticMessage(diagnostic.message) === message
|
|
184
|
+
);
|
|
185
|
+
const parsed = fromParseResult(error);
|
|
186
|
+
if (match >= 0) {
|
|
187
|
+
used.add(match);
|
|
188
|
+
const diagnostic = diagnostics[match];
|
|
189
|
+
issues.push({
|
|
190
|
+
source,
|
|
191
|
+
severity: mapSeverity(diagnostic.severity),
|
|
192
|
+
message: diagnosticMessage(diagnostic.message),
|
|
193
|
+
startOffset: parsed.startOffset,
|
|
194
|
+
startLine: diagnostic.range.start.line,
|
|
195
|
+
startColumn: diagnostic.range.start.character,
|
|
196
|
+
endLine: diagnostic.range.end.line,
|
|
197
|
+
endColumn: diagnostic.range.end.character,
|
|
198
|
+
});
|
|
199
|
+
} else {
|
|
200
|
+
issues.push(parsed);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
diagnostics.forEach((diagnostic, index) => {
|
|
204
|
+
if (!used.has(index)) {
|
|
205
|
+
issues.push({
|
|
206
|
+
source,
|
|
207
|
+
severity: mapSeverity(diagnostic.severity),
|
|
208
|
+
message: diagnosticMessage(diagnostic.message),
|
|
209
|
+
startLine: diagnostic.range.start.line,
|
|
210
|
+
startColumn: diagnostic.range.start.character,
|
|
211
|
+
endLine: diagnostic.range.end.line,
|
|
212
|
+
endColumn: diagnostic.range.end.character,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
return issues;
|
|
217
|
+
}
|
|
218
|
+
|
|
134
219
|
function mapSeverity(severity?: DiagnosticSeverity): DocumentIssueSeverity {
|
|
135
220
|
if (!severity) {
|
|
136
221
|
return DocumentIssueSeverity.UNKNOWN;
|
|
@@ -172,47 +257,57 @@ export function getDocumentIssues(
|
|
|
172
257
|
skipValidation = false,
|
|
173
258
|
} = params || {};
|
|
174
259
|
|
|
260
|
+
const diagnostics = document.diagnostics ?? [];
|
|
175
261
|
const issues: DocumentIssue[] = [];
|
|
176
262
|
if (!skipLexerErrors) {
|
|
177
|
-
|
|
178
|
-
|
|
263
|
+
issues.push(...mergeSyntaxErrors(
|
|
264
|
+
document.parseResult.lexerErrors,
|
|
265
|
+
diagnostics.filter((diagnostic) => syntaxSource(diagnostic) === DocumentIssueSource.LEXER),
|
|
266
|
+
DocumentIssueSource.LEXER,
|
|
267
|
+
(lexerIssue) => ({
|
|
179
268
|
source: DocumentIssueSource.LEXER,
|
|
180
269
|
message: lexerIssue.message,
|
|
181
270
|
severity: DocumentIssueSeverity.ERROR,
|
|
182
271
|
startOffset: lexerIssue.offset,
|
|
183
272
|
startLine: plus(lexerIssue.line, -1),
|
|
184
273
|
startColumn: plus(lexerIssue.column, -1),
|
|
185
|
-
})
|
|
186
|
-
|
|
274
|
+
}),
|
|
275
|
+
(lexerIssue) => lexerIssue.message,
|
|
276
|
+
));
|
|
187
277
|
}
|
|
188
278
|
|
|
189
279
|
if (!skipParserErrors) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
280
|
+
issues.push(...mergeSyntaxErrors(
|
|
281
|
+
document.parseResult.parserErrors,
|
|
282
|
+
diagnostics.filter((diagnostic) => syntaxSource(diagnostic) === DocumentIssueSource.PARSER),
|
|
283
|
+
DocumentIssueSource.PARSER,
|
|
284
|
+
(parserError) => {
|
|
285
|
+
// Chevrotain exposes the token before the failure. Inserted EOF tokens use -1
|
|
286
|
+
// for offset, line, and column, which is not a real position.
|
|
287
|
+
const previousToken = (parserError as unknown as { previousToken: IToken })?.previousToken as IToken;
|
|
288
|
+
return {
|
|
289
|
+
source: DocumentIssueSource.PARSER,
|
|
290
|
+
severity: DocumentIssueSeverity.ERROR,
|
|
291
|
+
message: parserError.message,
|
|
292
|
+
startOffset: firstDefinedNumber(parserError.token.startOffset, previousToken?.startOffset),
|
|
293
|
+
startLine: plus(firstDefinedNumber(parserError.token.startLine, previousToken?.startLine), -1),
|
|
294
|
+
startColumn: plus(firstDefinedNumber(parserError.token.startColumn, previousToken?.startColumn), -1),
|
|
295
|
+
};
|
|
296
|
+
},
|
|
297
|
+
(parserError) => parserError.message,
|
|
298
|
+
));
|
|
207
299
|
}
|
|
208
300
|
|
|
209
301
|
if (!skipValidation) {
|
|
210
|
-
|
|
302
|
+
diagnostics.forEach((diagnostic) => {
|
|
303
|
+
if (syntaxSource(diagnostic)) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
211
306
|
if (!skipNonErrorDiagnostics || diagnostic.severity === DiagnosticSeverity.Error) {
|
|
212
307
|
issues.push({
|
|
213
308
|
source: DocumentIssueSource.VALIDATION,
|
|
214
309
|
severity: mapSeverity(diagnostic.severity),
|
|
215
|
-
message: diagnostic.message,
|
|
310
|
+
message: diagnosticMessage(diagnostic.message),
|
|
216
311
|
startLine: diagnostic.range.start.line,
|
|
217
312
|
startColumn: diagnostic.range.start.character,
|
|
218
313
|
endLine: diagnostic.range.end.line,
|
|
@@ -403,17 +498,19 @@ function at(issue: DocumentIssue): string {
|
|
|
403
498
|
}
|
|
404
499
|
|
|
405
500
|
/**
|
|
406
|
-
* Returns the first
|
|
501
|
+
* Returns the first usable source position from two options.
|
|
502
|
+
* `null`, `undefined`, `NaN`, and negative values are skipped. Chevrotain uses `-1`
|
|
503
|
+
* on inserted tokens (typically EOF) when it has no position.
|
|
407
504
|
*
|
|
408
505
|
* @param a - The first number to consider.
|
|
409
506
|
* @param b - The second number to consider.
|
|
410
|
-
* @returns The first
|
|
507
|
+
* @returns The first usable number, or `undefined` if both are unusable.
|
|
411
508
|
*/
|
|
412
509
|
function firstDefinedNumber(a?: number, b?: number): number | undefined {
|
|
413
|
-
if (a != null && !Number.isNaN(a)) {
|
|
510
|
+
if (a != null && !Number.isNaN(a) && a >= 0) {
|
|
414
511
|
return a;
|
|
415
512
|
}
|
|
416
|
-
if (b != null && !Number.isNaN(b)) {
|
|
513
|
+
if (b != null && !Number.isNaN(b) && b >= 0) {
|
|
417
514
|
return b;
|
|
418
515
|
}
|
|
419
516
|
return undefined;
|
|
@@ -65,6 +65,16 @@ export interface GeneratorTestOptions<SERVICES, SHARED_SERVICES, MODEL extends A
|
|
|
65
65
|
|
|
66
66
|
const globalGenerateMode = process.env.GENERATOR_TEST === "generate" ? GeneratorMode.Generate : GeneratorMode.Verify;
|
|
67
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Vitest title for one workspace.
|
|
70
|
+
* The `(generating)` suffix is only present in generate mode.
|
|
71
|
+
* `GeneratorMode.Generate` is `0`, so the mode must be compared by value.
|
|
72
|
+
*/
|
|
73
|
+
export function generatorWorkspaceTestName(testDirName: string, generateMode: GeneratorMode): string {
|
|
74
|
+
const suffix = generateMode === GeneratorMode.Generate ? ' (generating)' : '';
|
|
75
|
+
return `DSL-Workspace "${testDirName}"${suffix}`;
|
|
76
|
+
}
|
|
77
|
+
|
|
68
78
|
/**
|
|
69
79
|
* Run generator snapshot tests for all workspaces (subdirectories of the `testSuiteDir` directory).
|
|
70
80
|
* For each workspace there will be a tests added to vitest suite.
|
|
@@ -80,7 +90,7 @@ export function langiumGeneratorSuite<SERVICES, SHARED_SERVICES, MODEL extends A
|
|
|
80
90
|
.forEach((dirent) => {
|
|
81
91
|
const testDirName = dirent.name;
|
|
82
92
|
|
|
83
|
-
test(
|
|
93
|
+
test(generatorWorkspaceTestName(testDirName, generateMode), async () => {
|
|
84
94
|
await langiumGeneratorTest<SERVICES, SHARED_SERVICES, MODEL>(path.join(testSuiteDir, testDirName), options, targets);
|
|
85
95
|
});
|
|
86
96
|
});
|
|
@@ -143,12 +153,20 @@ export async function langiumGeneratorTest<SERVICES, SHARED_SERVICES, MODEL exte
|
|
|
143
153
|
if (generateMode === GeneratorMode.Generate) {
|
|
144
154
|
cleanDir(outputDir);
|
|
145
155
|
for (const { dir, metadataFile, target } of dirsAndTargets) {
|
|
156
|
+
// An empty target has nothing to commit. Git does not keep the empty directory.
|
|
157
|
+
if (generatedContentManager.getGeneratedContent(target.name).size === 0) {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
146
160
|
await generatedContentManager.writeToDisk(dir, target.name);
|
|
147
161
|
writeMetaData(generatedContentManager, metadataFile, target.name);
|
|
148
162
|
}
|
|
149
163
|
} else {
|
|
150
164
|
for (const { dir, metadataFile, target } of dirsAndTargets) {
|
|
151
|
-
|
|
165
|
+
const generatedContent = generatedContentManager.getGeneratedContent(target.name);
|
|
166
|
+
if (generatedContent.size === 0 && !fs.existsSync(dir) && !fs.existsSync(metadataFile)) {
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
verifyFiles(generatedContent, dir, target.name);
|
|
152
170
|
verifyMetaData(generatedContentManager, metadataFile, target.name);
|
|
153
171
|
}
|
|
154
172
|
}
|
package/src/testing/matchers.ts
CHANGED
|
@@ -411,61 +411,72 @@ expect.extend({
|
|
|
411
411
|
});
|
|
412
412
|
|
|
413
413
|
/**
|
|
414
|
-
*
|
|
414
|
+
* Vitest builds `expect()` from Chai's `Assertion` in every supported line.
|
|
415
|
+
* Vitest's own `Assertion` is `Assertion<T>` before version 5 and `Assertion<R, T>` from 5 on.
|
|
416
|
+
* Those two declarations cannot be merged, so the matchers are added here instead.
|
|
415
417
|
*/
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
? (expectedIssue: IssueExpectation, parameters?: IgnoreParameters) => void
|
|
457
|
-
: never;
|
|
418
|
+
declare global {
|
|
419
|
+
// Chai publishes this surface as a global namespace. Vitest copies it onto `expect()`.
|
|
420
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
421
|
+
namespace Chai {
|
|
422
|
+
interface Assertion {
|
|
423
|
+
/**
|
|
424
|
+
* Asserts that a document has no errors after parsing.
|
|
425
|
+
* Non-error diagnostics (warnings, hints) are ignored by default.
|
|
426
|
+
*
|
|
427
|
+
* @param parameters - Optional parameters to customize which errors to ignore.
|
|
428
|
+
*/
|
|
429
|
+
toHaveNoErrors(parameters?: IgnoreParameters): void;
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Asserts that a document has no issues after parsing.
|
|
433
|
+
*
|
|
434
|
+
* @param parameters - Optional parameters to customize which issues to ignore.
|
|
435
|
+
*/
|
|
436
|
+
toHaveNoIssues(parameters?: IgnoreParameters): void;
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Asserts that a parsed document has specific issues at specified markers.
|
|
440
|
+
*
|
|
441
|
+
* @param expectedIssues - An array of expected issues.
|
|
442
|
+
* @param parameters - Optional parameters to customize which issues to ignore.
|
|
443
|
+
*/
|
|
444
|
+
toHaveDocumentIssues(
|
|
445
|
+
expectedIssues: Array<IssueExpectation>,
|
|
446
|
+
parameters?: IgnoreParameters
|
|
447
|
+
): void;
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Asserts that a document contains a specific issue.
|
|
451
|
+
*
|
|
452
|
+
* @param expectedIssue - The expected issue to look for.
|
|
453
|
+
* @param parameters - Optional parameters to customize which issues to ignore.
|
|
454
|
+
*/
|
|
455
|
+
toContainIssue(expectedIssue: IssueExpectation, parameters?: IgnoreParameters): void;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
458
|
}
|
|
459
459
|
|
|
460
|
+
type AssertTrue<T extends true> = T;
|
|
461
|
+
type ExpectOf<T> = typeof expect extends (value: T) => infer R ? R : never;
|
|
462
|
+
|
|
460
463
|
/**
|
|
461
|
-
*
|
|
464
|
+
* Fails the build when Vitest stops copying these Chai methods onto `expect()`.
|
|
462
465
|
*/
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
466
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
467
|
+
type _LangiumMatchersOnExpect = AssertTrue<
|
|
468
|
+
ExpectOf<LangiumDocument> extends {
|
|
469
|
+
toHaveNoErrors(parameters?: IgnoreParameters): void;
|
|
470
|
+
toHaveNoIssues(parameters?: IgnoreParameters): void;
|
|
471
|
+
toContainIssue(expectedIssue: IssueExpectation, parameters?: IgnoreParameters): void;
|
|
472
|
+
}
|
|
473
|
+
? ExpectOf<ParsedDocument> extends {
|
|
474
|
+
toHaveDocumentIssues(expectedIssues: Array<IssueExpectation>, parameters?: IgnoreParameters): void;
|
|
475
|
+
}
|
|
476
|
+
? true
|
|
477
|
+
: false
|
|
478
|
+
: false
|
|
479
|
+
>;
|
|
469
480
|
|
|
470
481
|
/**
|
|
471
482
|
* Converts an issue expectation into a readable string representation.
|