langium-tools 0.1.0 → 0.1.2
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 +15 -8
- package/dist/base/arrays.d.ts +20 -0
- package/dist/base/arrays.js +10 -0
- package/dist/testing/generator-testing.d.ts +1 -0
- package/dist/testing/generator-testing.js +2 -0
- package/package.json +1 -1
- package/src/base/arrays.ts +20 -0
- package/src/testing/generator-testing.ts +2 -0
package/README.md
CHANGED
|
@@ -594,7 +594,10 @@ You can customize the behavior by providing custom implementations for optional
|
|
|
594
594
|
#### Example: Custom Validation
|
|
595
595
|
|
|
596
596
|
```typescript
|
|
597
|
-
function customValidateDocuments(
|
|
597
|
+
function customValidateDocuments(
|
|
598
|
+
services: DslServices<MyDslService, MyDslSharedService>,
|
|
599
|
+
documents: LangiumDocument<MyModel>[],
|
|
600
|
+
) {
|
|
598
601
|
documents.forEach((doc) => {
|
|
599
602
|
const issues = getDocumentIssues(doc);
|
|
600
603
|
expect(issues.length).toBe(0);
|
|
@@ -676,7 +679,8 @@ const parsedDocument = await parseWithMarks(
|
|
|
676
679
|
|
|
677
680
|
state [[[UnusedRule]]];
|
|
678
681
|
`,
|
|
679
|
-
"[[[",
|
|
682
|
+
"[[[",
|
|
683
|
+
"]]]",
|
|
680
684
|
);
|
|
681
685
|
```
|
|
682
686
|
|
|
@@ -802,8 +806,8 @@ test("document contains specific issue", async () => {
|
|
|
802
806
|
##### Asserting No Errors
|
|
803
807
|
|
|
804
808
|
```typescript
|
|
805
|
-
test(
|
|
806
|
-
const document = await parse(
|
|
809
|
+
test("document has no errors", async () => {
|
|
810
|
+
const document = await parse("validCode");
|
|
807
811
|
expect(document).toHaveNoErrors();
|
|
808
812
|
});
|
|
809
813
|
```
|
|
@@ -811,25 +815,25 @@ test('document has no errors', async () => {
|
|
|
811
815
|
##### Asserting Specific Issues with Markers
|
|
812
816
|
|
|
813
817
|
```typescript
|
|
814
|
-
test(
|
|
818
|
+
test("document has expected validation issue at marker", async () => {
|
|
815
819
|
const dslCode = adjusted`
|
|
816
820
|
grammar MyLanguage
|
|
817
821
|
entry Rule: name=ID;
|
|
818
822
|
<<<UnusedRule>>>: name=ID;
|
|
819
823
|
terminal ID: /\\^?[_a-zA-Z][\\w_]*/;
|
|
820
824
|
`;
|
|
821
|
-
const parsedDocument = await parseWithMarks(parse, dslCode,
|
|
825
|
+
const parsedDocument = await parseWithMarks(parse, dslCode, "<<<", ">>>");
|
|
822
826
|
|
|
823
827
|
expect(parsedDocument).toHaveDocumentIssues([
|
|
824
828
|
{
|
|
825
829
|
source: DocumentIssueSource.VALIDATION, // Optional
|
|
826
830
|
severity: DocumentIssueSeverity.WARNING, // Optional
|
|
827
|
-
message:
|
|
831
|
+
message: "This rule is declared but never referenced.",
|
|
828
832
|
markerId: 0, // Optional
|
|
829
833
|
},
|
|
830
834
|
]);
|
|
831
835
|
});
|
|
832
|
-
|
|
836
|
+
```
|
|
833
837
|
|
|
834
838
|
##### Asserting Issue Matching Regex
|
|
835
839
|
|
|
@@ -1028,6 +1032,7 @@ generateJavaFile("MyClass", "com.example.project", generatorManager, (imp) => ex
|
|
|
1028
1032
|
##### Explanation:
|
|
1029
1033
|
|
|
1030
1034
|
- **Imports**:
|
|
1035
|
+
|
|
1031
1036
|
- The passed `imp` function is used to import `java.util.Properties`. It returns the appropriate class name (`Properties` in this case), handling imports automatically.
|
|
1032
1037
|
|
|
1033
1038
|
- **Generated Output**:
|
|
@@ -1119,6 +1124,8 @@ Don't forget to give the project a star! Thanks again!
|
|
|
1119
1124
|
|
|
1120
1125
|
4. Open a Pull Request
|
|
1121
1126
|
|
|
1127
|
+
5. Release with release-it
|
|
1128
|
+
|
|
1122
1129
|
### Top contributors:
|
|
1123
1130
|
|
|
1124
1131
|
<a href="https://github.com/borisbrodski/langium-tools/graphs/contributors">
|
package/dist/base/arrays.d.ts
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
declare global {
|
|
2
2
|
interface Array<T> {
|
|
3
|
+
/**
|
|
4
|
+
* Sorts an array in place.
|
|
5
|
+
* This method mutates the array and returns a reference to the same array.
|
|
6
|
+
* @param key Function used to determine the order of the elements. It is expected to return
|
|
7
|
+
* a comparable value for this item to sort upon.
|
|
8
|
+
* ```ts
|
|
9
|
+
* [{size: 11, name: 'John'}, {size: 22, name: 'Max'}].sortBy(obj => obj.name)
|
|
10
|
+
* ```
|
|
11
|
+
* @returns this
|
|
12
|
+
*/
|
|
3
13
|
sortBy<K extends keyof T, V>(key: K | ((item: T) => V)): this;
|
|
4
14
|
}
|
|
5
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Sorts an array in place.
|
|
18
|
+
* This method mutates the array and returns a reference to the same array.
|
|
19
|
+
* @param key Function used to determine the order of the elements. It is expected to return
|
|
20
|
+
* a comparable value for this item to sort upon.
|
|
21
|
+
* ```ts
|
|
22
|
+
* [{size: 11, name: 'John'}, {size: 22, name: 'Max'}].sortBy(obj => obj.name)
|
|
23
|
+
* ```
|
|
24
|
+
* @returns list (sorting in place)
|
|
25
|
+
*/
|
|
6
26
|
export declare function arraySortBy<T, K extends keyof T, V>(list: T[], key: K | ((item: T) => V)): T[];
|
package/dist/base/arrays.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
Array.prototype.sortBy = function (key) {
|
|
2
2
|
return arraySortBy(this, key);
|
|
3
3
|
};
|
|
4
|
+
/**
|
|
5
|
+
* Sorts an array in place.
|
|
6
|
+
* This method mutates the array and returns a reference to the same array.
|
|
7
|
+
* @param key Function used to determine the order of the elements. It is expected to return
|
|
8
|
+
* a comparable value for this item to sort upon.
|
|
9
|
+
* ```ts
|
|
10
|
+
* [{size: 11, name: 'John'}, {size: 22, name: 'Max'}].sortBy(obj => obj.name)
|
|
11
|
+
* ```
|
|
12
|
+
* @returns list (sorting in place)
|
|
13
|
+
*/
|
|
4
14
|
export function arraySortBy(list, key) {
|
|
5
15
|
const comparator = typeof key === 'function'
|
|
6
16
|
? key
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AstNode, LangiumDocument, WorkspaceFolder } from 'langium';
|
|
2
2
|
import { type DefaultSharedModuleContext, type LangiumSharedServices } from 'langium/lsp';
|
|
3
3
|
import { GeneratorManager, GeneratedContentManager, GeneratorTarget } from '../generator/generated-content-manager.js';
|
|
4
|
+
import "../base/arrays.js";
|
|
4
5
|
type DslServices<SERVICES, SHARED_SERVICES> = {
|
|
5
6
|
shared: LangiumSharedServices & SHARED_SERVICES;
|
|
6
7
|
} & SERVICES;
|
|
@@ -5,6 +5,7 @@ import fs from 'fs';
|
|
|
5
5
|
import { expect, test } from 'vitest';
|
|
6
6
|
import { getDocumentIssueSummary } from '../base/document-issues.js';
|
|
7
7
|
import { GeneratedContentManager, DEFAULT_TARGET } from '../generator/generated-content-manager.js';
|
|
8
|
+
import "../base/arrays.js";
|
|
8
9
|
export var GeneratorMode;
|
|
9
10
|
(function (GeneratorMode) {
|
|
10
11
|
GeneratorMode[GeneratorMode["Generate"] = 0] = "Generate";
|
|
@@ -166,6 +167,7 @@ function writeMetaData(generatedContent, metadataJsonFile, target) {
|
|
|
166
167
|
generatedContent.getGeneratedContent(target).forEach((contentData, fileName) => {
|
|
167
168
|
metadata.generatedFiles.push({ filename: fileName, overwrite: contentData.overwrite });
|
|
168
169
|
});
|
|
170
|
+
metadata.generatedFiles.sortBy(m => m.filename);
|
|
169
171
|
fs.writeFileSync(metadataJsonFile, JSON.stringify(metadata, null, 2));
|
|
170
172
|
}
|
|
171
173
|
/**
|
package/package.json
CHANGED
package/src/base/arrays.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
declare global {
|
|
2
2
|
interface Array<T> {
|
|
3
|
+
/**
|
|
4
|
+
* Sorts an array in place.
|
|
5
|
+
* This method mutates the array and returns a reference to the same array.
|
|
6
|
+
* @param key Function used to determine the order of the elements. It is expected to return
|
|
7
|
+
* a comparable value for this item to sort upon.
|
|
8
|
+
* ```ts
|
|
9
|
+
* [{size: 11, name: 'John'}, {size: 22, name: 'Max'}].sortBy(obj => obj.name)
|
|
10
|
+
* ```
|
|
11
|
+
* @returns this
|
|
12
|
+
*/
|
|
3
13
|
sortBy<K extends keyof T, V>(key: K | ((item: T) => V)): this;
|
|
4
14
|
}
|
|
5
15
|
}
|
|
@@ -9,6 +19,16 @@ Array.prototype.sortBy = function <T, K extends keyof T, V>(key: K | ((item: T)
|
|
|
9
19
|
};
|
|
10
20
|
|
|
11
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Sorts an array in place.
|
|
24
|
+
* This method mutates the array and returns a reference to the same array.
|
|
25
|
+
* @param key Function used to determine the order of the elements. It is expected to return
|
|
26
|
+
* a comparable value for this item to sort upon.
|
|
27
|
+
* ```ts
|
|
28
|
+
* [{size: 11, name: 'John'}, {size: 22, name: 'Max'}].sortBy(obj => obj.name)
|
|
29
|
+
* ```
|
|
30
|
+
* @returns list (sorting in place)
|
|
31
|
+
*/
|
|
12
32
|
export function arraySortBy<T, K extends keyof T, V>(list: T[], key: K | ((item: T) => V)): T[] {
|
|
13
33
|
const comparator = typeof key === 'function'
|
|
14
34
|
? key
|
|
@@ -6,6 +6,7 @@ import fs from 'fs';
|
|
|
6
6
|
import { expect, test } from 'vitest';
|
|
7
7
|
import { getDocumentIssueSummary } from '../base/document-issues.js';
|
|
8
8
|
import { GeneratedContent, GeneratorManager, GeneratedContentManager, GeneratorTarget, DEFAULT_TARGET } from '../generator/generated-content-manager.js';
|
|
9
|
+
import "../base/arrays.js";
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
type DslServices<SERVICES, SHARED_SERVICES> = { shared: LangiumSharedServices & SHARED_SERVICES } & SERVICES;
|
|
@@ -246,6 +247,7 @@ function writeMetaData(generatedContent: GeneratedContentManager, metadataJsonFi
|
|
|
246
247
|
generatedContent.getGeneratedContent(target).forEach((contentData, fileName) => {
|
|
247
248
|
metadata.generatedFiles.push({ filename: fileName, overwrite: contentData.overwrite });
|
|
248
249
|
});
|
|
250
|
+
metadata.generatedFiles.sortBy(m => m.filename);
|
|
249
251
|
fs.writeFileSync(metadataJsonFile, JSON.stringify(metadata, null, 2));
|
|
250
252
|
}
|
|
251
253
|
|