@likec4/language-server 1.18.0 → 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 (220) 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 +126 -0
  5. package/dist/ast.d.ts +200 -0
  6. package/dist/ast.js +276 -0
  7. package/dist/browser.d.ts +6 -20
  8. package/dist/browser.js +13 -0
  9. package/dist/formatting/LikeC4Formatter.d.ts +27 -0
  10. package/dist/formatting/LikeC4Formatter.js +261 -0
  11. package/dist/formatting/utils.d.ts +6 -0
  12. package/dist/formatting/utils.js +15 -0
  13. package/dist/generated/ast.d.ts +1242 -0
  14. package/dist/generated/ast.js +1945 -0
  15. package/dist/generated/grammar.d.ts +6 -0
  16. package/dist/generated/grammar.js +3 -0
  17. package/dist/generated/module.d.ts +9 -0
  18. package/dist/generated/module.js +23 -0
  19. package/dist/generated-lib/icons.d.ts +1 -0
  20. package/dist/{likec4lib.mjs → generated-lib/icons.js} +1 -6
  21. package/dist/index.d.ts +8 -31
  22. package/dist/index.js +13 -0
  23. package/dist/like-c4.langium +845 -0
  24. package/dist/likec4lib.d.ts +4 -6
  25. package/dist/likec4lib.js +4 -0
  26. package/dist/logger.d.ts +7 -0
  27. package/dist/logger.js +73 -0
  28. package/dist/lsp/CodeLensProvider.d.ts +9 -0
  29. package/dist/lsp/CodeLensProvider.js +40 -0
  30. package/dist/lsp/CompletionProvider.d.ts +6 -0
  31. package/dist/lsp/CompletionProvider.js +135 -0
  32. package/dist/lsp/DocumentHighlightProvider.d.ts +9 -0
  33. package/dist/lsp/DocumentHighlightProvider.js +10 -0
  34. package/dist/lsp/DocumentLinkProvider.d.ts +11 -0
  35. package/dist/lsp/DocumentLinkProvider.js +49 -0
  36. package/dist/lsp/DocumentSymbolProvider.d.ts +23 -0
  37. package/dist/lsp/DocumentSymbolProvider.js +202 -0
  38. package/dist/lsp/HoverProvider.d.ts +10 -0
  39. package/dist/lsp/HoverProvider.js +69 -0
  40. package/dist/lsp/RenameProvider.d.ts +5 -0
  41. package/dist/lsp/RenameProvider.js +6 -0
  42. package/dist/lsp/SemanticTokenProvider.d.ts +7 -0
  43. package/dist/lsp/SemanticTokenProvider.js +297 -0
  44. package/dist/lsp/index.d.ts +7 -0
  45. package/dist/lsp/index.js +7 -0
  46. package/dist/model/deployments-index.d.ts +60 -0
  47. package/dist/model/deployments-index.js +181 -0
  48. package/dist/model/fqn-computation.d.ts +3 -0
  49. package/dist/model/fqn-computation.js +72 -0
  50. package/dist/model/fqn-index.d.ts +25 -0
  51. package/dist/model/fqn-index.js +96 -0
  52. package/dist/model/index.d.ts +6 -0
  53. package/dist/model/index.js +6 -0
  54. package/dist/model/model-builder.d.ts +32 -0
  55. package/dist/model/model-builder.js +598 -0
  56. package/dist/model/model-locator.d.ts +23 -0
  57. package/dist/model/model-locator.js +126 -0
  58. package/dist/model/model-parser-where.d.ts +3 -0
  59. package/dist/model/model-parser-where.js +70 -0
  60. package/dist/model/model-parser.d.ts +292 -0
  61. package/dist/model/model-parser.js +72 -0
  62. package/dist/model/parser/Base.d.ts +28 -0
  63. package/dist/model/parser/Base.js +87 -0
  64. package/dist/model/parser/DeploymentModelParser.d.ts +33 -0
  65. package/dist/model/parser/DeploymentModelParser.js +162 -0
  66. package/dist/model/parser/DeploymentViewParser.d.ts +38 -0
  67. package/dist/model/parser/DeploymentViewParser.js +98 -0
  68. package/dist/model/parser/FqnRefParser.d.ts +29 -0
  69. package/dist/model/parser/FqnRefParser.js +108 -0
  70. package/dist/model/parser/GlobalsParser.d.ts +66 -0
  71. package/dist/model/parser/GlobalsParser.js +80 -0
  72. package/dist/model/parser/ModelParser.d.ts +27 -0
  73. package/dist/model/parser/ModelParser.js +122 -0
  74. package/dist/model/parser/PredicatesParser.d.ts +34 -0
  75. package/dist/model/parser/PredicatesParser.js +272 -0
  76. package/dist/model/parser/SpecificationParser.d.ts +27 -0
  77. package/dist/model/parser/SpecificationParser.js +120 -0
  78. package/dist/model/parser/ViewsParser.d.ts +64 -0
  79. package/dist/model/parser/ViewsParser.js +377 -0
  80. package/dist/model-change/ModelChanges.d.ts +15 -0
  81. package/dist/model-change/ModelChanges.js +89 -0
  82. package/dist/model-change/changeElementStyle.d.ts +16 -0
  83. package/dist/model-change/changeElementStyle.js +136 -0
  84. package/dist/model-change/changeViewLayout.d.ts +12 -0
  85. package/dist/model-change/changeViewLayout.js +32 -0
  86. package/dist/model-change/saveManualLayout.d.ts +11 -0
  87. package/dist/model-change/saveManualLayout.js +27 -0
  88. package/dist/module.d.ts +62 -0
  89. package/dist/module.js +123 -0
  90. package/dist/protocol.d.ts +20 -23
  91. package/dist/protocol.js +14 -0
  92. package/dist/references/index.d.ts +3 -0
  93. package/dist/references/index.js +3 -0
  94. package/dist/references/name-provider.d.ts +9 -0
  95. package/dist/references/name-provider.js +33 -0
  96. package/dist/references/scope-computation.d.ts +20 -0
  97. package/dist/references/scope-computation.js +281 -0
  98. package/dist/references/scope-provider.d.ts +16 -0
  99. package/dist/references/scope-provider.js +165 -0
  100. package/dist/shared/NodeKindProvider.d.ts +15 -0
  101. package/dist/shared/NodeKindProvider.js +108 -0
  102. package/dist/shared/WorkspaceManager.d.ts +18 -0
  103. package/dist/shared/WorkspaceManager.js +36 -0
  104. package/dist/shared/WorkspaceSymbolProvider.d.ts +3 -0
  105. package/dist/shared/WorkspaceSymbolProvider.js +3 -0
  106. package/dist/shared/index.d.ts +3 -0
  107. package/dist/shared/index.js +3 -0
  108. package/dist/test/index.d.ts +1 -0
  109. package/dist/test/index.js +1 -0
  110. package/dist/test/setup.d.ts +1 -0
  111. package/dist/test/setup.js +7 -0
  112. package/dist/test/testServices.d.ts +22 -0
  113. package/dist/test/testServices.js +119 -0
  114. package/dist/utils/elementRef.d.ts +11 -0
  115. package/dist/utils/elementRef.js +15 -0
  116. package/dist/utils/fqnRef.d.ts +8 -0
  117. package/dist/utils/fqnRef.js +46 -0
  118. package/dist/utils/index.d.ts +1 -0
  119. package/dist/utils/index.js +1 -0
  120. package/dist/utils/printDocs.d.ts +2 -0
  121. package/dist/utils/printDocs.js +1 -0
  122. package/dist/utils/stringHash.d.ts +1 -0
  123. package/dist/utils/stringHash.js +5 -0
  124. package/dist/validation/_shared.d.ts +3 -0
  125. package/dist/validation/_shared.js +22 -0
  126. package/dist/validation/deployment-checks.d.ts +6 -0
  127. package/dist/validation/deployment-checks.js +114 -0
  128. package/dist/validation/dynamic-view-rule.d.ts +4 -0
  129. package/dist/validation/dynamic-view-rule.js +16 -0
  130. package/dist/validation/dynamic-view-step.d.ts +4 -0
  131. package/dist/validation/dynamic-view-step.js +33 -0
  132. package/dist/validation/element.d.ts +4 -0
  133. package/dist/validation/element.js +49 -0
  134. package/dist/validation/index.d.ts +15 -0
  135. package/dist/validation/index.js +152 -0
  136. package/dist/validation/property-checks.d.ts +6 -0
  137. package/dist/validation/property-checks.js +38 -0
  138. package/dist/validation/relation.d.ts +5 -0
  139. package/dist/validation/relation.js +56 -0
  140. package/dist/validation/specification.d.ts +11 -0
  141. package/dist/validation/specification.js +136 -0
  142. package/dist/validation/view-predicates/element-with.d.ts +4 -0
  143. package/dist/validation/view-predicates/element-with.js +30 -0
  144. package/dist/validation/view-predicates/expanded-element.d.ts +4 -0
  145. package/dist/validation/view-predicates/expanded-element.js +11 -0
  146. package/dist/validation/view-predicates/expression-v2.d.ts +5 -0
  147. package/dist/validation/view-predicates/expression-v2.js +83 -0
  148. package/dist/validation/view-predicates/incoming.d.ts +4 -0
  149. package/dist/validation/view-predicates/incoming.js +15 -0
  150. package/dist/validation/view-predicates/index.d.ts +6 -0
  151. package/dist/validation/view-predicates/index.js +6 -0
  152. package/dist/validation/view-predicates/outgoing.d.ts +4 -0
  153. package/dist/validation/view-predicates/outgoing.js +15 -0
  154. package/dist/validation/view-predicates/relation-with.d.ts +4 -0
  155. package/dist/validation/view-predicates/relation-with.js +12 -0
  156. package/dist/validation/view.d.ts +4 -0
  157. package/dist/validation/view.js +23 -0
  158. package/dist/view-utils/assignNavigateTo.d.ts +2 -0
  159. package/dist/view-utils/assignNavigateTo.js +25 -0
  160. package/dist/view-utils/index.d.ts +2 -0
  161. package/dist/view-utils/index.js +2 -0
  162. package/dist/view-utils/manual-layout.d.ts +7 -0
  163. package/dist/view-utils/manual-layout.js +99 -0
  164. package/dist/view-utils/resolve-relative-paths.d.ts +2 -0
  165. package/dist/view-utils/resolve-relative-paths.js +78 -0
  166. package/package.json +36 -53
  167. package/src/LikeC4FileSystem.ts +22 -21
  168. package/src/ast.ts +44 -133
  169. package/src/browser.ts +10 -11
  170. package/src/generated/ast.ts +177 -177
  171. package/src/generated/grammar.ts +1 -1
  172. package/src/index.ts +10 -8
  173. package/src/like-c4.langium +37 -34
  174. package/src/logger.ts +34 -55
  175. package/src/lsp/CompletionProvider.ts +4 -4
  176. package/src/lsp/HoverProvider.ts +5 -3
  177. package/src/lsp/SemanticTokenProvider.ts +2 -2
  178. package/src/model/deployments-index.ts +18 -14
  179. package/src/model/model-builder.ts +10 -8
  180. package/src/model/model-parser.ts +62 -1574
  181. package/src/model/parser/Base.ts +107 -0
  182. package/src/model/parser/DeploymentModelParser.ts +192 -0
  183. package/src/model/parser/DeploymentViewParser.ts +116 -0
  184. package/src/model/parser/FqnRefParser.ts +118 -0
  185. package/src/model/parser/GlobalsParser.ts +96 -0
  186. package/src/model/parser/ModelParser.ts +141 -0
  187. package/src/model/parser/PredicatesParser.ts +291 -0
  188. package/src/model/parser/SpecificationParser.ts +133 -0
  189. package/src/model/parser/ViewsParser.ts +428 -0
  190. package/src/module.ts +17 -18
  191. package/src/references/scope-provider.ts +13 -7
  192. package/src/utils/{deploymentRef.ts → fqnRef.ts} +27 -2
  193. package/src/validation/_shared.ts +0 -1
  194. package/src/validation/deployment-checks.ts +49 -62
  195. package/src/validation/index.ts +100 -9
  196. package/src/validation/view-predicates/expression-v2.ts +101 -0
  197. package/src/validation/view-predicates/index.ts +1 -1
  198. package/src/view-utils/assignNavigateTo.ts +1 -1
  199. package/src/view-utils/manual-layout.ts +25 -0
  200. package/dist/browser.cjs +0 -25
  201. package/dist/browser.d.cts +0 -23
  202. package/dist/browser.d.mts +0 -23
  203. package/dist/browser.mjs +0 -20
  204. package/dist/index.cjs +0 -53
  205. package/dist/index.d.cts +0 -34
  206. package/dist/index.d.mts +0 -34
  207. package/dist/index.mjs +0 -46
  208. package/dist/likec4lib.cjs +0 -1546
  209. package/dist/likec4lib.d.cts +0 -6
  210. package/dist/likec4lib.d.mts +0 -6
  211. package/dist/protocol.cjs +0 -25
  212. package/dist/protocol.d.cts +0 -48
  213. package/dist/protocol.d.mts +0 -48
  214. package/dist/protocol.mjs +0 -17
  215. package/dist/shared/language-server.CO_nmHiL.cjs +0 -7689
  216. package/dist/shared/language-server.Da6ey08o.d.cts +0 -1619
  217. package/dist/shared/language-server.De7S3e5Z.d.ts +0 -1619
  218. package/dist/shared/language-server.Dj4iDjtB.d.mts +0 -1619
  219. package/dist/shared/language-server.oO_9JoAG.mjs +0 -7666
  220. package/src/validation/view-predicates/deployments.ts +0 -56
