@likec4/language-server 1.21.1 → 1.22.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 (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 +17 -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 +23 -2
  11. package/dist/logger.d.ts +9 -3
  12. package/dist/logger.js +35 -55
  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,639 +0,0 @@
1
- import { type AstNode, type CompositeCstNode, GrammarUtils } from 'langium'
2
- import { type NodeFormatter, AbstractFormatter, Formatting } from 'langium/lsp'
3
- import { filter, isTruthy } from 'remeda'
4
- import * as ast from '../generated/ast'
5
- import * as utils from './utils'
6
-
7
- const FormattingOptions = {
8
- newLine: Formatting.newLine({ allowMore: true }),
9
- oneSpace: Formatting.oneSpace(),
10
- noSpace: Formatting.noSpace(),
11
- indent: Formatting.indent({ allowMore: true }),
12
- noIndent: Formatting.noIndent(),
13
- }
14
- type Predicate<T extends AstNode> = (x: unknown) => x is T
15
-
16
- export class LikeC4Formatter extends AbstractFormatter {
17
- protected format(node: AstNode): void {
18
- this.removeIndentFromTopLevelStatements(node)
19
- this.indentContentInBraces(node)
20
-
21
- // Specification
22
- this.formatSpecificationRule(node)
23
-
24
- // Globals
25
- this.formatGlobals(node)
26
-
27
- // Models
28
- this.formatElementDeclaration(node)
29
- this.formatRelation(node)
30
- this.formatMetadataProperty(node)
31
-
32
- // Deployment
33
- this.formatDeploymentNodeDeclaration(node)
34
- this.formatDeployedInstance(node)
35
- this.formatDeploymentRelation(node)
36
-
37
- // Views
38
- this.formatView(node)
39
- this.formatViewRuleGroup(node)
40
- this.formatViewRuleGlobalStyle(node)
41
- this.formatViewRuleGlobalPredicate(node)
42
- this.formatIncludeExcludeExpressions(node)
43
- this.formatDeploymentViewRulePredicateExpressions(node)
44
- this.formatWhereExpression(node)
45
- this.formatWhereExpressionV2(node)
46
- this.formatWhereRelationExpression(node)
47
- this.formatWhereElementExpression(node)
48
- this.formatRelationExpression(node)
49
- this.formatAutolayoutProperty(node)
50
- this.formatWithPredicate(node)
51
-
52
- // Common
53
- this.formatViewRuleStyle(node)
54
- this.formatLeafProperty(node)
55
- this.formatLinkProperty(node)
56
- this.formatNavigateToProperty(node)
57
- this.formatTags(node)
58
- }
59
-
60
- protected formatTags(node: AstNode) {
61
- this.on(node, ast.isTags, (n, f) => {
62
- f.cst(GrammarUtils.findNodesForProperty(n.$cstNode, 'values').slice(1))
63
- .prepend(FormattingOptions.oneSpace)
64
-
65
- f.keywords(',')
66
- .prepend(FormattingOptions.noSpace)
67
- .append(FormattingOptions.oneSpace)
68
- })
69
- }
70
-
71
- protected formatDeploymentRelation(node: AstNode) {
72
- this.on(node, ast.isDeploymentRelation, (n, f) => {
73
- const sourceNodes = n?.source?.$cstNode ? [n?.source?.$cstNode] : []
74
-
75
- f.cst(sourceNodes).append(FormattingOptions.oneSpace)
76
-
77
- f.keywords(']->').prepend(FormattingOptions.noSpace)
78
- f.keywords('-[').append(FormattingOptions.noSpace)
79
-
80
- f.nodes(...filter([
81
- n.target,
82
- n.tags,
83
- ], isTruthy)).prepend(FormattingOptions.oneSpace)
84
- f.properties('title', 'technology').prepend(FormattingOptions.oneSpace)
85
- })
86
- }
87
-
88
- protected formatRelation(node: AstNode) {
89
- this.on(node, ast.isRelation, (n, f) => {
90
- const sourceNodes = n?.source?.$cstNode ? [n?.source?.$cstNode] : []
91
-
92
- f.cst(sourceNodes).append(FormattingOptions.oneSpace)
93
- f.keywords(']->').prepend(FormattingOptions.noSpace)
94
- f.keywords('-[').append(FormattingOptions.noSpace)
95
-
96
- f.nodes(...filter([
97
- n.target,
98
- n.tags,
99
- ], isTruthy)).prepend(FormattingOptions.oneSpace)
100
- f.properties('title', 'technology').prepend(FormattingOptions.oneSpace)
101
- })
102
-
103
- this.on(node, ast.isDynamicViewStep, (n, f) => {
104
- f.keywords('->', '<-').surround(FormattingOptions.oneSpace)
105
-
106
- const kind = f.property('kind')
107
- kind.nodes[0]?.text.startsWith('.') && kind.surround(FormattingOptions.oneSpace)
108
- f.keywords(']->')
109
- .prepend(FormattingOptions.noSpace)
110
- .append(FormattingOptions.oneSpace)
111
- f.keywords('-[')
112
- .prepend(FormattingOptions.oneSpace)
113
- .append(FormattingOptions.noSpace)
114
-
115
- f.properties('title').prepend(FormattingOptions.oneSpace)
116
- })
117
-
118
- this.on(node, ast.isDirectedRelationExpression)
119
- ?.property('target').prepend(FormattingOptions.oneSpace)
120
-
121
- this.on(node, ast.isOutgoingRelationExpression, (n, f) => {
122
- f.property('from').append(FormattingOptions.oneSpace)
123
- f.keywords(']->').prepend(FormattingOptions.noSpace)
124
- f.keywords('-[').append(FormattingOptions.noSpace)
125
- })
126
-
127
- this.on(node, ast.isIncomingRelationExpression)
128
- ?.keywords('->').append(FormattingOptions.oneSpace)
129
-
130
- this.on(node, ast.isInOutRelationExpression)
131
- ?.keyword('->').prepend(FormattingOptions.oneSpace)
132
- }
133
-
134
- protected removeIndentFromTopLevelStatements(node: AstNode) {
135
- if (
136
- ast.isModel(node)
137
- || ast.isSpecificationRule(node)
138
- || ast.isModelViews(node)
139
- || ast.isLikeC4Lib(node)
140
- || ast.isGlobals(node)
141
- || ast.isModelDeployments(node)
142
- ) {
143
- const formatter = this.getNodeFormatter(node)
144
- formatter.keywords('specification', 'model', 'views', 'likec4lib', 'global', 'deployments')
145
- .prepend(FormattingOptions.noIndent)
146
- }
147
- }
148
-
149
- protected indentContentInBraces(node: AstNode) {
150
- if (
151
- ast.isLikeC4Lib(node)
152
- || ast.isSpecificationRule(node)
153
- || ast.isSpecificationElementKind(node)
154
- || ast.isSpecificationRelationshipKind(node)
155
- || ast.isSpecificationDeploymentNodeKind(node)
156
- || ast.isGlobals(node)
157
- || ast.isGlobalStyle(node)
158
- || ast.isGlobalStyleGroup(node)
159
- || ast.isGlobalPredicateGroup(node)
160
- || ast.isGlobalDynamicPredicateGroup(node)
161
- || ast.isGlobalStyleGroup(node)
162
- || ast.isModel(node)
163
- || ast.isElementBody(node)
164
- || ast.isExtendElementBody(node)
165
- || ast.isRelationBody(node)
166
- || ast.isRelationStyleProperty(node)
167
- || ast.isMetadataBody(node)
168
- || ast.isModelViews(node)
169
- || ast.isElementViewBody(node)
170
- || ast.isDynamicViewBody(node)
171
- || ast.isDeploymentViewBody(node)
172
- || ast.isViewRuleStyle(node)
173
- || ast.isViewRuleGroup(node)
174
- || ast.isCustomElementProperties(node)
175
- || ast.isCustomRelationProperties(node)
176
- || ast.isElementStyleProperty(node)
177
- || ast.isDynamicViewParallelSteps(node)
178
- || ast.isModelDeployments(node)
179
- || ast.isDeploymentNodeBody(node)
180
- || ast.isDeploymentRelationBody(node)
181
- || ast.isDeployedInstanceBody(node)
182
- ) {
183
- const formatter = this.getNodeFormatter(node)
184
- const openBrace = formatter.keywords('{')
185
- const closeBrace = formatter.keywords('}')
186
-
187
- const interiorNodes = formatter.interior(openBrace, closeBrace)
188
-
189
- // Workaround for tags as they are parsed as overlapping regions.
190
- // E.g. '#tag1, #tag2' will be parsed as two nodes: '#tag1' and '#tag1, #tag2'
191
- let perviousNode = null
192
- for (const interiorNode of interiorNodes.nodes) {
193
- if (!perviousNode || !utils.areOverlap(perviousNode, interiorNode)) {
194
- formatter.cst([interiorNode]).prepend(FormattingOptions.indent)
195
- }
196
- perviousNode = interiorNode
197
- }
198
-
199
- openBrace
200
- .prepend(FormattingOptions.noIndent)
201
- .prepend(FormattingOptions.oneSpace)
202
- closeBrace
203
- .prepend(FormattingOptions.noIndent)
204
- .prepend(Formatting.newLine({ allowMore: true }))
205
- }
206
- }
207
-
208
- protected appendKeywordsWithSpace(node: AstNode) {
209
- this.on(node, ast.isElementKind)
210
- ?.keywords('element').append(FormattingOptions.oneSpace)
211
- }
212
-
213
- protected formatView(node: AstNode) {
214
- this.on(node, ast.isElementView, (n, f) => {
215
- if (n.extends || n.viewOf || n.name) {
216
- f.keywords('view').append(FormattingOptions.oneSpace)
217
- }
218
- f.keywords('of', 'extends').surround(FormattingOptions.oneSpace)
219
- })
220
-
221
- this.on(node, ast.isDynamicView)
222
- ?.keywords('dynamic', 'view').append(FormattingOptions.oneSpace)
223
-
224
- this.on(node, ast.isDeploymentView)
225
- ?.keywords('deployment', 'view').append(FormattingOptions.oneSpace)
226
- }
227
-
228
- protected formatLeafProperty(node: AstNode) {
229
- if (
230
- ast.isElementStringProperty(node)
231
- || ast.isRelationStringProperty(node)
232
- || ast.isViewStringProperty(node)
233
- || ast.isNotationProperty(node)
234
- || ast.isSpecificationElementStringProperty(node)
235
- || ast.isSpecificationRelationshipStringProperty(node)
236
- || ast.isColorProperty(node)
237
- || ast.isLineProperty(node)
238
- || ast.isArrowProperty(node)
239
- || ast.isIconProperty(node)
240
- || ast.isShapeProperty(node)
241
- || ast.isBorderProperty(node)
242
- || ast.isOpacityProperty(node)
243
- || ast.isMultipleProperty(node)
244
- || ast.isShapeSizeProperty(node)
245
- || ast.isPaddingSizeProperty(node)
246
- || ast.isTextSizeProperty(node)
247
- ) {
248
- const formatter = this.getNodeFormatter(node)
249
- const colon = formatter.keyword(':')
250
- const propertyName = formatter.keywords(
251
- 'title',
252
- 'description',
253
- 'technology',
254
- 'notation',
255
- 'color',
256
- 'line',
257
- 'head',
258
- 'tail',
259
- 'icon',
260
- 'shape',
261
- 'border',
262
- 'opacity',
263
- 'multiple',
264
- 'size',
265
- 'padding',
266
- 'textSize',
267
- )
268
-
269
- if (colon.nodes.length === 0) {
270
- propertyName
271
- .append(FormattingOptions.oneSpace)
272
- } else {
273
- colon
274
- .prepend(FormattingOptions.noSpace)
275
- .append(FormattingOptions.oneSpace)
276
- }
277
-
278
- formatter.keyword(';')
279
- .prepend(FormattingOptions.noSpace)
280
- .append(FormattingOptions.newLine)
281
- }
282
- }
283
-
284
- protected formatLinkProperty(node: AstNode) {
285
- this.on(node, ast.isLinkProperty, (n, f) => {
286
- f.keyword('link').append(FormattingOptions.oneSpace)
287
- f.property('value').append(FormattingOptions.oneSpace)
288
- f.keyword(':')
289
- .prepend(FormattingOptions.noSpace)
290
- .append(FormattingOptions.oneSpace)
291
-
292
- f.keyword(';')
293
- .prepend(FormattingOptions.noSpace)
294
- .append(FormattingOptions.newLine)
295
- })
296
- }
297
-
298
- protected formatNavigateToProperty(node: AstNode) {
299
- this.on(node, ast.isNavigateToProperty)
300
- ?.property('key').append(FormattingOptions.oneSpace)
301
- }
302
-
303
- protected formatAutolayoutProperty(node: AstNode) {
304
- this.on(node, ast.isViewRuleAutoLayout, (n, f) => {
305
- f.keyword('autoLayout').append(FormattingOptions.oneSpace)
306
- f.property('rankSep').prepend(FormattingOptions.oneSpace)
307
- f.property('nodeSep').prepend(FormattingOptions.oneSpace)
308
- })
309
- }
310
-
311
- protected formatMetadataProperty(node: AstNode) {
312
- this.on(node, ast.isMetadataAttribute, (n, f) => {
313
- f.property('key').append(FormattingOptions.oneSpace)
314
- f.keyword(':')
315
- .prepend(FormattingOptions.noSpace)
316
- .append(FormattingOptions.oneSpace)
317
- f.keyword(';')
318
- .prepend(FormattingOptions.noSpace)
319
- .append(FormattingOptions.newLine)
320
- })
321
- }
322
-
323
- protected formatElementDeclaration(node: AstNode) {
324
- this.on(node, ast.isElement, (n, f) => {
325
- const kind = GrammarUtils.findNodeForProperty(n.$cstNode, 'kind')
326
- const name = GrammarUtils.findNodeForProperty(n.$cstNode, 'name')
327
-
328
- if (name && kind) {
329
- // system sys1
330
- if (utils.compareRanges(name, kind) > 0) {
331
- f.cst([kind]).append(FormattingOptions.oneSpace)
332
- }
333
- // sys1 = system
334
- else {
335
- f.cst([name]).append(FormattingOptions.oneSpace)
336
- f.cst([kind]).prepend(FormattingOptions.oneSpace)
337
- }
338
- }
339
-
340
- f.properties('props').prepend(FormattingOptions.oneSpace)
341
- })
342
- }
343
-
344
- protected formatGlobals(node: AstNode) {
345
- this.on(node, ast.isGlobalStyle, (n, f) => {
346
- f.keyword('style').append(FormattingOptions.oneSpace)
347
- f.property('id').append(FormattingOptions.oneSpace)
348
- })
349
-
350
- this.on(node, ast.isGlobalStyleGroup, (n, f) => {
351
- f.keyword('styleGroup').append(FormattingOptions.oneSpace)
352
- })
353
-
354
- this.on(node, ast.isGlobalPredicateGroup, (n, f) => {
355
- f.keyword('predicateGroup').append(FormattingOptions.oneSpace)
356
- })
357
-
358
- this.on(node, ast.isGlobalDynamicPredicateGroup, (n, f) => {
359
- f.keyword('dynamicPredicateGroup').append(FormattingOptions.oneSpace)
360
- })
361
- }
362
-
363
- protected formatSpecificationRule(node: AstNode) {
364
- if (
365
- ast.isSpecificationElementKind(node)
366
- || ast.isSpecificationRelationshipKind(node)
367
- || ast.isSpecificationTag(node)
368
- || ast.isSpecificationDeploymentNodeKind(node)
369
- ) {
370
- const formatter = this.getNodeFormatter(node)
371
-
372
- formatter.keywords('element', 'relationship', 'tag', 'deploymentNode')
373
- .append(FormattingOptions.oneSpace)
374
- }
375
- if (
376
- ast.isSpecificationColor(node)
377
- ) {
378
- const formatter = this.getNodeFormatter(node)
379
- formatter.keyword('color').append(FormattingOptions.oneSpace)
380
- formatter.property('name').append(FormattingOptions.oneSpace)
381
- }
382
- }
383
-
384
- protected formatWithPredicate(node: AstNode) {
385
- const formatter = this.getNodeFormatter(node)
386
- if (
387
- ast.isElementPredicateWith(node)
388
- || ast.isRelationPredicateWith(node)
389
- ) {
390
- formatter.keyword('with').prepend(FormattingOptions.oneSpace)
391
- }
392
- }
393
-
394
- protected formatDeploymentNodeDeclaration(node: AstNode) {
395
- this.on(node, ast.isDeploymentNode, (n, f) => {
396
- const kind = GrammarUtils.findNodeForProperty(n.$cstNode, 'kind')
397
- const name = GrammarUtils.findNodeForProperty(n.$cstNode, 'name')
398
-
399
- if (name && kind) {
400
- // system sys1
401
- if (utils.compareRanges(name, kind) > 0) {
402
- f.cst([kind]).append(FormattingOptions.oneSpace)
403
- }
404
- // sys1 = system
405
- else {
406
- f.cst([name]).append(FormattingOptions.oneSpace)
407
- f.cst([kind]).prepend(FormattingOptions.oneSpace)
408
- }
409
- }
410
-
411
- f.properties('title').prepend(FormattingOptions.oneSpace)
412
- })
413
- }
414
-
415
- protected formatDeployedInstance(node: AstNode) {
416
- this.on(node, ast.isDeployedInstance, (n, f) => {
417
- const eqNode = (<CompositeCstNode>n.$cstNode)?.content.find(c => c.text === '=')
418
- if (eqNode) {
419
- f.cst([eqNode]).surround(FormattingOptions.oneSpace)
420
- }
421
-
422
- f.keyword('instanceOf').append(FormattingOptions.oneSpace)
423
- f.property('title').prepend(FormattingOptions.oneSpace)
424
- })
425
- }
426
-
427
- protected formatViewRuleGlobalStyle(node: AstNode) {
428
- this.on(node, ast.isViewRuleGlobalStyle, (n, f) => {
429
- f.keywords('global', 'style').append(FormattingOptions.oneSpace)
430
- })
431
- }
432
-
433
- protected formatViewRuleGlobalPredicate(node: AstNode) {
434
- const formatter = this.getNodeFormatter(node)
435
- if (
436
- ast.isViewRuleGlobalPredicateRef(node)
437
- || ast.isDynamicViewGlobalPredicateRef(node)
438
- ) {
439
- formatter.keywords('global', 'predicate').append(FormattingOptions.oneSpace)
440
- }
441
- }
442
-
443
- protected formatViewRuleGroup(node: AstNode) {
444
- this.on(node, ast.isViewRuleGroup, (n, f) => {
445
- f.keyword('group').append(FormattingOptions.oneSpace)
446
- })
447
- }
448
-
449
- protected formatViewRuleStyle(node: AstNode) {
450
- this.on(node, ast.isViewRuleStyle)
451
- ?.keyword('style').append(FormattingOptions.oneSpace)
452
-
453
- this.on(node, ast.isDeploymentViewRuleStyle)
454
- ?.keyword('style').append(FormattingOptions.oneSpace)
455
-
456
- this.on(node, ast.isElementExpressionsIterator)
457
- ?.keyword(',')
458
- .prepend(FormattingOptions.noSpace)
459
- .append(FormattingOptions.oneSpace)
460
-
461
- this.on(node, ast.isFqnExpressions)
462
- ?.keyword(',')
463
- .prepend(FormattingOptions.noSpace)
464
- .append(FormattingOptions.oneSpace)
465
- }
466
-
467
- protected formatWhereExpression(node: AstNode) {
468
- if (
469
- ast.isRelationPredicateOrWhere(node)
470
- || ast.isElementPredicateOrWhere(node)
471
- ) {
472
- const formatter = this.getNodeFormatter(node)
473
- formatter.keyword('where').append(FormattingOptions.oneSpace)
474
- }
475
- }
476
-
477
- protected formatWhereExpressionV2(node: AstNode) {
478
- if (
479
- ast.isRelationPredicateOrWhereV2(node)
480
- || ast.isElementPredicateOrWhereV2(node)
481
- ) {
482
- const formatter = this.getNodeFormatter(node)
483
- formatter.keyword('where').append(FormattingOptions.oneSpace)
484
- }
485
- }
486
-
487
- protected formatWhereRelationExpression(node: AstNode) {
488
- this.on(node, ast.isWhereRelationExpression, (n, f) => {
489
- f.property('operator').surround(FormattingOptions.oneSpace)
490
- })
491
- this.on(node, ast.isWhereRelationNegation, (n, f) => {
492
- f.keyword('not').append(FormattingOptions.oneSpace)
493
- })
494
- if (
495
- ast.isWhereRelation(node)
496
- || ast.isWhereRelationTag(node)
497
- || ast.isWhereRelationKind(node)
498
- ) {
499
- const formatter = this.getNodeFormatter(node)
500
- formatter.property('operator').surround(FormattingOptions.oneSpace)
501
- formatter.property('not').surround(FormattingOptions.oneSpace)
502
- }
503
- }
504
-
505
- protected formatWhereElementExpression(node: AstNode) {
506
- this.on(node, ast.isWhereElementExpression, (n, f) => {
507
- f.property('operator').surround(FormattingOptions.oneSpace)
508
- })
509
- this.on(node, ast.isWhereElementNegation, (n, f) => {
510
- f.keyword('not').append(FormattingOptions.oneSpace)
511
- })
512
- if (
513
- ast.isWhereElement(node)
514
- || ast.isWhereElementTag(node)
515
- || ast.isWhereElementKind(node)
516
- ) {
517
- const formatter = this.getNodeFormatter(node)
518
- formatter.property('operator').surround(FormattingOptions.oneSpace)
519
- formatter.property('not').surround(FormattingOptions.oneSpace)
520
- }
521
- }
522
-
523
- protected formatIncludeExcludeExpressions(node: AstNode) {
524
- if (
525
- ast.isDynamicViewRule(node)
526
- || ast.isIncludePredicate(node)
527
- || ast.isExcludePredicate(node)
528
- || ast.isDeploymentViewRulePredicate(node)
529
- ) {
530
- const formatter = this.getNodeFormatter(node)
531
-
532
- if (!node.$cstNode || !utils.isMultiline(node.$cstNode)) {
533
- formatter.keywords('include', 'exclude')
534
- .append(FormattingOptions.oneSpace)
535
- }
536
- }
537
-
538
- if (
539
- ast.isDynamicViewPredicateIterator(node)
540
- || ast.isPredicates(node)
541
- || ast.isPredicates(node)
542
- ) {
543
- const formatter = this.getNodeFormatter(node)
544
- const parent = this.findPredicateExpressionRoot(node)
545
- const isMultiline = parent?.$cstNode && utils.isMultiline(parent?.$cstNode)
546
-
547
- if (isMultiline) {
548
- formatter.property('value').prepend(FormattingOptions.indent)
549
- }
550
- formatter.keyword(',')
551
- .prepend(FormattingOptions.noSpace)
552
- .append(isMultiline ? FormattingOptions.newLine : FormattingOptions.oneSpace)
553
- }
554
- }
555
-
556
- protected formatRelationExpression(node: AstNode) {
557
- this.on(node, ast.isIncomingRelationExpr, (n, f) => {
558
- f.keyword('->').append(FormattingOptions.oneSpace)
559
- })
560
- this.on(node, ast.isInOutRelationExpr, (n, f) => {
561
- f.keyword('->').prepend(FormattingOptions.oneSpace)
562
- })
563
- this.on(node, ast.isOutgoingRelationExpr, (n, f) => {
564
- f.keywords('->', '<->').prepend(FormattingOptions.oneSpace)
565
- f.keywords('-[')
566
- .prepend(FormattingOptions.oneSpace)
567
- .append(FormattingOptions.noSpace)
568
- f.keywords(']->')
569
- .prepend(FormattingOptions.noSpace)
570
- .append(FormattingOptions.oneSpace)
571
-
572
- const kind = f.property('kind')
573
- kind.nodes[0]?.text.startsWith('.') && kind.surround(FormattingOptions.oneSpace)
574
- })
575
- this.on(node, ast.isDirectedRelationExpr, (n, f) => {
576
- f.property('target').prepend(FormattingOptions.oneSpace)
577
- })
578
- }
579
-
580
- protected formatDeploymentViewRulePredicateExpressions(node: AstNode) {
581
- if (
582
- ast.isDynamicViewRule(node)
583
- || ast.isIncludePredicate(node)
584
- || ast.isExcludePredicate(node)
585
- || ast.isDeploymentViewRulePredicate(node)
586
- ) {
587
- const formatter = this.getNodeFormatter(node)
588
-
589
- if (!node.$cstNode || !utils.isMultiline(node.$cstNode)) {
590
- formatter.keywords('include', 'exclude')
591
- .append(FormattingOptions.oneSpace)
592
- }
593
- }
594
-
595
- if (
596
- ast.isDeploymentViewRulePredicateExpression(node)
597
- ) {
598
- const formatter = this.getNodeFormatter(node)
599
- const parent = this.findPredicateExpressionRoot(node)
600
- const isMultiline = parent?.$cstNode && utils.isMultiline(parent?.$cstNode)
601
-
602
- if (isMultiline) {
603
- formatter.property('value').prepend(FormattingOptions.indent)
604
- }
605
- formatter.keyword(',')
606
- .prepend(FormattingOptions.noSpace)
607
- .append(isMultiline ? FormattingOptions.newLine : FormattingOptions.oneSpace)
608
- }
609
- }
610
-
611
- private findPredicateExpressionRoot(node: AstNode): AstNode | undefined {
612
- let parent = node.$container
613
- while (true) {
614
- if (
615
- !parent
616
- || ast.isDynamicViewRule(parent)
617
- || ast.isIncludePredicate(parent)
618
- || ast.isExcludePredicate(parent)
619
- || ast.isDeploymentViewRulePredicate(parent)
620
- ) {
621
- return parent
622
- }
623
-
624
- parent = parent.$container
625
- }
626
- }
627
-
628
- private on<T extends AstNode>(
629
- node: AstNode,
630
- predicate: Predicate<T>,
631
- format?: (node: T, f: NodeFormatter<T>) => void,
632
- ): NodeFormatter<T> | undefined {
633
- const formatter = predicate(node) ? this.getNodeFormatter(node) : undefined
634
-
635
- format && formatter && format(node as T, formatter)
636
-
637
- return formatter
638
- }
639
- }
@@ -1,26 +0,0 @@
1
- import type { CstNode } from "langium"
2
- import type { Position, Range } from "vscode-languageserver-types"
3
-
4
-
5
- export function areOverlap(a: CstNode, b: CstNode): boolean {
6
- ;[a, b] = compareRanges(a, b) > 0 ? [b, a] : [a, b]
7
-
8
- return isInRagne(a.range, b.range.start)
9
- }
10
-
11
- export function compareRanges(a: CstNode, b: CstNode): number {
12
- const lineDiff = a.range.start.line - b.range.start.line
13
-
14
- return lineDiff !== 0 ? lineDiff : a.range.start.character - b.range.start.character
15
- }
16
-
17
- export function isInRagne(range: Range, pos: Position): boolean {
18
- return !(pos.line < range.start.line
19
- || pos.line > range.end.line
20
- || pos.line == range.start.line && pos.character < range.start.character
21
- || pos.line == range.end.line && pos.character > range.end.character)
22
- }
23
-
24
- export function isMultiline(node: CstNode): boolean {
25
- return node.range.start.line != node.range.end.line
26
- }