@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
package/src/ast.ts CHANGED
@@ -1,15 +1,15 @@
1
- import { DefaultArrowType, DefaultLineStyle, DefaultRelationshipColor, nonexhaustive } from '@likec4/core'
2
1
  import type * as c4 from '@likec4/core'
2
+ import { DefaultArrowType, DefaultLineStyle, DefaultRelationshipColor, LinkedList, nonexhaustive } from '@likec4/core'
3
3
  import type { AstNode, AstNodeDescription, DiagnosticInfo, LangiumDocument, MultiMap } from 'langium'
4
4
  import { DocumentState } from 'langium'
5
5
  import { clamp, isDefined, isNullish, isTruthy } from 'remeda'
6
- import type { ConditionalPick, SetRequired, ValueOf } from 'type-fest'
6
+ import type { ConditionalPick, SetRequired, ValueOf, Writable } from 'type-fest'
7
7
  import type { Diagnostic } from 'vscode-languageserver-types'
8
- import { DiagnosticSeverity } from 'vscode-languageserver-types'
9
- import { elementRef } from './elementRef'
10
8
  import type { LikeC4Grammar } from './generated/ast'
11
9
  import * as ast from './generated/ast'
12
10
  import { LikeC4LanguageMetaData } from './generated/module'
11
+ import { elementRef } from './utils/elementRef'
12
+ import type { IsValidFn } from './validation'
13
13
 
14
14
  export { ast }
15
15
 
@@ -20,10 +20,19 @@ declare module './generated/ast' {
20
20
  [idattr]?: c4.Fqn | undefined
21
21
  }
22
22
  export interface ElementView {
23
- [idattr]?: c4.ViewID | undefined
23
+ [idattr]?: c4.ViewId | undefined
24
24
  }
25
25
  export interface DynamicView {
26
- [idattr]?: c4.ViewID | undefined
26
+ [idattr]?: c4.ViewId | undefined
27
+ }
28
+ export interface DeploymentView {
29
+ [idattr]?: c4.ViewId | undefined
30
+ }
31
+ export interface DeploymentNode {
32
+ [idattr]?: c4.Fqn | undefined
33
+ }
34
+ export interface DeployedInstance {
35
+ [idattr]?: c4.Fqn | undefined
27
36
  }
28
37
  }
29
38
 
@@ -59,6 +68,7 @@ export interface ParsedAstSpecification {
59
68
  color: c4.HexColorLiteral
60
69
  }
61
70
  >
71
+ deployments: Record<c4.DeploymentNodeKind, c4.DeploymentNodeKindSpecification>
62
72
  }
63
73
 
