@likec4/language-server 1.17.1 → 1.19.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.
Files changed (268) hide show
  1. package/contrib/likec4.tmLanguage.json +1 -1
  2. package/dist/LikeC4FileSystem.d.ts +13 -0
  3. package/dist/LikeC4FileSystem.js +27 -0
  4. package/dist/Rpc.d.ts +9 -0
  5. package/dist/Rpc.js +126 -0
  6. package/dist/ast.d.ts +200 -0
  7. package/dist/ast.js +276 -0
  8. package/dist/browser.d.ts +6 -20
  9. package/dist/browser.js +13 -0
  10. package/dist/formatting/LikeC4Formatter.d.ts +27 -0
  11. package/dist/formatting/LikeC4Formatter.js +261 -0
  12. package/dist/formatting/utils.d.ts +6 -0
  13. package/dist/formatting/utils.js +15 -0
  14. package/dist/generated/ast.d.ts +1242 -0
  15. package/dist/generated/ast.js +1945 -0
  16. package/dist/generated/grammar.d.ts +6 -0
  17. package/dist/generated/grammar.js +3 -0
  18. package/dist/generated/module.d.ts +9 -0
  19. package/dist/generated/module.js +23 -0
  20. package/dist/generated-lib/icons.d.ts +1 -0
  21. package/dist/{likec4lib.mjs → generated-lib/icons.js} +1 -6
  22. package/dist/index.d.ts +8 -31
  23. package/dist/index.js +13 -0
  24. package/dist/like-c4.langium +845 -0
  25. package/dist/likec4lib.d.ts +4 -6
  26. package/dist/likec4lib.js +4 -0
  27. package/dist/logger.d.ts +7 -0
  28. package/dist/logger.js +73 -0
  29. package/dist/lsp/CodeLensProvider.d.ts +9 -0
  30. package/dist/lsp/CodeLensProvider.js +40 -0
  31. package/dist/lsp/CompletionProvider.d.ts +6 -0
  32. package/dist/lsp/CompletionProvider.js +135 -0
  33. package/dist/lsp/DocumentHighlightProvider.d.ts +9 -0
  34. package/dist/lsp/DocumentHighlightProvider.js +10 -0
  35. package/dist/lsp/DocumentLinkProvider.d.ts +11 -0
  36. package/dist/lsp/DocumentLinkProvider.js +49 -0
  37. package/dist/lsp/DocumentSymbolProvider.d.ts +23 -0
  38. package/dist/lsp/DocumentSymbolProvider.js +202 -0
  39. package/dist/lsp/HoverProvider.d.ts +10 -0
  40. package/dist/lsp/HoverProvider.js +69 -0
  41. package/dist/lsp/RenameProvider.d.ts +5 -0
  42. package/dist/lsp/RenameProvider.js +6 -0
  43. package/dist/lsp/SemanticTokenProvider.d.ts +7 -0
  44. package/dist/lsp/SemanticTokenProvider.js +297 -0
  45. package/dist/lsp/index.d.ts +7 -0
  46. package/dist/lsp/index.js +7 -0
  47. package/dist/model/deployments-index.d.ts +60 -0
  48. package/dist/model/deployments-index.js +181 -0
  49. package/dist/model/fqn-computation.d.ts +3 -0
  50. package/dist/model/fqn-computation.js +72 -0
  51. package/dist/model/fqn-index.d.ts +25 -0
  52. package/dist/model/fqn-index.js +96 -0
  53. package/dist/model/index.d.ts +6 -0
  54. package/dist/model/index.js +6 -0
  55. package/dist/model/model-builder.d.ts +32 -0
  56. package/dist/model/model-builder.js +598 -0
  57. package/dist/model/model-locator.d.ts +23 -0
  58. package/dist/model/model-locator.js +126 -0
  59. package/dist/model/model-parser-where.d.ts +3 -0
  60. package/dist/model/model-parser-where.js +70 -0
  61. package/dist/model/model-parser.d.ts +292 -0
  62. package/dist/model/model-parser.js +72 -0
  63. package/dist/model/parser/Base.d.ts +28 -0
  64. package/dist/model/parser/Base.js +87 -0
  65. package/dist/model/parser/DeploymentModelParser.d.ts +33 -0
  66. package/dist/model/parser/DeploymentModelParser.js +162 -0
  67. package/dist/model/parser/DeploymentViewParser.d.ts +38 -0
  68. package/dist/model/parser/DeploymentViewParser.js +98 -0
  69. package/dist/model/parser/FqnRefParser.d.ts +29 -0
  70. package/dist/model/parser/FqnRefParser.js +108 -0
  71. package/dist/model/parser/GlobalsParser.d.ts +66 -0
  72. package/dist/model/parser/GlobalsParser.js +80 -0
  73. package/dist/model/parser/ModelParser.d.ts +27 -0
  74. package/dist/model/parser/ModelParser.js +122 -0
  75. package/dist/model/parser/PredicatesParser.d.ts +34 -0
  76. package/dist/model/parser/PredicatesParser.js +272 -0
  77. package/dist/model/parser/SpecificationParser.d.ts +27 -0
  78. package/dist/model/parser/SpecificationParser.js +120 -0
  79. package/dist/model/parser/ViewsParser.d.ts +64 -0
  80. package/dist/model/parser/ViewsParser.js +377 -0
  81. package/dist/model-change/ModelChanges.d.ts +15 -0
  82. package/dist/model-change/ModelChanges.js +89 -0
  83. package/dist/model-change/changeElementStyle.d.ts +16 -0
  84. package/dist/model-change/changeElementStyle.js +136 -0
  85. package/dist/model-change/changeViewLayout.d.ts +12 -0
  86. package/dist/model-change/changeViewLayout.js +32 -0
  87. package/dist/model-change/saveManualLayout.d.ts +11 -0
  88. package/dist/model-change/saveManualLayout.js +27 -0
  89. package/dist/module.d.ts +62 -0
  90. package/dist/module.js +123 -0
  91. package/dist/protocol.d.ts +27 -27
  92. package/dist/protocol.js +14 -0
  93. package/dist/references/index.d.ts +3 -0
  94. package/dist/references/index.js +3 -0
  95. package/dist/references/name-provider.d.ts +9 -0
  96. package/dist/references/name-provider.js +33 -0
  97. package/dist/references/scope-computation.d.ts +20 -0
  98. package/dist/references/scope-computation.js +281 -0
  99. package/dist/references/scope-provider.d.ts +16 -0
  100. package/dist/references/scope-provider.js +165 -0
  101. package/dist/shared/NodeKindProvider.d.ts +15 -0
  102. package/dist/shared/NodeKindProvider.js +108 -0
  103. package/dist/shared/WorkspaceManager.d.ts +18 -0
  104. package/dist/shared/WorkspaceManager.js +36 -0
  105. package/dist/shared/WorkspaceSymbolProvider.d.ts +3 -0
  106. package/dist/shared/WorkspaceSymbolProvider.js +3 -0
  107. package/dist/shared/index.d.ts +3 -0
  108. package/dist/shared/index.js +3 -0
  109. package/dist/test/index.d.ts +1 -0
  110. package/dist/test/index.js +1 -0
  111. package/dist/test/setup.d.ts +1 -0
  112. package/dist/test/setup.js +7 -0
  113. package/dist/test/testServices.d.ts +22 -0
  114. package/dist/test/testServices.js +119 -0
  115. package/dist/utils/elementRef.d.ts +11 -0
  116. package/dist/utils/elementRef.js +15 -0
  117. package/dist/utils/fqnRef.d.ts +8 -0
  118. package/dist/utils/fqnRef.js +46 -0
  119. package/dist/utils/index.d.ts +1 -0
  120. package/dist/utils/index.js +1 -0
  121. package/dist/utils/printDocs.d.ts +2 -0
  122. package/dist/utils/printDocs.js +1 -0
  123. package/dist/utils/stringHash.d.ts +1 -0
  124. package/dist/utils/stringHash.js +5 -0
  125. package/dist/validation/_shared.d.ts +3 -0
  126. package/dist/validation/_shared.js +22 -0
  127. package/dist/validation/deployment-checks.d.ts +6 -0
  128. package/dist/validation/deployment-checks.js +114 -0
  129. package/dist/validation/dynamic-view-rule.d.ts +4 -0
  130. package/dist/validation/dynamic-view-rule.js +16 -0
  131. package/dist/validation/dynamic-view-step.d.ts +4 -0
  132. package/dist/validation/dynamic-view-step.js +33 -0
  133. package/dist/validation/element.d.ts +4 -0
  134. package/dist/validation/element.js +49 -0
  135. package/dist/validation/index.d.ts +15 -0
  136. package/dist/validation/index.js +152 -0
  137. package/dist/validation/property-checks.d.ts +6 -0
  138. package/dist/validation/property-checks.js +38 -0
  139. package/dist/validation/relation.d.ts +5 -0
  140. package/dist/validation/relation.js +56 -0
  141. package/dist/validation/specification.d.ts +11 -0
  142. package/dist/validation/specification.js +136 -0
  143. package/dist/validation/view-predicates/element-with.d.ts +4 -0
  144. package/dist/validation/view-predicates/element-with.js +30 -0
  145. package/dist/validation/view-predicates/expanded-element.d.ts +4 -0
  146. package/dist/validation/view-predicates/expanded-element.js +11 -0
  147. package/dist/validation/view-predicates/expression-v2.d.ts +5 -0
  148. package/dist/validation/view-predicates/expression-v2.js +83 -0
  149. package/dist/validation/view-predicates/incoming.d.ts +4 -0
  150. package/dist/validation/view-predicates/incoming.js +15 -0
  151. package/dist/validation/view-predicates/index.d.ts +6 -0
  152. package/dist/validation/view-predicates/index.js +6 -0
  153. package/dist/validation/view-predicates/outgoing.d.ts +4 -0
  154. package/dist/validation/view-predicates/outgoing.js +15 -0
  155. package/dist/validation/view-predicates/relation-with.d.ts +4 -0
  156. package/dist/validation/view-predicates/relation-with.js +12 -0
  157. package/dist/validation/view.d.ts +4 -0
  158. package/dist/validation/view.js +23 -0
  159. package/dist/view-utils/assignNavigateTo.d.ts +2 -0
  160. package/dist/view-utils/assignNavigateTo.js +25 -0
  161. package/dist/view-utils/index.d.ts +2 -0
  162. package/dist/view-utils/index.js +2 -0
  163. package/dist/view-utils/manual-layout.d.ts +7 -0
  164. package/dist/view-utils/manual-layout.js +99 -0
  165. package/dist/view-utils/resolve-relative-paths.d.ts +2 -0
  166. package/dist/view-utils/resolve-relative-paths.js +78 -0
  167. package/package.json +42 -73
  168. package/src/LikeC4FileSystem.ts +22 -21
  169. package/src/Rpc.ts +6 -3
  170. package/src/ast.ts +136 -172
  171. package/src/browser.ts +10 -11
  172. package/src/generated/ast.ts +656 -40
  173. package/src/generated/grammar.ts +1 -1
  174. package/src/index.ts +11 -8
  175. package/src/like-c4.langium +173 -22
  176. package/src/logger.ts +41 -57
  177. package/src/lsp/CodeLensProvider.ts +0 -1
  178. package/src/lsp/CompletionProvider.ts +20 -5
  179. package/src/lsp/DocumentSymbolProvider.ts +5 -2
  180. package/src/lsp/HoverProvider.ts +37 -3
  181. package/src/lsp/SemanticTokenProvider.ts +58 -32
  182. package/src/model/deployments-index.ts +222 -0
  183. package/src/model/fqn-computation.ts +1 -1
  184. package/src/model/fqn-index.ts +0 -1
  185. package/src/model/index.ts +1 -0
  186. package/src/model/model-builder.ts +176 -39
  187. package/src/model/model-locator.ts +36 -7
  188. package/src/model/model-parser.ts +69 -1119
  189. package/src/model/parser/Base.ts +107 -0
  190. package/src/model/parser/DeploymentModelParser.ts +192 -0
  191. package/src/model/parser/DeploymentViewParser.ts +116 -0
  192. package/src/model/parser/FqnRefParser.ts +118 -0
  193. package/src/model/parser/GlobalsParser.ts +96 -0
  194. package/src/model/parser/ModelParser.ts +141 -0
  195. package/src/model/parser/PredicatesParser.ts +291 -0
  196. package/src/model/parser/SpecificationParser.ts +133 -0
  197. package/src/model/parser/ViewsParser.ts +428 -0
  198. package/src/model-change/changeViewLayout.ts +2 -2
  199. package/src/module.ts +26 -21
  200. package/src/protocol.ts +10 -6
  201. package/src/references/index.ts +1 -0
  202. package/src/references/name-provider.ts +37 -0
  203. package/src/references/scope-computation.ts +130 -21
  204. package/src/references/scope-provider.ts +68 -35
  205. package/src/shared/NodeKindProvider.ts +15 -3
  206. package/src/{elementRef.ts → utils/elementRef.ts} +1 -1
  207. package/src/utils/fqnRef.ts +56 -0
  208. package/src/utils/stringHash.ts +2 -2
  209. package/src/validation/_shared.ts +6 -5
  210. package/src/validation/deployment-checks.ts +131 -0
  211. package/src/validation/dynamic-view-step.ts +1 -1
  212. package/src/validation/index.ts +104 -6
  213. package/src/validation/relation.ts +1 -1
  214. package/src/validation/view-predicates/expression-v2.ts +101 -0
  215. package/src/validation/view-predicates/index.ts +1 -0
  216. package/src/view-utils/assignNavigateTo.ts +6 -5
  217. package/src/view-utils/index.ts +0 -1
  218. package/src/view-utils/manual-layout.ts +25 -0
  219. package/dist/browser.cjs +0 -25
  220. package/dist/browser.d.cts +0 -23
  221. package/dist/browser.d.mts +0 -23
  222. package/dist/browser.mjs +0 -20
  223. package/dist/index.cjs +0 -53
  224. package/dist/index.d.cts +0 -34
  225. package/dist/index.d.mts +0 -34
  226. package/dist/index.mjs +0 -46
  227. package/dist/likec4lib.cjs +0 -1546
  228. package/dist/likec4lib.d.cts +0 -6
  229. package/dist/likec4lib.d.mts +0 -6
  230. package/dist/model-graph/index.cjs +0 -10
  231. package/dist/model-graph/index.d.cts +0 -81
  232. package/dist/model-graph/index.d.mts +0 -81
  233. package/dist/model-graph/index.d.ts +0 -81
  234. package/dist/model-graph/index.mjs +0 -1
  235. package/dist/protocol.cjs +0 -25
  236. package/dist/protocol.d.cts +0 -45
  237. package/dist/protocol.d.mts +0 -45
  238. package/dist/protocol.mjs +0 -17
  239. package/dist/shared/language-server.BIbAD1T-.mjs +0 -6292
  240. package/dist/shared/language-server.BQRvVmE0.d.cts +0 -1303
  241. package/dist/shared/language-server.BysPcTxr.d.ts +0 -1303
  242. package/dist/shared/language-server.D2QdbOJO.cjs +0 -1995
  243. package/dist/shared/language-server.DGrBGmsd.mjs +0 -1981
  244. package/dist/shared/language-server.DKV_FdPN.cjs +0 -6304
  245. package/dist/shared/language-server._wkyPgso.d.mts +0 -1303
  246. package/src/model-graph/LikeC4ModelGraph.ts +0 -338
  247. package/src/model-graph/compute-view/__test__/fixture.ts +0 -630
  248. package/src/model-graph/compute-view/compute.ts +0 -788
  249. package/src/model-graph/compute-view/index.ts +0 -33
  250. package/src/model-graph/compute-view/predicates.ts +0 -509
  251. package/src/model-graph/dynamic-view/__test__/fixture.ts +0 -61
  252. package/src/model-graph/dynamic-view/compute.ts +0 -313
  253. package/src/model-graph/dynamic-view/index.ts +0 -29
  254. package/src/model-graph/index.ts +0 -3
  255. package/src/model-graph/utils/applyCustomElementProperties.ts +0 -65
  256. package/src/model-graph/utils/applyCustomRelationProperties.ts +0 -41
  257. package/src/model-graph/utils/applyViewRuleStyles.ts +0 -49
  258. package/src/model-graph/utils/buildComputeNodes.ts +0 -113
  259. package/src/model-graph/utils/buildElementNotations.ts +0 -63
  260. package/src/model-graph/utils/elementExpressionToPredicate.ts +0 -39
  261. package/src/model-graph/utils/relationExpressionToPredicates.ts +0 -43
  262. package/src/model-graph/utils/sortNodes.ts +0 -105
  263. package/src/model-graph/utils/uniqueTags.test.ts +0 -42
  264. package/src/model-graph/utils/uniqueTags.ts +0 -19
  265. package/src/utils/graphlib.ts +0 -9
  266. package/src/view-utils/resolve-extended-views.ts +0 -66
  267. package/src/view-utils/resolve-global-rules.ts +0 -88
  268. package/src/view-utils/view-hash.ts +0 -27
