@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/index.ts CHANGED
@@ -1,14 +1,20 @@
1
1
  import { startLanguageServer as startLanguim } from 'langium/lsp'
2
2
  import { createConnection, ProposedFeatures } from 'vscode-languageserver/node'
3
3
  import { LikeC4FileSystem } from './LikeC4FileSystem'
4
- import { createLanguageServices } from './module'
4
+ import { createLanguageServices, type LikeC4Services, type LikeC4SharedServices } from './module'
5
5
 
6
6
  export { logger as lspLogger, setLogLevel } from './logger'
7
- export type * from './model'
8
- export type * from './module'
7
+
8
+ export type { DocumentParser, LikeC4ModelBuilder, LikeC4ModelLocator, LikeC4ModelParser } from './model'
9
+
9
10
  export { createCustomLanguageServices, createLanguageServices, LikeC4Module } from './module'
11
+ export type { LikeC4Services, LikeC4SharedServices } from './module'
10
12
  export { LikeC4FileSystem }
11
- export function startLanguageServer() {
13
+
14
+ export function startLanguageServer(): {
15
+ shared: LikeC4SharedServices
16
+ likec4: LikeC4Services
17
+ } {
12
18
  /* browser specific setup code */
13
19
  const connection = createConnection(ProposedFeatures.all)
14
20
 
@@ -18,8 +24,5 @@ export function startLanguageServer() {
18
24
  // Start the language server with the shared services
19
25
  startLanguim(services.shared)
20
26
 
21
- return {
22
- ...services,
23
- connection
24
- }
27
+ return services
25
28
  }
@@ -6,6 +6,7 @@ entry LikeC4Grammar:
6
6
  models+=Model |
7
7
  views+=ModelViews |
8
8
  globals+=Globals |
9
+ deployments+=ModelDeployments |
9
10
  likec4lib+=LikeC4Lib
10
11
  )*
11
12
  ;
@@ -18,22 +19,15 @@ LikeC4Lib:
18
19
  '}'
19
20
  '}';
20
21
 
21
- LibIcon:
22
- name=IconId;
22
+ LibIcon: name=IconId;
23
23
 
24
24
  // Specification -------------------------------------
25
25
 
26
- ElementKind:
27
- name=Id;
28
-
29
- Tag:
30
- name=Id;
31
-
32
- RelationshipKind:
33
- name=Id;
34
-
35
- CustomColor:
36
- name=CustomColorId;
26
+ ElementKind: name=Id;
27
+ Tag: name=Id;
28
+ RelationshipKind: name=Id;
29
+ CustomColor: name=CustomColorId;
30
+ DeploymentNodeKind: name=Id;
37
31
 
38
32
  SpecificationRule:
39
33
  name='specification' '{'
@@ -41,7 +35,8 @@ SpecificationRule:
41
35
  elements+=SpecificationElementKind |
42
36
  tags+=SpecificationTag |
43
37
  relationships+=SpecificationRelationshipKind |
44
- colors+=SpecificationColor
38
+ colors+=SpecificationColor |
39
+ deploymentNodes+=SpecificationDeploymentNodeKind
45
40
  )*
46
41
  '}';
47
42
 
@@ -56,6 +51,14 @@ SpecificationElementKind:
56
51
  SpecificationElementStringProperty:
57
52
  key=('technology' | 'notation') ':'? value=String ';'?;
58
53
 
54
+ SpecificationDeploymentNodeKind:
55
+ 'deploymentNode' kind=DeploymentNodeKind ('{'
56
+ props+=(
57
+ SpecificationElementStringProperty |
58
+ ElementStyleProperty
59
+ )*
60
+ '}')?;
61
+
59
62
  SpecificationTag:
60
63
  'tag' tag=Tag;
61
64
 
@@ -201,9 +204,9 @@ ModelViews:
201
204
  )*
202
205
  '}';
203
206
 
204
- type LikeC4View = ElementView | DynamicView;
207
+ type LikeC4View = ElementView | DynamicView | DeploymentView;
205
208
  LikeC4ViewRule returns LikeC4View:
206
- ElementView | DynamicView;
209
+ ElementView | DynamicView | DeploymentView;
207
210
 
208
211
  ElementView:
209
212
  'view' name=Id? (
@@ -372,7 +375,7 @@ ElementSelectorExpression infers ElementExpression:
372
375
  ElementDescedantsExpression infers ElementExpression:
373
376
  ElementRef (
374
377
  {infer ExpandElementExpression.expand=current} DotUnderscore |
375
- {infer ElementDescedantsExpression.parent=current} DotWildcard
378
+ {infer ElementDescedantsExpression.parent=current} suffix=DotWildcard
376
379
  )?
377
380
  ;
378
381
 
@@ -410,7 +413,7 @@ WhereRelationNegation:
410
413
 
411
414
  WhereRelation:
412
415
  {infer WhereRelationTag} 'tag' EqOperator value=[Tag:TagId]? |
413
- {infer WhereRelationKind} 'kind' EqOperator value=[RelationshipKind]?
416
+ {infer WhereRelationKind} 'kind' EqOperator value=[RelationshipKind:Id]?
414
417
  ;
415
418
 
416
419
  type WhereTagEqual = WhereElementTag | WhereRelationTag;
@@ -436,7 +439,7 @@ DirectedRelationExpressions infers RelationExpression:
436
439
 
437
440
  OutgoingRelationExpression:
438
441
  from=ElementExpression
439
- (isBidirectional?='<->' | '->' | '-[' kind=[RelationshipKind] ']->' | kind=[RelationshipKind:DotId])
442
+ (isBidirectional?='<->' | '->' | '-[' kind=[RelationshipKind:Id] ']->' | kind=[RelationshipKind:DotId])
440
443
  ;
441
444
 
442
445
  // Comma-separated list of ElementExpressions
@@ -509,6 +512,152 @@ NavigateToProperty:
509
512
  RelationNavigateToProperty:
510
513
  key='navigateTo' value=DynamicViewRef;
511
514
 
515
+ // Deployment -------------------------------------
516
+
517
+ ModelDeployments:
518
+ name='deployment' '{'
519
+ elements+=(
520
+ DeploymentNode |
521
+ DeploymentRelation
522
+ )*
523
+ '}';
524
+
525
+ type DeploymentElement = DeploymentNode | DeployedInstance;
526
+
527
+ DeploymentNode:
528
+ (
529
+ kind=[DeploymentNodeKind:Id] name=Id |
530
+ name=Id Eq kind=[DeploymentNodeKind:Id]
531
+ )
532
+ title=String?
533
+ body=DeploymentNodeBody?
534
+ ;
535
+
536
+ DeploymentNodeBody: '{'
537
+ tags=Tags?
538
+ props+=ElementProperty*
539
+ elements+=(
540
+ DeployedInstance |
541
+ DeploymentRelation |
542
+ DeploymentNode
543
+ )*
544
+ '}';
545
+
546
+ DeployedInstance:
547
+ (name=Id Eq)?
548
+ 'instanceOf'
549
+ element=ElementRef
550
+ title=String?
551
+ body=DeployedInstanceBody?
552
+ ';'?
553
+ ;
554
+
555
+ DeployedInstanceBody: '{'
556
+ tags=Tags?
557
+ props+=ElementProperty*
558
+ '}';
559
+
560
+ type Referenceable = DeploymentNode | DeployedInstance | Element;
561
+ // Reference to Elements in logical or deployment model
562
+ // Scope computation is based on the parent element:
563
+ // - If parent is DeploymentNode, then it can reference nested DeploymentNodes and DeployedInstances
564
+ // - If parent is DeployedInstance, then it can reference nested Element
565
+ // - If parent is Element, then it can reference nested Element
566
+ // Mix of DeploymentRef and ElementRef
567
+ FqnRef:
568
+ value=[Referenceable:Id] ({infer FqnRef.parent=current} StickyDot value=[Referenceable:Id])*;
569
+
570
+ DeploymentRelation:
571
+ source=FqnRef
572
+ ('->' | '-[' kind=[RelationshipKind:Id] ']->' | kind=[RelationshipKind:DotId])
573
+ target=FqnRef
574
+ (
575
+ title=String
576
+ technology=String?
577
+ )?
578
+ tags=Tags?
579
+ body=DeploymentRelationBody?
580
+ ;
581
+
582
+ DeploymentRelationBody: '{'
583
+ tags=Tags?
584
+ props+=RelationProperty*
585
+ '}'
586
+ ;
587
+
588
+ DeploymentView:
589
+ 'deployment' 'view' name=Id body=DeploymentViewBody?
590
+ ;
591
+
592
+ DeploymentViewBody: '{'
593
+ tags=Tags?
594
+ props+=ViewProperty*
595
+ rules+=DeploymentViewRule*
596
+ '}';
597
+
598
+ DeploymentViewRule:
599
+ DeploymentViewRulePredicate |
600
+ DeploymentViewRuleStyle |
601
+ ViewRuleAutoLayout
602
+ ;
603
+
604
+ DeploymentViewRuleStyle:
605
+ 'style' targets=FqnExpressions '{'
606
+ props+=(
607
+ StyleProperty |
608
+ NotationProperty
609
+ )*
610
+ '}';
611
+
612
+
613
+ DeploymentViewRulePredicate:
614
+ (isInclude?='include' | 'exclude')
615
+ expr=DeploymentViewRulePredicateExpression
616
+ ;
617
+
618
+ DeploymentViewRulePredicateExpression:
619
+ value=ExpressionV2 ({infer DeploymentViewRulePredicateExpression.prev=current} ',' (value=ExpressionV2)?)*
620
+ ;
621
+
622
+ ExpressionV2:
623
+ RelationExpr |
624
+ FqnExpr
625
+ ;
626
+
627
+
628
+ FqnExpr:
629
+ {infer WildcardExpression} isWildcard?='*' |
630
+ FqnRefExpr
631
+ ;
632
+
633
+ FqnRefExpr:
634
+ ref=FqnRef selector=(DotUnderscore | DotWildcard)?
635
+ ;
636
+
637
+ RelationExpr:
638
+ InOutRelationExpr |
639
+ DirectedRelationExpr
640
+ ;
641
+
642
+ InOutRelationExpr infers RelationExpr:
643
+ IncomingRelationExpr ({infer InOutRelationExpr.inout=current} '->')?
644
+ ;
645
+
646
+ IncomingRelationExpr:
647
+ '->' to=FqnExpr;
648
+
649
+ DirectedRelationExpr infers RelationExpr:
650
+ OutgoingRelationExpr ({infer DirectedRelationExpr.source=current} target=FqnExpr)?
651
+ ;
652
+
653
+ OutgoingRelationExpr:
654
+ from=FqnExpr
655
+ (isBidirectional?='<->' | '->' | '-[' kind=[RelationshipKind:Id] ']->' | kind=[RelationshipKind:DotId])
656
+ ;
657
+
658
+ FqnExpressions:
659
+ value=FqnExpr ({infer FqnExpressions.prev=current} ',' (value=FqnExpr)?)*
660
+ ;
512
661
  // Global -------------------------------------
513
662
 
514
663
  Globals:
@@ -545,6 +694,8 @@ GlobalStyleGroup:
545
694
  styles+=ViewRuleStyle*
546
695
  '}';
547
696
 
697
+ type FqnReferenceable = Referenceable | Element | ExtendElement;
698
+
548
699
  // Common properties -------------------------------------
549
700
 
550
701
  LinkProperty:
@@ -635,7 +786,7 @@ CustomColorId returns string:
635
786
  IdTerminal | ElementShape | ArrowType | LineOptions | 'element' | 'model';
636
787
 
637
788
  Id returns string:
638
- IdTerminal | ElementShape | ThemeColor | ArrowType | LineOptions | 'element' | 'model' | 'group';
789
+ IdTerminal | ElementShape | ThemeColor | ArrowType | LineOptions | 'element' | 'model' | 'group' | 'node' | 'deployment' | 'instance';
639
790
 
640
791
  fragment EqOperator:
641
792
  (
@@ -674,8 +825,8 @@ terminal LIB_ICON: /(aws|azure|gcp|tech):[-\w]*/;
674
825
  terminal URI_WITH_SCHEMA: /\w+:\/\/\S+/;
675
826
  terminal URI_RELATIVE: /\.{0,2}\/[^\/]\S+/;
676
827
 
677
- terminal DotUnderscore: /\b\._/;
678
- terminal DotWildcard: /\b\.\*/;
828
+ terminal DotUnderscore: /\b\._(?![_a-zA-Z])/;
829
+ terminal DotWildcard: /\b\.\*{1,2}/;
679
830
  terminal Hash: '#';
680
831
 
681
832
  // No space allowed before dot
package/src/logger.ts CHANGED
@@ -1,9 +1,10 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { type ConsolaReporter, LogLevels, rootLogger as root } from '@likec4/log'
3
- import { isError } from 'remeda'
1
+ import { nonexhaustive } from '@likec4/core'
2
+ import { type ConsolaReporter, formatLogObj, LogLevels, rootLogger as root } from '@likec4/log'
3
+ import { BROWSER } from 'esm-env'
4
4
  import type { Connection } from 'vscode-languageserver'
5
5
 
6
6
  export const logger = root.withTag('lsp')
7
+ // export const logger = root
7
8
 
8
9
  export function logError(err: unknown): void {
9
10
  logger.error(err)
@@ -21,77 +22,60 @@ export function setLogLevel(level: keyof typeof LogLevels): void {
21
22
  logger.level = LogLevels[level]
22
23
  }
23
24
 
24
- export function logErrorToTelemetry(connection: Connection): void {
25
- const reporter: ConsolaReporter = {
26
- log: ({ level, ...logObj }, ctx) => {
27
- if (level !== LogLevels.error && level !== LogLevels.fatal) {
28
- return
29
- }
30
- const tag = logObj.tag || ''
31
- const parts = logObj.args.map((arg) => {
32
- if (isError(arg)) {
33
- return arg.stack ?? arg.message
34
- }
35
- if (typeof arg === 'string') {
36
- return arg
37
- }
38
- return '' + arg
39
- })
40
- if (tag) {
41
- parts.unshift(`[${tag}]`)
42
- }
43
- const message = parts.join(' ')
44
- connection.telemetry.logEvent({ eventName: 'error', error: message })
45
- }
46
- }
47
- root.addReporter(reporter)
48
- logger.setReporters(root.options.reporters)
49
- }
50
-
51
25
  export function logToLspConnection(connection: Connection): void {
52
26
  const reporter: ConsolaReporter = {
53
- log: ({ level, ...logObj }, ctx) => {
54
- const tag = logObj.tag || ''
55
- const parts = logObj.args.map((arg) => {
56
- if (isError(arg)) {
57
- return arg.stack ?? arg.message
27
+ log: (logObj, _ctx) => {
28
+ const { message, error } = formatLogObj(logObj)
29
+ switch (logObj.type) {
30
+ case 'silent': {
31
+ // ignore
32
+ break
58
33
  }
59
- if (typeof arg === 'string') {
60
- return arg
34
+ case 'verbose':
35
+ case 'trace': {
36
+ connection.tracer.log(message)
37
+ break
61
38
  }
62
- return '' + arg
63
- })
64
- if (tag) {
65
- parts.unshift(`[${tag}]`)
66
- }
67
- const message = parts.join(' ')
68
- switch (true) {
69
- case level >= LogLevels.debug: {
39
+ case 'debug': {
70
40
  connection.console.debug(message)
71
41
  break
72
42
  }
73
- // case level >= LogLevels.info: {
74
- // connection.console.info(message)
75
- // break
76
- // }
77
- case level >= LogLevels.log: {
43
+ case 'log': {
44
+ connection.console.log(message)
45
+ break
46
+ }
47
+ case 'info':
48
+ case 'box':
49
+ case 'ready':
50
+ case 'start':
51
+ case 'success': {
78
52
  connection.console.info(message)
79
53
  break
80
54
  }
81
- case level >= LogLevels.warn: {
55
+ case 'warn': {
82
56
  connection.console.warn(message)
83
57
  break
84
58
  }
85
- case level >= LogLevels.fatal: {
59
+ case 'fail':
60
+ case 'error':
61
+ case 'fatal': {
86
62
  connection.console.error(message)
63
+ if (error) {
64
+ connection.telemetry.logEvent({ eventName: 'error', ...error })
65
+ } else {
66
+ connection.telemetry.logEvent({ eventName: 'error', message })
67
+ }
87
68
  break
88
69
  }
89
- default: {
90
- connection.console.log(message)
91
- }
70
+ default:
71
+ nonexhaustive(logObj.type)
92
72
  }
93
- }
73
+ },
74
+ }
75
+ if (BROWSER) {
76
+ root.addReporter(reporter)
77
+ } else {
78
+ root.setReporters([reporter])
94
79
  }
95
- root.setReporters([reporter])
96
80
  logger.setReporters(root.options.reporters)
97
81
  }
@@ -7,7 +7,6 @@ import type { LikeC4Services } from '../module'
7
7
 
8
8
  export class LikeC4CodeLensProvider implements CodeLensProvider {
9
9
  constructor(private services: LikeC4Services) {
10
- //
11
10
  }
12
11
 
13
12
  async provideCodeLens(
@@ -22,6 +22,21 @@ export class LikeC4CompletionProvider extends DefaultCompletionProvider {
22
22
  if (!this.filterKeyword(context, keyword)) {
23
23
  return
24
24
  }
25
+ if (keyword.value === 'deployment' && AstUtils.hasContainerOfType(context.node, ast.isModelViews)) {
26
+ return acceptor(context, {
27
+ label: keyword.value,
28
+ detail: `Insert deployment view`,
29
+ kind: CompletionItemKind.Class,
30
+ insertTextFormat: InsertTextFormat.Snippet,
31
+ insertText: [
32
+ 'deployment view ${1:view_${TM_FILENAME_BASE}_${CURRENT_SECOND}} {',
33
+ '\ttitle \'${2:Untitled}\'',
34
+ '\t',
35
+ '\tinclude $0',
36
+ '}'
37
+ ].join('\n')
38
+ })
39
+ }
25
40
  if (['title', 'description', 'technology'].includes(keyword.value)) {
26
41
  return acceptor(context, {
27
42
  label: keyword.value,
@@ -30,7 +45,7 @@ export class LikeC4CompletionProvider extends DefaultCompletionProvider {
30
45
  insertText: `${keyword.value} '\${0}'`
31
46
  })
32
47
  }
33
- if (['views', 'specification', 'model', 'with'].includes(keyword.value)) {
48
+ if (['views', 'specification', 'model', 'deployment', 'with'].includes(keyword.value)) {
34
49
  return acceptor(context, {
35
50
  label: keyword.value,
36
51
  detail: `Insert ${keyword.value} block`,
@@ -52,7 +67,7 @@ export class LikeC4CompletionProvider extends DefaultCompletionProvider {
52
67
  ].join('\n')
53
68
  })
54
69
  }
55
- if (keyword.value === 'dynamic') {
70
+ if (keyword.value === 'dynamic' && AstUtils.hasContainerOfType(context.node, ast.isModelViews)) {
56
71
  return acceptor(context, {
57
72
  label: keyword.value,
58
73
  detail: `Insert dynamic view`,
@@ -74,7 +89,7 @@ export class LikeC4CompletionProvider extends DefaultCompletionProvider {
74
89
  detail: `Insert ${keyword.value} block`,
75
90
  kind: CompletionItemKind.Module,
76
91
  insertTextFormat: InsertTextFormat.Snippet,
77
- insertText: `${keyword.value} \${1:name} \${2:*} {\n\t\${3|color,shape,border,opacity,icon|} \$0\n}`
92
+ insertText: `${keyword.value} \${1:name} \${2:*} {\n\t\${3|color,shape,border,opacity,icon|} $0\n}`
78
93
  })
79
94
  }
80
95
  if (AstUtils.hasContainerOfType(context.node, anyPass([ast.isModelViews, ast.isGlobalStyleGroup]))) {
@@ -83,7 +98,7 @@ export class LikeC4CompletionProvider extends DefaultCompletionProvider {
83
98
  detail: `Insert ${keyword.value} block`,
84
99
  kind: CompletionItemKind.Module,
85
100
  insertTextFormat: InsertTextFormat.Snippet,
86
- insertText: `${keyword.value} \${1:*} {\n\t\${2|color,shape,border,opacity,icon|} \$0\n}`
101
+ insertText: `${keyword.value} \${1:*} {\n\t\${2|color,shape,border,opacity,icon|} $0\n}`
87
102
  })
88
103
  }
89
104
  return acceptor(context, {
@@ -91,7 +106,7 @@ export class LikeC4CompletionProvider extends DefaultCompletionProvider {
91
106
  detail: `Insert ${keyword.value} block`,
92
107
  kind: CompletionItemKind.Module,
93
108
  insertTextFormat: InsertTextFormat.Snippet,
94
- insertText: `${keyword.value} {\n\t\${1|color,shape,border,opacity,icon|} \$0\n}`
109
+ insertText: `${keyword.value} {\n\t\${1|color,shape,border,opacity,icon|} $0\n}`
95
110
  })
96
111
  }
97
112
  if (keyword.value === 'extend') {
@@ -4,9 +4,9 @@ import type { DocumentSymbolProvider, NodeKindProvider } from 'langium/lsp'
4
4
  import { filter, isEmpty, isTruthy, map, pipe } from 'remeda'
5
5
  import { type DocumentSymbol, SymbolKind } from 'vscode-languageserver-types'
6
6
  import { ast, type LikeC4LangiumDocument } from '../ast'
7
- import { getFqnElementRef } from '../elementRef'
8
7
  import { logError } from '../logger'
9
8
  import type { LikeC4Services } from '../module'
9
+ import { getFqnElementRef } from '../utils/elementRef'
10
10
 
11
11
  export class LikeC4DocumentSymbolProvider implements DocumentSymbolProvider {
12
12
  protected readonly nodeKindProvider: NodeKindProvider
@@ -61,7 +61,10 @@ export class LikeC4DocumentSymbolProvider implements DocumentSymbolProvider {
61
61
  [...astSpec.elements, ...astSpec.tags, ...astSpec.relationships],
62
62
  map(nd => {
63
63
  try {
64
- if (ast.isSpecificationElementKind(nd) || ast.isSpecificationRelationshipKind(nd)) {
64
+ if (
65
+ ast.isSpecificationElementKind(nd) || ast.isSpecificationRelationshipKind(nd)
66
+ || ast.isSpecificationDeploymentNodeKind(nd)
67
+ ) {
65
68
  return this.getKindSymbol(nd)
66
69
  }
67
70
  if (ast.isSpecificationTag(nd)) {
@@ -1,17 +1,19 @@
1
- import { type AstNode, type MaybePromise } from 'langium'
1
+ import { type AstNode, AstUtils, type MaybePromise } from 'langium'
2
2
  import { AstNodeHoverProvider } from 'langium/lsp'
3
3
  import { isTruthy } from 'remeda'
4
4
  import stripIndent from 'strip-indent'
5
5
  import type { Hover } from 'vscode-languageserver-types'
6
6
  import { ast } from '../ast'
7
- import type { LikeC4ModelLocator } from '../model'
7
+ import type { LikeC4ModelLocator, LikeC4ModelParser } from '../model'
8
8
  import type { LikeC4Services } from '../module'
9
9
 
10
10
  export class LikeC4HoverProvider extends AstNodeHoverProvider {
11
+ private parser: LikeC4ModelParser
11
12
  private locator: LikeC4ModelLocator
12
13
 
13
14
  constructor(services: LikeC4Services) {
14
15
  super(services)
16
+ this.parser = services.likec4.ModelParser
15
17
  this.locator = services.likec4.ModelLocator
16
18
  }
17
19
 
@@ -27,6 +29,38 @@ export class LikeC4HoverProvider extends AstNodeHoverProvider {
27
29
  }
28
30
  }
29
31
 
32
+ if (ast.isDeploymentNode(node)) {
33
+ const doc = AstUtils.getDocument(node)
34
+ const el = this.parser.forDocument(doc).parseDeploymentNode(node)
35
+ const lines = [el.id as string + ' ']
36
+ if (el.title !== node.name) {
37
+ lines.push(`### ${el.title}`)
38
+ }
39
+ lines.push('Deployment: `' + el.kind + '` ')
40
+ return {
41
+ contents: {
42
+ kind: 'markdown',
43
+ value: lines.join('\n')
44
+ }
45
+ }
46
+ }
47
+
48
+ if (ast.isDeployedInstance(node)) {
49
+ const doc = AstUtils.getDocument(node)
50
+ const instance = this.parser.forDocument(doc).parseDeployedInstance(node)
51
+ const el = this.locator.getParsedElement(instance.element)
52
+ const lines = [instance.id + ' ', `instance of \`${instance.element}\``]
53
+ if (el) {
54
+ lines.push(`### ${el.title}`, 'Element: `' + el.kind + '` ')
55
+ }
56
+ return {
57
+ contents: {
58
+ kind: 'markdown',
59
+ value: lines.join('\n')
60
+ }
61
+ }
62
+ }
63
+
30
64
  // if (ast.isElementKind(node)) {
31
65
  // const spec = this.specIndex.get(node.name as ElementKind)
32
66
  // return {
@@ -45,7 +79,7 @@ export class LikeC4HoverProvider extends AstNodeHoverProvider {
45
79
  if (!el) {
46
80
  return
47
81
  }
48
- const lines = [el.id, `### ${el.title}`, '`' + el.kind + '` ']
82
+ const lines = [el.id, `### ${el.title}`, 'Element: `' + el.kind + '` ']
49
83
  return {
50
84
  contents: {
51
85
  kind: 'markdown',