package/src/index.ts CHANGED
@@ -1,15 +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
13
 
12
- export function startLanguageServer() {
14
+ export function startLanguageServer(): {
15
+ shared: LikeC4SharedServices
16
+ likec4: LikeC4Services
17
+ } {
13
18
  /* browser specific setup code */
14
19
  const connection = createConnection(ProposedFeatures.all)
15
20
 
@@ -19,8 +24,5 @@ export function startLanguageServer() {
19
24
  // Start the language server with the shared services
20
25
  startLanguim(services.shared)
21
26
 
22
- return {
23
- ...services,
24
- connection
25
- }
27
+ return services
26
28
  }
@@ -545,7 +545,7 @@ DeploymentNodeBody: '{'
545
545
 
546
546
  DeployedInstance:
547
547
  (name=Id Eq)?
548
- ('instanceOf' | 'instance' 'of')
548
+ 'instanceOf'
549
549
  element=ElementRef
550
550
  title=String?
551
551
  body=DeployedInstanceBody?
@@ -557,18 +557,20 @@ DeployedInstanceBody: '{'
557
557
  props+=ElementProperty*
558
558
  '}';
559
559
 
560
- // Rules:
561
- // - DeployedInstance can be referenced from DeploymentNode
562
- // - Element can be referenced from DeployedInstance
563
- // Forced by scope computation
564
- type DeploymentReferenceable = DeploymentNode | DeployedInstance | Element;
565
- DeploymentRef:
566
- value=[DeploymentReferenceable:Id] ({infer DeploymentRef.parent=current} StickyDot value=[DeploymentReferenceable:Id])*;
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])*;
567
569
 
