@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.
Files changed (250) hide show
  1. package/dist/LikeC4FileSystem.d.ts +13 -0
  2. package/dist/LikeC4FileSystem.js +27 -0
  3. package/dist/Rpc.d.ts +9 -0
  4. package/dist/Rpc.js +132 -0
  5. package/dist/ast.d.ts +200 -0
  6. package/dist/ast.js +276 -0
  7. package/dist/browser.d.ts +7 -20
  8. package/dist/browser.js +13 -0
  9. package/dist/documentation/documentation-provider.d.ts +8 -0
  10. package/dist/documentation/documentation-provider.js +46 -0
  11. package/dist/documentation/index.d.ts +1 -0
  12. package/dist/documentation/index.js +1 -0
  13. package/dist/formatting/LikeC4Formatter.d.ts +27 -0
  14. package/dist/formatting/LikeC4Formatter.js +261 -0
  15. package/dist/formatting/utils.d.ts +6 -0
  16. package/dist/formatting/utils.js +15 -0
  17. package/dist/generated/ast.d.ts +1242 -0
  18. package/dist/generated/ast.js +1945 -0
  19. package/dist/generated/grammar.d.ts +6 -0
  20. package/dist/generated/grammar.js +3 -0
  21. package/dist/generated/module.d.ts +9 -0
  22. package/dist/generated/module.js +23 -0
  23. package/dist/generated-lib/icons.d.ts +1 -0
  24. package/dist/{likec4lib.mjs → generated-lib/icons.js} +1 -6
  25. package/dist/index.d.ts +9 -31
  26. package/dist/index.js +14 -0
  27. package/dist/like-c4.langium +845 -0
  28. package/dist/likec4lib.d.ts +4 -6
  29. package/dist/likec4lib.js +4 -0
  30. package/dist/logger.d.ts +7 -0
  31. package/dist/logger.js +73 -0
  32. package/dist/lsp/CodeLensProvider.d.ts +9 -0
  33. package/dist/lsp/CodeLensProvider.js +40 -0
  34. package/dist/lsp/CompletionProvider.d.ts +6 -0
  35. package/dist/lsp/CompletionProvider.js +135 -0
  36. package/dist/lsp/DocumentHighlightProvider.d.ts +9 -0
  37. package/dist/lsp/DocumentHighlightProvider.js +10 -0
  38. package/dist/lsp/DocumentLinkProvider.d.ts +11 -0
  39. package/dist/lsp/DocumentLinkProvider.js +49 -0
  40. package/dist/lsp/DocumentSymbolProvider.d.ts +32 -0
  41. package/dist/lsp/DocumentSymbolProvider.js +274 -0
  42. package/dist/lsp/HoverProvider.d.ts +10 -0
  43. package/dist/lsp/HoverProvider.js +69 -0
  44. package/dist/lsp/RenameProvider.d.ts +5 -0
  45. package/dist/lsp/RenameProvider.js +6 -0
  46. package/dist/lsp/SemanticTokenProvider.d.ts +7 -0
  47. package/dist/lsp/SemanticTokenProvider.js +297 -0
  48. package/dist/lsp/index.d.ts +7 -0
  49. package/dist/lsp/index.js +7 -0
  50. package/dist/model/deployments-index.d.ts +60 -0
  51. package/dist/model/deployments-index.js +181 -0
  52. package/dist/model/fqn-computation.d.ts +3 -0
  53. package/dist/model/fqn-computation.js +72 -0
  54. package/dist/model/fqn-index.d.ts +25 -0
  55. package/dist/model/fqn-index.js +96 -0
  56. package/dist/model/index.d.ts +6 -0
  57. package/dist/model/index.js +6 -0
  58. package/dist/model/model-builder.d.ts +32 -0
  59. package/dist/model/model-builder.js +598 -0
  60. package/dist/model/model-locator.d.ts +23 -0
  61. package/dist/model/model-locator.js +126 -0
  62. package/dist/model/model-parser-where.d.ts +3 -0
  63. package/dist/model/model-parser-where.js +70 -0
  64. package/dist/model/model-parser.d.ts +292 -0
  65. package/dist/model/model-parser.js +72 -0
  66. package/dist/model/parser/Base.d.ts +28 -0
  67. package/dist/model/parser/Base.js +87 -0
  68. package/dist/model/parser/DeploymentModelParser.d.ts +33 -0
  69. package/dist/model/parser/DeploymentModelParser.js +162 -0
  70. package/dist/model/parser/DeploymentViewParser.d.ts +38 -0
  71. package/dist/model/parser/DeploymentViewParser.js +98 -0
  72. package/dist/model/parser/FqnRefParser.d.ts +29 -0
  73. package/dist/model/parser/FqnRefParser.js +108 -0
  74. package/dist/model/parser/GlobalsParser.d.ts +66 -0
  75. package/dist/model/parser/GlobalsParser.js +80 -0
  76. package/dist/model/parser/ModelParser.d.ts +27 -0
  77. package/dist/model/parser/ModelParser.js +122 -0
  78. package/dist/model/parser/PredicatesParser.d.ts +34 -0
  79. package/dist/model/parser/PredicatesParser.js +272 -0
  80. package/dist/model/parser/SpecificationParser.d.ts +27 -0
  81. package/dist/model/parser/SpecificationParser.js +120 -0
  82. package/dist/model/parser/ViewsParser.d.ts +64 -0
  83. package/dist/model/parser/ViewsParser.js +377 -0
  84. package/dist/model-change/ModelChanges.d.ts +15 -0
  85. package/dist/model-change/ModelChanges.js +89 -0
  86. package/dist/model-change/changeElementStyle.d.ts +16 -0
  87. package/dist/model-change/changeElementStyle.js +136 -0
  88. package/dist/model-change/changeViewLayout.d.ts +12 -0
  89. package/dist/model-change/changeViewLayout.js +32 -0
  90. package/dist/model-change/saveManualLayout.d.ts +11 -0
  91. package/dist/model-change/saveManualLayout.js +27 -0
  92. package/dist/module.d.ts +70 -0
  93. package/dist/module.js +162 -0
  94. package/dist/protocol.d.ts +38 -23
  95. package/dist/protocol.js +15 -0
  96. package/dist/references/index.d.ts +3 -0
  97. package/dist/references/index.js +3 -0
  98. package/dist/references/name-provider.d.ts +9 -0
  99. package/dist/references/name-provider.js +33 -0
  100. package/dist/references/scope-computation.d.ts +20 -0
  101. package/dist/references/scope-computation.js +281 -0
  102. package/dist/references/scope-provider.d.ts +16 -0
  103. package/dist/references/scope-provider.js +165 -0
  104. package/dist/shared/NodeKindProvider.d.ts +15 -0
  105. package/dist/shared/NodeKindProvider.js +108 -0
  106. package/dist/shared/WorkspaceManager.d.ts +18 -0
  107. package/dist/shared/WorkspaceManager.js +36 -0
  108. package/dist/shared/WorkspaceSymbolProvider.d.ts +3 -0
  109. package/dist/shared/WorkspaceSymbolProvider.js +3 -0
  110. package/dist/shared/index.d.ts +3 -0
  111. package/dist/shared/index.js +3 -0
  112. package/dist/test/index.d.ts +1 -0
  113. package/dist/test/index.js +1 -0
  114. package/dist/test/setup.d.ts +1 -0
  115. package/dist/test/setup.js +7 -0
  116. package/dist/test/testServices.d.ts +22 -0
  117. package/dist/test/testServices.js +119 -0
  118. package/dist/utils/elementRef.d.ts +11 -0
  119. package/dist/utils/elementRef.js +15 -0
  120. package/dist/utils/fqnRef.d.ts +8 -0
  121. package/dist/utils/fqnRef.js +46 -0
  122. package/dist/utils/index.d.ts +1 -0
  123. package/dist/utils/index.js +1 -0
  124. package/dist/utils/printDocs.d.ts +2 -0
  125. package/dist/utils/printDocs.js +1 -0
  126. package/dist/utils/stringHash.d.ts +1 -0
  127. package/dist/utils/stringHash.js +5 -0
  128. package/dist/validation/_shared.d.ts +3 -0
  129. package/dist/validation/_shared.js +22 -0
  130. package/dist/validation/deployment-checks.d.ts +6 -0
  131. package/dist/validation/deployment-checks.js +114 -0
  132. package/dist/validation/dynamic-view-rule.d.ts +4 -0
  133. package/dist/validation/dynamic-view-rule.js +17 -0
  134. package/dist/validation/dynamic-view-step.d.ts +4 -0
  135. package/dist/validation/dynamic-view-step.js +29 -0
  136. package/dist/validation/element.d.ts +4 -0
  137. package/dist/validation/element.js +49 -0
  138. package/dist/validation/index.d.ts +15 -0
  139. package/dist/validation/index.js +152 -0
  140. package/dist/validation/property-checks.d.ts +6 -0
  141. package/dist/validation/property-checks.js +39 -0
  142. package/dist/validation/relation.d.ts +5 -0
  143. package/dist/validation/relation.js +56 -0
  144. package/dist/validation/specification.d.ts +11 -0
  145. package/dist/validation/specification.js +136 -0
  146. package/dist/validation/view-predicates/element-with.d.ts +4 -0
  147. package/dist/validation/view-predicates/element-with.js +31 -0
  148. package/dist/validation/view-predicates/expanded-element.d.ts +4 -0
  149. package/dist/validation/view-predicates/expanded-element.js +12 -0
  150. package/dist/validation/view-predicates/expression-v2.d.ts +5 -0
  151. package/dist/validation/view-predicates/expression-v2.js +83 -0
  152. package/dist/validation/view-predicates/incoming.d.ts +4 -0
  153. package/dist/validation/view-predicates/incoming.js +16 -0
  154. package/dist/validation/view-predicates/index.d.ts +6 -0
  155. package/dist/validation/view-predicates/index.js +6 -0
  156. package/dist/validation/view-predicates/outgoing.d.ts +4 -0
  157. package/dist/validation/view-predicates/outgoing.js +16 -0
  158. package/dist/validation/view-predicates/relation-with.d.ts +4 -0
  159. package/dist/validation/view-predicates/relation-with.js +13 -0
  160. package/dist/validation/view.d.ts +4 -0
  161. package/dist/validation/view.js +23 -0
  162. package/dist/view-utils/assignNavigateTo.d.ts +2 -0
  163. package/dist/view-utils/assignNavigateTo.js +25 -0
  164. package/dist/view-utils/index.d.ts +2 -0
  165. package/dist/view-utils/index.js +2 -0
  166. package/dist/view-utils/manual-layout.d.ts +7 -0
  167. package/dist/view-utils/manual-layout.js +99 -0
  168. package/dist/view-utils/resolve-relative-paths.d.ts +2 -0
  169. package/dist/view-utils/resolve-relative-paths.js +78 -0
  170. package/dist/views/configurable-layouter.d.ts +7 -0
  171. package/dist/views/configurable-layouter.js +55 -0
  172. package/dist/views/index.d.ts +1 -0
  173. package/dist/views/index.js +1 -0
  174. package/dist/views/likec4-views.d.ts +26 -0
  175. package/dist/views/likec4-views.js +113 -0
  176. package/package.json +40 -54
  177. package/src/LikeC4FileSystem.ts +22 -21
  178. package/src/Rpc.ts +13 -7
  179. package/src/ast.ts +44 -133
  180. package/src/browser.ts +11 -11
  181. package/src/documentation/documentation-provider.ts +52 -0
  182. package/src/documentation/index.ts +1 -0
  183. package/src/generated/ast.ts +177 -177
  184. package/src/generated/grammar.ts +1 -1
  185. package/src/index.ts +13 -9
  186. package/src/like-c4.langium +37 -34
  187. package/src/logger.ts +34 -55
  188. package/src/lsp/CompletionProvider.ts +4 -4
  189. package/src/lsp/DocumentSymbolProvider.ts +110 -28
  190. package/src/lsp/HoverProvider.ts +5 -3
  191. package/src/lsp/SemanticTokenProvider.ts +2 -2
  192. package/src/model/deployments-index.ts +18 -14
  193. package/src/model/fqn-computation.ts +8 -8
  194. package/src/model/model-builder.ts +62 -60
  195. package/src/model/model-parser.ts +62 -1574
  196. package/src/model/parser/Base.ts +107 -0
  197. package/src/model/parser/DeploymentModelParser.ts +192 -0
  198. package/src/model/parser/DeploymentViewParser.ts +116 -0
  199. package/src/model/parser/FqnRefParser.ts +118 -0
  200. package/src/model/parser/GlobalsParser.ts +96 -0
  201. package/src/model/parser/ModelParser.ts +141 -0
  202. package/src/model/parser/PredicatesParser.ts +291 -0
  203. package/src/model/parser/SpecificationParser.ts +133 -0
  204. package/src/model/parser/ViewsParser.ts +428 -0
  205. package/src/module.ts +71 -25
  206. package/src/protocol.ts +29 -4
  207. package/src/references/scope-computation.ts +35 -35
  208. package/src/references/scope-provider.ts +13 -7
  209. package/src/utils/{deploymentRef.ts → fqnRef.ts} +27 -2
  210. package/src/validation/_shared.ts +0 -1
  211. package/src/validation/deployment-checks.ts +49 -62
  212. package/src/validation/dynamic-view-rule.ts +5 -4
  213. package/src/validation/dynamic-view-step.ts +23 -26
  214. package/src/validation/index.ts +100 -9
  215. package/src/validation/property-checks.ts +11 -10
  216. package/src/validation/specification.ts +38 -38
  217. package/src/validation/view-predicates/element-with.ts +6 -5
  218. package/src/validation/view-predicates/expanded-element.ts +6 -5
  219. package/src/validation/view-predicates/expression-v2.ts +101 -0
  220. package/src/validation/view-predicates/incoming.ts +6 -5
  221. package/src/validation/view-predicates/index.ts +1 -1
  222. package/src/validation/view-predicates/outgoing.ts +6 -5
  223. package/src/validation/view-predicates/relation-with.ts +6 -5
  224. package/src/validation/view.ts +5 -5
  225. package/src/view-utils/assignNavigateTo.ts +1 -1
  226. package/src/view-utils/manual-layout.ts +25 -0
  227. package/src/views/configurable-layouter.ts +65 -0
  228. package/src/views/index.ts +1 -0
  229. package/src/views/likec4-views.ts +139 -0
  230. package/dist/browser.cjs +0 -25
  231. package/dist/browser.d.cts +0 -23
  232. package/dist/browser.d.mts +0 -23
  233. package/dist/browser.mjs +0 -20
  234. package/dist/index.cjs +0 -53
  235. package/dist/index.d.cts +0 -34
  236. package/dist/index.d.mts +0 -34
  237. package/dist/index.mjs +0 -46
  238. package/dist/likec4lib.cjs +0 -1546
  239. package/dist/likec4lib.d.cts +0 -6
  240. package/dist/likec4lib.d.mts +0 -6
  241. package/dist/protocol.cjs +0 -25
  242. package/dist/protocol.d.cts +0 -48
  243. package/dist/protocol.d.mts +0 -48
  244. package/dist/protocol.mjs +0 -17
  245. package/dist/shared/language-server.CO_nmHiL.cjs +0 -7689
  246. package/dist/shared/language-server.Da6ey08o.d.cts +0 -1619
  247. package/dist/shared/language-server.De7S3e5Z.d.ts +0 -1619
  248. package/dist/shared/language-server.Dj4iDjtB.d.mts +0 -1619
  249. package/dist/shared/language-server.oO_9JoAG.mjs +0 -7666
  250. package/src/validation/view-predicates/deployments.ts +0 -56