64
74
  export interface ParsedAstElement {
@@ -75,7 +85,7 @@ export interface ParsedAstElement {
75
85
  }
76
86
 
77
87
  export interface ParsedAstRelation {
78
- id: c4.RelationID
88
+ id: c4.RelationId
79
89
  astPath: string
80
90
  source: c4.Fqn
81
91
  target: c4.Fqn
@@ -89,23 +99,28 @@ export interface ParsedAstRelation {
89
99
  head?: c4.RelationshipArrowType
90
100
  tail?: c4.RelationshipArrowType
91
101
  links?: c4.NonEmptyArray<ParsedLink>
92
- navigateTo?: c4.ViewID
102
+ navigateTo?: c4.ViewId
93
103
  metadata?: { [key: string]: string }
94
104
  }
95
105
 
96
- // export interface ParsedAstGlobals {
97
- // predicates: Record<c4.GlobalElRelID, c4.NonEmptyArray<c4.ViewRulePredicate>>
98
- // dynamicPredicates: Record<c4.GlobalElRelID, c4.NonEmptyArray<c4.DynamicViewIncludeRule>>
99
- // styles: Record<c4.GlobalStyleID, c4.NonEmptyArray<c4.ViewRuleStyle>>
100
- // }
106
+ // Alias for easier refactoring
107
+ export type ParsedAstDeployment = c4.DeploymentElement
108
+ export namespace ParsedAstDeployment {
109
+ export type Node = c4.DeploymentNode
110
+ export type Instance = c4.DeployedInstance
111
+ }
112
+ export type ParsedAstDeploymentRelation = c4.DeploymentRelation & {
113
+ astPath: string
114
+ }
115
+
101
116
  // Alias for refactoring
102
- export type ParsedAstGlobals = c4.ModelGlobals
117
+ export type ParsedAstGlobals = Writable<c4.ModelGlobals>
103
118
 
104
119
  export interface ParsedAstElementView {
105
120
  __: 'element'
106
- id: c4.ViewID
121
+ id: c4.ViewId
107
122
  viewOf?: c4.Fqn
108
- extends?: c4.ViewID
123
+ extends?: c4.ViewId
109
124
  astPath: string
110
125
  title: string | null
111
126
  description: string | null
@@ -117,7 +132,7 @@ export interface ParsedAstElementView {
117
132
 
118
133
  export interface ParsedAstDynamicView {
119
134
  __: 'dynamic'
120
- id: c4.ViewID
135
+ id: c4.ViewId
121
136
  astPath: string
122
137
  title: string | null
123
138
  description: string | null
@@ -128,15 +143,26 @@ export interface ParsedAstDynamicView {
128
143
  manualLayout?: c4.ViewManualLayout
129
144
  }
130
145
 
131
- export type ParsedAstView = ParsedAstElementView | ParsedAstDynamicView
146
+ export interface ParsedAstDeploymentView {
147
+ __: 'deployment'
148
+ id: c4.ViewId
149
+ astPath: string
150
+ title: string | null
151
+ description: string | null
152
+ tags: c4.NonEmptyArray<c4.Tag> | null
153
+ links: c4.NonEmptyArray<ParsedLink> | null
154
+ rules: Array<c4.DeploymentViewRule>
155
+ }
156
+
157
+ export type ParsedAstView = ParsedAstElementView | ParsedAstDynamicView | ParsedAstDeploymentView
132
158
  export const ViewOps = {
133
- writeId<T extends ast.LikeC4View>(node: T, id: c4.ViewID): T {
159
+ writeId<T extends ast.LikeC4View>(node: T, id: c4.ViewId): T {
134
160
  node[idattr] = id
135
161
  return node
136
162
  },
137
- readId(node: ast.LikeC4View): c4.ViewID | undefined {
163
+ readId(node: ast.LikeC4View): c4.ViewId | undefined {
138
164
  return node[idattr]
139
- }
165
+ },
140
166
  }
141
167
 
142
168
  export interface ParsedLink {
@@ -145,7 +171,7 @@ export interface ParsedLink {
145
171
  }
146
172
 
147
173
  export const ElementOps = {
148
- writeId(node: ast.Element, id: c4.Fqn | null) {
174
+ writeId(node: ast.Element | ast.DeploymentElement, id: c4.Fqn | null) {
149
175
  if (isNullish(id)) {
150
176
  node[idattr] = undefined
151
177
  } else {
@@ -153,15 +179,20 @@ export const ElementOps = {
153
179
  }
154
180
  return node
155
181
  },
156
- readId(node: ast.Element) {
182
+ readId(node: ast.Element | ast.DeploymentElement) {
157
183
  return node[idattr]
158
- }
184
+ },
159
185
  }
160
186
 
161
187
  export interface DocFqnIndexAstNodeDescription extends AstNodeDescription {
162
188
  fqn: c4.Fqn
163
189
  }
164
190
 
191
+ export interface DeploymentAstNodeDescription extends AstNodeDescription {
192
+ // Fullname of the artifact or node
193
+ fqn: string
194
+ }
195
+
165
196
  // export type LikeC4AstNode = ast.LikeC4AstType[keyof ast.LikeC4AstType]
166
197
  export type LikeC4AstNode = ValueOf<ConditionalPick<ast.LikeC4AstType, AstNode>>
167
198
  type LikeC4DocumentDiagnostic = Diagnostic & DiagnosticInfo<LikeC4AstNode>
@@ -173,41 +204,18 @@ export interface LikeC4DocumentProps {
173
204
  c4Relations?: ParsedAstRelation[]
174
205
  c4Globals?: ParsedAstGlobals
175
206
  c4Views?: ParsedAstView[]
207
+ c4Deployments?: ParsedAstDeployment[]
208
+ c4DeploymentRelations?: ParsedAstDeploymentRelation[]
176
209
  // Fqn -> Element
177
210
  c4fqnIndex?: MultiMap<c4.Fqn, DocFqnIndexAstNodeDescription>
178
211
  }
179
212
 
180
- export interface LikeC4LangiumDocument
181
- extends Omit<LangiumDocument<LikeC4Grammar>, 'diagnostics'>, LikeC4DocumentProps
182
- {}
183
- export interface FqnIndexedDocument
184
- extends Omit<LangiumDocument<LikeC4Grammar>, 'diagnostics'>, SetRequired<LikeC4DocumentProps, 'c4fqnIndex'>
185
- {}
186
-
187
- // export type ParsedLikeC4LangiumDocument = SetRequired<FqnIndexedDocument, keyof LikeC4DocumentProps>
188
- export interface ParsedLikeC4LangiumDocument
189
- extends Omit<LangiumDocument<LikeC4Grammar>, 'diagnostics'>, Required<LikeC4DocumentProps>
190
- {}
191
-
192
- export function cleanParsedModel(doc: LikeC4LangiumDocument) {
193
- const props: Required<Omit<LikeC4DocumentProps, 'c4fqnIndex' | 'diagnostics'>> = {
194
- c4Specification: {
195
- tags: new Set(),
196
- elements: {},
197
- relationships: {},
198
- colors: {}
199
- },
200
- c4Elements: [],
201
- c4Relations: [],
202
- c4Globals: {
203
- predicates: {},
204
- dynamicPredicates: {},
205
- styles: {}
206
- },
207
- c4Views: []
208
- }
209
- return Object.assign(doc, props) as ParsedLikeC4LangiumDocument
210
- }
213
+ type LikeC4GrammarDocument = Omit<LangiumDocument<LikeC4Grammar>, 'diagnostics'>
214
+
215
+ export interface LikeC4LangiumDocument extends LikeC4GrammarDocument, LikeC4DocumentProps {}
216
+ export interface FqnIndexedDocument extends SetRequired<LikeC4LangiumDocument, 'c4fqnIndex'> {}
217
+
218
+ export interface ParsedLikeC4LangiumDocument extends LikeC4GrammarDocument, Required<LikeC4DocumentProps> {}
211
219
 
212
220
  export function isLikeC4LangiumDocument(doc: LangiumDocument): doc is LikeC4LangiumDocument {
213
221
  return doc.textDocument.languageId === LikeC4LanguageMetaData.languageId
@@ -218,7 +226,7 @@ export function isFqnIndexedDocument(doc: LangiumDocument): doc is FqnIndexedDoc
218
226
  }
219
227
 
220
228
  export function isParsedLikeC4LangiumDocument(
221
- doc: LangiumDocument
229
+ doc: LangiumDocument,
222
230
  ): doc is ParsedLikeC4LangiumDocument {
223
231
  return (
224
232
  isLikeC4LangiumDocument(doc)
@@ -228,110 +236,59 @@ export function isParsedLikeC4LangiumDocument(
228
236
  && !!doc.c4Relations
229
237
  && !!doc.c4Views
230
238
  && !!doc.c4fqnIndex
239
+ && !!doc.c4Deployments
240
+ && !!doc.c4DeploymentRelations
231
241
  )
232
242
  }
233
243
 
234
- type Guard<N extends AstNode> = (n: AstNode) => n is N
235
- type Guarded<G> = G extends Guard<infer N> ? N : never
236
-
237
- function validatableAstNodeGuards<const Predicates extends Guard<AstNode>[]>(
238
- predicates: Predicates
239
- ) {
240
- return (n: AstNode): n is Guarded<Predicates[number]> => predicates.some(p => p(n))
241
- }
242
- const isValidatableAstNode = validatableAstNodeGuards([
243
- ast.isGlobals,
244
- ast.isGlobalPredicateGroup,
245
- ast.isGlobalDynamicPredicateGroup,
246
- ast.isGlobalStyle,
247
- ast.isGlobalStyleGroup,
248
- ast.isDynamicViewPredicateIterator,
249
- ast.isElementPredicateWith,
250
- ast.isRelationPredicateWith,
251
- ast.isElementExpression,
252
- ast.isRelationExpression,
253
- ast.isDynamicViewParallelSteps,
254
- ast.isDynamicViewStep,
255
- ast.isViewProperty,
256
- ast.isStyleProperty,
257
- ast.isTags,
258
- ast.isViewRule,
259
- ast.isDynamicViewRule,
260
- ast.isElementViewBody,
261
- ast.isDynamicViewBody,
262
- ast.isLikeC4View,
263
- ast.isRelationProperty,
264
- ast.isRelationBody,
265
- ast.isRelation,
266
- ast.isElementProperty,
267
- ast.isElementBody,
268
- ast.isElement,
269
- ast.isExtendElementBody,
270
- ast.isExtendElement,
271
- ast.isSpecificationElementKind,
272
- ast.isSpecificationRelationshipKind,
273
- ast.isSpecificationTag,
274
- ast.isSpecificationColor,
275
- ast.isSpecificationRule,
276
- ast.isModelViews,
277
- ast.isModel
278
- ])
279
- type ValidatableAstNode = Guarded<typeof isValidatableAstNode>
280
-
281
- const findInvalidContainer = (node: LikeC4AstNode): ValidatableAstNode | undefined => {
282
- let nd = node as LikeC4AstNode['$container']
283
- while (nd) {
284
- if (isValidatableAstNode(nd)) {
285
- return nd
286
- }
287
- nd = nd.$container
288
- }
289
- return undefined
290
- }
291
-
292
- export function checksFromDiagnostics(doc: LikeC4LangiumDocument) {
293
- const errors = doc.diagnostics?.filter(d => d.severity === DiagnosticSeverity.Error) ?? []
294
- const invalidNodes = new WeakSet(
295
- errors.flatMap(d => {
296
- return findInvalidContainer(d.node) ?? []
297
- })
298
- )
299
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
300
- const isValid = (n: ValidatableAstNode) => !invalidNodes.has(n)
301
- return {
302
- isValid,
303
- invalidNodes
304
- }
305
- }
306
- export type ChecksFromDiagnostics = ReturnType<typeof checksFromDiagnostics>
307
- export type IsValidFn = ChecksFromDiagnostics['isValid']
308
-
309
- export function* streamModel(doc: LikeC4LangiumDocument, isValid: IsValidFn) {
310
- const traverseStack = doc.parseResult.value.models.flatMap(m => m.elements)
244
+ export function* streamModel(doc: LikeC4LangiumDocument) {
245
+ const traverseStack = LinkedList.from(doc.parseResult.value.models.flatMap(m => m.elements))
311
246
  const relations = [] as ast.Relation[]
312
247
  let el
313
248
  while ((el = traverseStack.shift())) {
314
- if (!isValid(el)) {
315
- continue
316
- }
317
249
  if (ast.isRelation(el)) {
318
250
  relations.push(el)
319
251
  continue
320
252
  }
321
253
  if (ast.isExtendElement(el)) {
322
254
  if (el.body && el.body.elements.length > 0) {
323
- traverseStack.push(...el.body.elements)
255
+ for (const child of el.body.elements) {
256
+ traverseStack.push(child)
257
+ }
324
258
  }
325
259
  continue
326
260
  }
327
261
  if (el.body && el.body.elements.length > 0) {
328
- traverseStack.push(...el.body.elements)
262
+ for (const child of el.body.elements) {
263
+ traverseStack.push(child)
264
+ }
329
265
  }
330
266
  yield el
331
267
  }
332
- for (const relation of relations) {
333
- yield relation
268
+ yield* relations
269
+ return
270
+ }
271
+
272
+ export function* streamDeploymentModel(doc: LikeC4LangiumDocument) {
273
+ const traverseStack = LinkedList.from<ast.DeploymentRelation | ast.DeploymentElement>(
274
+ doc.parseResult.value.deployments.flatMap(m => m.elements),
275
+ )
276
+ const relations = [] as ast.DeploymentRelation[]
277
+ let el
278
+ while ((el = traverseStack.shift())) {
279
+ if (ast.isDeploymentRelation(el)) {
280
+ relations.push(el)
281
+ continue
282
+ }
283
+ if (ast.isDeploymentNode(el) && el.body && el.body.elements.length > 0) {
284
+ for (const child of el.body.elements) {
285
+ traverseStack.push(child)
286
+ }
287
+ }
288
+ yield el
334
289
  }
290
+ yield* relations
291
+ return
335
292
  }
336
293
 
337
294
  export function resolveRelationPoints(node: ast.Relation): {
@@ -349,7 +306,7 @@ export function resolveRelationPoints(node: ast.Relation): {
349
306
  }
350
307
  return {
351
308
  source,
352
- target
309
+ target,
353
310
  }
354
311
  }
355
312
  if (!ast.isElementBody(node.$container)) {
@@ -357,7 +314,7 @@ export function resolveRelationPoints(node: ast.Relation): {
357
314
  }
358
315
  return {
359
316
  source: node.$container.$container,
360
- target
317
+ target,
361
318
  }
362
319
  }
363
320
 
@@ -407,14 +364,13 @@ export function toElementStyle(props: Array<ast.StyleProperty> | undefined, isVa
407
364
  break
408
365
  }
409
366
  default:
410
- // @ts-expect-error
411
- nonexhaustive(prop.$type)
367
+ nonexhaustive(prop)
412
368
  }
413
369
  }
414
370
  return result
415
371
  }
416
372
 
417
- export function toRelationshipStyle(props?: ast.RelationshipStyleProperty[]) {
373
+ export function toRelationshipStyle(props: ast.RelationshipStyleProperty[] | undefined, isValid: IsValidFn) {
418
374
  const result = {} as {
419
375
  color?: c4.Color
420
376
  line?: c4.RelationshipLineType
@@ -425,47 +381,55 @@ export function toRelationshipStyle(props?: ast.RelationshipStyleProperty[]) {
425
381
  return result
426
382
  }
427
383
  for (const prop of props) {
428
- if (ast.isColorProperty(prop)) {
429
- const color = toColor(prop)
430
- if (isTruthy(color)) {
431
- result.color = color
432
- }
433
- continue
434
- }
435
- if (ast.isLineProperty(prop)) {
436
- result.line = prop.value
384
+ if (!isValid(prop)) {
437
385
  continue
438
386
  }
439
- if (ast.isArrowProperty(prop)) {
440
- switch (prop.key) {
441
- case 'head': {
442
- result.head = prop.value
443
- break
444
- }
445
- case 'tail': {
446
- result.tail = prop.value
447
- break
387
+ switch (true) {
388
+ case ast.isColorProperty(prop): {
389
+ const color = toColor(prop)
390
+ if (isTruthy(color)) {
391
+ result.color = color
448
392
  }
449
- default: {
450
- nonexhaustive(prop)
393
+ break
394
+ }
395
+ case ast.isLineProperty(prop): {
396
+ result.line = prop.value
397
+ break
398
+ }
399
+ case ast.isArrowProperty(prop): {
400
+ switch (prop.key) {
401
+ case 'head': {
402
+ result.head = prop.value
403
+ break
404
+ }
405
+ case 'tail': {
406
+ result.tail = prop.value
407
+ break
408
+ }
409
+ default: {
410
+ nonexhaustive(prop)
411
+ }
451
412
  }
413
+ break
414
+ }
415
+ default: {
416
+ nonexhaustive(prop)
452
417
  }
453
- continue
454
418
  }
455
- nonexhaustive(prop)
456
419
  }
457
420
  return result
458
421
  }
459
422
 
460
423
  export function toRelationshipStyleExcludeDefaults(
461
- props?: ast.SpecificationRelationshipKind['props']
424
+ props: ast.SpecificationRelationshipKind['props'] | undefined,
425
+ isValid: IsValidFn,
462
426
  ) {
463
- const { color, line, head, tail } = toRelationshipStyle(props?.filter(ast.isRelationshipStyleProperty))
427
+ const { color, line, head, tail } = toRelationshipStyle(props?.filter(ast.isRelationshipStyleProperty), isValid)
464
428
  return {
465
429
  ...(color && color !== DefaultRelationshipColor ? { color } : {}),
466
430
  ...(line && line !== DefaultLineStyle ? { line } : {}),
467
431
  ...(head && head !== DefaultArrowType ? { head } : {}),
468
- ...(tail ? { tail } : {})
432
+ ...(tail ? { tail } : {}),
469
433
  }
470
434
  }
471
435
 
@@ -474,7 +438,7 @@ export function toColor(astNode: ast.ColorProperty): c4.Color | undefined {
474
438
  }
475
439
 
476
440
  export function toAutoLayout(
477
- rule: ast.ViewRuleAutoLayout
441
+ rule: ast.ViewRuleAutoLayout,
478
442
  ): c4.ViewRuleAutoLayout {
479
443
  const rankSep = rule.rankSep
480
444
  const nodeSep = rule.nodeSep
@@ -504,7 +468,7 @@ export function toAutoLayout(
504
468
  return {
505
469
  direction,
506
470
  ...(nodeSep && { nodeSep }),
507
- ...(rankSep && { rankSep })
471
+ ...(rankSep && { rankSep }),
508
472
  }
509
473
  }
510
474
 
package/src/browser.ts CHANGED
@@ -1,18 +1,22 @@
1
1
  import { startLanguageServer as startLanguim } from 'langium/lsp'
2
2
  import { BrowserMessageReader, BrowserMessageWriter, createConnection } from 'vscode-languageserver/browser'
3
- import { createLanguageServices } from './module'
3
+ import { type LikeC4Services, type LikeC4SharedServices, createLanguageServices } from './module'
4
+
5
+ export { logger as lspLogger, setLogLevel } from './logger'
6
+ export type { DocumentParser, LikeC4ModelBuilder, LikeC4ModelLocator, LikeC4ModelParser } from './model'
4
7
 
5
- export { setLogLevel } from './logger'
6
- export type * from './model'
7
- export type * from './module'
8
8
  export { createCustomLanguageServices, createLanguageServices, LikeC4Module } from './module'
9
+ export type { LikeC4Services, LikeC4SharedServices } from './module'
9
10
 
10
11
  // This is an example copied as is from here:
11
12
  // https://github.com/microsoft/vscode-extension-samples/blob/main/lsp-web-extension-sample/server/src/browserServerMain.ts
12
13
  // the only addition is the following line:
13
14
  declare const self: DedicatedWorkerGlobalScope
14
15
 
15
- export function startLanguageServer() {
16
+ export function startLanguageServer(): {
17
+ shared: LikeC4SharedServices
18
+ likec4: LikeC4Services
19
+ } {
16
20
  /* browser specific setup code */
17
21
 
18
22
  const messageReader = new BrowserMessageReader(self)
@@ -26,10 +30,5 @@ export function startLanguageServer() {
26
30
  // Start the language server with the shared services
27
31
  startLanguim(services.shared)
28
32
 
29
- return {
30
- ...services,
31
- connection,
32
- messageReader,
33
- messageWriter
34
- }
33
+ return services
35
34
  }