@likec4/language-server 1.21.1 → 1.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/README.md +4 -1
  2. package/bin/likec4-language-server.mjs +5 -2
  3. package/dist/LikeC4FileSystem.js +2 -2
  4. package/dist/browser.d.ts +3 -3
  5. package/dist/browser.js +15 -2
  6. package/dist/bundled.d.ts +8 -0
  7. package/dist/bundled.js +25 -0
  8. package/dist/bundled.mjs +2555 -4022
  9. package/dist/index.d.ts +3 -3
  10. package/dist/index.js +19 -2
  11. package/dist/logger.d.ts +10 -3
  12. package/dist/logger.js +56 -50
  13. package/dist/model/fqn-computation.js +2 -2
  14. package/dist/model/model-builder.js +13 -14
  15. package/dist/model-change/ModelChanges.js +2 -2
  16. package/dist/module.js +1 -4
  17. package/dist/references/scope-provider.js +3 -3
  18. package/dist/view-utils/manual-layout.js +2 -2
  19. package/dist/views/configurable-layouter.js +4 -4
  20. package/dist/views/likec4-views.d.ts +2 -1
  21. package/dist/views/likec4-views.js +2 -2
  22. package/package.json +14 -12
  23. package/dist/test/setup.d.ts +0 -1
  24. package/dist/test/setup.js +0 -7
  25. package/src/LikeC4FileSystem.ts +0 -38
  26. package/src/Rpc.ts +0 -134
  27. package/src/ast.ts +0 -556
  28. package/src/browser.ts +0 -35
  29. package/src/documentation/documentation-provider.ts +0 -52
  30. package/src/documentation/index.ts +0 -1
  31. package/src/formatting/LikeC4Formatter.ts +0 -639
  32. package/src/formatting/utils.ts +0 -26
  33. package/src/generated/ast.ts +0 -3735
  34. package/src/generated/grammar.ts +0 -10
  35. package/src/generated/module.ts +0 -33
  36. package/src/generated-lib/icons.ts +0 -1538
  37. package/src/index.ts +0 -30
  38. package/src/like-c4.langium +0 -901
  39. package/src/likec4lib.ts +0 -6
  40. package/src/logger.ts +0 -80
  41. package/src/lsp/CodeLensProvider.ts +0 -50
  42. package/src/lsp/CompletionProvider.ts +0 -147
  43. package/src/lsp/DocumentHighlightProvider.ts +0 -12
  44. package/src/lsp/DocumentLinkProvider.ts +0 -65
  45. package/src/lsp/DocumentSymbolProvider.ts +0 -313
  46. package/src/lsp/HoverProvider.ts +0 -92
  47. package/src/lsp/RenameProvider.ts +0 -8
  48. package/src/lsp/SemanticTokenProvider.ts +0 -383
  49. package/src/lsp/index.ts +0 -8
  50. package/src/model/deployments-index.ts +0 -209
  51. package/src/model/fqn-computation.ts +0 -83
  52. package/src/model/fqn-index.ts +0 -138
  53. package/src/model/index.ts +0 -6
  54. package/src/model/model-builder.ts +0 -724
  55. package/src/model/model-locator.ts +0 -146
  56. package/src/model/model-parser-where.ts +0 -84
  57. package/src/model/model-parser.ts +0 -86
  58. package/src/model/parser/Base.ts +0 -113
  59. package/src/model/parser/DeploymentModelParser.ts +0 -192
  60. package/src/model/parser/DeploymentViewParser.ts +0 -122
  61. package/src/model/parser/FqnRefParser.ts +0 -143
  62. package/src/model/parser/GlobalsParser.ts +0 -96
  63. package/src/model/parser/ModelParser.ts +0 -170
  64. package/src/model/parser/PredicatesParser.ts +0 -315
  65. package/src/model/parser/SpecificationParser.ts +0 -133
  66. package/src/model/parser/ViewsParser.ts +0 -428
  67. package/src/model-change/ModelChanges.ts +0 -101
  68. package/src/model-change/changeElementStyle.ts +0 -172
  69. package/src/model-change/changeViewLayout.ts +0 -47
  70. package/src/model-change/saveManualLayout.ts +0 -41
  71. package/src/module.ts +0 -255
  72. package/src/protocol.ts +0 -93
  73. package/src/references/index.ts +0 -3
  74. package/src/references/name-provider.ts +0 -37
  75. package/src/references/scope-computation.ts +0 -364
  76. package/src/references/scope-provider.ts +0 -201
  77. package/src/shared/NodeKindProvider.ts +0 -121
  78. package/src/shared/WorkspaceManager.ts +0 -48
  79. package/src/shared/WorkspaceSymbolProvider.ts +0 -3
  80. package/src/shared/index.ts +0 -3
  81. package/src/test/index.ts +0 -1
  82. package/src/test/setup.ts +0 -8
  83. package/src/test/testServices.ts +0 -152
  84. package/src/utils/disposable.ts +0 -30
  85. package/src/utils/elementRef.ts +0 -26
  86. package/src/utils/fqnRef.ts +0 -56
  87. package/src/utils/index.ts +0 -2
  88. package/src/utils/printDocs.ts +0 -3
  89. package/src/utils/stringHash.ts +0 -6
  90. package/src/validation/_shared.ts +0 -29
  91. package/src/validation/deployment-checks.ts +0 -131
  92. package/src/validation/dynamic-view-rule.ts +0 -23
  93. package/src/validation/dynamic-view-step.ts +0 -36
  94. package/src/validation/element.ts +0 -56
  95. package/src/validation/index.ts +0 -171
  96. package/src/validation/property-checks.ts +0 -52
  97. package/src/validation/relation.ts +0 -63
  98. package/src/validation/specification.ts +0 -205
  99. package/src/validation/view-predicates/element-with.ts +0 -36
  100. package/src/validation/view-predicates/expanded-element.ts +0 -16
  101. package/src/validation/view-predicates/expression-v2.ts +0 -101
  102. package/src/validation/view-predicates/incoming.ts +0 -20
  103. package/src/validation/view-predicates/index.ts +0 -6
  104. package/src/validation/view-predicates/outgoing.ts +0 -20
  105. package/src/validation/view-predicates/relation-with.ts +0 -17
  106. package/src/validation/view.ts +0 -37
  107. package/src/view-utils/assignNavigateTo.ts +0 -31
  108. package/src/view-utils/index.ts +0 -2
  109. package/src/view-utils/manual-layout.ts +0 -116
  110. package/src/view-utils/resolve-relative-paths.ts +0 -90
  111. package/src/views/configurable-layouter.ts +0 -65
  112. package/src/views/index.ts +0 -1
  113. package/src/views/likec4-views.ts +0 -139
