@likec4/language-server 1.18.0 → 1.19.1
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/LikeC4FileSystem.d.ts +13 -0
- package/dist/LikeC4FileSystem.js +27 -0
- package/dist/Rpc.d.ts +9 -0
- package/dist/Rpc.js +132 -0
- package/dist/ast.d.ts +200 -0
- package/dist/ast.js +276 -0
- package/dist/browser.d.ts +7 -20
- package/dist/browser.js +13 -0
- package/dist/documentation/documentation-provider.d.ts +8 -0
- package/dist/documentation/documentation-provider.js +46 -0
- package/dist/documentation/index.d.ts +1 -0
- package/dist/documentation/index.js +1 -0
- package/dist/formatting/LikeC4Formatter.d.ts +27 -0
- package/dist/formatting/LikeC4Formatter.js +261 -0
- package/dist/formatting/utils.d.ts +6 -0
- package/dist/formatting/utils.js +15 -0
- package/dist/generated/ast.d.ts +1242 -0
- package/dist/generated/ast.js +1945 -0
- package/dist/generated/grammar.d.ts +6 -0
- package/dist/generated/grammar.js +3 -0
- package/dist/generated/module.d.ts +9 -0
- package/dist/generated/module.js +23 -0
- package/dist/generated-lib/icons.d.ts +1 -0
- package/dist/{likec4lib.mjs → generated-lib/icons.js} +1 -6
- package/dist/index.d.ts +9 -31
- package/dist/index.js +14 -0
- package/dist/like-c4.langium +845 -0
- package/dist/likec4lib.d.ts +4 -6
- package/dist/likec4lib.js +4 -0
- package/dist/logger.d.ts +7 -0
- package/dist/logger.js +73 -0
- package/dist/lsp/CodeLensProvider.d.ts +9 -0
- package/dist/lsp/CodeLensProvider.js +40 -0
- package/dist/lsp/CompletionProvider.d.ts +6 -0
- package/dist/lsp/CompletionProvider.js +135 -0
- package/dist/lsp/DocumentHighlightProvider.d.ts +9 -0
- package/dist/lsp/DocumentHighlightProvider.js +10 -0
- package/dist/lsp/DocumentLinkProvider.d.ts +11 -0
- package/dist/lsp/DocumentLinkProvider.js +49 -0
- package/dist/lsp/DocumentSymbolProvider.d.ts +32 -0
- package/dist/lsp/DocumentSymbolProvider.js +274 -0
- package/dist/lsp/HoverProvider.d.ts +10 -0
- package/dist/lsp/HoverProvider.js +69 -0
- package/dist/lsp/RenameProvider.d.ts +5 -0
- package/dist/lsp/RenameProvider.js +6 -0
- package/dist/lsp/SemanticTokenProvider.d.ts +7 -0
- package/dist/lsp/SemanticTokenProvider.js +297 -0
- package/dist/lsp/index.d.ts +7 -0
- package/dist/lsp/index.js +7 -0
- package/dist/model/deployments-index.d.ts +60 -0
- package/dist/model/deployments-index.js +181 -0
- package/dist/model/fqn-computation.d.ts +3 -0
- package/dist/model/fqn-computation.js +72 -0
- package/dist/model/fqn-index.d.ts +25 -0
- package/dist/model/fqn-index.js +96 -0
- package/dist/model/index.d.ts +6 -0
- package/dist/model/index.js +6 -0
- package/dist/model/model-builder.d.ts +32 -0
- package/dist/model/model-builder.js +598 -0
- package/dist/model/model-locator.d.ts +23 -0
- package/dist/model/model-locator.js +126 -0
- package/dist/model/model-parser-where.d.ts +3 -0
- package/dist/model/model-parser-where.js +70 -0
- package/dist/model/model-parser.d.ts +292 -0
- package/dist/model/model-parser.js +72 -0
- package/dist/model/parser/Base.d.ts +28 -0
- package/dist/model/parser/Base.js +87 -0
- package/dist/model/parser/DeploymentModelParser.d.ts +33 -0
- package/dist/model/parser/DeploymentModelParser.js +162 -0
- package/dist/model/parser/DeploymentViewParser.d.ts +38 -0
- package/dist/model/parser/DeploymentViewParser.js +98 -0
- package/dist/model/parser/FqnRefParser.d.ts +29 -0
- package/dist/model/parser/FqnRefParser.js +108 -0
- package/dist/model/parser/GlobalsParser.d.ts +66 -0
- package/dist/model/parser/GlobalsParser.js +80 -0
- package/dist/model/parser/ModelParser.d.ts +27 -0
- package/dist/model/parser/ModelParser.js +122 -0
- package/dist/model/parser/PredicatesParser.d.ts +34 -0
- package/dist/model/parser/PredicatesParser.js +272 -0
- package/dist/model/parser/SpecificationParser.d.ts +27 -0
- package/dist/model/parser/SpecificationParser.js +120 -0
- package/dist/model/parser/ViewsParser.d.ts +64 -0
- package/dist/model/parser/ViewsParser.js +377 -0
- package/dist/model-change/ModelChanges.d.ts +15 -0
- package/dist/model-change/ModelChanges.js +89 -0
- package/dist/model-change/changeElementStyle.d.ts +16 -0
- package/dist/model-change/changeElementStyle.js +136 -0
- package/dist/model-change/changeViewLayout.d.ts +12 -0
- package/dist/model-change/changeViewLayout.js +32 -0
- package/dist/model-change/saveManualLayout.d.ts +11 -0
- package/dist/model-change/saveManualLayout.js +27 -0
- package/dist/module.d.ts +70 -0
- package/dist/module.js +162 -0
- package/dist/protocol.d.ts +38 -23
- package/dist/protocol.js +15 -0
- package/dist/references/index.d.ts +3 -0
- package/dist/references/index.js +3 -0
- package/dist/references/name-provider.d.ts +9 -0
- package/dist/references/name-provider.js +33 -0
- package/dist/references/scope-computation.d.ts +20 -0
- package/dist/references/scope-computation.js +281 -0
- package/dist/references/scope-provider.d.ts +16 -0
- package/dist/references/scope-provider.js +165 -0
- package/dist/shared/NodeKindProvider.d.ts +15 -0
- package/dist/shared/NodeKindProvider.js +108 -0
- package/dist/shared/WorkspaceManager.d.ts +18 -0
- package/dist/shared/WorkspaceManager.js +36 -0
- package/dist/shared/WorkspaceSymbolProvider.d.ts +3 -0
- package/dist/shared/WorkspaceSymbolProvider.js +3 -0
- package/dist/shared/index.d.ts +3 -0
- package/dist/shared/index.js +3 -0
- package/dist/test/index.d.ts +1 -0
- package/dist/test/index.js +1 -0
- package/dist/test/setup.d.ts +1 -0
- package/dist/test/setup.js +7 -0
- package/dist/test/testServices.d.ts +22 -0
- package/dist/test/testServices.js +119 -0
- package/dist/utils/elementRef.d.ts +11 -0
- package/dist/utils/elementRef.js +15 -0
- package/dist/utils/fqnRef.d.ts +8 -0
- package/dist/utils/fqnRef.js +46 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/printDocs.d.ts +2 -0
- package/dist/utils/printDocs.js +1 -0
- package/dist/utils/stringHash.d.ts +1 -0
- package/dist/utils/stringHash.js +5 -0
- package/dist/validation/_shared.d.ts +3 -0
- package/dist/validation/_shared.js +22 -0
- package/dist/validation/deployment-checks.d.ts +6 -0
- package/dist/validation/deployment-checks.js +114 -0
- package/dist/validation/dynamic-view-rule.d.ts +4 -0
- package/dist/validation/dynamic-view-rule.js +17 -0
- package/dist/validation/dynamic-view-step.d.ts +4 -0
- package/dist/validation/dynamic-view-step.js +29 -0
- package/dist/validation/element.d.ts +4 -0
- package/dist/validation/element.js +49 -0
- package/dist/validation/index.d.ts +15 -0
- package/dist/validation/index.js +152 -0
- package/dist/validation/property-checks.d.ts +6 -0
- package/dist/validation/property-checks.js +39 -0
- package/dist/validation/relation.d.ts +5 -0
- package/dist/validation/relation.js +56 -0
- package/dist/validation/specification.d.ts +11 -0
- package/dist/validation/specification.js +136 -0
- package/dist/validation/view-predicates/element-with.d.ts +4 -0
- package/dist/validation/view-predicates/element-with.js +31 -0
- package/dist/validation/view-predicates/expanded-element.d.ts +4 -0
- package/dist/validation/view-predicates/expanded-element.js +12 -0
- package/dist/validation/view-predicates/expression-v2.d.ts +5 -0
- package/dist/validation/view-predicates/expression-v2.js +83 -0
- package/dist/validation/view-predicates/incoming.d.ts +4 -0
- package/dist/validation/view-predicates/incoming.js +16 -0
- package/dist/validation/view-predicates/index.d.ts +6 -0
- package/dist/validation/view-predicates/index.js +6 -0
- package/dist/validation/view-predicates/outgoing.d.ts +4 -0
- package/dist/validation/view-predicates/outgoing.js +16 -0
- package/dist/validation/view-predicates/relation-with.d.ts +4 -0
- package/dist/validation/view-predicates/relation-with.js +13 -0
- package/dist/validation/view.d.ts +4 -0
- package/dist/validation/view.js +23 -0
- package/dist/view-utils/assignNavigateTo.d.ts +2 -0
- package/dist/view-utils/assignNavigateTo.js +25 -0
- package/dist/view-utils/index.d.ts +2 -0
- package/dist/view-utils/index.js +2 -0
- package/dist/view-utils/manual-layout.d.ts +7 -0
- package/dist/view-utils/manual-layout.js +99 -0
- package/dist/view-utils/resolve-relative-paths.d.ts +2 -0
- package/dist/view-utils/resolve-relative-paths.js +78 -0
- package/dist/views/configurable-layouter.d.ts +7 -0
- package/dist/views/configurable-layouter.js +55 -0
- package/dist/views/index.d.ts +1 -0
- package/dist/views/index.js +1 -0
- package/dist/views/likec4-views.d.ts +26 -0
- package/dist/views/likec4-views.js +113 -0
- package/package.json +40 -54
- package/src/LikeC4FileSystem.ts +22 -21
- package/src/Rpc.ts +13 -7
- package/src/ast.ts +44 -133
- package/src/browser.ts +11 -11
- package/src/documentation/documentation-provider.ts +52 -0
- package/src/documentation/index.ts +1 -0
- package/src/generated/ast.ts +177 -177
- package/src/generated/grammar.ts +1 -1
- package/src/index.ts +13 -9
- package/src/like-c4.langium +37 -34
- package/src/logger.ts +34 -55
- package/src/lsp/CompletionProvider.ts +4 -4
- package/src/lsp/DocumentSymbolProvider.ts +110 -28
- package/src/lsp/HoverProvider.ts +5 -3
- package/src/lsp/SemanticTokenProvider.ts +2 -2
- package/src/model/deployments-index.ts +18 -14
- package/src/model/fqn-computation.ts +8 -8
- package/src/model/model-builder.ts +62 -60
- package/src/model/model-parser.ts +62 -1574
- package/src/model/parser/Base.ts +107 -0
- package/src/model/parser/DeploymentModelParser.ts +192 -0
- package/src/model/parser/DeploymentViewParser.ts +116 -0
- package/src/model/parser/FqnRefParser.ts +118 -0
- package/src/model/parser/GlobalsParser.ts +96 -0
- package/src/model/parser/ModelParser.ts +141 -0
- package/src/model/parser/PredicatesParser.ts +291 -0
- package/src/model/parser/SpecificationParser.ts +133 -0
- package/src/model/parser/ViewsParser.ts +428 -0
- package/src/module.ts +71 -25
- package/src/protocol.ts +29 -4
- package/src/references/scope-computation.ts +35 -35
- package/src/references/scope-provider.ts +13 -7
- package/src/utils/{deploymentRef.ts → fqnRef.ts} +27 -2
- package/src/validation/_shared.ts +0 -1
- package/src/validation/deployment-checks.ts +49 -62
- package/src/validation/dynamic-view-rule.ts +5 -4
- package/src/validation/dynamic-view-step.ts +23 -26
- package/src/validation/index.ts +100 -9
- package/src/validation/property-checks.ts +11 -10
- package/src/validation/specification.ts +38 -38
- package/src/validation/view-predicates/element-with.ts +6 -5
- package/src/validation/view-predicates/expanded-element.ts +6 -5
- package/src/validation/view-predicates/expression-v2.ts +101 -0
- package/src/validation/view-predicates/incoming.ts +6 -5
- package/src/validation/view-predicates/index.ts +1 -1
- package/src/validation/view-predicates/outgoing.ts +6 -5
- package/src/validation/view-predicates/relation-with.ts +6 -5
- package/src/validation/view.ts +5 -5
- package/src/view-utils/assignNavigateTo.ts +1 -1
- package/src/view-utils/manual-layout.ts +25 -0
- package/src/views/configurable-layouter.ts +65 -0
- package/src/views/index.ts +1 -0
- package/src/views/likec4-views.ts +139 -0
- package/dist/browser.cjs +0 -25
- package/dist/browser.d.cts +0 -23
- package/dist/browser.d.mts +0 -23
- package/dist/browser.mjs +0 -20
- package/dist/index.cjs +0 -53
- package/dist/index.d.cts +0 -34
- package/dist/index.d.mts +0 -34
- package/dist/index.mjs +0 -46
- package/dist/likec4lib.cjs +0 -1546
- package/dist/likec4lib.d.cts +0 -6
- package/dist/likec4lib.d.mts +0 -6
- package/dist/protocol.cjs +0 -25
- package/dist/protocol.d.cts +0 -48
- package/dist/protocol.d.mts +0 -48
- package/dist/protocol.mjs +0 -17
- package/dist/shared/language-server.CO_nmHiL.cjs +0 -7689
- package/dist/shared/language-server.Da6ey08o.d.cts +0 -1619
- package/dist/shared/language-server.De7S3e5Z.d.ts +0 -1619
- package/dist/shared/language-server.Dj4iDjtB.d.mts +0 -1619
- package/dist/shared/language-server.oO_9JoAG.mjs +0 -7666
- package/src/validation/view-predicates/deployments.ts +0 -56
|
@@ -3,11 +3,11 @@ import type { LangiumDocument, LangiumDocuments, Stream } from 'langium'
|
|
|
3
3
|
import { AstUtils, DocumentState, MultiMap } from 'langium'
|
|
4
4
|
import { forEachObj, groupBy, isTruthy, pipe, prop } from 'remeda'
|
|
5
5
|
import {
|
|
6
|
-
ast,
|
|
7
6
|
type DeploymentAstNodeDescription,
|
|
7
|
+
type LikeC4LangiumDocument,
|
|
8
|
+
ast,
|
|
8
9
|
ElementOps,
|
|
9
10
|
isLikeC4LangiumDocument,
|
|
10
|
-
type LikeC4LangiumDocument
|
|
11
11
|
} from '../ast'
|
|
12
12
|
import { logWarnError } from '../logger'
|
|
13
13
|
import type { LikeC4Services } from '../module'
|
|
@@ -33,7 +33,7 @@ export class DeploymentsIndex {
|
|
|
33
33
|
for (const doc of docs) {
|
|
34
34
|
delete (doc as IndexedDocument)[DeploymentsIndexKey]
|
|
35
35
|
}
|
|
36
|
-
}
|
|
36
|
+
},
|
|
37
37
|
)
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -55,7 +55,7 @@ export class DeploymentsIndex {
|
|
|
55
55
|
* @returns Stream of artifacts
|
|
56
56
|
*/
|
|
57
57
|
public nested(node: ast.DeploymentNode): Stream<DeploymentAstNodeDescription> {
|
|
58
|
-
const fqnName = this.
|
|
58
|
+
const fqnName = this.getFqn(node)
|
|
59
59
|
return this.documents().flatMap(doc => this.get(doc).nested(fqnName))
|
|
60
60
|
}
|
|
61
61
|
|
|
@@ -63,18 +63,19 @@ export class DeploymentsIndex {
|
|
|
63
63
|
return this.documents().flatMap(doc => this.get(doc).byFqn(fqnName))
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
public
|
|
66
|
+
public getFqn(node: ast.DeploymentElement): Fqn {
|
|
67
67
|
let id = ElementOps.readId(node)
|
|
68
68
|
if (isTruthy(id)) {
|
|
69
69
|
return id
|
|
70
70
|
}
|
|
71
71
|
const fqn = [
|
|
72
|
-
this.Names.getNameStrict(node)
|
|
72
|
+
this.Names.getNameStrict(node),
|
|
73
73
|
]
|
|
74
|
+
let _node = node
|
|
74
75
|
let parentNode: ast.DeploymentNode | undefined
|
|
75
|
-
while ((parentNode = AstUtils.getContainerOfType(
|
|
76
|
+
while ((parentNode = AstUtils.getContainerOfType(_node.$container, ast.isDeploymentNode))) {
|
|
76
77
|
fqn.push(this.Names.getNameStrict(parentNode))
|
|
77
|
-
|
|
78
|
+
_node = parentNode
|
|
78
79
|
}
|
|
79
80
|
id = fqn.reduceRight((acc, cur) => `${acc}.${cur}`) as Fqn
|
|
80
81
|
ElementOps.writeId(node, id)
|
|
@@ -93,11 +94,11 @@ export class DeploymentsIndex {
|
|
|
93
94
|
const Descriptions = this.services.workspace.AstNodeDescriptionProvider
|
|
94
95
|
|
|
95
96
|
const createAndSaveDescription = (
|
|
96
|
-
props: { node: ast.DeploymentNode | ast.DeployedInstance; name: string; fqn: string }
|
|
97
|
+
props: { node: ast.DeploymentNode | ast.DeployedInstance; name: string; fqn: string },
|
|
97
98
|
) => {
|
|
98
99
|
const desc = {
|
|
99
100
|
...Descriptions.createDescription(props.node, props.name, document),
|
|
100
|
-
fqn: props.fqn
|
|
101
|
+
fqn: props.fqn,
|
|
101
102
|
}
|
|
102
103
|
ElementOps.writeId(props.node, props.fqn as Fqn)
|
|
103
104
|
_byfqn.add(props.fqn, desc)
|
|
@@ -106,7 +107,7 @@ export class DeploymentsIndex {
|
|
|
106
107
|
|
|
107
108
|
const traverseNode = (
|
|
108
109
|
container: ast.DeploymentNode,
|
|
109
|
-
parentFqn: string
|
|
110
|
+
parentFqn: string,
|
|
110
111
|
): readonly DeploymentAstNodeDescription[] => {
|
|
111
112
|
const _descedants = [] as DeploymentAstNodeDescription[]
|
|
112
113
|
const children = container.body?.elements
|
|
@@ -142,7 +143,7 @@ export class DeploymentsIndex {
|
|
|
142
143
|
return
|
|
143
144
|
}
|
|
144
145
|
_nested.add(parentFqn, descs[0])
|
|
145
|
-
})
|
|
146
|
+
}),
|
|
146
147
|
)
|
|
147
148
|
}
|
|
148
149
|
return _nested.get(parentFqn)
|
|
@@ -166,6 +167,9 @@ export class DeploymentsIndex {
|
|
|
166
167
|
}
|
|
167
168
|
}
|
|
168
169
|
|
|
170
|
+
/**
|
|
171
|
+
* Index of deployment elements in the document
|
|
172
|
+
*/
|
|
169
173
|
export class DocumentDeploymentsIndex {
|
|
170
174
|
static readonly EMPTY = new DocumentDeploymentsIndex([], new MultiMap(), new MultiMap())
|
|
171
175
|
|
|
@@ -178,7 +182,7 @@ export class DocumentDeploymentsIndex {
|
|
|
178
182
|
/**
|
|
179
183
|
* All elements by FQN
|
|
180
184
|
*/
|
|
181
|
-
private _byfqn: MultiMap<string, DeploymentAstNodeDescription
|
|
185
|
+
private _byfqn: MultiMap<string, DeploymentAstNodeDescription>,
|
|
182
186
|
) {}
|
|
183
187
|
|
|
184
188
|
public rootNodes(): readonly DeploymentAstNodeDescription[] {
|
|
@@ -211,7 +215,7 @@ export class DocumentDeploymentsIndex {
|
|
|
211
215
|
if (descs.length === 1) {
|
|
212
216
|
result.push(descs[0])
|
|
213
217
|
}
|
|
214
|
-
})
|
|
218
|
+
}),
|
|
215
219
|
)
|
|
216
220
|
return result
|
|
217
221
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { AsFqn, nonexhaustive } from '@likec4/core'
|
|
2
1
|
import type * as c4 from '@likec4/core'
|
|
2
|
+
import { AsFqn, LinkedList, nonexhaustive } from '@likec4/core'
|
|
3
3
|
import { type AstNodeDescription, type AstNodeLocator, AstUtils, CstUtils, GrammarUtils, MultiMap } from 'langium'
|
|
4
4
|
import { isDefined, isEmpty } from 'remeda'
|
|
5
|
-
import { ast, ElementOps
|
|
5
|
+
import { type LikeC4LangiumDocument, ast, ElementOps } from '../ast'
|
|
6
6
|
import { logError } from '../logger'
|
|
7
7
|
import type { LikeC4Services } from '../module'
|
|
8
8
|
import { getFqnElementRef } from '../utils/elementRef'
|
|
@@ -16,20 +16,20 @@ type TraversePair = [el: ast.Element | ast.ExtendElement | ast.Relation, parent:
|
|
|
16
16
|
function toAstNodeDescription(
|
|
17
17
|
locator: AstNodeLocator,
|
|
18
18
|
entry: ast.Element,
|
|
19
|
-
doc: LikeC4LangiumDocument
|
|
19
|
+
doc: LikeC4LangiumDocument,
|
|
20
20
|
): AstNodeDescription {
|
|
21
21
|
const $cstNode = findNodeForProperty(entry.$cstNode, 'name')
|
|
22
22
|
return {
|
|
23
23
|
documentUri: doc.uri,
|
|
24
24
|
name: entry.name,
|
|
25
25
|
...(entry.$cstNode && {
|
|
26
|
-
selectionSegment: toDocumentSegment(entry.$cstNode)
|
|
26
|
+
selectionSegment: toDocumentSegment(entry.$cstNode),
|
|
27
27
|
}),
|
|
28
28
|
...($cstNode && {
|
|
29
|
-
nameSegment: toDocumentSegment($cstNode)
|
|
29
|
+
nameSegment: toDocumentSegment($cstNode),
|
|
30
30
|
}),
|
|
31
31
|
path: locator.getAstNodePath(entry),
|
|
32
|
-
type: ast.Element
|
|
32
|
+
type: ast.Element,
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -40,7 +40,7 @@ export function computeDocumentFqn(document: LikeC4LangiumDocument, services: Li
|
|
|
40
40
|
return
|
|
41
41
|
}
|
|
42
42
|
const locator = services.workspace.AstNodeLocator
|
|
43
|
-
const traverseStack
|
|
43
|
+
const traverseStack = LinkedList.from(elements.map(el => [el, null] as TraversePair))
|
|
44
44
|
let pair
|
|
45
45
|
while ((pair = traverseStack.shift())) {
|
|
46
46
|
try {
|
|
@@ -63,7 +63,7 @@ export function computeDocumentFqn(document: LikeC4LangiumDocument, services: Li
|
|
|
63
63
|
const fqn = AsFqn(el.name, parent)
|
|
64
64
|
c4fqnIndex.add(fqn, {
|
|
65
65
|
...toAstNodeDescription(locator, el, document),
|
|
66
|
-
fqn
|
|
66
|
+
fqn,
|
|
67
67
|
})
|
|
68
68
|
ElementOps.writeId(el, fqn)
|
|
69
69
|
if (isDefined(el.body) && !isEmpty(el.body.elements)) {
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import * as c4 from '@likec4/core'
|
|
1
|
+
import type * as c4 from '@likec4/core'
|
|
2
2
|
import {
|
|
3
|
+
type CustomColorDefinitions,
|
|
4
|
+
type ViewId,
|
|
3
5
|
compareRelations,
|
|
4
6
|
computeColorValues,
|
|
5
|
-
|
|
7
|
+
DeploymentElement,
|
|
6
8
|
isScopedElementView,
|
|
9
|
+
LikeC4Model,
|
|
7
10
|
parentFqn,
|
|
8
11
|
sortByFqnHierarchically,
|
|
9
|
-
type ViewId
|
|
10
12
|
} from '@likec4/core'
|
|
11
|
-
import {
|
|
13
|
+
import { resolveRulesExtendedViews } from '@likec4/core/compute-view'
|
|
12
14
|
import { deepEqual as eq } from 'fast-equals'
|
|
13
15
|
import type { Cancellation, LangiumDocument, LangiumDocuments, URI, WorkspaceCache } from 'langium'
|
|
14
16
|
import { Disposable, DocumentState, interruptAndCheck } from 'langium'
|
|
@@ -32,7 +34,7 @@ import {
|
|
|
32
34
|
reduce,
|
|
33
35
|
reverse,
|
|
34
36
|
sort,
|
|
35
|
-
values
|
|
37
|
+
values,
|
|
36
38
|
} from 'remeda'
|
|
37
39
|
import type {
|
|
38
40
|
ParsedAstDeploymentRelation,
|
|
@@ -41,10 +43,10 @@ import type {
|
|
|
41
43
|
ParsedAstSpecification,
|
|
42
44
|
ParsedAstView,
|
|
43
45
|
ParsedLikeC4LangiumDocument,
|
|
44
|
-
ParsedLink
|
|
46
|
+
ParsedLink,
|
|
45
47
|
} from '../ast'
|
|
46
48
|
import { isParsedLikeC4LangiumDocument } from '../ast'
|
|
47
|
-
import {
|
|
49
|
+
import { logger, logWarnError } from '../logger'
|
|
48
50
|
import type { LikeC4Services } from '../module'
|
|
49
51
|
import { assignNavigateTo, resolveRelativePaths } from '../view-utils'
|
|
50
52
|
|
|
@@ -55,17 +57,17 @@ function buildModel(services: LikeC4Services, docs: ParsedLikeC4LangiumDocument[
|
|
|
55
57
|
deployments: {},
|
|
56
58
|
elements: {},
|
|
57
59
|
relationships: {},
|
|
58
|
-
colors: {}
|
|
60
|
+
colors: {},
|
|
59
61
|
}
|
|
60
62
|
const globals: c4.ModelGlobals = {
|
|
61
63
|
predicates: {},
|
|
62
64
|
dynamicPredicates: {},
|
|
63
|
-
styles: {}
|
|
65
|
+
styles: {},
|
|
64
66
|
}
|
|
65
67
|
for (const doc of docs) {
|
|
66
68
|
const {
|
|
67
69
|
c4Specification: spec,
|
|
68
|
-
c4Globals
|
|
70
|
+
c4Globals,
|
|
69
71
|
} = doc
|
|
70
72
|
|
|
71
73
|
spec.tags.forEach(t => c4Specification.tags.add(t))
|
|
@@ -87,20 +89,20 @@ function buildModel(services: LikeC4Services, docs: ParsedLikeC4LangiumDocument[
|
|
|
87
89
|
if (relative && relative !== link.url) {
|
|
88
90
|
return {
|
|
89
91
|
...link,
|
|
90
|
-
relative
|
|
92
|
+
relative,
|
|
91
93
|
}
|
|
92
94
|
}
|
|
93
95
|
} catch (e) {
|
|
94
96
|
logWarnError(e)
|
|
95
97
|
}
|
|
96
98
|
return link
|
|
97
|
-
}
|
|
99
|
+
},
|
|
98
100
|
)
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
const customColorDefinitions: CustomColorDefinitions = mapValues(
|
|
102
104
|
c4Specification.colors,
|
|
103
|
-
c => computeColorValues(c.color)
|
|
105
|
+
c => computeColorValues(c.color),
|
|
104
106
|
)
|
|
105
107
|
|
|
106
108
|
function toModelElement(doc: LangiumDocument) {
|
|
@@ -112,14 +114,14 @@ function buildModel(services: LikeC4Services, docs: ParsedLikeC4LangiumDocument[
|
|
|
112
114
|
shape,
|
|
113
115
|
icon,
|
|
114
116
|
opacity,
|
|
115
|
-
border
|
|
117
|
+
border,
|
|
116
118
|
},
|
|
117
119
|
id,
|
|
118
120
|
kind,
|
|
119
121
|
title,
|
|
120
122
|
description,
|
|
121
123
|
technology,
|
|
122
|
-
metadata
|
|
124
|
+
metadata,
|
|
123
125
|
}: ParsedAstElement): c4.Element | null => {
|
|
124
126
|
try {
|
|
125
127
|
const __kind = c4Specification.elements[kind]
|
|
@@ -142,7 +144,7 @@ function buildModel(services: LikeC4Services, docs: ParsedLikeC4LangiumDocument[
|
|
|
142
144
|
...(__kind.notation && { notation: __kind.notation }),
|
|
143
145
|
style: {
|
|
144
146
|
...(border && { border }),
|
|
145
|
-
...(isNumber(opacity) && { opacity })
|
|
147
|
+
...(isNumber(opacity) && { opacity }),
|
|
146
148
|
},
|
|
147
149
|
links,
|
|
148
150
|
tags: tags ?? null,
|
|
@@ -150,7 +152,7 @@ function buildModel(services: LikeC4Services, docs: ParsedLikeC4LangiumDocument[
|
|
|
150
152
|
description: description ?? null,
|
|
151
153
|
title,
|
|
152
154
|
kind,
|
|
153
|
-
id
|
|
155
|
+
id,
|
|
154
156
|
}
|
|
155
157
|
} catch (e) {
|
|
156
158
|
logWarnError(e)
|
|
@@ -176,8 +178,8 @@ function buildModel(services: LikeC4Services, docs: ParsedLikeC4LangiumDocument[
|
|
|
176
178
|
acc[el.id] = el
|
|
177
179
|
return acc
|
|
178
180
|
},
|
|
179
|
-
{} as c4.ParsedLikeC4Model['elements']
|
|
180
|
-
)
|
|
181
|
+
{} as c4.ParsedLikeC4Model['elements'],
|
|
182
|
+
),
|
|
181
183
|
)
|
|
182
184
|
|
|
183
185
|
function toModelRelation(doc: LangiumDocument) {
|
|
@@ -189,12 +191,12 @@ function buildModel(services: LikeC4Services, docs: ParsedLikeC4LangiumDocument[
|
|
|
189
191
|
links: unresolvedLinks,
|
|
190
192
|
id,
|
|
191
193
|
...model
|
|
192
|
-
}: ParsedAstRelation): c4.
|
|
194
|
+
}: ParsedAstRelation): c4.ModelRelation | null => {
|
|
193
195
|
if (isNullish(elements[source]) || isNullish(elements[target])) {
|
|
194
196
|
logger.warn(
|
|
195
197
|
`Invalid relation ${id} at ${doc.uri.path} ${astPath}, source: ${source}(${!!elements[
|
|
196
198
|
source
|
|
197
|
-
]}), target: ${target}(${!!elements[target]})
|
|
199
|
+
]}), target: ${target}(${!!elements[target]})`,
|
|
198
200
|
)
|
|
199
201
|
return null
|
|
200
202
|
}
|
|
@@ -208,16 +210,16 @@ function buildModel(services: LikeC4Services, docs: ParsedLikeC4LangiumDocument[
|
|
|
208
210
|
source,
|
|
209
211
|
target,
|
|
210
212
|
kind,
|
|
211
|
-
id
|
|
212
|
-
} satisfies c4.
|
|
213
|
+
id,
|
|
214
|
+
} satisfies c4.ModelRelation
|
|
213
215
|
}
|
|
214
216
|
return {
|
|
215
217
|
...links && { links },
|
|
216
218
|
...model,
|
|
217
219
|
source,
|
|
218
220
|
target,
|
|
219
|
-
id
|
|
220
|
-
} satisfies c4.
|
|
221
|
+
id,
|
|
222
|
+
} satisfies c4.ModelRelation
|
|
221
223
|
}
|
|
222
224
|
}
|
|
223
225
|
|
|
@@ -227,19 +229,19 @@ function buildModel(services: LikeC4Services, docs: ParsedLikeC4LangiumDocument[
|
|
|
227
229
|
filter(isTruthy),
|
|
228
230
|
sort(compareRelations),
|
|
229
231
|
reverse(),
|
|
230
|
-
indexBy(prop('id'))
|
|
232
|
+
indexBy(prop('id')),
|
|
231
233
|
)
|
|
232
234
|
|
|
233
235
|
function toDeploymentElement(doc: LangiumDocument) {
|
|
234
236
|
return (parsed: c4.DeploymentElement): c4.DeploymentElement | null => {
|
|
235
|
-
if (!
|
|
237
|
+
if (!DeploymentElement.isDeploymentNode(parsed)) {
|
|
236
238
|
if (!parsed.links || parsed.links.length === 0) {
|
|
237
239
|
return parsed
|
|
238
240
|
}
|
|
239
241
|
const links = resolveLinks(doc, parsed.links)
|
|
240
242
|
return {
|
|
241
243
|
...parsed,
|
|
242
|
-
links
|
|
244
|
+
links,
|
|
243
245
|
}
|
|
244
246
|
}
|
|
245
247
|
try {
|
|
@@ -252,7 +254,7 @@ function buildModel(services: LikeC4Services, docs: ParsedLikeC4LangiumDocument[
|
|
|
252
254
|
technology = __kind.technology,
|
|
253
255
|
notation = __kind.notation,
|
|
254
256
|
links,
|
|
255
|
-
style
|
|
257
|
+
style,
|
|
256
258
|
} = parsed
|
|
257
259
|
return {
|
|
258
260
|
...parsed,
|
|
@@ -262,9 +264,9 @@ function buildModel(services: LikeC4Services, docs: ParsedLikeC4LangiumDocument[
|
|
|
262
264
|
border: 'dashed',
|
|
263
265
|
opacity: 10,
|
|
264
266
|
...__kind.style,
|
|
265
|
-
...style
|
|
267
|
+
...style,
|
|
266
268
|
},
|
|
267
|
-
links: links ? resolveLinks(doc, links) : null
|
|
269
|
+
links: links ? resolveLinks(doc, links) : null,
|
|
268
270
|
}
|
|
269
271
|
} catch (e) {
|
|
270
272
|
logWarnError(e)
|
|
@@ -290,8 +292,8 @@ function buildModel(services: LikeC4Services, docs: ParsedLikeC4LangiumDocument[
|
|
|
290
292
|
acc[el.id] = el
|
|
291
293
|
return acc
|
|
292
294
|
},
|
|
293
|
-
{} as c4.ParsedLikeC4Model['deployments']['elements']
|
|
294
|
-
)
|
|
295
|
+
{} as c4.ParsedLikeC4Model['deployments']['elements'],
|
|
296
|
+
),
|
|
295
297
|
)
|
|
296
298
|
|
|
297
299
|
function toDeploymentRelation(doc: LangiumDocument) {
|
|
@@ -308,7 +310,7 @@ function buildModel(services: LikeC4Services, docs: ParsedLikeC4LangiumDocument[
|
|
|
308
310
|
logger.warn(
|
|
309
311
|
`Invalid deployment relation ${id} at ${doc.uri.path} ${astPath}, source: ${source.id}(${!!deploymentElements[
|
|
310
312
|
source.id
|
|
311
|
-
]}), target: ${target.id}(${!!deploymentElements[target.id]})
|
|
313
|
+
]}), target: ${target.id}(${!!deploymentElements[target.id]})`,
|
|
312
314
|
)
|
|
313
315
|
return null
|
|
314
316
|
}
|
|
@@ -322,7 +324,7 @@ function buildModel(services: LikeC4Services, docs: ParsedLikeC4LangiumDocument[
|
|
|
322
324
|
source,
|
|
323
325
|
target,
|
|
324
326
|
kind,
|
|
325
|
-
id
|
|
327
|
+
id,
|
|
326
328
|
} satisfies c4.DeploymentRelation
|
|
327
329
|
}
|
|
328
330
|
return {
|
|
@@ -330,7 +332,7 @@ function buildModel(services: LikeC4Services, docs: ParsedLikeC4LangiumDocument[
|
|
|
330
332
|
...model,
|
|
331
333
|
source,
|
|
332
334
|
target,
|
|
333
|
-
id
|
|
335
|
+
id,
|
|
334
336
|
} satisfies c4.DeploymentRelation
|
|
335
337
|
}
|
|
336
338
|
}
|
|
@@ -348,8 +350,8 @@ function buildModel(services: LikeC4Services, docs: ParsedLikeC4LangiumDocument[
|
|
|
348
350
|
acc[el.id] = el
|
|
349
351
|
return acc
|
|
350
352
|
},
|
|
351
|
-
{} as c4.ParsedLikeC4Model['deployments']['relations']
|
|
352
|
-
)
|
|
353
|
+
{} as c4.ParsedLikeC4Model['deployments']['relations'],
|
|
354
|
+
),
|
|
353
355
|
)
|
|
354
356
|
|
|
355
357
|
function toC4View(doc: LangiumDocument) {
|
|
@@ -385,7 +387,7 @@ function buildModel(services: LikeC4Services, docs: ParsedLikeC4LangiumDocument[
|
|
|
385
387
|
docUri,
|
|
386
388
|
description,
|
|
387
389
|
title,
|
|
388
|
-
id
|
|
390
|
+
id,
|
|
389
391
|
}
|
|
390
392
|
}
|
|
391
393
|
}
|
|
@@ -394,7 +396,7 @@ function buildModel(services: LikeC4Services, docs: ParsedLikeC4LangiumDocument[
|
|
|
394
396
|
docs,
|
|
395
397
|
flatMap(d => map(d.c4Views, toC4View(d))),
|
|
396
398
|
// Resolve relative paths and sort by
|
|
397
|
-
resolveRelativePaths
|
|
399
|
+
resolveRelativePaths,
|
|
398
400
|
)
|
|
399
401
|
// Add index view if not present
|
|
400
402
|
if (!parsedViews.some(v => v.id === 'index')) {
|
|
@@ -410,18 +412,18 @@ function buildModel(services: LikeC4Services, docs: ParsedLikeC4LangiumDocument[
|
|
|
410
412
|
{
|
|
411
413
|
include: [
|
|
412
414
|
{
|
|
413
|
-
wildcard: true
|
|
414
|
-
}
|
|
415
|
-
]
|
|
416
|
-
}
|
|
417
|
-
]
|
|
415
|
+
wildcard: true,
|
|
416
|
+
},
|
|
417
|
+
],
|
|
418
|
+
},
|
|
419
|
+
],
|
|
418
420
|
})
|
|
419
421
|
}
|
|
420
422
|
|
|
421
423
|
const views = pipe(
|
|
422
424
|
parsedViews,
|
|
423
425
|
indexBy(prop('id')),
|
|
424
|
-
resolveRulesExtendedViews
|
|
426
|
+
resolveRulesExtendedViews,
|
|
425
427
|
)
|
|
426
428
|
|
|
427
429
|
return {
|
|
@@ -429,7 +431,7 @@ function buildModel(services: LikeC4Services, docs: ParsedLikeC4LangiumDocument[
|
|
|
429
431
|
tags: Array.from(c4Specification.tags),
|
|
430
432
|
elements: c4Specification.elements,
|
|
431
433
|
relationships: c4Specification.relationships,
|
|
432
|
-
deployments: c4Specification.deployments
|
|
434
|
+
deployments: c4Specification.deployments,
|
|
433
435
|
},
|
|
434
436
|
elements,
|
|
435
437
|
relations,
|
|
@@ -437,8 +439,8 @@ function buildModel(services: LikeC4Services, docs: ParsedLikeC4LangiumDocument[
|
|
|
437
439
|
views,
|
|
438
440
|
deployments: {
|
|
439
441
|
elements: deploymentElements,
|
|
440
|
-
relations: deploymentRelations
|
|
441
|
-
}
|
|
442
|
+
relations: deploymentRelations,
|
|
443
|
+
},
|
|
442
444
|
}
|
|
443
445
|
}
|
|
444
446
|
|
|
@@ -477,7 +479,7 @@ export class LikeC4ModelBuilder {
|
|
|
477
479
|
this.notifyListeners(parsed)
|
|
478
480
|
}
|
|
479
481
|
return await Promise.resolve()
|
|
480
|
-
}
|
|
482
|
+
},
|
|
481
483
|
)
|
|
482
484
|
logger.debug(`[ModelBuilder] Created`)
|
|
483
485
|
}
|
|
@@ -525,7 +527,7 @@ export class LikeC4ModelBuilder {
|
|
|
525
527
|
const cache = this.services.WorkspaceCache as WorkspaceCache<string, c4.ComputedLikeC4Model>
|
|
526
528
|
const viewsCache = this.services.WorkspaceCache as WorkspaceCache<string, c4.ComputedView | null>
|
|
527
529
|
return cache.get(CACHE_KEY_COMPUTED_MODEL, () => {
|
|
528
|
-
const computeView =
|
|
530
|
+
const computeView = LikeC4Model.makeCompute(model)
|
|
529
531
|
const allViews = [] as c4.ComputedView[]
|
|
530
532
|
for (const view of values(model.views)) {
|
|
531
533
|
const result = computeView(view)
|
|
@@ -550,16 +552,16 @@ export class LikeC4ModelBuilder {
|
|
|
550
552
|
'elements',
|
|
551
553
|
'relations',
|
|
552
554
|
'globals',
|
|
553
|
-
'deployments'
|
|
554
|
-
])
|
|
555
|
+
'deployments',
|
|
556
|
+
]),
|
|
555
557
|
),
|
|
556
|
-
views
|
|
558
|
+
views,
|
|
557
559
|
}
|
|
558
560
|
})
|
|
559
561
|
}
|
|
560
562
|
|
|
561
563
|
public async buildComputedModel(
|
|
562
|
-
cancelToken?: Cancellation.CancellationToken
|
|
564
|
+
cancelToken?: Cancellation.CancellationToken,
|
|
563
565
|
): Promise<c4.ComputedLikeC4Model | null> {
|
|
564
566
|
const cache = this.services.WorkspaceCache as WorkspaceCache<string, c4.ComputedLikeC4Model | null>
|
|
565
567
|
if (cache.has(CACHE_KEY_COMPUTED_MODEL)) {
|
|
@@ -579,7 +581,7 @@ export class LikeC4ModelBuilder {
|
|
|
579
581
|
|
|
580
582
|
public async computeView(
|
|
581
583
|
viewId: ViewId,
|
|
582
|
-
cancelToken?: Cancellation.CancellationToken
|
|
584
|
+
cancelToken?: Cancellation.CancellationToken,
|
|
583
585
|
): Promise<c4.ComputedView | null> {
|
|
584
586
|
const cache = this.services.WorkspaceCache as WorkspaceCache<string, c4.ComputedView | null>
|
|
585
587
|
const cacheKey = computedViewKey(viewId)
|
|
@@ -597,9 +599,9 @@ export class LikeC4ModelBuilder {
|
|
|
597
599
|
logger.warn(`[ModelBuilder] Cannot find view ${viewId}`)
|
|
598
600
|
return null
|
|
599
601
|
}
|
|
600
|
-
const result =
|
|
602
|
+
const result = LikeC4Model.makeCompute(model)(view)
|
|
601
603
|
if (!result.isSuccess) {
|
|
602
|
-
|
|
604
|
+
logWarnError(result.error)
|
|
603
605
|
return null
|
|
604
606
|
}
|
|
605
607
|
let computedView = result.view
|
|
@@ -609,7 +611,7 @@ export class LikeC4ModelBuilder {
|
|
|
609
611
|
values(),
|
|
610
612
|
filter(isScopedElementView),
|
|
611
613
|
filter(v => v.id !== viewId),
|
|
612
|
-
groupBy(v => v.viewOf)
|
|
614
|
+
groupBy(v => v.viewOf),
|
|
613
615
|
)
|
|
614
616
|
|
|
615
617
|
for (const node of computedView.nodes) {
|
|
@@ -652,7 +654,7 @@ export class LikeC4ModelBuilder {
|
|
|
652
654
|
try {
|
|
653
655
|
listener(docs)
|
|
654
656
|
} catch (e) {
|
|
655
|
-
|
|
657
|
+
logWarnError(e)
|
|
656
658
|
}
|
|
657
659
|
}
|
|
658
660
|
}
|