@@ -2,27 +2,27 @@ import { nonexhaustive } from '@likec4/core'
2
2
  import {
3
3
  type AstNode,
4
4
  type AstNodeDescription,
5
+ type PrecomputedScopes,
5
6
  DefaultScopeComputation,
6
7
  MultiMap,
7
- type PrecomputedScopes
8
8
  } from 'langium'
9
- import { entries, filter, flatMap, forEach, forEachObj, groupBy, isNullish, isTruthy, pipe } from 'remeda'
9
+ import { entries, filter, flatMap, forEachObj, groupBy, isNullish, isTruthy, pipe } from 'remeda'
10
10
  import type { CancellationToken } from 'vscode-languageserver'
11
- import { ast, type LikeC4LangiumDocument } from '../ast'
12
- import { logError, logWarnError } from '../logger'
11
+ import { type LikeC4LangiumDocument, ast } from '../ast'
12
+ import { logWarnError } from '../logger'
13
13
  import type { LikeC4Services } from '../module'
14
14
 
15
15
  type ElementsContainer = ast.Model | ast.ElementBody | ast.ExtendElementBody
16
16
  type DeploymentsContainer = ast.ModelDeployments | ast.DeploymentNodeBody
17
17
 
18
18
  function uniqueDescriptions(
19
- descs: AstNodeDescription[]
19
+ descs: AstNodeDescription[],
20
20
  ): AstNodeDescription[] {
21
21
  return pipe(
22
22
  descs,
23
23
  groupBy(desc => `${desc.type}.${desc.name}`),
24
24
  entries(),
25
- flatMap(([_, descs]) => descs.length === 1 ? descs : [])
25
+ flatMap(([_, descs]) => descs.length === 1 ? descs : []),
26
26
  )
27
27
  }
