@likec4/language-server 0.37.1 → 0.40.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/dist/Rpc.d.ts +6 -0
- package/dist/Rpc.js +130 -0
- package/dist/ast.d.ts +0 -97
- package/dist/ast.js +127 -143
- package/dist/elementRef.d.ts +1 -2
- package/dist/elementRef.js +31 -44
- package/dist/generated/ast.d.ts +4 -5
- package/dist/generated/ast.js +310 -315
- package/dist/generated/grammar.d.ts +0 -2
- package/dist/generated/grammar.js +2 -3177
- package/dist/generated/module.d.ts +1 -6
- package/dist/generated/module.js +13 -18
- package/dist/index.d.ts +0 -1
- package/dist/index.js +2 -3
- package/dist/logger.d.ts +0 -1
- package/dist/logger.js +39 -42
- package/dist/lsp/CodeLensProvider.d.ts +0 -1
- package/dist/lsp/CodeLensProvider.js +28 -32
- package/dist/lsp/DocumentLinkProvider.d.ts +0 -1
- package/dist/lsp/DocumentLinkProvider.js +26 -33
- package/dist/lsp/DocumentSymbolProvider.d.ts +0 -1
- package/dist/lsp/DocumentSymbolProvider.js +165 -167
- package/dist/lsp/HoverProvider.d.ts +0 -1
- package/dist/lsp/HoverProvider.js +35 -48
- package/dist/lsp/SemanticTokenProvider.d.ts +0 -1
- package/dist/lsp/SemanticTokenProvider.js +153 -201
- package/dist/lsp/index.d.ts +0 -1
- package/dist/lsp/index.js +5 -6
- package/dist/model/fqn-computation.d.ts +0 -1
- package/dist/model/fqn-computation.js +39 -40
- package/dist/model/fqn-index.d.ts +0 -1
- package/dist/model/fqn-index.js +112 -142
- package/dist/model/index.d.ts +0 -1
- package/dist/model/index.js +5 -6
- package/dist/model/model-builder.d.ts +10 -6
- package/dist/model/model-builder.js +242 -177
- package/dist/model/model-locator.d.ts +1 -2
- package/dist/model/model-locator.js +102 -100
- package/dist/model/model-parser.d.ts +2 -7
- package/dist/model/model-parser.js +296 -287
- package/dist/module.d.ts +4 -2
- package/dist/module.js +69 -60
- package/dist/protocol.d.ts +16 -20
- package/dist/protocol.js +14 -22
- package/dist/references/index.d.ts +0 -1
- package/dist/references/index.js +2 -3
- package/dist/references/scope-computation.d.ts +2 -3
- package/dist/references/scope-computation.js +68 -70
- package/dist/references/scope-provider.d.ts +1 -2
- package/dist/references/scope-provider.js +126 -116
- package/dist/shared/WorkspaceManager.d.ts +2 -4
- package/dist/shared/WorkspaceManager.js +13 -16
- package/dist/shared/index.d.ts +0 -1
- package/dist/shared/index.js +1 -2
- package/dist/test/index.d.ts +0 -1
- package/dist/test/index.js +1 -2
- package/dist/test/testServices.d.ts +6 -7
- package/dist/test/testServices.js +64 -61
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +4 -3
- package/dist/validation/element.d.ts +0 -2
- package/dist/validation/element.js +28 -39
- package/dist/validation/index.d.ts +0 -1
- package/dist/validation/index.js +36 -46
- package/dist/validation/relation.d.ts +0 -2
- package/dist/validation/relation.js +43 -47
- package/dist/validation/specification.d.ts +0 -2
- package/dist/validation/specification.js +21 -30
- package/dist/validation/view.d.ts +0 -2
- package/dist/validation/view.js +16 -22
- package/package.json +20 -13
- package/contrib/likec4.monarch.ts +0 -48
- package/contrib/likec4.tmLanguage.json +0 -73
- package/dist/registerProtocolHandlers.d.ts +0 -3
- package/dist/registerProtocolHandlers.js +0 -112
|
@@ -1,129 +1,139 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {
|
|
2
|
+
DONE_RESULT,
|
|
3
|
+
DefaultScopeProvider,
|
|
4
|
+
EMPTY_STREAM,
|
|
5
|
+
StreamImpl,
|
|
6
|
+
StreamScope,
|
|
7
|
+
getDocument,
|
|
8
|
+
stream,
|
|
9
|
+
findNodeForProperty,
|
|
10
|
+
toDocumentSegment
|
|
11
|
+
} from "langium";
|
|
12
|
+
import { ast } from "../ast.js";
|
|
13
|
+
import { elementRef, isElementRefHead, parentFqnElementRef } from "../elementRef.js";
|
|
14
|
+
import { logError } from "../logger.js";
|
|
5
15
|
function toAstNodeDescription(entry) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
const $cstNode = findNodeForProperty(entry.el.$cstNode, "name");
|
|
17
|
+
return {
|
|
18
|
+
documentUri: entry.doc.uri,
|
|
19
|
+
name: entry.name,
|
|
20
|
+
...entry.el.$cstNode && {
|
|
21
|
+
selectionSegment: toDocumentSegment(entry.el.$cstNode)
|
|
22
|
+
},
|
|
23
|
+
...$cstNode && {
|
|
24
|
+
nameSegment: toDocumentSegment($cstNode)
|
|
25
|
+
},
|
|
26
|
+
path: entry.path,
|
|
27
|
+
type: ast.Element
|
|
28
|
+
};
|
|
19
29
|
}
|
|
20
30
|
export class LikeC4ScopeProvider extends DefaultScopeProvider {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return null;
|
|
38
|
-
}, iterator => {
|
|
39
|
-
if (iterator) {
|
|
40
|
-
return iterator.next();
|
|
41
|
-
}
|
|
42
|
-
return DONE_RESULT;
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
scopeElementRef(ref) {
|
|
46
|
-
const parentNode = ref.$container;
|
|
47
|
-
if (!ast.isElementRef(parentNode)) {
|
|
48
|
-
throw new Error('Expected be inside ElementRef');
|
|
31
|
+
fqnIndex;
|
|
32
|
+
constructor(services) {
|
|
33
|
+
super(services);
|
|
34
|
+
this.fqnIndex = services.likec4.FqnIndex;
|
|
35
|
+
}
|
|
36
|
+
directChildrenOf(parent) {
|
|
37
|
+
return this.fqnIndex.directChildrenOf(parent).map(toAstNodeDescription);
|
|
38
|
+
}
|
|
39
|
+
// we need lazy resolving here
|
|
40
|
+
uniqueDescedants(of) {
|
|
41
|
+
return new StreamImpl(
|
|
42
|
+
() => {
|
|
43
|
+
const element = of();
|
|
44
|
+
const fqn = element && this.fqnIndex.getFqn(element);
|
|
45
|
+
if (fqn) {
|
|
46
|
+
return this.fqnIndex.uniqueDescedants(fqn).map(toAstNodeDescription).iterator();
|
|
49
47
|
}
|
|
50
|
-
return
|
|
48
|
+
return null;
|
|
49
|
+
},
|
|
50
|
+
(iterator) => {
|
|
51
|
+
if (iterator) {
|
|
52
|
+
return iterator.next();
|
|
53
|
+
}
|
|
54
|
+
return DONE_RESULT;
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
scopeElementRef(ref) {
|
|
59
|
+
const parentNode = ref.$container;
|
|
60
|
+
if (!ast.isElementRef(parentNode)) {
|
|
61
|
+
throw new Error("Expected be inside ElementRef");
|
|
51
62
|
}
|
|
52
|
-
|
|
53
|
-
|
|
63
|
+
return this.uniqueDescedants(() => parentNode.el.ref);
|
|
64
|
+
}
|
|
65
|
+
scopeExtendElement(extend) {
|
|
66
|
+
return this.uniqueDescedants(() => elementRef(extend.element));
|
|
67
|
+
}
|
|
68
|
+
scopeElementView({ viewOf, extends: ext }) {
|
|
69
|
+
if (ext) {
|
|
70
|
+
return stream([ext]).flatMap((v) => {
|
|
71
|
+
const view = v.view.ref;
|
|
72
|
+
return view ? this.scopeElementView(view) : EMPTY_STREAM;
|
|
73
|
+
});
|
|
54
74
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return stream([ext]).flatMap(v => {
|
|
58
|
-
const view = v.view.ref;
|
|
59
|
-
return view ? this.scopeElementView(view) : EMPTY_STREAM;
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
if (viewOf) {
|
|
63
|
-
return this.uniqueDescedants(() => elementRef(viewOf));
|
|
64
|
-
}
|
|
65
|
-
return EMPTY_STREAM;
|
|
75
|
+
if (viewOf) {
|
|
76
|
+
return this.uniqueDescedants(() => elementRef(viewOf));
|
|
66
77
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
const parent = parentFqnElementRef(container);
|
|
78
|
-
return new StreamScope(this.directChildrenOf(parent));
|
|
79
|
-
}
|
|
80
|
-
if (ast.isElementRef(container) && !isElementRefHead(container)) {
|
|
81
|
-
return new StreamScope(this.scopeElementRef(container));
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return this.computeScope(container, referenceType);
|
|
85
|
-
}
|
|
86
|
-
catch (e) {
|
|
87
|
-
logError(e);
|
|
78
|
+
return EMPTY_STREAM;
|
|
79
|
+
}
|
|
80
|
+
getScope(context) {
|
|
81
|
+
const referenceType = this.reflection.getReferenceType(context);
|
|
82
|
+
try {
|
|
83
|
+
const container = context.container;
|
|
84
|
+
if (referenceType === ast.Element) {
|
|
85
|
+
if (ast.isStrictElementRef(container)) {
|
|
86
|
+
if (isElementRefHead(container)) {
|
|
88
87
|
return this.getGlobalScope(referenceType);
|
|
88
|
+
}
|
|
89
|
+
const parent = parentFqnElementRef(container);
|
|
90
|
+
return new StreamScope(this.directChildrenOf(parent));
|
|
89
91
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const scopes = [];
|
|
93
|
-
const doc = getDocument(node);
|
|
94
|
-
const precomputed = doc.precomputedScopes;
|
|
95
|
-
const byReferenceType = (desc) => this.reflection.isSubtype(desc.type, referenceType);
|
|
96
|
-
if (precomputed) {
|
|
97
|
-
const elements = precomputed.get(node).filter(byReferenceType);
|
|
98
|
-
if (elements.length > 0) {
|
|
99
|
-
scopes.push(stream(elements));
|
|
100
|
-
}
|
|
101
|
-
let container = node.$container;
|
|
102
|
-
while (container) {
|
|
103
|
-
const elements = precomputed.get(container).filter(byReferenceType);
|
|
104
|
-
if (elements.length > 0) {
|
|
105
|
-
scopes.push(stream(elements));
|
|
106
|
-
}
|
|
107
|
-
if (referenceType === ast.Element) {
|
|
108
|
-
if (ast.isExtendElementBody(container)) {
|
|
109
|
-
scopes.push(this.scopeExtendElement(container.$container));
|
|
110
|
-
}
|
|
111
|
-
if (ast.isElementViewBody(container)) {
|
|
112
|
-
scopes.push(this.scopeElementView(container.$container));
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
container = container.$container;
|
|
116
|
-
}
|
|
92
|
+
if (ast.isElementRef(container) && !isElementRefHead(container)) {
|
|
93
|
+
return new StreamScope(this.scopeElementRef(container));
|
|
117
94
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
95
|
+
}
|
|
96
|
+
return this.computeScope(container, referenceType);
|
|
97
|
+
} catch (e) {
|
|
98
|
+
logError(e);
|
|
99
|
+
return this.getGlobalScope(referenceType);
|
|
121
100
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
101
|
+
}
|
|
102
|
+
computeScope(node, referenceType) {
|
|
103
|
+
const scopes = [];
|
|
104
|
+
const doc = getDocument(node);
|
|
105
|
+
const precomputed = doc.precomputedScopes;
|
|
106
|
+
const byReferenceType = (desc) => this.reflection.isSubtype(desc.type, referenceType);
|
|
107
|
+
if (precomputed) {
|
|
108
|
+
const elements = precomputed.get(node).filter(byReferenceType);
|
|
109
|
+
if (elements.length > 0) {
|
|
110
|
+
scopes.push(stream(elements));
|
|
111
|
+
}
|
|
112
|
+
let container = node.$container;
|
|
113
|
+
while (container) {
|
|
114
|
+
const elements2 = precomputed.get(container).filter(byReferenceType);
|
|
115
|
+
if (elements2.length > 0) {
|
|
116
|
+
scopes.push(stream(elements2));
|
|
117
|
+
}
|
|
118
|
+
if (referenceType === ast.Element) {
|
|
119
|
+
if (ast.isExtendElementBody(container)) {
|
|
120
|
+
scopes.push(this.scopeExtendElement(container.$container));
|
|
121
|
+
}
|
|
122
|
+
if (ast.isElementViewBody(container)) {
|
|
123
|
+
scopes.push(this.scopeElementView(container.$container));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
container = container.$container;
|
|
127
|
+
}
|
|
127
128
|
}
|
|
129
|
+
return scopes.reduceRight((outerScope, elements) => {
|
|
130
|
+
return this.createScope(elements, outerScope);
|
|
131
|
+
}, this.getGlobalScope(referenceType));
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Create a global scope filtered for the given reference type.
|
|
135
|
+
*/
|
|
136
|
+
getGlobalScope(referenceType) {
|
|
137
|
+
return new StreamScope(this.indexManager.allElements(referenceType));
|
|
138
|
+
}
|
|
128
139
|
}
|
|
129
|
-
//# sourceMappingURL=scope-provider.js.map
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import type { LangiumDocument
|
|
1
|
+
import type { LangiumDocument } from 'langium';
|
|
2
2
|
import { DefaultWorkspaceManager } from 'langium';
|
|
3
3
|
import type { WorkspaceFolder } from 'vscode-languageserver';
|
|
4
4
|
export declare class LikeC4WorkspaceManager extends DefaultWorkspaceManager {
|
|
5
|
-
protected readonly documentFactory: LangiumDocumentFactory;
|
|
6
|
-
constructor(services: LangiumSharedServices);
|
|
7
5
|
/**
|
|
8
6
|
* Load all additional documents that shall be visible in the context of the given workspace
|
|
9
7
|
* folders and add them to the collector. This can be used to include built-in libraries of
|
|
10
8
|
* your language, which can be either loaded from provided files or constructed in memory.
|
|
11
9
|
*/
|
|
12
10
|
protected loadAdditionalDocuments(_folders: WorkspaceFolder[], _collector: (document: LangiumDocument) => void): Promise<void>;
|
|
11
|
+
workspace(): any;
|
|
13
12
|
}
|
|
14
|
-
//# sourceMappingURL=WorkspaceManager.d.ts.map
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { nonNullable } from "@likec4/core";
|
|
2
|
+
import { DefaultWorkspaceManager } from "langium";
|
|
2
3
|
export class LikeC4WorkspaceManager extends DefaultWorkspaceManager {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
// collector(this.documentFactory.fromString(builtin.specification.document, URI.parse(builtin.specification.uri)))
|
|
15
|
-
return Promise.resolve();
|
|
16
|
-
}
|
|
4
|
+
/**
|
|
5
|
+
* Load all additional documents that shall be visible in the context of the given workspace
|
|
6
|
+
* folders and add them to the collector. This can be used to include built-in libraries of
|
|
7
|
+
* your language, which can be either loaded from provided files or constructed in memory.
|
|
8
|
+
*/
|
|
9
|
+
loadAdditionalDocuments(_folders, _collector) {
|
|
10
|
+
return Promise.resolve();
|
|
11
|
+
}
|
|
12
|
+
workspace() {
|
|
13
|
+
return this.folders && this.folders.length > 0 ? nonNullable(this.folders[0]) : null;
|
|
14
|
+
}
|
|
17
15
|
}
|
|
18
|
-
//# sourceMappingURL=WorkspaceManager.js.map
|
package/dist/shared/index.d.ts
CHANGED
package/dist/shared/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from "./WorkspaceManager.js";
|
package/dist/test/index.d.ts
CHANGED
package/dist/test/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from "./testServices.js";
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import type { LikeC4LangiumDocument } from '../ast';
|
|
2
2
|
export declare function createTestServices(workspace?: string): {
|
|
3
|
-
services:
|
|
3
|
+
services: any;
|
|
4
4
|
parse: (input: string, uri?: string) => Promise<LikeC4LangiumDocument>;
|
|
5
5
|
validate: (input: string | LikeC4LangiumDocument, uri?: string) => Promise<{
|
|
6
6
|
document: LikeC4LangiumDocument;
|
|
7
|
-
diagnostics:
|
|
8
|
-
errors:
|
|
7
|
+
diagnostics: any;
|
|
8
|
+
errors: any;
|
|
9
9
|
}>;
|
|
10
10
|
validateAll: () => Promise<{
|
|
11
|
-
diagnostics:
|
|
12
|
-
errors:
|
|
11
|
+
diagnostics: any;
|
|
12
|
+
errors: any;
|
|
13
13
|
}>;
|
|
14
|
-
buildModel: () => Promise<
|
|
14
|
+
buildModel: () => Promise<any>;
|
|
15
15
|
};
|
|
16
|
-
//# sourceMappingURL=testServices.d.ts.map
|
|
@@ -1,65 +1,68 @@
|
|
|
1
|
-
import { createLanguageServices } from
|
|
2
|
-
import { EmptyFileSystem } from
|
|
3
|
-
import { URI, Utils } from
|
|
4
|
-
import stripIndent from
|
|
5
|
-
export function createTestServices(workspace =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const docs = langiumDocuments.all.toArray();
|
|
42
|
-
await documentBuilder.build(docs, { validation: true });
|
|
43
|
-
const diagnostics = docs.flatMap(doc => doc.diagnostics ?? []);
|
|
44
|
-
const errors = diagnostics.map(d => d.message);
|
|
45
|
-
return {
|
|
46
|
-
diagnostics,
|
|
47
|
-
errors
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
const buildModel = async () => {
|
|
51
|
-
await validateAll();
|
|
52
|
-
const model = modelBuilder.buildModel();
|
|
53
|
-
if (!model)
|
|
54
|
-
throw new Error('No model found');
|
|
55
|
-
return model;
|
|
1
|
+
import { createLanguageServices } from "../module.js";
|
|
2
|
+
import { EmptyFileSystem } from "langium";
|
|
3
|
+
import { URI, Utils } from "vscode-uri";
|
|
4
|
+
import stripIndent from "strip-indent";
|
|
5
|
+
export function createTestServices(workspace = "file:///test/workspace") {
|
|
6
|
+
const services = createLanguageServices(EmptyFileSystem).likec4;
|
|
7
|
+
const metaData = services.LanguageMetaData;
|
|
8
|
+
const langiumDocuments = services.shared.workspace.LangiumDocuments;
|
|
9
|
+
const documentBuilder = services.shared.workspace.DocumentBuilder;
|
|
10
|
+
const modelBuilder = services.likec4.ModelBuilder;
|
|
11
|
+
const workspaceUri = URI.parse(workspace);
|
|
12
|
+
const workspaceFolder = {
|
|
13
|
+
name: "test",
|
|
14
|
+
uri: workspaceUri.toString()
|
|
15
|
+
};
|
|
16
|
+
const initPromise = services.shared.workspace.WorkspaceManager.initializeWorkspace([workspaceFolder]);
|
|
17
|
+
void initPromise.finally(() => {
|
|
18
|
+
Object.assign(services.shared.workspace.WorkspaceManager, {
|
|
19
|
+
folders: [workspaceFolder]
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
let documentIndex = 1;
|
|
23
|
+
const parse = async (input, uri) => {
|
|
24
|
+
await initPromise;
|
|
25
|
+
const docUri = Utils.resolvePath(workspaceUri, "./src/", uri ?? `${documentIndex++}${metaData.fileExtensions[0]}`);
|
|
26
|
+
const document = services.shared.workspace.LangiumDocumentFactory.fromString(stripIndent(input), docUri);
|
|
27
|
+
langiumDocuments.addDocument(document);
|
|
28
|
+
await documentBuilder.build([document], { validation: false });
|
|
29
|
+
return document;
|
|
30
|
+
};
|
|
31
|
+
const validate = async (input, uri) => {
|
|
32
|
+
await initPromise;
|
|
33
|
+
const document = typeof input === "string" ? await parse(input, uri) : input;
|
|
34
|
+
await documentBuilder.build([document], { validation: true });
|
|
35
|
+
const diagnostics = document.diagnostics ?? [];
|
|
36
|
+
const errors = diagnostics.map((d) => d.message);
|
|
37
|
+
return {
|
|
38
|
+
document,
|
|
39
|
+
diagnostics,
|
|
40
|
+
errors
|
|
56
41
|
};
|
|
42
|
+
};
|
|
43
|
+
const validateAll = async () => {
|
|
44
|
+
await initPromise;
|
|
45
|
+
const docs = langiumDocuments.all.toArray();
|
|
46
|
+
await documentBuilder.build(docs, { validation: true });
|
|
47
|
+
const diagnostics = docs.flatMap((doc) => doc.diagnostics ?? []);
|
|
48
|
+
const errors = diagnostics.map((d) => d.message);
|
|
57
49
|
return {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
validate,
|
|
61
|
-
validateAll,
|
|
62
|
-
buildModel
|
|
50
|
+
diagnostics,
|
|
51
|
+
errors
|
|
63
52
|
};
|
|
53
|
+
};
|
|
54
|
+
const buildModel = async () => {
|
|
55
|
+
await validateAll();
|
|
56
|
+
const model = modelBuilder.buildModel();
|
|
57
|
+
if (!model)
|
|
58
|
+
throw new Error("No model found");
|
|
59
|
+
return model;
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
services,
|
|
63
|
+
parse,
|
|
64
|
+
validate,
|
|
65
|
+
validateAll,
|
|
66
|
+
buildModel
|
|
67
|
+
};
|
|
64
68
|
}
|
|
65
|
-
//# sourceMappingURL=testServices.js.map
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
1
|
+
export const printDocs = (docs) => docs.map((d) => " - " + d.uri.path).join("\n");
|
|
2
|
+
export function queueMicrotask(cb) {
|
|
3
|
+
return Promise.resolve().then(cb);
|
|
4
|
+
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { type ValidationCheck } from 'langium';
|
|
2
1
|
import type { ast } from '../ast';
|
|
3
2
|
import type { LikeC4Services } from '../module';
|
|
4
3
|
export declare const elementChecks: (services: LikeC4Services) => ValidationCheck<ast.Element>;
|
|
5
|
-
//# sourceMappingURL=element.d.ts.map
|
|
@@ -1,41 +1,30 @@
|
|
|
1
|
-
import { getDocument } from
|
|
1
|
+
import { getDocument } from "langium";
|
|
2
2
|
export const elementChecks = (services) => {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
// for (let i = 3; i < el.props.length; i++) {
|
|
33
|
-
// accept('error', `Too many properties, max 3 allowed`, {
|
|
34
|
-
// node: el,
|
|
35
|
-
// property: 'props',
|
|
36
|
-
// index: i
|
|
37
|
-
// })
|
|
38
|
-
// }
|
|
39
|
-
};
|
|
3
|
+
const fqnIndex = services.likec4.FqnIndex;
|
|
4
|
+
return (el, accept) => {
|
|
5
|
+
const fqn = fqnIndex.getFqn(el);
|
|
6
|
+
if (!fqn) {
|
|
7
|
+
accept("error", "Not indexed element", {
|
|
8
|
+
node: el,
|
|
9
|
+
property: "name"
|
|
10
|
+
});
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const withSameFqn = fqnIndex.byFqn(fqn).filter((v) => v.el !== el).head();
|
|
14
|
+
if (withSameFqn) {
|
|
15
|
+
accept("error", `Duplicate element name ${el.name !== fqn ? el.name + " (" + fqn + ")" : el.name}`, {
|
|
16
|
+
node: el,
|
|
17
|
+
property: "name",
|
|
18
|
+
relatedInformation: [
|
|
19
|
+
{
|
|
20
|
+
location: {
|
|
21
|
+
range: withSameFqn.el.$cstNode.range,
|
|
22
|
+
uri: getDocument(withSameFqn.el).uri.toString()
|
|
23
|
+
},
|
|
24
|
+
message: `Already defined here`
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
};
|
|
40
30
|
};
|
|
41
|
-
//# sourceMappingURL=element.js.map
|