@likec4/language-server 0.37.0 → 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 -157
- 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
package/dist/Rpc.d.ts
ADDED
package/dist/Rpc.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { logError, logger } from "./logger.js";
|
|
2
|
+
import pThrottle from "p-throttle";
|
|
3
|
+
import { nonexhaustive } from "@likec4/core";
|
|
4
|
+
import { URI } from "langium";
|
|
5
|
+
import { isLikeC4LangiumDocument } from "./ast.js";
|
|
6
|
+
import {
|
|
7
|
+
buildDocuments,
|
|
8
|
+
computeView,
|
|
9
|
+
fetchModel,
|
|
10
|
+
fetchRawModel,
|
|
11
|
+
locate,
|
|
12
|
+
onDidChangeModel,
|
|
13
|
+
rebuild
|
|
14
|
+
} from "./protocol.js";
|
|
15
|
+
export class Rpc {
|
|
16
|
+
constructor(services) {
|
|
17
|
+
this.services = services;
|
|
18
|
+
}
|
|
19
|
+
init() {
|
|
20
|
+
const { ModelBuilder: modelBuilder, ModelLocator: modelLocator } = this.services.likec4;
|
|
21
|
+
const connection = this.services.shared.lsp.Connection;
|
|
22
|
+
if (!connection) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
logger.info(`[ServerRpc] init`);
|
|
26
|
+
const LangiumDocuments = this.services.shared.workspace.LangiumDocuments;
|
|
27
|
+
const DocumentBuilder = this.services.shared.workspace.DocumentBuilder;
|
|
28
|
+
const notifyClient = pThrottle({
|
|
29
|
+
limit: 4,
|
|
30
|
+
interval: 1e3
|
|
31
|
+
})(() => connection.sendNotification(onDidChangeModel, ""));
|
|
32
|
+
modelBuilder.onModelParsed(() => {
|
|
33
|
+
void notifyClient();
|
|
34
|
+
});
|
|
35
|
+
connection.onRequest(fetchModel, async (_cancelToken) => {
|
|
36
|
+
let model;
|
|
37
|
+
try {
|
|
38
|
+
model = modelBuilder.buildModel() ?? null;
|
|
39
|
+
} catch (e) {
|
|
40
|
+
model = null;
|
|
41
|
+
logError(e);
|
|
42
|
+
}
|
|
43
|
+
return Promise.resolve({ model });
|
|
44
|
+
});
|
|
45
|
+
connection.onRequest(fetchRawModel, async (_cancelToken) => {
|
|
46
|
+
let rawmodel;
|
|
47
|
+
try {
|
|
48
|
+
rawmodel = modelBuilder.buildRawModel() ?? null;
|
|
49
|
+
} catch (e) {
|
|
50
|
+
rawmodel = null;
|
|
51
|
+
logError(e);
|
|
52
|
+
}
|
|
53
|
+
return Promise.resolve({ rawmodel });
|
|
54
|
+
});
|
|
55
|
+
connection.onRequest(computeView, ({ viewId }) => {
|
|
56
|
+
return {
|
|
57
|
+
view: modelBuilder.computeView(viewId)
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
connection.onRequest(rebuild, async (cancelToken) => {
|
|
61
|
+
const changed = LangiumDocuments.all.map((d) => {
|
|
62
|
+
if (isLikeC4LangiumDocument(d)) {
|
|
63
|
+
delete d.c4Specification;
|
|
64
|
+
delete d.c4Elements;
|
|
65
|
+
delete d.c4Relations;
|
|
66
|
+
delete d.c4Views;
|
|
67
|
+
delete d.c4fqns;
|
|
68
|
+
}
|
|
69
|
+
return d.uri;
|
|
70
|
+
}).toArray();
|
|
71
|
+
logger.debug(`[ServerRpc] rebuild all documents: [
|
|
72
|
+
${changed.map((d) => d.toString()).join("\n ")}
|
|
73
|
+
]`);
|
|
74
|
+
await DocumentBuilder.update(changed, [], cancelToken);
|
|
75
|
+
return {
|
|
76
|
+
docs: changed.map((d) => d.toString())
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
connection.onRequest(buildDocuments, async ({ docs }, cancelToken) => {
|
|
80
|
+
if (docs.length === 0) {
|
|
81
|
+
logger.debug(`[ServerRpc] received empty request to rebuild`);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
logger.debug(
|
|
85
|
+
`[ServerRpc] received request to buildDocuments:
|
|
86
|
+
${docs.map((d) => " - " + d).join("\n")}`
|
|
87
|
+
);
|
|
88
|
+
const changed = [];
|
|
89
|
+
for (const d of docs) {
|
|
90
|
+
try {
|
|
91
|
+
const uri = URI.parse(d);
|
|
92
|
+
if (LangiumDocuments.hasDocument(uri)) {
|
|
93
|
+
changed.push(uri);
|
|
94
|
+
} else {
|
|
95
|
+
logger.warn(`[ServerRpc] LangiumDocuments does not have document: ${d}`);
|
|
96
|
+
LangiumDocuments.getOrCreateDocument(uri);
|
|
97
|
+
}
|
|
98
|
+
} catch (e) {
|
|
99
|
+
logError(e);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (changed.length !== docs.length) {
|
|
103
|
+
const all = LangiumDocuments.all.map((d) => d.uri.toString()).toArray();
|
|
104
|
+
logger.warn(
|
|
105
|
+
`
|
|
106
|
+
[ServerRpc] We have in LangiumDocuments: [
|
|
107
|
+
${all.join("\n ")}
|
|
108
|
+
]
|
|
109
|
+
We rebuild: [
|
|
110
|
+
${changed.join("\n ")}
|
|
111
|
+
]
|
|
112
|
+
`.trim()
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
await DocumentBuilder.update(changed, [], cancelToken);
|
|
116
|
+
});
|
|
117
|
+
connection.onRequest(locate, (params) => {
|
|
118
|
+
if ("element" in params) {
|
|
119
|
+
return modelLocator.locateElement(params.element, params.property ?? "name");
|
|
120
|
+
}
|
|
121
|
+
if ("relation" in params) {
|
|
122
|
+
return modelLocator.locateRelation(params.relation);
|
|
123
|
+
}
|
|
124
|
+
if ("view" in params) {
|
|
125
|
+
return modelLocator.locateView(params.view);
|
|
126
|
+
}
|
|
127
|
+
nonexhaustive(params);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
package/dist/ast.d.ts
CHANGED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { type c4 } from '@likec4/core';
|
|
2
|
-
import type { LangiumDocument, MultiMap } from 'langium';
|
|
3
|
-
import type { LikeC4Document } from './generated/ast';
|
|
4
|
-
import * as ast from './generated/ast';
|
|
5
|
-
export { ast };
|
|
6
|
-
declare module './generated/ast' {
|
|
7
|
-
interface Element {
|
|
8
|
-
fqn?: c4.Fqn;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
export interface ParsedAstSpecification {
|
|
12
|
-
kinds: Record<c4.ElementKind, {
|
|
13
|
-
shape?: c4.ElementShape;
|
|
14
|
-
color?: c4.ThemeColor;
|
|
15
|
-
icon?: c4.IconUrl;
|
|
16
|
-
}>;
|
|
17
|
-
}
|
|
18
|
-
export interface ParsedAstElement {
|
|
19
|
-
id: c4.Fqn;
|
|
20
|
-
astPath: string;
|
|
21
|
-
kind: c4.ElementKind;
|
|
22
|
-
title: string;
|
|
23
|
-
description?: string;
|
|
24
|
-
technology?: string;
|
|
25
|
-
icon?: c4.IconUrl;
|
|
26
|
-
tags?: c4.NonEmptyArray<c4.Tag>;
|
|
27
|
-
links?: c4.NonEmptyArray<string>;
|
|
28
|
-
shape?: c4.ElementShape;
|
|
29
|
-
color?: c4.ThemeColor;
|
|
30
|
-
}
|
|
31
|
-
export interface ParsedAstRelation {
|
|
32
|
-
id: c4.RelationID;
|
|
33
|
-
astPath: string;
|
|
34
|
-
source: c4.Fqn;
|
|
35
|
-
target: c4.Fqn;
|
|
36
|
-
title: string;
|
|
37
|
-
}
|
|
38
|
-
export interface ParsedAstElementView {
|
|
39
|
-
id: c4.ViewID;
|
|
40
|
-
viewOf?: c4.Fqn;
|
|
41
|
-
extends?: c4.ViewID;
|
|
42
|
-
astPath: string;
|
|
43
|
-
title?: string;
|
|
44
|
-
description?: string;
|
|
45
|
-
tags?: c4.NonEmptyArray<c4.Tag>;
|
|
46
|
-
links?: c4.NonEmptyArray<string>;
|
|
47
|
-
rules: c4.ViewRule[];
|
|
48
|
-
}
|
|
49
|
-
export declare const ElementViewOps: {
|
|
50
|
-
writeId(node: ast.ElementView, id: c4.ViewID): ast.ElementView;
|
|
51
|
-
readId(node: ast.ElementView): c4.ViewID | undefined;
|
|
52
|
-
};
|
|
53
|
-
export declare const ElementOps: {
|
|
54
|
-
writeId(node: ast.Element, id: c4.Fqn | null): ast.Element;
|
|
55
|
-
readId(node: ast.Element): c4.Fqn | undefined;
|
|
56
|
-
};
|
|
57
|
-
export interface DocFqnIndexEntry {
|
|
58
|
-
name: string;
|
|
59
|
-
el: WeakRef<ast.Element>;
|
|
60
|
-
path: string;
|
|
61
|
-
}
|
|
62
|
-
export interface LikeC4DocumentProps {
|
|
63
|
-
c4Specification?: ParsedAstSpecification;
|
|
64
|
-
c4Elements?: ParsedAstElement[];
|
|
65
|
-
c4Relations?: ParsedAstRelation[];
|
|
66
|
-
c4Views?: ParsedAstElementView[];
|
|
67
|
-
c4fqns?: MultiMap<c4.Fqn, DocFqnIndexEntry>;
|
|
68
|
-
}
|
|
69
|
-
export interface LikeC4LangiumDocument extends LangiumDocument<LikeC4Document>, LikeC4DocumentProps {
|
|
70
|
-
}
|
|
71
|
-
export type ParsedLikeC4LangiumDocument = Omit<LikeC4LangiumDocument, keyof LikeC4DocumentProps> & Required<LikeC4DocumentProps>;
|
|
72
|
-
export declare function cleanParsedModel(doc: LikeC4LangiumDocument): {
|
|
73
|
-
elements: ParsedAstElement[];
|
|
74
|
-
relations: ParsedAstRelation[];
|
|
75
|
-
views: ParsedAstElementView[];
|
|
76
|
-
specification: ParsedAstSpecification;
|
|
77
|
-
};
|
|
78
|
-
export declare function isLikeC4LangiumDocument(doc: LangiumDocument): doc is LikeC4LangiumDocument;
|
|
79
|
-
export declare function isParsedLikeC4LangiumDocument(doc: LangiumDocument): doc is ParsedLikeC4LangiumDocument;
|
|
80
|
-
export declare const isValidLikeC4LangiumDocument: (doc: LangiumDocument) => doc is ParsedLikeC4LangiumDocument;
|
|
81
|
-
export declare function streamModel(doc: LikeC4LangiumDocument): Generator<ast.Relation | ast.Element, void, unknown>;
|
|
82
|
-
export declare function resolveRelationPoints(node: ast.Relation): {
|
|
83
|
-
source: ast.Element;
|
|
84
|
-
target: ast.Element;
|
|
85
|
-
};
|
|
86
|
-
export declare function toElementStyle(props?: ast.StyleProperties['props']): {
|
|
87
|
-
color?: c4.ThemeColor;
|
|
88
|
-
shape?: c4.ElementShape;
|
|
89
|
-
icon?: c4.IconUrl;
|
|
90
|
-
};
|
|
91
|
-
export declare function toElementStyleExcludeDefaults(props?: ast.StyleProperties['props']): {
|
|
92
|
-
shape?: "person" | "browser" | "mobile" | "cylinder" | "storage" | "queue";
|
|
93
|
-
color?: "amber" | "blue" | "gray" | "slate" | "green" | "indigo" | "muted" | "red" | "secondary" | "sky";
|
|
94
|
-
icon?: c4.IconUrl;
|
|
95
|
-
};
|
|
96
|
-
export declare function toAutoLayout(direction: ast.ViewRuleLayoutDirection): c4.ViewRuleAutoLayout['autoLayout'];
|
|
97
|
-
//# sourceMappingURL=ast.d.ts.map
|
package/dist/ast.js
CHANGED
|
@@ -1,175 +1,159 @@
|
|
|
1
|
-
import { DefaultElementShape, DefaultThemeColor, RelationRefError, nonexhaustive } from
|
|
2
|
-
import { DocumentState } from
|
|
3
|
-
import { elementRef } from
|
|
4
|
-
import * as ast from
|
|
5
|
-
import { LikeC4LanguageMetaData } from
|
|
1
|
+
import { DefaultElementShape, DefaultThemeColor, RelationRefError, nonexhaustive } from "@likec4/core";
|
|
2
|
+
import { DocumentState } from "langium";
|
|
3
|
+
import { elementRef } from "./elementRef.js";
|
|
4
|
+
import * as ast from "./generated/ast.js";
|
|
5
|
+
import { LikeC4LanguageMetaData } from "./generated/module.js";
|
|
6
6
|
export { ast };
|
|
7
|
-
const idattr = Symbol.for(
|
|
7
|
+
const idattr = Symbol.for("idattr");
|
|
8
8
|
export const ElementViewOps = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return node[idattr];
|
|
18
|
-
}
|
|
9
|
+
writeId(node, id) {
|
|
10
|
+
;
|
|
11
|
+
node[idattr] = id;
|
|
12
|
+
return node;
|
|
13
|
+
},
|
|
14
|
+
readId(node) {
|
|
15
|
+
return node[idattr];
|
|
16
|
+
}
|
|
19
17
|
};
|
|
20
18
|
export const ElementOps = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
;
|
|
30
|
-
node[idattr] = id;
|
|
31
|
-
node.fqn = id;
|
|
32
|
-
}
|
|
33
|
-
return node;
|
|
34
|
-
},
|
|
35
|
-
readId(node) {
|
|
36
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
-
return node[idattr];
|
|
19
|
+
writeId(node, id) {
|
|
20
|
+
if (id === null) {
|
|
21
|
+
delete node[idattr];
|
|
22
|
+
delete node.fqn;
|
|
23
|
+
} else {
|
|
24
|
+
;
|
|
25
|
+
node[idattr] = id;
|
|
26
|
+
node.fqn = id;
|
|
38
27
|
}
|
|
28
|
+
return node;
|
|
29
|
+
},
|
|
30
|
+
readId(node) {
|
|
31
|
+
return node[idattr];
|
|
32
|
+
}
|
|
39
33
|
};
|
|
40
34
|
export function cleanParsedModel(doc) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
35
|
+
const specification = doc.c4Specification = {
|
|
36
|
+
kinds: {}
|
|
37
|
+
};
|
|
38
|
+
const elements = doc.c4Elements = [];
|
|
39
|
+
const relations = doc.c4Relations = [];
|
|
40
|
+
const views = doc.c4Views = [];
|
|
41
|
+
return {
|
|
42
|
+
elements,
|
|
43
|
+
relations,
|
|
44
|
+
views,
|
|
45
|
+
specification
|
|
46
|
+
};
|
|
53
47
|
}
|
|
54
48
|
export function isLikeC4LangiumDocument(doc) {
|
|
55
|
-
|
|
49
|
+
return doc.textDocument.languageId === LikeC4LanguageMetaData.languageId;
|
|
56
50
|
}
|
|
57
51
|
export function isParsedLikeC4LangiumDocument(doc) {
|
|
58
|
-
|
|
59
|
-
doc.state >= DocumentState.Validated &&
|
|
60
|
-
!!doc.c4Specification &&
|
|
61
|
-
!!doc.c4Elements &&
|
|
62
|
-
!!doc.c4Relations &&
|
|
63
|
-
!!doc.c4Views &&
|
|
64
|
-
!!doc.c4fqns);
|
|
52
|
+
return isLikeC4LangiumDocument(doc) && doc.state >= DocumentState.Validated && !!doc.c4Specification && !!doc.c4Elements && !!doc.c4Relations && !!doc.c4Views && !!doc.c4fqns;
|
|
65
53
|
}
|
|
66
54
|
export const isValidLikeC4LangiumDocument = (doc) => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
parseResult.lexerErrors.length === 0 &&
|
|
72
|
-
(!diagnostics || diagnostics.every(d => d.severity !== 1)));
|
|
55
|
+
if (!isParsedLikeC4LangiumDocument(doc))
|
|
56
|
+
return false;
|
|
57
|
+
const { state, parseResult, diagnostics } = doc;
|
|
58
|
+
return state === DocumentState.Validated && parseResult.lexerErrors.length === 0 && (!diagnostics || diagnostics.every((d) => d.severity !== 1));
|
|
73
59
|
};
|
|
74
60
|
export function* streamModel(doc) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
if (ast.isExtendElement(el)) {
|
|
85
|
-
if (el.body && el.body.elements.length > 0) {
|
|
86
|
-
traverseStack.push(...el.body.elements);
|
|
87
|
-
}
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
if (el.body && el.body.elements.length > 0) {
|
|
91
|
-
for (const nested of el.body.elements) {
|
|
92
|
-
if (ast.isRelation(nested)) {
|
|
93
|
-
relations.push(nested);
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
traverseStack.push(nested);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
yield el;
|
|
101
|
-
}
|
|
102
|
-
for (const relation of relations) {
|
|
103
|
-
yield relation;
|
|
61
|
+
const elements = doc.parseResult.value.model?.elements ?? [];
|
|
62
|
+
const traverseStack = [...elements];
|
|
63
|
+
const relations = [];
|
|
64
|
+
let el;
|
|
65
|
+
while (el = traverseStack.shift()) {
|
|
66
|
+
if (ast.isRelation(el)) {
|
|
67
|
+
relations.push(el);
|
|
68
|
+
continue;
|
|
104
69
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
70
|
+
if (ast.isExtendElement(el)) {
|
|
71
|
+
if (el.body && el.body.elements.length > 0) {
|
|
72
|
+
traverseStack.push(...el.body.elements);
|
|
73
|
+
}
|
|
74
|
+
continue;
|
|
110
75
|
}
|
|
111
|
-
if (
|
|
112
|
-
|
|
113
|
-
if (
|
|
114
|
-
|
|
76
|
+
if (el.body && el.body.elements.length > 0) {
|
|
77
|
+
for (const nested of el.body.elements) {
|
|
78
|
+
if (ast.isRelation(nested)) {
|
|
79
|
+
relations.push(nested);
|
|
80
|
+
} else {
|
|
81
|
+
traverseStack.push(nested);
|
|
115
82
|
}
|
|
116
|
-
|
|
117
|
-
source,
|
|
118
|
-
target
|
|
119
|
-
};
|
|
83
|
+
}
|
|
120
84
|
}
|
|
121
|
-
|
|
122
|
-
|
|
85
|
+
yield el;
|
|
86
|
+
}
|
|
87
|
+
for (const relation of relations) {
|
|
88
|
+
yield relation;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
export function resolveRelationPoints(node) {
|
|
92
|
+
const target = elementRef(node.target);
|
|
93
|
+
if (!target) {
|
|
94
|
+
throw new RelationRefError("Invalid reference to target");
|
|
95
|
+
}
|
|
96
|
+
if ("source" in node) {
|
|
97
|
+
const source = elementRef(node.source);
|
|
98
|
+
if (!source) {
|
|
99
|
+
throw new RelationRefError("Invalid reference to source");
|
|
123
100
|
}
|
|
124
101
|
return {
|
|
125
|
-
|
|
126
|
-
|
|
102
|
+
source,
|
|
103
|
+
target
|
|
127
104
|
};
|
|
105
|
+
}
|
|
106
|
+
if (!ast.isElementBody(node.$container)) {
|
|
107
|
+
throw new RelationRefError("Invalid relation parent, expected Element");
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
source: node.$container.$container,
|
|
111
|
+
target
|
|
112
|
+
};
|
|
128
113
|
}
|
|
129
114
|
export function toElementStyle(props) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
115
|
+
const result = {};
|
|
116
|
+
if (!props || props.length === 0) {
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
for (const prop of props) {
|
|
120
|
+
if (ast.isColorProperty(prop)) {
|
|
121
|
+
result.color = prop.value;
|
|
122
|
+
continue;
|
|
133
123
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
if (ast.isShapeProperty(prop)) {
|
|
140
|
-
result.shape = prop.value;
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
if (ast.isIconProperty(prop)) {
|
|
144
|
-
result.icon = prop.value;
|
|
145
|
-
continue;
|
|
146
|
-
}
|
|
147
|
-
nonexhaustive(prop);
|
|
124
|
+
if (ast.isShapeProperty(prop)) {
|
|
125
|
+
result.shape = prop.value;
|
|
126
|
+
continue;
|
|
148
127
|
}
|
|
149
|
-
|
|
128
|
+
if (ast.isIconProperty(prop)) {
|
|
129
|
+
result.icon = prop.value;
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
nonexhaustive(prop);
|
|
133
|
+
}
|
|
134
|
+
return result;
|
|
150
135
|
}
|
|
151
136
|
export function toElementStyleExcludeDefaults(props) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
137
|
+
const { color, shape, ...rest } = toElementStyle(props);
|
|
138
|
+
return {
|
|
139
|
+
...rest,
|
|
140
|
+
...color && color !== DefaultThemeColor ? { color } : {},
|
|
141
|
+
...shape && shape !== DefaultElementShape ? { shape } : {}
|
|
142
|
+
};
|
|
158
143
|
}
|
|
159
144
|
export function toAutoLayout(direction) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
145
|
+
switch (direction) {
|
|
146
|
+
case "TopBottom": {
|
|
147
|
+
return "TB";
|
|
148
|
+
}
|
|
149
|
+
case "BottomTop": {
|
|
150
|
+
return "BT";
|
|
151
|
+
}
|
|
152
|
+
case "LeftRight": {
|
|
153
|
+
return "LR";
|
|
154
|
+
}
|
|
155
|
+
case "RightLeft": {
|
|
156
|
+
return "RL";
|
|
173
157
|
}
|
|
158
|
+
}
|
|
174
159
|
}
|
|
175
|
-
//# sourceMappingURL=ast.js.map
|
package/dist/elementRef.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare function isElementRefHead(node: ast.ElementRef | ast.StrictElemen
|
|
|
5
5
|
* Returns referenced AST Element
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
export declare function elementRef(node: ast.ElementRef | ast.StrictElementRef):
|
|
8
|
+
export declare function elementRef(node: ast.ElementRef | ast.StrictElementRef): any;
|
|
9
9
|
/**
|
|
10
10
|
* Returns FQN of strictElementRef
|
|
11
11
|
* a.b.c.d - for c node returns a.b
|
|
@@ -16,4 +16,3 @@ export declare function fqnElementRef(node: ast.StrictElementRef): c4.Fqn;
|
|
|
16
16
|
* a.b.c.d - for c node returns a.b
|
|
17
17
|
*/
|
|
18
18
|
export declare function parentFqnElementRef(node: ast.StrictElementRef): c4.Fqn;
|
|
19
|
-
//# sourceMappingURL=elementRef.d.ts.map
|
package/dist/elementRef.js
CHANGED
|
@@ -1,52 +1,39 @@
|
|
|
1
|
-
import { invariant, nonexhaustive } from
|
|
2
|
-
import { ast } from
|
|
1
|
+
import { invariant, nonexhaustive } from "@likec4/core";
|
|
2
|
+
import { ast } from "./ast.js";
|
|
3
3
|
export function isElementRefHead(node) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
if (ast.isElementRef(node)) {
|
|
5
|
+
return !ast.isElementRef(node.$container);
|
|
6
|
+
}
|
|
7
|
+
if (ast.isStrictElementRef(node)) {
|
|
8
|
+
return !ast.isStrictElementRef(node.$container);
|
|
9
|
+
}
|
|
10
|
+
nonexhaustive(node);
|
|
11
11
|
}
|
|
12
|
-
/**
|
|
13
|
-
* Returns referenced AST Element
|
|
14
|
-
*
|
|
15
|
-
*/
|
|
16
12
|
export function elementRef(node) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
invariant(isElementRefHead(node), "Expected head ElementRef");
|
|
14
|
+
while (node.next) {
|
|
15
|
+
node = node.next;
|
|
16
|
+
}
|
|
17
|
+
return node.el.ref;
|
|
22
18
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Returns FQN of strictElementRef
|
|
25
|
-
* a.b.c.d - for c node returns a.b
|
|
26
|
-
*/
|
|
27
19
|
export function fqnElementRef(node) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
20
|
+
invariant(isElementRefHead(node), "Expected head StrictElementRef");
|
|
21
|
+
const name = [node.el.$refText];
|
|
22
|
+
let child = node.next;
|
|
23
|
+
while (child) {
|
|
24
|
+
name.push(child.el.$refText);
|
|
25
|
+
child = child.next;
|
|
26
|
+
}
|
|
27
|
+
return name.join(".");
|
|
36
28
|
}
|
|
37
|
-
/**
|
|
38
|
-
* Returns parent FQN
|
|
39
|
-
* a.b.c.d - for c node returns a.b
|
|
40
|
-
*/
|
|
41
29
|
export function parentFqnElementRef(node) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
30
|
+
invariant(!isElementRefHead(node), "Expected next StrictElementRef");
|
|
31
|
+
const path = [];
|
|
32
|
+
let parent = node.$container;
|
|
33
|
+
while (ast.isStrictElementRef(parent)) {
|
|
34
|
+
path.unshift(parent.el.$refText);
|
|
35
|
+
parent = parent.$container;
|
|
36
|
+
}
|
|
37
|
+
invariant(path.length > 0, "Expected non-empty parent path");
|
|
38
|
+
return path.join(".");
|
|
51
39
|
}
|
|
52
|
-
//# sourceMappingURL=elementRef.js.map
|
package/dist/generated/ast.d.ts
CHANGED
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
import type { AstNode, Reference, ReferenceInfo, TypeMetaData } from 'langium';
|
|
6
6
|
import { AbstractAstReflection } from 'langium';
|
|
7
7
|
export declare const LikeC4Terminals: {
|
|
8
|
+
BLOCK_COMMENT: RegExp;
|
|
9
|
+
LINE_COMMENT: RegExp;
|
|
10
|
+
WS: RegExp;
|
|
8
11
|
URI_WITH_SCHEMA: RegExp;
|
|
9
12
|
URI_RELATIVE: RegExp;
|
|
10
13
|
RARROW: RegExp;
|
|
@@ -16,12 +19,9 @@ export declare const LikeC4Terminals: {
|
|
|
16
19
|
Colon: RegExp;
|
|
17
20
|
SemiColon: RegExp;
|
|
18
21
|
Comma: RegExp;
|
|
22
|
+
STRING: RegExp;
|
|
19
23
|
TagID: RegExp;
|
|
20
24
|
ID: RegExp;
|
|
21
|
-
STRING: RegExp;
|
|
22
|
-
WS: RegExp;
|
|
23
|
-
BLOCK_COMMENT: RegExp;
|
|
24
|
-
LINE_COMMENT: RegExp;
|
|
25
25
|
};
|
|
26
26
|
export type ElementExpression = ElementKindExpression | ElementRefExpression | ElementTagExpression | WildcardExpression;
|
|
27
27
|
export declare const ElementExpression = "ElementExpression";
|
|
@@ -419,4 +419,3 @@ export declare class LikeC4AstReflection extends AbstractAstReflection {
|
|
|
419
419
|
getTypeMetaData(type: string): TypeMetaData;
|
|
420
420
|
}
|
|
421
421
|
export declare const reflection: LikeC4AstReflection;
|
|
422
|
-
//# sourceMappingURL=ast.d.ts.map
|