28
28
 
@@ -33,7 +33,7 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
33
33
 
34
34
  override async computeExports(
35
35
  document: LikeC4LangiumDocument,
36
- _cancelToken?: CancellationToken
36
+ _cancelToken?: CancellationToken,
37
37
  ): Promise<AstNodeDescription[]> {
38
38
  const docExports: AstNodeDescription[] = []
39
39
  try {
@@ -56,7 +56,7 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
56
56
 
57
57
  this.exportDeployments(deployments, docExports, document)
58
58
  } catch (e) {
59
- logError(e)
59
+ logWarnError(e)
60
60
  }
61
61
  return docExports
62
62
  }
@@ -64,7 +64,7 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
64
64
  private exportViews(
65
65
  modelViews: ast.ModelViews[] | undefined,
66
66
  docExports: AstNodeDescription[],
67
- document: LikeC4LangiumDocument
67
+ document: LikeC4LangiumDocument,
68
68
  ) {
69
69
  const views = modelViews?.flatMap(m => m.views)
70
70
  if (isNullish(views) || views.length === 0) {
@@ -76,7 +76,7 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
76
76
  docExports.push(this.descriptions.createDescription(viewAst, viewAst.name, document))
77
77
  }
78
78
  } catch (e) {
79
- logError(e)
79
+ logWarnError(e)
80
80
  }