568
570
  DeploymentRelation:
569
- source=DeploymentRef
571
+ source=FqnRef
570
572
  ('->' | '-[' kind=[RelationshipKind:Id] ']->' | kind=[RelationshipKind:DotId])
571
- target=DeploymentRef
573
+ target=FqnRef
572
574
  (
573
575
  title=String
574
576
  technology=String?
@@ -600,7 +602,7 @@ DeploymentViewRule:
600
602
  ;
601
603
 
602
604
  DeploymentViewRuleStyle:
603
- 'style' target=DeploymentExpressionIterator '{'
605
+ 'style' targets=FqnExpressions '{'
604
606
  props+=(
605
607
  StyleProperty |
606
608
  NotationProperty
@@ -614,46 +616,47 @@ DeploymentViewRulePredicate:
614
616
  ;
615
617
 
616
618
  DeploymentViewRulePredicateExpression:
617
- value=DeploymentExpression ({infer DeploymentViewRulePredicateExpression.prev=current} ',' (value=DeploymentExpression)?)*
619
+ value=ExpressionV2 ({infer DeploymentViewRulePredicateExpression.prev=current} ',' (value=ExpressionV2)?)*
618
620
  ;
619
621
 
620
- DeploymentExpression:
621
- DeploymentRelationExpression |
622
- DeploymentElementExpression
622
+ ExpressionV2:
623
+ RelationExpr |
624
+ FqnExpr
623
625
  ;
624
626
 
625
- DeploymentElementExpression:
627
+
628
+ FqnExpr:
626
629
  {infer WildcardExpression} isWildcard?='*' |
627
- DeploymentRefExpression
630
+ FqnRefExpr
628
631
  ;
629
632
 
630
- DeploymentRefExpression:
631
- ref=DeploymentRef selector=(DotUnderscore | DotWildcard)?
633
+ FqnRefExpr:
634
+ ref=FqnRef selector=(DotUnderscore | DotWildcard)?
632
635
  ;
633
636
 
634
- DeploymentRelationExpression:
635
- InOutDeploymentRelationExpression |
636
- DirectedDeploymentRelationExpression
637
+ RelationExpr:
638
+ InOutRelationExpr |
639
+ DirectedRelationExpr
637
640
  ;
638
641
 
639
- InOutDeploymentRelationExpression infers DeploymentRelationExpression:
640
- IncomingDeploymentRelationExpression ({infer InOutDeploymentRelationExpression.inout=current} '->')?
642
+ InOutRelationExpr infers RelationExpr:
643
+ IncomingRelationExpr ({infer InOutRelationExpr.inout=current} '->')?
641
644
  ;
642
645
 
643
- IncomingDeploymentRelationExpression:
644
- '->' to=DeploymentElementExpression;
646
+ IncomingRelationExpr:
647
+ '->' to=FqnExpr;
645
648
 
646
- DirectedDeploymentRelationExpression infers DeploymentRelationExpression:
647
- OutgoingDeploymentRelationExpression ({infer DirectedDeploymentRelationExpression.source=current} target=DeploymentElementExpression)?
649
+ DirectedRelationExpr infers RelationExpr:
650
+ OutgoingRelationExpr ({infer DirectedRelationExpr.source=current} target=FqnExpr)?
648
651
  ;
649
652
 
650
- OutgoingDeploymentRelationExpression:
651
- from=DeploymentElementExpression
653
+ OutgoingRelationExpr:
654
+ from=FqnExpr
652
655
  (isBidirectional?='<->' | '->' | '-[' kind=[RelationshipKind:Id] ']->' | kind=[RelationshipKind:DotId])
653
656
  ;
654
657
 
655
- DeploymentExpressionIterator:
656
- value=DeploymentElementExpression ({infer DeploymentExpressionIterator.prev=current} ',' (value=DeploymentElementExpression)?)*
658
+ FqnExpressions:
659
+ value=FqnExpr ({infer FqnExpressions.prev=current} ',' (value=FqnExpr)?)*
657
660
  ;
658
661
  // Global -------------------------------------
659
662
 
@@ -691,7 +694,7 @@ GlobalStyleGroup:
691
694
  styles+=ViewRuleStyle*
692
695
  '}';
693
696
 
694
- type FqnReferenceable = DeploymentReferenceable | Element | ExtendElement;
697
+ type FqnReferenceable = Referenceable | Element | ExtendElement;
695
698
 
696
699
  // Common properties -------------------------------------
697
700
 
@@ -783,7 +786,7 @@ CustomColorId returns string:
783
786
  IdTerminal | ElementShape | ArrowType | LineOptions | 'element' | 'model';
784
787
 
785
788
  Id returns string:
786
- IdTerminal | ElementShape | ThemeColor | ArrowType | LineOptions | 'element' | 'model' | 'group' | 'node' | 'deployment';
789
+ IdTerminal | ElementShape | ThemeColor | ArrowType | LineOptions | 'element' | 'model' | 'group' | 'node' | 'deployment' | 'instance';
787
790
 
788
791
  fragment EqOperator:
789
792
  (
package/src/logger.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { type ConsolaReporter, LogLevels, rootLogger as root } from '@likec4/log'
1
+ import { nonexhaustive } from '@likec4/core'
2
+ import { type ConsolaReporter, formatLogObj, LogLevels, rootLogger as root } from '@likec4/log'
2
3
  import { BROWSER } from 'esm-env'
3
- import { isError } from 'remeda'
4
4
  import type { Connection } from 'vscode-languageserver'
5
5
 
6
6
  export const logger = root.withTag('lsp')
@@ -22,76 +22,55 @@ export function setLogLevel(level: keyof typeof LogLevels): void {
22
22
  logger.level = LogLevels[level]
23
23
  }
24
24
 
25
- export function logErrorToTelemetry(connection: Connection): void {
26
- const reporter: ConsolaReporter = {
27
- log: ({ level, ...logObj }, ctx) => {
28
- if (level !== LogLevels.error && level !== LogLevels.fatal) {
29
- return
30
- }
31
- const tag = logObj.tag || ''
32
- const parts = logObj.args.map((arg) => {
33
- if (isError(arg)) {
34
- return arg.stack ?? arg.message
35
- }
36
- if (typeof arg === 'string') {
37
- return arg
38
- }
39
- return '' + arg
40
- })
41
- if (tag) {
42
- parts.unshift(`[${tag}]`)
43
- }
44
- const message = parts.join(' ')
45
- connection.telemetry.logEvent({ eventName: 'error', error: message })
46
- }
47
- }
48
- root.addReporter(reporter)
49
- logger.setReporters(root.options.reporters)
50
- }
51
-
52
25
  export function logToLspConnection(connection: Connection): void {
53
26
  const reporter: ConsolaReporter = {
54
- log: ({ level, ...logObj }, ctx) => {
55
- const tag = logObj.tag || ''
56
- const parts = logObj.args.map((arg) => {
57
- if (isError(arg)) {
58
- 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
59
33
  }
60
- if (typeof arg === 'string') {
61
- return arg
34
+ case 'verbose':
35
+ case 'trace': {
36
+ connection.tracer.log(message)
37
+ break
62
38
  }
63
- return '' + arg
64
- })
65
- if (tag) {
66
- parts.unshift(`[${tag}]`)
67
- }
68
- const message = parts.join(' ')
69
- switch (true) {
70
- case level >= LogLevels.debug: {
39
+ case 'debug': {
71
40
  connection.console.debug(message)
72
41
  break
73
42
  }
74
- // case level >= LogLevels.info: {
75
- // connection.console.info(message)
76
- // break
77
- // }
78
- 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': {
79
52
  connection.console.info(message)
80
53
  break
81
54
  }
82
- case level >= LogLevels.warn: {
55
+ case 'warn': {
83
56
  connection.console.warn(message)
84
57
  break
85
58
  }
86
- case level >= LogLevels.fatal: {
59
+ case 'fail':
60
+ case 'error':
61
+ case 'fatal': {
87
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
+ }
88
68
  break
89
69
  }
90
- default: {
91
- connection.console.log(message)
92
- }
70
+ default:
71
+ nonexhaustive(logObj.type)
93
72
  }
94
- }
73
+ },
95
74
  }
96
75
  if (BROWSER) {
97
76
  root.addReporter(reporter)
@@ -32,7 +32,7 @@ export class LikeC4CompletionProvider extends DefaultCompletionProvider {
32
32
  'deployment view ${1:view_${TM_FILENAME_BASE}_${CURRENT_SECOND}} {',
33
33
  '\ttitle \'${2:Untitled}\'',
34
34
  '\t',
35
- '\t$0',
35
+ '\tinclude $0',
36
36
  '}'
37
37
  ].join('\n')
38
38
  })
@@ -89,7 +89,7 @@ export class LikeC4CompletionProvider extends DefaultCompletionProvider {
89
89
  detail: `Insert ${keyword.value} block`,
90
90
  kind: CompletionItemKind.Module,
91
91
  insertTextFormat: InsertTextFormat.Snippet,
92
- 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}`
93
93
  })
94
94
  }
95
95
  if (AstUtils.hasContainerOfType(context.node, anyPass([ast.isModelViews, ast.isGlobalStyleGroup]))) {
@@ -98,7 +98,7 @@ export class LikeC4CompletionProvider extends DefaultCompletionProvider {
98
98
  detail: `Insert ${keyword.value} block`,
99
99
  kind: CompletionItemKind.Module,
100
100
  insertTextFormat: InsertTextFormat.Snippet,
101
- 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}`
102
102
  })
103
103
  }
104
104
  return acceptor(context, {
@@ -106,7 +106,7 @@ export class LikeC4CompletionProvider extends DefaultCompletionProvider {
106
106
  detail: `Insert ${keyword.value} block`,
107
107
  kind: CompletionItemKind.Module,
108
108
  insertTextFormat: InsertTextFormat.Snippet,
109
- 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}`
110
110
  })
111
111
  }
112
112
  if (keyword.value === 'extend') {
@@ -1,4 +1,4 @@
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'
@@ -30,7 +30,8 @@ export class LikeC4HoverProvider extends AstNodeHoverProvider {
30
30
  }
31
31
 
32
32
  if (ast.isDeploymentNode(node)) {
33
- const el = this.parser.parseDeploymentNode(node, () => true)
33
+ const doc = AstUtils.getDocument(node)
34
+ const el = this.parser.forDocument(doc).parseDeploymentNode(node)
34
35
  const lines = [el.id as string + ' ']
35
36
  if (el.title !== node.name) {
36
37
  lines.push(`### ${el.title}`)
@@ -45,7 +46,8 @@ export class LikeC4HoverProvider extends AstNodeHoverProvider {
45
46
  }
46
47
 
47
48
  if (ast.isDeployedInstance(node)) {
48
- const instance = this.parser.parseDeployedInstance(node, () => true)
49
+ const doc = AstUtils.getDocument(node)
50
+ const instance = this.parser.forDocument(doc).parseDeployedInstance(node)
49
51
  const el = this.locator.getParsedElement(instance.element)
50
52
  const lines = [instance.id + ' ', `instance of \`${instance.element}\``]
51
53
  if (el) {
@@ -90,7 +90,7 @@ export class LikeC4SemanticTokenProvider extends AbstractSemanticTokenProvider {
90
90
  })
91
91
  return 'prune'
92
92
  }
93
- if (ast.isDeploymentRefExpression(node)) {
93
+ if (ast.isFqnRefExpr(node)) {
94
94
  if (node.selector) {
95
95
  acceptor({
96
96
  node,
@@ -142,7 +142,7 @@ export class LikeC4SemanticTokenProvider extends AbstractSemanticTokenProvider {
142
142
  })
143
143
  return 'prune'
144
144
  }
145
- if (ast.isDeploymentRef(node)) {
145
+ if (ast.isFqnRef(node)) {
146
146
  acceptor({
147
147
  node,
148
148
  property: 'value',
@@ -3,11 +3,11 @@ import type { LangiumDocument, LangiumDocuments, Stream } from 'langium'
3
3
  import { AstUtils, DocumentState, MultiMap } from 'langium'
4
4
  import { forEachObj, groupBy, isTruthy, pipe, prop } from 'remeda'
5
5
  import {
6
- ast,
7
6
  type DeploymentAstNodeDescription,
7
+ type LikeC4LangiumDocument,
8
+ ast,
8
9
  ElementOps,
9
10
  isLikeC4LangiumDocument,
10
- type LikeC4LangiumDocument
11
11
  } from '../ast'
12
12
  import { logWarnError } from '../logger'
13
13
  import type { LikeC4Services } from '../module'
@@ -33,7 +33,7 @@ export class DeploymentsIndex {
33
33
  for (const doc of docs) {
34
34
  delete (doc as IndexedDocument)[DeploymentsIndexKey]
35
35
  }
36
- }
36
+ },
37
37
  )
38
38
  }
39
39
 
@@ -55,7 +55,7 @@ export class DeploymentsIndex {
55
55
  * @returns Stream of artifacts
56
56
  */
57
57
  public nested(node: ast.DeploymentNode): Stream<DeploymentAstNodeDescription> {
58
- const fqnName = this.getFqnName(node)
58
+ const fqnName = this.getFqn(node)
59
59
  return this.documents().flatMap(doc => this.get(doc).nested(fqnName))
60
60
  }
61
61
 
@@ -63,18 +63,19 @@ export class DeploymentsIndex {
63
63
  return this.documents().flatMap(doc => this.get(doc).byFqn(fqnName))
64
64
  }
65
65
 
66
- public getFqnName(node: ast.DeploymentElement): Fqn {
66
+ public getFqn(node: ast.DeploymentElement): Fqn {
67
67
  let id = ElementOps.readId(node)
68
68
  if (isTruthy(id)) {
69
69
  return id
70
70
  }
71
71
  const fqn = [
72
- this.Names.getNameStrict(node)
72
+ this.Names.getNameStrict(node),
73
73
  ]
74
+ let _node = node
74
75
  let parentNode: ast.DeploymentNode | undefined
75
- while ((parentNode = AstUtils.getContainerOfType(node.$container, ast.isDeploymentNode))) {
76
+ while ((parentNode = AstUtils.getContainerOfType(_node.$container, ast.isDeploymentNode))) {
76
77
  fqn.push(this.Names.getNameStrict(parentNode))
77
- node = parentNode
78
+ _node = parentNode
78
79
  }
79
80
  id = fqn.reduceRight((acc, cur) => `${acc}.${cur}`) as Fqn
80
81
  ElementOps.writeId(node, id)
@@ -93,11 +94,11 @@ export class DeploymentsIndex {
93
94
  const Descriptions = this.services.workspace.AstNodeDescriptionProvider
94
95
 
95
96
  const createAndSaveDescription = (
96
- props: { node: ast.DeploymentNode | ast.DeployedInstance; name: string; fqn: string }
97
+ props: { node: ast.DeploymentNode | ast.DeployedInstance; name: string; fqn: string },
97
98
  ) => {
98
99
  const desc = {
99
100
  ...Descriptions.createDescription(props.node, props.name, document),
100
- fqn: props.fqn
101
+ fqn: props.fqn,
101
102
  }
102
103
  ElementOps.writeId(props.node, props.fqn as Fqn)
103
104
  _byfqn.add(props.fqn, desc)
@@ -106,7 +107,7 @@ export class DeploymentsIndex {
106
107
 
107
108
  const traverseNode = (
108
109
  container: ast.DeploymentNode,
109
- parentFqn: string
110
+ parentFqn: string,
110
111
  ): readonly DeploymentAstNodeDescription[] => {
111
112
  const _descedants = [] as DeploymentAstNodeDescription[]
112
113
  const children = container.body?.elements
@@ -142,7 +143,7 @@ export class DeploymentsIndex {
142
143
  return
143
144
  }
144
145
  _nested.add(parentFqn, descs[0])
145
- })
146
+ }),
146
147
  )
147
148
  }
148
149
  return _nested.get(parentFqn)
@@ -166,6 +167,9 @@ export class DeploymentsIndex {
166
167
  }
167
168
  }
168
169
 
170
+ /**
171
+ * Index of deployment elements in the document
172
+ */
169
173
  export class DocumentDeploymentsIndex {
170
174
  static readonly EMPTY = new DocumentDeploymentsIndex([], new MultiMap(), new MultiMap())
171
175
 
@@ -178,7 +182,7 @@ export class DocumentDeploymentsIndex {
178
182
  /**
179
183
  * All elements by FQN
180
184
  */
181
- private _byfqn: MultiMap<string, DeploymentAstNodeDescription>
185
+ private _byfqn: MultiMap<string, DeploymentAstNodeDescription>,
182
186
  ) {}
183
187
 
184
188
  public rootNodes(): readonly DeploymentAstNodeDescription[] {
@@ -211,7 +215,7 @@ export class DocumentDeploymentsIndex {
211
215
  if (descs.length === 1) {
212
216
  result.push(descs[0])
213
217
  }
214
- })
218
+ }),
215
219
  )
216
220
  return result
217
221
  }
@@ -1,14 +1,16 @@
1
- import * as c4 from '@likec4/core'
1
+ import type * as c4 from '@likec4/core'
2
2
  import {
3
3
  compareRelations,
4
4
  computeColorValues,
5
5
  type CustomColorDefinitions,
6
+ DeploymentElement,
6
7
  isScopedElementView,
8
+ LikeC4Model,
7
9
  parentFqn,
8
10
  sortByFqnHierarchically,
9
11
  type ViewId
10
12
  } from '@likec4/core'
11
- import { mkComputeView, resolveRulesExtendedViews } from '@likec4/core/compute-view'
13
+ import { resolveRulesExtendedViews } from '@likec4/core/compute-view'
12
14
  import { deepEqual as eq } from 'fast-equals'
13
15
  import type { Cancellation, LangiumDocument, LangiumDocuments, URI, WorkspaceCache } from 'langium'
14
16
  import { Disposable, DocumentState, interruptAndCheck } from 'langium'
@@ -189,7 +191,7 @@ function buildModel(services: LikeC4Services, docs: ParsedLikeC4LangiumDocument[
189
191
  links: unresolvedLinks,
190
192
  id,
191
193
  ...model
192
- }: ParsedAstRelation): c4.Relation | null => {
194
+ }: ParsedAstRelation): c4.ModelRelation | null => {
193
195
  if (isNullish(elements[source]) || isNullish(elements[target])) {
194
196
  logger.warn(
195
197
  `Invalid relation ${id} at ${doc.uri.path} ${astPath}, source: ${source}(${!!elements[
@@ -209,7 +211,7 @@ function buildModel(services: LikeC4Services, docs: ParsedLikeC4LangiumDocument[
209
211
  target,
210
212
  kind,
211
213
  id
212
- } satisfies c4.Relation
214
+ } satisfies c4.ModelRelation
213
215
  }
214
216
  return {
215
217
  ...links && { links },
@@ -217,7 +219,7 @@ function buildModel(services: LikeC4Services, docs: ParsedLikeC4LangiumDocument[
217
219
  source,
218
220
  target,
219
221
  id
220
- } satisfies c4.Relation
222
+ } satisfies c4.ModelRelation
221
223
  }
222
224
  }
223
225
 
@@ -232,7 +234,7 @@ function buildModel(services: LikeC4Services, docs: ParsedLikeC4LangiumDocument[
232
234
 
233
235
  function toDeploymentElement(doc: LangiumDocument) {
234
236
  return (parsed: c4.DeploymentElement): c4.DeploymentElement | null => {
235
- if (!c4.DeploymentElement.isDeploymentNode(parsed)) {
237
+ if (!DeploymentElement.isDeploymentNode(parsed)) {
236
238
  if (!parsed.links || parsed.links.length === 0) {
237
239
  return parsed
238
240
  }
@@ -525,7 +527,7 @@ export class LikeC4ModelBuilder {
525
527
  const cache = this.services.WorkspaceCache as WorkspaceCache<string, c4.ComputedLikeC4Model>
526
528
  const viewsCache = this.services.WorkspaceCache as WorkspaceCache<string, c4.ComputedView | null>
527
529
  return cache.get(CACHE_KEY_COMPUTED_MODEL, () => {
528
- const computeView = mkComputeView(model)
530
+ const computeView = LikeC4Model.makeCompute(model)
529
531
  const allViews = [] as c4.ComputedView[]
530
532
  for (const view of values(model.views)) {
531
533
  const result = computeView(view)
@@ -597,7 +599,7 @@ export class LikeC4ModelBuilder {
597
599
  logger.warn(`[ModelBuilder] Cannot find view ${viewId}`)
598
600
  return null
599
601
  }
600
- const result = mkComputeView(model)(view)
602
+ const result = LikeC4Model.makeCompute(model)(view)
601
603
  if (!result.isSuccess) {
602
604
  logError(result.error)
603
605
  return null