@@ -0,0 +1,5 @@
1
+ import { DefaultRenameProvider } from 'langium/lsp';
2
+ import type { LikeC4Services } from '../module';
3
+ export declare class LikeC4RenameProvider extends DefaultRenameProvider {
4
+ constructor(services: LikeC4Services);
5
+ }
@@ -0,0 +1,6 @@
1
+ import { DefaultRenameProvider } from "langium/lsp";
2
+ export class LikeC4RenameProvider extends DefaultRenameProvider {
3
+ constructor(services) {
4
+ super(services);
5
+ }
6
+ }
@@ -0,0 +1,7 @@
1
+ import type { AstNode } from 'langium';
2
+ import { AbstractSemanticTokenProvider, type SemanticTokenAcceptor } from 'langium/lsp';
3
+ export declare class LikeC4SemanticTokenProvider extends AbstractSemanticTokenProvider {
4
+ protected highlightElement(node: AstNode, acceptor: SemanticTokenAcceptor): void | undefined | 'prune';
5
+ private highlightNameAndKind;
6
+ private highlightView;
7
+ }
@@ -0,0 +1,297 @@
1
+ import { AbstractSemanticTokenProvider } from "langium/lsp";
2
+ import { isTruthy } from "remeda";
3
+ import { SemanticTokenModifiers, SemanticTokenTypes } from "vscode-languageserver-types";
4
+ import { ast } from "../ast.js";
5
+ export class LikeC4SemanticTokenProvider extends AbstractSemanticTokenProvider {
6
+ // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
7
+ highlightElement(node, acceptor) {
8
+ if (ast.isElement(node) || ast.isDeploymentNode(node)) {
9
+ return this.highlightNameAndKind(node, acceptor);
10
+ }
11
+ if (ast.isDeployedInstance(node)) {
12
+ if ("name" in node) {
13
+ acceptor({
14
+ node,
15
+ property: "name",
16
+ type: SemanticTokenTypes.variable,
17
+ modifier: [
18
+ SemanticTokenModifiers.definition,
19
+ SemanticTokenModifiers.readonly
20
+ ]
21
+ });
22
+ }
23
+ return;
24
+ }
25
+ if (ast.isLikeC4View(node)) {
26
+ return this.highlightView(node, acceptor);
27
+ }
28
+ if (ast.isRelationshipKind(node)) {
29
+ return acceptor({
30
+ node,
31
+ property: "name",
32
+ type: SemanticTokenTypes.function
33
+ });
34
+ }
35
+ if (ast.isLibIcon(node)) {
36
+ acceptor({
37
+ node,
38
+ property: "name",
39
+ type: SemanticTokenTypes.type,
40
+ modifier: [SemanticTokenModifiers.definition]
41
+ });
42
+ return "prune";
43
+ }
44
+ if (ast.isOutgoingRelationExpression(node) && "kind" in node) {
45
+ acceptor({
46
+ node,
47
+ property: "kind",
48
+ type: SemanticTokenTypes.function
49
+ });
50
+ return;
51
+ }
52
+ if (ast.isRelation(node) && "kind" in node) {
53
+ acceptor({
54
+ node,
55
+ property: "kind",
56
+ type: SemanticTokenTypes.function
57
+ });
58
+ }
59
+ if (ast.isNavigateToProperty(node) || ast.isRelationNavigateToProperty(node)) {
60
+ acceptor({
61
+ node,
62
+ property: "key",
63
+ type: SemanticTokenTypes.property
64
+ });
65
+ acceptor({
66
+ node,
67
+ property: "value",
68
+ type: SemanticTokenTypes.variable,
69
+ modifier: [
70
+ SemanticTokenModifiers.definition,
71
+ SemanticTokenModifiers.readonly
72
+ ]
73
+ });
74
+ return "prune";
75
+ }
76
+ if ((ast.isElementDescedantsExpression(node) || ast.isWildcardExpression(node)) && node.$cstNode) {
77
+ acceptor({
78
+ cst: node.$cstNode,
79
+ type: SemanticTokenTypes.variable,
80
+ modifier: [
81
+ SemanticTokenModifiers.definition,
82
+ SemanticTokenModifiers.readonly
83
+ ]
84
+ });
85
+ return "prune";
86
+ }
87
+ if (ast.isFqnRefExpr(node)) {
88
+ if (node.selector) {
89
+ acceptor({
90
+ node,
91
+ property: "selector",
92
+ type: SemanticTokenTypes.variable,
93
+ modifier: [
94
+ SemanticTokenModifiers.definition,
95
+ SemanticTokenModifiers.readonly
96
+ ]
97
+ });
98
+ }
99
+ return;
100
+ }
101
+ if (ast.isWhereRelationKind(node) && isTruthy(node.value)) {
102
+ acceptor({
103
+ node,
104
+ property: "value",
105
+ type: SemanticTokenTypes.function
106
+ });
107
+ return;
108
+ }
109
+ if ((ast.isWhereElement(node) || ast.isWhereRelation(node)) && isTruthy(node.value)) {
110
+ acceptor({
111
+ node,
112
+ property: "value",
113
+ type: SemanticTokenTypes.type,
114
+ modifier: [
115
+ SemanticTokenModifiers.definition,
116
+ SemanticTokenModifiers.readonly
117
+ ]
118
+ });
119
+ return;
120
+ }
121
+ if (ast.isElementKindExpression(node) && isTruthy(node.kind)) {
122
+ acceptor({
123
+ node,
124
+ property: "kind",
125
+ type: SemanticTokenTypes.type,
126
+ modifier: [SemanticTokenModifiers.definition]
127
+ });
128
+ return "prune";
129
+ }
130
+ if (ast.isElementTagExpression(node) && isTruthy(node.tag)) {
131
+ acceptor({
132
+ node,
133
+ property: "tag",
134
+ type: SemanticTokenTypes.type,
135
+ modifier: [SemanticTokenModifiers.definition]
136
+ });
137
+ return "prune";
138
+ }
139
+ if (ast.isFqnRef(node)) {
140
+ acceptor({
141
+ node,
142
+ property: "value",
143
+ type: node.parent ? SemanticTokenTypes.property : SemanticTokenTypes.variable,
144
+ modifier: [
145
+ SemanticTokenModifiers.definition,
146
+ SemanticTokenModifiers.readonly
147
+ ]
148
+ });
149
+ return !node.parent ? "prune" : void 0;
150
+ }
151
+ if (ast.isElementRef(node) || ast.isFqnElementRef(node)) {
152
+ acceptor({
153
+ node,
154
+ property: "el",
155
+ type: node.parent ? SemanticTokenTypes.property : SemanticTokenTypes.variable,
156
+ modifier: [
157
+ SemanticTokenModifiers.definition,
158
+ SemanticTokenModifiers.readonly
159
+ ]
160
+ });
161
+ return !node.parent ? "prune" : void 0;
162
+ }
163
+ if (ast.isSpecificationColor(node)) {
164
+ acceptor({
165
+ node,
166
+ keyword: "color",
167
+ type: SemanticTokenTypes.keyword
168
+ });
169
+ acceptor({
170
+ node,
171
+ property: "name",
172
+ type: SemanticTokenTypes.type,
173
+ modifier: [
174
+ SemanticTokenModifiers.declaration,
175
+ SemanticTokenModifiers.readonly
176
+ ]
177
+ });
178
+ return;
179
+ }
180
+ if (ast.isSpecificationElementKind(node) || ast.isSpecificationRelationshipKind(node) || ast.isSpecificationDeploymentNodeKind(node)) {
181
+ acceptor({
182
+ node,
183
+ property: "kind",
184
+ type: SemanticTokenTypes.type,
185
+ modifier: [
186
+ SemanticTokenModifiers.declaration,
187
+ SemanticTokenModifiers.readonly
188
+ ]
189
+ });
190
+ }
191
+ if (ast.isTags(node)) {
192
+ return acceptor({
193
+ node,
194
+ property: "values",
195
+ type: SemanticTokenTypes.interface
196
+ });
197
+ }
198
+ if (ast.isTag(node)) {
199
+ return acceptor({
200
+ node,
201
+ property: "name",
202
+ type: SemanticTokenTypes.type,
203
+ modifier: [SemanticTokenModifiers.definition]
204
+ });
205
+ }
206
+ if (ast.isRelationStyleProperty(node) || ast.isElementStyleProperty(node) && ast.isElementBody(node.$container)) {
207
+ acceptor({
208
+ node,
209
+ property: "key",
210
+ type: SemanticTokenTypes.property
211
+ });
212
+ }
213
+ if (ast.isOpacityProperty(node)) {
214
+ acceptor({
215
+ node,
216
+ property: "key",
217
+ type: SemanticTokenTypes.property
218
+ });
219
+ acceptor({
220
+ node,
221
+ property: "value",
222
+ type: SemanticTokenTypes.number
223
+ });
224
+ return "prune";
225
+ }
226
+ if (ast.isLinkProperty(node) || ast.isIconProperty(node) || ast.isStringProperty(node)) {
227
+ acceptor({
228
+ node,
229
+ property: "key",
230
+ type: SemanticTokenTypes.property
231
+ });
232
+ if (ast.isIconProperty(node) && (node.libicon || node.value === "none")) {
233
+ acceptor({
234
+ node,
235
+ property: node.libicon ? "libicon" : "value",
236
+ type: SemanticTokenTypes.enum,
237
+ modifier: [SemanticTokenModifiers.defaultLibrary]
238
+ });
239
+ return "prune";
240
+ }
241
+ if ("value" in node && node.value) {
242
+ acceptor({
243
+ node,
244
+ property: "value",
245
+ type: SemanticTokenTypes.string
246
+ });
247
+ }
248
+ return "prune";
249
+ }
250
+ if (ast.isColorProperty(node) || ast.isShapeProperty(node) || ast.isArrowProperty(node) || ast.isLineProperty(node) || ast.isBorderProperty(node)) {
251
+ acceptor({
252
+ node,
253
+ property: "key",
254
+ type: SemanticTokenTypes.property
255
+ });
256
+ if ("value" in node) {
257
+ acceptor({
258
+ node,
259
+ property: "value",
260
+ type: SemanticTokenTypes.enum
261
+ });
262
+ }
263
+ return "prune";
264
+ }
265
+ }
266
+ highlightNameAndKind(node, acceptor) {
267
+ acceptor({
268
+ node,
269
+ property: "name",
270
+ type: SemanticTokenTypes.variable,
271
+ modifier: [
272
+ SemanticTokenModifiers.declaration,
273
+ SemanticTokenModifiers.readonly
274
+ ]
275
+ });
276
+ acceptor({
277
+ node,
278
+ property: "kind",
279
+ type: SemanticTokenTypes.keyword,
280
+ modifier: []
281
+ });
282
+ }
283
+ highlightView(node, acceptor) {
284
+ if (node.name) {
285
+ acceptor({
286
+ node,
287
+ property: "name",
288
+ type: SemanticTokenTypes.variable,
289
+ modifier: [
290
+ SemanticTokenModifiers.declaration,
291
+ SemanticTokenModifiers.readonly,
292
+ "local"
293
+ ]
294
+ });
295
+ }
296
+ }
297
+ }
@@ -0,0 +1,7 @@
1
+ export * from './CodeLensProvider';
2
+ export * from './CompletionProvider';
3
+ export * from './DocumentHighlightProvider';
4
+ export * from './DocumentLinkProvider';
5
+ export * from './DocumentSymbolProvider';
6
+ export * from './HoverProvider';
7
+ export * from './SemanticTokenProvider';
@@ -0,0 +1,7 @@
1
+ export * from "./CodeLensProvider.js";
2
+ export * from "./CompletionProvider.js";
3
+ export * from "./DocumentHighlightProvider.js";
4
+ export * from "./DocumentLinkProvider.js";
5
+ export * from "./DocumentSymbolProvider.js";
6
+ export * from "./HoverProvider.js";
7
+ export * from "./SemanticTokenProvider.js";
@@ -0,0 +1,60 @@
1
+ import type { Fqn } from '@likec4/core';
2
+ import type { LangiumDocuments, Stream } from 'langium';
3
+ import { MultiMap } from 'langium';
4
+ import { type DeploymentAstNodeDescription, type LikeC4LangiumDocument, ast } from '../ast';
5
+ import type { LikeC4Services } from '../module';
6
+ import type { LikeC4NameProvider } from '../references';
7
+ export declare class DeploymentsIndex {
8
+ private services;
9
+ protected Names: LikeC4NameProvider;
10
+ protected langiumDocuments: LangiumDocuments;
11
+ constructor(services: LikeC4Services);
12
+ private documents;
13
+ get(document: LikeC4LangiumDocument): DocumentDeploymentsIndex;
14
+ /**
15
+ * Nested elements (nodes/artifacts) of the node
16
+ * @param nodeName Name of the deployment node
17
+ * @returns Stream of artifacts
18
+ */
19
+ nested(node: ast.DeploymentNode): Stream<DeploymentAstNodeDescription>;
20
+ byFqn(fqnName: string): Stream<DeploymentAstNodeDescription>;
21
+ getFqn(node: ast.DeploymentElement): Fqn;
22
+ createDocumentIndex(document: LikeC4LangiumDocument): DocumentDeploymentsIndex;
23
+ }
24
+ /**
25
+ * Index of deployment elements in the document
26
+ */
27
+ export declare class DocumentDeploymentsIndex {
28
+ private _rootNodes;
29
+ /**
30
+ * Nested of a deployment node
31
+ */
32
+ private _nested;
33
+ /**
34
+ * All elements by FQN
35
+ */
36
+ private _byfqn;
37
+ static readonly EMPTY: DocumentDeploymentsIndex;
38
+ constructor(_rootNodes: Array<DeploymentAstNodeDescription>,
39
+ /**
40
+ * Nested of a deployment node
41
+ */
42
+ _nested: MultiMap<string, DeploymentAstNodeDescription>,
43
+ /**
44
+ * All elements by FQN
45
+ */
46
+ _byfqn: MultiMap<string, DeploymentAstNodeDescription>);
47
+ rootNodes(): readonly DeploymentAstNodeDescription[];
48
+ byFqn(fqnName: string): readonly DeploymentAstNodeDescription[];
49
+ /**
50
+ * Returns artifacts of a deployment node
51
+ * @param nodeName Name of the deployment node
52
+ * @returns Stream of artifacts
53
+ */
54
+ nested(nodeName: string): readonly DeploymentAstNodeDescription[];
55
+ /**
56
+ * Returns all deployment elements in the document,
57
+ * with unique combination "type and name"
58
+ */
59
+ unique(): readonly DeploymentAstNodeDescription[];
60
+ }
@@ -0,0 +1,181 @@
1
+ import { AstUtils, DocumentState, MultiMap } from "langium";
2
+ import { forEachObj, groupBy, isTruthy, pipe, prop } from "remeda";
3
+ import {
4
+ ast,
5
+ ElementOps,
6
+ isLikeC4LangiumDocument
7
+ } from "../ast.js";
8
+ import { logWarnError } from "../logger.js";
9
+ const DeploymentsIndexKey = Symbol.for("DeploymentsIndex");
10
+ export class DeploymentsIndex {
11
+ constructor(services) {
12
+ this.services = services;
13
+ this.Names = services.references.NameProvider;
14
+ this.langiumDocuments = services.shared.workspace.LangiumDocuments;
15
+ services.shared.workspace.DocumentBuilder.onBuildPhase(
16
+ DocumentState.IndexedContent,
17
+ (docs, _cancelToken) => {
18
+ for (const doc of docs) {
19
+ delete doc[DeploymentsIndexKey];
20
+ }
21
+ }
22
+ );
23
+ }
24
+ Names;
25
+ langiumDocuments;
26
+ documents() {
27
+ return this.langiumDocuments.all.filter(
28
+ (d) => isLikeC4LangiumDocument(d) && d.state >= DocumentState.IndexedContent
29
+ );
30
+ }
31
+ get(document) {
32
+ if (document.state < DocumentState.IndexedContent) {
33
+ logWarnError(`Document ${document.uri.path} is not indexed`);
34
+ }
35
+ return document[DeploymentsIndexKey] ??= this.createDocumentIndex(document);
36
+ }
37
+ /**
38
+ * Nested elements (nodes/artifacts) of the node
39
+ * @param nodeName Name of the deployment node
40
+ * @returns Stream of artifacts
41
+ */
42
+ nested(node) {
43
+ const fqnName = this.getFqn(node);
44
+ return this.documents().flatMap((doc) => this.get(doc).nested(fqnName));
45
+ }
46
+ byFqn(fqnName) {
47
+ return this.documents().flatMap((doc) => this.get(doc).byFqn(fqnName));
48
+ }
49
+ getFqn(node) {
50
+ let id = ElementOps.readId(node);
51
+ if (isTruthy(id)) {
52
+ return id;
53
+ }
54
+ const fqn = [
55
+ this.Names.getNameStrict(node)
56
+ ];
57
+ let _node = node;
58
+ let parentNode;
59
+ while (parentNode = AstUtils.getContainerOfType(_node.$container, ast.isDeploymentNode)) {
60
+ fqn.push(this.Names.getNameStrict(parentNode));
61
+ _node = parentNode;
62
+ }
63
+ id = fqn.reduceRight((acc, cur) => `${acc}.${cur}`);
64
+ ElementOps.writeId(node, id);
65
+ return id;
66
+ }
67
+ createDocumentIndex(document) {
68
+ const rootNodes = document.parseResult.value.deployments.flatMap((m) => m.elements);
69
+ if (rootNodes.length === 0) {
70
+ return DocumentDeploymentsIndex.EMPTY;
71
+ }
72
+ const _root = new Array();
73
+ const _nested = new MultiMap();
74
+ const _byfqn = new MultiMap();
75
+ const Names = this.Names;
76
+ const Descriptions = this.services.workspace.AstNodeDescriptionProvider;
77
+ const createAndSaveDescription = (props) => {
78
+ const desc = {
79
+ ...Descriptions.createDescription(props.node, props.name, document),
80
+ fqn: props.fqn
81
+ };
82
+ ElementOps.writeId(props.node, props.fqn);
83
+ _byfqn.add(props.fqn, desc);
84
+ return desc;
85
+ };
86
+ const traverseNode = (container, parentFqn) => {
87
+ const _descedants = [];
88
+ const children = container.body?.elements;
89
+ if (!children || children.length === 0) {
90
+ return [];
91
+ }
92
+ const directChildren = /* @__PURE__ */ new Set();
93
+ for (const node of children) {
94
+ if (ast.isDeploymentRelation(node)) {
95
+ continue;
96
+ }
97
+ try {
98
+ const name = Names.getName(node);
99
+ if (isTruthy(name)) {
100
+ const fqn = `${parentFqn}.${name}`;
101
+ const desc = createAndSaveDescription({ node, name, fqn });
102
+ _nested.add(parentFqn, desc);
103
+ directChildren.add(desc.name);
104
+ if (ast.isDeploymentNode(node) && node.body) {
105
+ _descedants.push(...traverseNode(node, fqn));
106
+ }
107
+ }
108
+ } catch (e) {
109
+ logWarnError(e);
110
+ }
111
+ }
112
+ if (_descedants.length > 0) {
113
+ pipe(
114
+ _descedants,
115
+ groupBy(prop("name")),
116
+ forEachObj((descs, key) => {
117
+ if (descs.length > 1 || directChildren.has(key)) {
118
+ return;
119
+ }
120
+ _nested.add(parentFqn, descs[0]);
121
+ })
122
+ );
123
+ }
124
+ return _nested.get(parentFqn);
125
+ };
126
+ for (const node of rootNodes) {
127
+ try {
128
+ if (ast.isDeploymentRelation(node)) {
129
+ continue;
130
+ }
131
+ const name = Names.getName(node);
132
+ if (isTruthy(name)) {
133
+ _root.push(createAndSaveDescription({ node, name, fqn: name }));
134
+ traverseNode(node, name);
135
+ }
136
+ } catch (e) {
137
+ logWarnError(e);
138
+ }
139
+ }
140
+ return new DocumentDeploymentsIndex(_root, _nested, _byfqn);
141
+ }
142
+ }
143
+ export class DocumentDeploymentsIndex {
144
+ constructor(_rootNodes, _nested, _byfqn) {
145
+ this._rootNodes = _rootNodes;
146
+ this._nested = _nested;
147
+ this._byfqn = _byfqn;
148
+ }
149
+ static EMPTY = new DocumentDeploymentsIndex([], new MultiMap(), new MultiMap());
150
+ rootNodes() {
151
+ return this._rootNodes;
152
+ }
153
+ byFqn(fqnName) {
154
+ return this._byfqn.get(fqnName);
155
+ }
156
+ /**
157
+ * Returns artifacts of a deployment node
158
+ * @param nodeName Name of the deployment node
159
+ * @returns Stream of artifacts
160
+ */
161
+ nested(nodeName) {
162
+ return this._nested.get(nodeName);
163
+ }
164
+ /**
165
+ * Returns all deployment elements in the document,
166
+ * with unique combination "type and name"
167
+ */
168
+ unique() {
169
+ const result = [];
170
+ pipe(
171
+ [...this._byfqn.values()],
172
+ groupBy(prop("name")),
173
+ forEachObj((descs) => {
174
+ if (descs.length === 1) {
175
+ result.push(descs[0]);
176
+ }
177
+ })
178
+ );
179
+ return result;
180
+ }
181
+ }
@@ -0,0 +1,3 @@
1
+ import { type LikeC4LangiumDocument } from '../ast';
2
+ import type { LikeC4Services } from '../module';
3
+ export declare function computeDocumentFqn(document: LikeC4LangiumDocument, services: LikeC4Services): void;
@@ -0,0 +1,72 @@
1
+ import { AsFqn, nonexhaustive } from "@likec4/core";
2
+ import { AstUtils, CstUtils, GrammarUtils, MultiMap } from "langium";
3
+ import { isDefined, isEmpty } from "remeda";
4
+ import { ast, ElementOps } from "../ast.js";
5
+ import { logError } from "../logger.js";
6
+ import { getFqnElementRef } from "../utils/elementRef.js";
7
+ const { findNodeForProperty } = GrammarUtils;
8
+ const { toDocumentSegment } = CstUtils;
9
+ const { getDocument } = AstUtils;
10
+ function toAstNodeDescription(locator, entry, doc) {
11
+ const $cstNode = findNodeForProperty(entry.$cstNode, "name");
12
+ return {
13
+ documentUri: doc.uri,
14
+ name: entry.name,
15
+ ...entry.$cstNode && {
16
+ selectionSegment: toDocumentSegment(entry.$cstNode)
17
+ },
18
+ ...$cstNode && {
19
+ nameSegment: toDocumentSegment($cstNode)
20
+ },
21
+ path: locator.getAstNodePath(entry),
22
+ type: ast.Element
23
+ };
24
+ }
25
+ export function computeDocumentFqn(document, services) {
26
+ const c4fqnIndex = document.c4fqnIndex = new MultiMap();
27
+ const elements = document.parseResult.value.models.flatMap((m) => m.elements);
28
+ if (elements.length === 0) {
29
+ return;
30
+ }
31
+ const locator = services.workspace.AstNodeLocator;
32
+ const traverseStack = elements.map((el) => [el, null]);
33
+ let pair;
34
+ while (pair = traverseStack.shift()) {
35
+ try {
36
+ const [el, parent] = pair;
37
+ if (ast.isRelation(el)) {
38
+ continue;
39
+ }
40
+ if (ast.isExtendElement(el)) {
41
+ if (isDefined(el.body) && !isEmpty(el.body.elements)) {
42
+ const fqn = getFqnElementRef(el.element);
43
+ for (const child of el.body.elements) {
44
+ if (!ast.isRelation(child)) {
45
+ traverseStack.push([child, fqn]);
46
+ }
47
+ }
48
+ }
49
+ continue;
50
+ }
51
+ if (ast.isElement(el)) {
52
+ const fqn = AsFqn(el.name, parent);
53
+ c4fqnIndex.add(fqn, {
54
+ ...toAstNodeDescription(locator, el, document),
55
+ fqn
56
+ });
57
+ ElementOps.writeId(el, fqn);
58
+ if (isDefined(el.body) && !isEmpty(el.body.elements)) {
59
+ for (const child of el.body.elements) {
60
+ if (!ast.isRelation(child)) {
61
+ traverseStack.push([child, fqn]);
62
+ }
63
+ }
64
+ }
65
+ continue;
66
+ }
67
+ nonexhaustive(el);
68
+ } catch (e) {
69
+ logError(e);
70
+ }
71
+ }
72
+ }
@@ -0,0 +1,25 @@
1
+ import type { Fqn } from '@likec4/core';
2
+ import type { AstNodeDescription, LangiumDocuments, Stream } from 'langium';
3
+ import type { ast, FqnIndexedDocument } from '../ast';
4
+ import type { LikeC4Services } from '../module';
5
+ export interface FqnIndexEntry {
6
+ fqn: Fqn;
7
+ name: string;
8
+ el: ast.Element;
9
+ doc: FqnIndexedDocument;
10
+ path: string;
11
+ }
12
+ export declare class FqnIndex {
13
+ private services;
14
+ protected langiumDocuments: LangiumDocuments;
15
+ constructor(services: LikeC4Services);
16
+ get documents(): any;
17
+ private entries;
18
+ getFqn(el: ast.Element): Fqn | null;
19
+ byFqn(fqn: Fqn): Stream<AstNodeDescription>;
20
+ directChildrenOf(parent: Fqn): Stream<AstNodeDescription>;
21
+ /**
22
+ * Returns descedant elements with unique names in the scope
23
+ */
24
+ uniqueDescedants(parent: Fqn): Stream<AstNodeDescription>;
25
+ }