81
81
  }
82
82
  }
@@ -84,7 +84,7 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
84
84
  private exportGlobals(
85
85
  globals: ast.Globals[] | undefined,
86
86
  docExports: AstNodeDescription[],
87
- document: LikeC4LangiumDocument
87
+ document: LikeC4LangiumDocument,
88
88
  ) {
89
89
  if (isNullish(globals) || globals.length === 0) {
90
90
  return
@@ -96,7 +96,7 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
96
96
  docExports.push(this.descriptions.createDescription(id, id.name, document))
97
97
  }
98
98
  } catch (e) {
99
- logError(e)
99
+ logWarnError(e)
100
100
  }
101
101
  }
102
102
  for (const globalStyleAst of globals.flatMap(g => g.styles)) {
@@ -106,7 +106,7 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
106
106
  docExports.push(this.descriptions.createDescription(id, id.name, document))
107
107
  }
108
108
  } catch (e) {
109
- logError(e)
109
+ logWarnError(e)
110
110
  }
111
111
  }
112
112
  }
@@ -114,7 +114,7 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
114
114
  private exportModel(
115
115
  models: ast.Model[] | undefined,
116
116
  docExports: AstNodeDescription[],
117
- document: LikeC4LangiumDocument
117
+ document: LikeC4LangiumDocument,
118
118
  ) {
119
119
  if (isNullish(models) || models.length === 0) {
120
120
  return
@@ -125,7 +125,7 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
125
125
  docExports.push(this.descriptions.createDescription(elAst, elAst.name, document))
126
126
  }
127
127
  } catch (e) {
128
- logError(e)
128
+ logWarnError(e)
129
129
  }
130
130
  }
131
131
  }
@@ -133,7 +133,7 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
133
133
  private exportLibrary(
134
134
  likec4lib: ast.LikeC4Lib[] | undefined,
135
135
  docExports: AstNodeDescription[],
136
- document: LikeC4LangiumDocument
136
+ document: LikeC4LangiumDocument,
137
137
  ) {
138
138
  if (isNullish(likec4lib)) {
139
139
  return
@@ -143,14 +143,14 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
143
143
  docExports.push(this.descriptions.createDescription(iconAst, iconAst.name, document))
144
144
  }
145
145
  } catch (e) {
146
- logError(e)
146
+ logWarnError(e)
147
147
  }
148
148
  }
149
149
 