@@ -1,315 +0,0 @@
1
- import type * as c4 from '@likec4/core'
2
- import { invariant, nonexhaustive } from '@likec4/core'
3
- import { isBoolean, isDefined, isTruthy } from 'remeda'
4
- import { ast, parseAstOpacityProperty, parseAstSizeValue, toColor } from '../../ast'
5
- import { logWarnError } from '../../logger'
6
- import { elementRef } from '../../utils/elementRef'
7
- import { parseWhereClause } from '../model-parser-where'
8
- import { type Base, removeIndent } from './Base'
9
-
10
- export type WithPredicates = ReturnType<typeof PredicatesParser>
11
-
12
- export function PredicatesParser<TBase extends Base>(B: TBase) {
13
- return class PredicatesParser extends B {
14
- parsePredicate(astNode: ast.Predicate): c4.Expression {
15
- if (ast.isElementPredicate(astNode)) {
16
- return this.parseElementPredicate(astNode)
17
- }
18
- if (ast.isRelationPredicate(astNode)) {
19
- return this.parseRelationPredicate(astNode)
20
- }
21
- nonexhaustive(astNode)
22
- }
23
-
24
- parseElementPredicate(astNode: ast.ElementPredicate): c4.ElementPredicateExpression {
25
- if (ast.isElementPredicateWith(astNode)) {
26
- return this.parseElementPredicateWith(astNode)
27
- }
28
- if (ast.isElementPredicateWhere(astNode)) {
29
- return this.parseElementPredicateWhere(astNode)
30
- }
31
- if (ast.isElementExpression(astNode)) {
32
- return this.parseElementExpression(astNode)
33
- }
34
- nonexhaustive(astNode)
35
- }
36
-
37
- parseElementExpressionsIterator(astNode: ast.ElementExpressionsIterator): c4.ElementExpression[] {
38
- const exprs = [] as c4.ElementExpression[]
39
- let iter: ast.ElementExpressionsIterator['prev'] = astNode
40
- while (iter) {
41
- try {
42
- if (iter.value) {
43
- exprs.unshift(this.parseElementExpression(iter.value))
44
- }
45
- } catch (e) {
46
- logWarnError(e)
47
- }
48
- iter = iter.prev
49
- }
50
- return exprs
51
- }
52
-
53
- parseElementExpression(astNode: ast.ElementExpression): c4.ElementExpression {
54
- if (ast.isWildcardExpression(astNode)) {
55
- return {
56
- wildcard: true,
57
- }
58
- }
59
- if (ast.isElementKindExpression(astNode)) {
60
- invariant(astNode.kind?.ref, 'ElementKindExpr kind is not resolved: ' + astNode.$cstNode?.text)
61
- return {
62
- elementKind: astNode.kind.ref.name as c4.ElementKind,
63
- isEqual: astNode.isEqual,
64
- }
65
- }
66
- if (ast.isElementTagExpression(astNode)) {
67
- invariant(astNode.tag?.ref, 'ElementTagExpr tag is not resolved: ' + astNode.$cstNode?.text)
68
- let elementTag = astNode.tag.$refText
69
- if (elementTag.startsWith('#')) {
70
- elementTag = elementTag.slice(1)
71
- }
72
- return {
73
- elementTag: elementTag as c4.Tag,
74
- isEqual: astNode.isEqual,
75
- }
76
- }
77
- if (ast.isExpandElementExpression(astNode)) {
78
- const elementNode = elementRef(astNode.expand)
79
- invariant(elementNode, 'Element not found ' + astNode.expand.$cstNode?.text)
80
- const expanded = this.resolveFqn(elementNode)
81
- return {
82
- expanded,
83
- }
84
- }
85
- if (ast.isElementDescedantsExpression(astNode)) {
86
- const elementNode = elementRef(astNode.parent)
87
- invariant(elementNode, 'Element not found ' + astNode.parent.$cstNode?.text)
88
- const element = this.resolveFqn(elementNode)
89
- return {
90
- element,
91
- isChildren: astNode.suffix === '.*',
92
- isDescendants: astNode.suffix === '.**',
93
- }
94
- }
95
- if (ast.isElementRef(astNode)) {
96
- const elementNode = elementRef(astNode)
97
- invariant(elementNode, 'Element not found ' + astNode.$cstNode?.text)
98
- const element = this.resolveFqn(elementNode)
99
- return {
100
- element,
101
- }
102
- }
103
- nonexhaustive(astNode)
104
- }
105
-
106
- parseElementPredicateWhere(astNode: ast.ElementPredicateWhere): c4.ElementWhereExpr {
107
- const expr = this.parseElementExpression(astNode.subject)
108
- return {
109
- where: {
110
- expr,
111
- condition: astNode.where ? parseWhereClause(astNode.where) : {
112
- kind: { neq: '--always-true--' },
113
- },
114
- },
115
- }
116
- }
117
-
118
- parseElementPredicateWith(astNode: ast.ElementPredicateWith): c4.CustomElementExpr {
119
- const expr = this.parseElementPredicate(astNode.subject)
120
- const props = astNode.custom?.props ?? []
121
- return props.reduce(
122
- (acc, prop) => {
123
- if (!this.isValid(prop)) {
124
- return acc
125
- }
126
- if (ast.isNavigateToProperty(prop)) {
127
- const viewId = prop.value.view.$refText
128
- if (isTruthy(viewId)) {
129
- acc.custom.navigateTo = viewId as c4.ViewId
130
- }
131
- return acc
132
- }
133
- if (ast.isElementStringProperty(prop)) {
134
- if (isDefined(prop.value)) {
135
- acc.custom[prop.key] = removeIndent(prop.value) || ''
136
- }
137
- return acc
138
- }
139
- if (ast.isIconProperty(prop)) {
140
- const value = prop.libicon?.ref?.name ?? prop.value
141
- if (isDefined(value)) {
142
- acc.custom[prop.key] = value as c4.IconUrl
143
- }
144
- return acc
145
- }
146
- if (ast.isColorProperty(prop)) {
147
- const value = toColor(prop)
148
- if (isDefined(value)) {
149
- acc.custom[prop.key] = value
150
- }
151
- return acc
152
- }
153
- if (ast.isShapeProperty(prop)) {
154
- if (isDefined(prop.value)) {
155
- acc.custom[prop.key] = prop.value
156
- }
157
- return acc
158
- }
159
- if (ast.isBorderProperty(prop)) {
160
- if (isDefined(prop.value)) {
161
- acc.custom[prop.key] = prop.value
162
- }
163
- return acc
164
- }
165
- if (ast.isOpacityProperty(prop)) {
166
- if (isDefined(prop.value)) {
167
- acc.custom[prop.key] = parseAstOpacityProperty(prop)
168
- }
169
- return acc
170
- }
171
- if (ast.isNotationProperty(prop)) {
172
- if (isTruthy(prop.value)) {
173
- acc.custom[prop.key] = removeIndent(prop.value)
174
- }
175
- return acc
176
- }
177
- if (ast.isMultipleProperty(prop)) {
178
- if (isBoolean(prop.value)) {
179
- acc.custom[prop.key] = prop.value
180
- }
181
- return acc
182
- }
183
- if (ast.isShapeSizeProperty(prop)) {
184
- if (isTruthy(prop.value)) {
185
- acc.custom[prop.key] = parseAstSizeValue(prop)
186
- }
187
- return acc
188
- }
189
- if (ast.isTextSizeProperty(prop)) {
190
- if (isTruthy(prop.value)) {
191
- acc.custom[prop.key] = parseAstSizeValue(prop)
192
- }
193
- return acc
194
- }
195
- if (ast.isPaddingSizeProperty(prop)) {
196
- if (isTruthy(prop.value)) {
197
- acc.custom[prop.key] = parseAstSizeValue(prop)
198
- }
199
- return acc
200
- }
201
- nonexhaustive(prop)
202
- },
203
- {
204
- custom: {
205
- expr,
206
- },
207
- } as c4.CustomElementExpr,
208
- )
209
- }
210
-
211
- parseRelationPredicate(astNode: ast.RelationPredicate): c4.RelationPredicateExpression {
212
- if (ast.isRelationPredicateWith(astNode)) {
213
- let relation = ast.isRelationPredicateWhere(astNode.subject)
214
- ? this.parseRelationPredicateWhere(astNode.subject)
215
- : this.parseRelationExpression(astNode.subject)
216
-
217
- return this.parseRelationPredicateWith(astNode, relation)
218
- }
219
- if (ast.isRelationPredicateWhere(astNode)) {
220
- return this.parseRelationPredicateWhere(astNode)
221
- }
222
- if (ast.isRelationExpression(astNode)) {
223
- return this.parseRelationExpression(astNode)
224
- }
225
- nonexhaustive(astNode)
226
- }
227
-
228
- parseRelationPredicateWhere(astNode: ast.RelationPredicateWhere): c4.RelationWhereExpr {
229
- const expr = this.parseRelationExpression(astNode.subject)
230
- return {
231
- where: {
232
- expr,
233
- condition: astNode.where ? parseWhereClause(astNode.where) : {
234
- kind: { neq: '--always-true--' },
235
- },
236
- },
237
- }
238
- }
239
-
240
- parseRelationPredicateWith(
241
- astNode: ast.RelationPredicateWith,
242
- relation: c4.RelationExpression | c4.RelationWhereExpr,
243
- ): c4.CustomRelationExpr {
244
- const props = astNode.custom?.props ?? []
245
- return props.reduce(
246
- (acc, prop) => {
247
- if (ast.isRelationStringProperty(prop) || ast.isNotationProperty(prop) || ast.isNotesProperty(prop)) {
248
- if (isDefined(prop.value)) {
249
- acc.customRelation[prop.key] = removeIndent(prop.value) ?? ''
250
- }
251
- return acc
252
- }
253
- if (ast.isArrowProperty(prop)) {
254
- if (isTruthy(prop.value)) {
255
- acc.customRelation[prop.key] = prop.value
256
- }
257
- return acc
258
- }
259
- if (ast.isColorProperty(prop)) {
260
- const value = toColor(prop)
261
- if (isTruthy(value)) {
262
- acc.customRelation[prop.key] = value
263
- }
264
- return acc
265
- }
266
- if (ast.isLineProperty(prop)) {
267
- if (isTruthy(prop.value)) {
268
- acc.customRelation[prop.key] = prop.value
269
- }
270
- return acc
271
- }
272
- if (ast.isRelationNavigateToProperty(prop)) {
273
- const viewId = prop.value.view.ref?.name
274
- if (isTruthy(viewId)) {
275
- acc.customRelation.navigateTo = viewId as c4.ViewId
276
- }
277
- return acc
278
- }
279
- nonexhaustive(prop)
280
- },
281
- {
282
- customRelation: {
283
- relation,
284
- },
285
- } as c4.CustomRelationExpr,
286
- )
287
- }
288
-
289
- parseRelationExpression(astNode: ast.RelationExpression): c4.RelationExpression {
290
- if (ast.isDirectedRelationExpression(astNode)) {
291
- return {
292
- source: this.parseElementExpression(astNode.source.from),
293
- target: this.parseElementExpression(astNode.target),
294
- isBidirectional: astNode.source.isBidirectional,
295
- }
296
- }
297
- if (ast.isInOutRelationExpression(astNode)) {
298
- return {
299
- inout: this.parseElementExpression(astNode.inout.to),
300
- }
301
- }
302
- if (ast.isOutgoingRelationExpression(astNode)) {
303
- return {
304
- outgoing: this.parseElementExpression(astNode.from),
305
- }
306
- }
307
- if (ast.isIncomingRelationExpression(astNode)) {
308
- return {
309
- incoming: this.parseElementExpression(astNode.to),
310
- }
311
- }
312
- nonexhaustive(astNode)
313
- }
314
- }
315
- }
@@ -1,133 +0,0 @@
1
- import type * as c4 from '@likec4/core'
2
- import type { HexColorLiteral } from '@likec4/core'
3
- import { filter, isNonNullish, isTruthy, mapToObj, pipe } from 'remeda'
4
- import { ast, toElementStyle, toRelationshipStyleExcludeDefaults } from '../../ast'
5
- import { logger, logWarnError } from '../../logger'
6
- import { type Base, removeIndent } from './Base'
7
-
8
- export function SpecificationParser<TBase extends Base>(B: TBase) {
9
- return class SpecificationParser extends B {
10
- parseSpecification() {
11
- const {
12
- parseResult: {
13
- value: {
14
- specifications
15
- }
16
- },
17
- c4Specification
18
- } = this.doc
19
- const isValid = this.isValid
20
-
21
- const element_specs = specifications.flatMap(s => s.elements.filter(this.isValid))
22
- for (const { kind, props } of element_specs) {
23
- try {
24
- const kindName = kind.name as c4.ElementKind
25
- if (!isTruthy(kindName)) {
26
- continue
27
- }
28
- if (kindName in c4Specification.elements) {
29
- logger.warn(`Element kind "${kindName}" is already defined`)
30
- continue
31
- }
32
- const style = props.find(ast.isElementStyleProperty)
33
- const bodyProps = pipe(
34
- props.filter(ast.isSpecificationElementStringProperty) ?? [],
35
- filter(p => this.isValid(p) && isNonNullish(p.value)),
36
- mapToObj(p => [p.key, removeIndent(p.value)] satisfies [string, string])
37
- )
38
- c4Specification.elements[kindName] = {
39
- ...bodyProps,
40
- style: {
41
- ...toElementStyle(style?.props, this.isValid)
42
- }
43
- }
44
- } catch (e) {
45
- logWarnError(e)
46
- }
47
- }
48
-
49
- const relations_specs = specifications.flatMap(s => s.relationships.filter(this.isValid))
50
- for (const { kind, props } of relations_specs) {
51
- try {
52
- const kindName = kind.name as c4.RelationshipKind
53
- if (!isTruthy(kindName)) {
54
- continue
55
- }
56
- if (kindName in c4Specification.relationships) {
57
- logger.warn(`Relationship kind "${kindName}" is already defined`)
58
- continue
59
- }
60
- const bodyProps = pipe(
61
- props.filter(ast.isSpecificationRelationshipStringProperty) ?? [],
62
- filter(p => this.isValid(p) && isNonNullish(p.value)),
63
- mapToObj(p => [p.key, removeIndent(p.value)] satisfies [string, string])
64
- )
65
- c4Specification.relationships[kindName] = {
66
- ...bodyProps,
67
- ...toRelationshipStyleExcludeDefaults(props, this.isValid)
68
- }
69
- } catch (e) {
70
- logWarnError(e)
71
- }
72
- }
73
-
74
- const tags_specs = specifications.flatMap(s => s.tags.filter(this.isValid))
75
- for (const tagSpec of tags_specs) {
76
- const tag = tagSpec.tag.name as c4.Tag
77
- if (isTruthy(tag)) {
78
- c4Specification.tags.add(tag)
79
- }
80
- }
81
-
82
- const deploymentNodes_specs = specifications.flatMap(s => s.deploymentNodes.filter(isValid))
83
- for (const deploymentNode of deploymentNodes_specs) {
84
- try {
85
- Object.assign(c4Specification.deployments, this.parseSpecificationDeploymentNodeKind(deploymentNode))
86
- } catch (e) {
87
- logWarnError(e)
88
- }
89
- }
90
-
91
- const colors_specs = specifications.flatMap(s => s.colors.filter(isValid))
92
- for (const { name, color } of colors_specs) {
93
- try {
94
- const colorName = name.name as c4.CustomColor
95
- if (colorName in c4Specification.colors) {
96
- logger.warn(`Custom color "${colorName}" is already defined`)
97
- continue
98
- }
99
-
100
- c4Specification.colors[colorName] = {
101
- color: color as HexColorLiteral
102
- }
103
- } catch (e) {
104
- logWarnError(e)
105
- }
106
- }
107
- }
108
-
109
- parseSpecificationDeploymentNodeKind(
110
- { kind, props }: ast.SpecificationDeploymentNodeKind
111
- ): { [key: c4.DeploymentNodeKind]: c4.DeploymentNodeKindSpecification } {
112
- const kindName = kind.name as c4.DeploymentNodeKind
113
- if (!isTruthy(kindName)) {
114
- throw new Error('DeploymentNodeKind name is not resolved')
115
- }
116
-
117
- const style = props.find(ast.isElementStyleProperty)
118
- const bodyProps = pipe(
119
- props.filter(ast.isSpecificationElementStringProperty) ?? [],
120
- filter(p => this.isValid(p) && isNonNullish(p.value)),
121
- mapToObj(p => [p.key, removeIndent(p.value)] satisfies [string, string])
122
- )
123
- return {
124
- [kindName]: {
125
- ...bodyProps,
126
- style: {
127
- ...toElementStyle(style?.props, this.isValid)
128
- }
129
- }
130
- }
131
- }
132
- }
133
- }