150
150
  private exportSpecification(
151
151
  specifications: ast.SpecificationRule[] | undefined,
152
152
  docExports: AstNodeDescription[],
153
- document: LikeC4LangiumDocument
153
+ document: LikeC4LangiumDocument,
154
154
  ) {
155
155
  if (isNullish(specifications) || specifications.length === 0) {
156
156
  return
@@ -161,7 +161,7 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
161
161
  ...s.relationships,
162
162
  ...s.deploymentNodes,
163
163
  ...s.tags,
164
- ...s.colors
164
+ ...s.colors,
165
165
  ])
166
166
  ) {
167
167
  try {
@@ -170,7 +170,7 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
170
170
  case ast.isSpecificationElementKind(spec): {
171
171
  if (isTruthy(spec.kind.name)) {
172
172
  docExports.push(
173
- this.descriptions.createDescription(spec.kind, spec.kind.name, document)
173
+ this.descriptions.createDescription(spec.kind, spec.kind.name, document),
174
174
  )
175
175
  }
176
176
  continue
@@ -178,7 +178,7 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
178
178
  case ast.isSpecificationTag(spec): {
179
179
  if (isTruthy(spec.tag.name)) {
180
180
  docExports.push(
181
- this.descriptions.createDescription(spec.tag, '#' + spec.tag.name, document)
181
+ this.descriptions.createDescription(spec.tag, '#' + spec.tag.name, document),
182
182
  )
183
183
  }
184
184
  continue
@@ -187,7 +187,7 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
187
187
  if (isTruthy(spec.kind.name)) {
188
188
  docExports.push(
189
189
  this.descriptions.createDescription(spec.kind, spec.kind.name, document),
190
- this.descriptions.createDescription(spec.kind, '.' + spec.kind.name, document)
190
+ this.descriptions.createDescription(spec.kind, '.' + spec.kind.name, document),
191
191
  )
192
192
  }
193
193
  continue
@@ -195,7 +195,7 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
195
195
  case ast.isSpecificationColor(spec): {
196
196
  if (isTruthy(spec.name.name)) {
197
197
  docExports.push(
198
- this.descriptions.createDescription(spec.name, spec.name.name, document)
198
+ this.descriptions.createDescription(spec.name, spec.name.name, document),
199
199
  )
200
200
  }
201
201
  continue
@@ -205,7 +205,7 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
205
205
  nonexhaustive(spec)
206
206
  }
207
207
  } catch (e) {
208
- logError(e)
208
+ logWarnError(e)
209
209
  }
210
210
  }
211
211
  }
@@ -213,7 +213,7 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
213
213
  private exportDeployments(
214
214
  modelDeployments: ast.ModelDeployments[] | undefined,
215
215
  docExports: AstNodeDescription[],
216
- document: LikeC4LangiumDocument
216
+ document: LikeC4LangiumDocument,
217
217
  ) {
218
218
  const nodes = modelDeployments?.flatMap(m => m.elements)
219
219
  if (isNullish(nodes) || nodes.length === 0) {
@@ -232,7 +232,7 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
232
232
 
233
233
  override computeLocalScopes(
234
234
  document: LikeC4LangiumDocument,
235
- _cancelToken?: CancellationToken
235
+ _cancelToken?: CancellationToken,
236
236
  ): Promise<PrecomputedScopes> {
237
237
  return new Promise(resolve => {
238
238
  const root = document.parseResult.value
@@ -242,16 +242,16 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
242
242
  for (const model of root.models) {
243
243
  try {
244
244
  descendants.push(
245
- ...this.processContainer(model, scopes, document)
245
+ ...this.processContainer(model, scopes, document),
246
246
  )
247
247
  } catch (e) {
248
- logError(e)
248
+ logWarnError(e)
249
249
  }
250
250
  }
251
251
  for (const deployment of root.deployments) {
252
252
  try {
253
253
  descendants.push(
254
- ...this.processDeployments(deployment, scopes, document)
254
+ ...this.processDeployments(deployment, scopes, document),
255
255
  )
256
256
  } catch (e) {
257
257
  logWarnError(e)
@@ -269,7 +269,7 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
269
269
  protected processContainer(
270
270
  container: ElementsContainer,
271
271
  scopes: PrecomputedScopes,
272
- document: LikeC4LangiumDocument
272
+ document: LikeC4LangiumDocument,
273
273
  ): AstNodeDescription[] {
274
274
  const localScope = new MultiMap<string, AstNodeDescription>()
275
275
  const descedants = [] as AstNodeDescription[]
@@ -292,7 +292,7 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
292
292
  if (subcontainer && subcontainer.elements.length > 0) {
293
293
  try {
294
294
  descedants.push(
295
- ...this.processContainer(subcontainer, scopes, document)
295
+ ...this.processContainer(subcontainer, scopes, document),
296
296
  )
297
297
  } catch (e) {
298
298
  logWarnError(e)
@@ -309,7 +309,7 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
309
309
  if (descs.length === 1) {
310
310
  localScope.add(name, descs[0])
311
311
  }
312
- })
312
+ }),
313
313
  )
314
314
  }
315
315
  const local = [...localScope.values()]
@@ -320,7 +320,7 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
320
320
  protected processDeployments(
321
321
  container: DeploymentsContainer,
322
322
  scopes: PrecomputedScopes,
323
- document: LikeC4LangiumDocument
323
+ document: LikeC4LangiumDocument,
324
324
  ): AstNodeDescription[] {
325
325
  const localnames = new Set<string>()
326
326
  const descedants = [] as AstNodeDescription[]
@@ -340,7 +340,7 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
340
340
  if (ast.isDeploymentNode(el) && el.body) {
341
341
  try {
342
342
  descedants.push(
343
- ...this.processDeployments(el.body, scopes, document)
343
+ ...this.processDeployments(el.body, scopes, document),
344
344
  )
345
345
  } catch (e) {
346
346
  logWarnError(e)
@@ -356,7 +356,7 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
356
356
  if (descs.length === 1) {
357
357
  scopes.add(container, descs[0])
358
358
  }
359
- })
359
+ }),
360
360
  )
361
361
  }
362
362
  return [...scopes.get(container).values()]
@@ -16,7 +16,7 @@ import {
16
16
  StreamImpl,
17
17
  StreamScope
18
18
  } from 'langium'
19
- import { ast, isLikeC4LangiumDocument } from '../ast'
19
+ import { ast } from '../ast'
20
20
  import { logger } from '../logger'
21
21
  import type { DeploymentsIndex, FqnIndex } from '../model'
22
22
  import type { LikeC4Services } from '../module'
@@ -91,8 +91,8 @@ export class LikeC4ScopeProvider extends DefaultScopeProvider {
91
91
  const referenceType = this.reflection.getReferenceType(context)
92
92
  try {
93
93
  const container = context.container
94
- if (ast.isDeploymentRef(container)) {
95
- return this.getScopeForDeploymentRef(container, context)
94
+ if (ast.isFqnRef(container)) {
95
+ return this.getScopeForFqnRef(container, context)
96
96
  }
97
97
 
98
98
  if (referenceType !== ast.Element) {
@@ -134,14 +134,20 @@ export class LikeC4ScopeProvider extends DefaultScopeProvider {
134
134
  }
135
135
  }
136
136
 
137
- protected getScopeForDeploymentRef(container: ast.DeploymentRef, context: ReferenceInfo) {
137
+ protected getScopeForFqnRef(container: ast.FqnRef, context: ReferenceInfo) {
138
138
  const parent = container.parent
139
139
  if (!parent) {
140
- return new MapScope(
140
+ return this.createScope(
141
141
  // First preference for deployment nodes
142
142
  this.computeScope(context, ast.DeploymentNode).getAllElements(),
143
- // Second preference for deployed instances
144
- this.computeScope(context, ast.DeployedInstance)
143
+ this.createScope(
144
+ // Second preference for deployed instances
145
+ this.computeScope(context, ast.DeployedInstance).getAllElements(),
146
+ // Third preference for elements if we are in deployment view
147
+ AstUtils.hasContainerOfType(container, ast.isDeploymentView)
148
+ ? this.computeScope(context, ast.Element)
149
+ : EMPTY_SCOPE
150
+ )
145
151
  )
146
152
  }
147
153
  const parentRef = parent.value.ref
@@ -2,7 +2,7 @@ import { AstUtils } from 'langium'
2
2
  import { isNullish } from 'remeda'
3
3
  import { ast } from '../ast'
4
4
 
5
- export function instanceRef(deploymentRef: ast.DeploymentRef): ast.DeployedInstance | null {
5
+ export function instanceRef(deploymentRef: ast.FqnRef): ast.DeployedInstance | null {
6
6
  let referenceable
7
7
  while ((referenceable = deploymentRef.value?.ref)) {
8
8
  if (ast.isDeploymentNode(referenceable)) {
@@ -19,7 +19,7 @@ export function instanceRef(deploymentRef: ast.DeploymentRef): ast.DeployedInsta
19
19
  return null
20
20
  }
21
21
 
22
- export function deploymentNodeRef(deploymentRef: ast.DeploymentRef): ast.DeploymentNode | null {
22
+ export function deploymentNodeRef(deploymentRef: ast.FqnRef): ast.DeploymentNode | null {
23
23
  let referenceable = deploymentRef.value.ref ?? null
24
24
  if (!referenceable || ast.isDeploymentNode(referenceable)) {
25
25
  return referenceable
@@ -29,3 +29,28 @@ export function deploymentNodeRef(deploymentRef: ast.DeploymentRef): ast.Deploym
29
29
  // we find artifact first and then its container
30
30
  return artifact ? AstUtils.getContainerOfType(artifact, ast.isDeploymentNode) ?? null : null
31
31
  }
32
+
33
+ export function isReferenceToLogicalModel(node: ast.FqnRef) {
34
+ // iterate up the root parent
35
+ while (node.parent) {
36
+ node = node.parent
37
+ }
38
+ return ast.isElement(node.value.ref)
39
+ }
40
+
41
+ /**
42
+ * Returns true if node references deployment model
43
+ */
44
+ export function isReferenceToDeploymentModel(node: ast.FqnRef) {
45
+ let referenceable
46
+ while ((referenceable = node.value?.ref)) {
47
+ if (ast.isDeploymentElement(referenceable)) {
48
+ return true
49
+ }
50
+ if (isNullish(node.parent)) {
51
+ return false
52
+ }
53
+ node = node.parent
54
+ }
55
+ return false
56
+ }
@@ -8,7 +8,6 @@ export const RESERVED_WORDS = [
8
8
  'it',
9
9
  'self',
10
10
  'super',
11
- 'instance',
12
11
  'likec4lib',
13
12
  'global'
14
13
  ]
@@ -1,5 +1,5 @@
1
- import { nonNullable } from '@likec4/core'
2
- import { AstUtils, type ValidationCheck } from 'langium'
1
+ import { FqnRef, isSameHierarchy, nonNullable } from '@likec4/core'
2
+ import { type ValidationCheck, AstUtils } from 'langium'
3
3
  import { ast } from '../ast'
4
4
  import type { LikeC4Services } from '../module'
5
5
  import type { LikeC4NameProvider } from '../references'
@@ -14,7 +14,7 @@ export const deploymentNodeChecks = (services: LikeC4Services): ValidationCheck<
14
14
  const nodeName = Names.getName(el)
15
15
  if (!nodeName) {
16
16
  accept('error', 'DeploymentNode must be named', {
17
- node: el
17
+ node: el,
18
18
  })
19
19
  return
20
20
  }
@@ -23,10 +23,10 @@ export const deploymentNodeChecks = (services: LikeC4Services): ValidationCheck<
23
23
  if (RESERVED_WORDS.includes(nodeName)) {
24
24
  accept('error', `Reserved word: ${nodeName}`, {
25
25
  node: el,
26
- range
26
+ range,
27
27
  })
28
28
  }
29
- const fqnName = DeploymentsIndex.getFqnName(el)
29
+ const fqnName = DeploymentsIndex.getFqn(el)
30
30
 
31
31
  const withSameName = DeploymentsIndex.byFqn(fqnName).limit(2).toArray()
32
32
  if (withSameName.length > 1) {
@@ -35,8 +35,8 @@ export const deploymentNodeChecks = (services: LikeC4Services): ValidationCheck<
35
35
  `Duplicate node name "${fqnName}"`,
36
36
  {
37
37
  node: el,
38
- range
39
- }
38
+ range,
39
+ },
40
40
  )
41
41
  }
42
42
  })
@@ -50,7 +50,7 @@ export const deployedInstanceChecks = (services: LikeC4Services): ValidationChec
50
50
  const artifactName = Names.getName(el)
51
51
  if (!artifactName) {
52
52
  accept('error', 'Deployed instance must be named, unique inside node', {
53
- node: el
53
+ node: el,
54
54
  })
55
55
  return
56
56
  }
@@ -59,10 +59,11 @@ export const deployedInstanceChecks = (services: LikeC4Services): ValidationChec
59
59
  if (RESERVED_WORDS.includes(artifactName)) {
60
60
  accept('error', `Reserved word: ${artifactName}`, {
61
61
  node: el,
62
- range
62
+ range,
63
63
  })
64
64
  }
65
- const fqnName = DeploymentsIndex.getFqnName(el)
65
+
66
+ const fqnName = DeploymentsIndex.getFqn(el)
66
67
 
67
68
  const withSameName = DeploymentsIndex.byFqn(fqnName).limit(2).toArray()
68
69
  if (withSameName.length > 1) {
@@ -71,74 +72,60 @@ export const deployedInstanceChecks = (services: LikeC4Services): ValidationChec
71
72
  `Duplicate instance name "${fqnName}"`,
72
73
  {
73
74
  node: el,
74
- range
75
- }
75
+ range,
76
+ },
76
77
  )
77
78
  }
78
79
  })
79
80
  }
80
81
 
81
82
  export const deploymentRelationChecks = (services: LikeC4Services): ValidationCheck<ast.DeploymentRelation> => {
82
- // const DeploymentsIndex = services.likec4.DeploymentsIndex
83
- // const Names = services.references.NameProvider as LikeC4NameProvider
84
- // const Locator = services.workspace.AstNodeLocator
85
- // const fqnIndex = services.likec4.FqnIndex
83
+ const ModelParser = services.likec4.ModelParser
86
84
  return tryOrLog((el, accept) => {
87
85
  const source = el.source?.value?.ref
88
- const target = el.target?.value?.ref
89
-
90
- if (!source || !target) {
86
+ if (!source) {
87
+ let sourceCstText = el.source?.$cstNode?.text ?? ''
88
+ accept('error', `DeploymentRelation source '${sourceCstText}' not resolved`, {
89
+ node: el,
90
+ property: 'source',
91
+ })
91
92
  return
92
93
  }
93
-
94
- if (
95
- ast.isElement(source) && ast.isDeploymentNode(target) || ast.isElement(target) && ast.isDeploymentNode(source)
96
- ) {
97
- const range = el.target.$cstNode?.range ?? el.source.$cstNode?.range
98
- accept('error', 'Relations between deployment nodes and instance internals are not supported', {
94
+ const target = el.target?.value?.ref
95
+ if (!target) {
96
+ let targetCstText = el.target?.$cstNode?.text ?? ''
97
+ accept('error', `DeploymentRelation target '${targetCstText}' not resolved`, {
99
98
  node: el,
100
- ...range && { range }
99
+ property: 'target',
101
100
  })
101
+ return
102
102
  }
103
103
 
104
- // const sourceEl = ast.isDeployedInstance(source)
105
- // ? elementRef(source.element)
106
- // : source
107
- // const targetEl = ast.isDeployedInstance(target)
108
- // ? elementRef(target.element)
109
- // : target
110
-
111
- // if (!sourceEl || !targetEl) {
112
- // return
113
- // }
104
+ const doc = getDocument(el)
105
+ const parser = ModelParser.forDocument(doc)
114
106
 
115
- // const sourceFqn = ast.isElement(sourceEl) ? fqnIndex.getFqn(sourceEl) : DeploymentsIndex.getFqnName(sourceEl) as Fqn
116
- // if (!sourceFqn) {
117
- // accept('error', 'Source not resolved', {
118
- // node: el,
119
- // property: 'source'
120
- // })
121
- // }
122
-
123
- // const targetFqn = ast.isElement(targetEl) ? fqnIndex.getFqn(targetEl) : DeploymentsIndex.getFqnName(targetEl) as Fqn
124
- // if (!targetFqn) {
125
- // accept('error', 'Target not resolved', {
126
- // node: el,
127
- // property: 'target'
128
- // })
129
- // }
107
+ const sourceFqnRef = parser.parseFqnRef(el.source)
108
+ if (FqnRef.isModelRef(sourceFqnRef)) {
109
+ accept('error', 'DeploymentRelation must refer deployment element', {
110
+ node: el,
111
+ property: 'source',
112
+ })
113
+ return
114
+ }
130
115
 
131
- // if (!!sourceFqn && sourceFqn === targetFqn) {
132
- // accept('error', 'Self-relation is not allowed', {
133
- // node: el
134
- // })
135
- // return
136
- // }
116
+ const targetFqnRef = parser.parseFqnRef(el.target)
117
+ if (FqnRef.isModelRef(targetFqnRef)) {
118
+ accept('error', 'DeploymentRelation must refer deployment element', {
119
+ node: el,
120
+ property: 'target',
121
+ })
122
+ return
123
+ }
137
124
 
138
- // if (sourceFqn && targetFqn && isSameHierarchy(sourceFqn, targetFqn)) {
139
- // accept('error', 'Invalid parent-child relationship', {
140
- // node: el
141
- // })
142
- // }
125
+ if (isSameHierarchy(sourceFqnRef.deployment, targetFqnRef.deployment)) {
126
+ accept('error', 'Invalid parent-child relationship', {
127
+ node: el,
128
+ })
129
+ }
143
130
  })
144
131
  }
@@ -2,21 +2,22 @@ import { nonexhaustive } from '@likec4/core'
2
2
  import type { ValidationCheck } from 'langium'
3
3
  import { ast, elementExpressionFromPredicate } from '../ast'
4
4
  import type { LikeC4Services } from '../module'
5
+ import { tryOrLog } from './_shared'
5
6
 
6
7
  export const dynamicViewRulePredicate = (
7
- _services: LikeC4Services
8
+ _services: LikeC4Services,
8
9
  ): ValidationCheck<ast.DynamicViewPredicateIterator> => {
9
- return (predicate, accept) => {
10
+ return tryOrLog((predicate, accept) => {
10
11
  const expr = elementExpressionFromPredicate(predicate.value)
11
12
  switch (true) {
12
13
  case ast.isElementKindExpression(expr):
13
14
  case ast.isElementTagExpression(expr):
14
15
  case ast.isWildcardExpression(expr): {
15
16
  accept('warning', `Predicate is ignored, as not supported in dynamic views`, {
16
- node: predicate
17
+ node: predicate,
17
18
  })
18
19
  return
19
20
  }
20
21
  }
21
- }
22
+ })
22
23
  }
@@ -4,36 +4,33 @@ import { ast } from '../ast'
4
4
  import { logError } from '../logger'
5
5
  import type { LikeC4Services } from '../module'
6
6
  import { elementRef } from '../utils/elementRef'
7
+ import { tryOrLog } from './_shared'
7
8
 
8
9
  export const dynamicViewStep = (services: LikeC4Services): ValidationCheck<ast.DynamicViewStep> => {
9
10
  const fqnIndex = services.likec4.FqnIndex
10
- return (el, accept) => {
11
- try {
12
- const sourceEl: ast.Element | undefined = elementRef(el.source)
13
- const source = sourceEl && fqnIndex.getFqn(sourceEl)
14
- if (!source) {
15
- accept('error', 'Source not found (not parsed/indexed yet)', {
16
- node: el,
17
- property: 'source'
18
- })
19
- }
11
+ return tryOrLog((el, accept) => {
12
+ const sourceEl: ast.Element | undefined = elementRef(el.source)
13
+ const source = sourceEl && fqnIndex.getFqn(sourceEl)
14
+ if (!source) {
15
+ accept('error', 'Source not found (not parsed/indexed yet)', {
16
+ node: el,
17
+ property: 'source',
18
+ })
19
+ }
20
20
 
21
- const targetEl: ast.Element | undefined = elementRef(el.target)
22
- const target = targetEl && fqnIndex.getFqn(targetEl)
23
- if (!target) {
24
- accept('error', 'Target not found (not parsed/indexed yet)', {
25
- node: el,
26
- property: 'target'
27
- })
28
- }
21
+ const targetEl: ast.Element | undefined = elementRef(el.target)
22
+ const target = targetEl && fqnIndex.getFqn(targetEl)
23
+ if (!target) {
24
+ accept('error', 'Target not found (not parsed/indexed yet)', {
25
+ node: el,
26
+ property: 'target',
27
+ })
28
+ }
29
29
 
30
- if (source && target && (isAncestor(source, target) || isAncestor(target, source))) {
31
- accept('error', 'Invalid parent-child relationship', {
32
- node: el
33
- })
34
- }
35
- } catch (e) {
36
- logError(e)
30
+ if (source && target && (isAncestor(source, target) || isAncestor(target, source))) {
31
+ accept('error', 'Invalid parent-child relationship', {
32
+ node: el,
33
+ })
37
34
  }
38
- }
35
+ })
39
36
  }