@likec4/language-server 1.18.0 → 1.19.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 (250) 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 +132 -0
  5. package/dist/ast.d.ts +200 -0
  6. package/dist/ast.js +276 -0
  7. package/dist/browser.d.ts +7 -20
  8. package/dist/browser.js +13 -0
  9. package/dist/documentation/documentation-provider.d.ts +8 -0
  10. package/dist/documentation/documentation-provider.js +46 -0
  11. package/dist/documentation/index.d.ts +1 -0
  12. package/dist/documentation/index.js +1 -0
  13. package/dist/formatting/LikeC4Formatter.d.ts +27 -0
  14. package/dist/formatting/LikeC4Formatter.js +261 -0
  15. package/dist/formatting/utils.d.ts +6 -0
  16. package/dist/formatting/utils.js +15 -0
  17. package/dist/generated/ast.d.ts +1242 -0
  18. package/dist/generated/ast.js +1945 -0
  19. package/dist/generated/grammar.d.ts +6 -0
  20. package/dist/generated/grammar.js +3 -0
  21. package/dist/generated/module.d.ts +9 -0
  22. package/dist/generated/module.js +23 -0
  23. package/dist/generated-lib/icons.d.ts +1 -0
  24. package/dist/{likec4lib.mjs → generated-lib/icons.js} +1 -6
  25. package/dist/index.d.ts +9 -31
  26. package/dist/index.js +14 -0
  27. package/dist/like-c4.langium +845 -0
  28. package/dist/likec4lib.d.ts +4 -6
  29. package/dist/likec4lib.js +4 -0
  30. package/dist/logger.d.ts +7 -0
  31. package/dist/logger.js +73 -0
  32. package/dist/lsp/CodeLensProvider.d.ts +9 -0
  33. package/dist/lsp/CodeLensProvider.js +40 -0
  34. package/dist/lsp/CompletionProvider.d.ts +6 -0
  35. package/dist/lsp/CompletionProvider.js +135 -0
  36. package/dist/lsp/DocumentHighlightProvider.d.ts +9 -0
  37. package/dist/lsp/DocumentHighlightProvider.js +10 -0
  38. package/dist/lsp/DocumentLinkProvider.d.ts +11 -0
  39. package/dist/lsp/DocumentLinkProvider.js +49 -0
  40. package/dist/lsp/DocumentSymbolProvider.d.ts +32 -0
  41. package/dist/lsp/DocumentSymbolProvider.js +274 -0
  42. package/dist/lsp/HoverProvider.d.ts +10 -0
  43. package/dist/lsp/HoverProvider.js +69 -0
  44. package/dist/lsp/RenameProvider.d.ts +5 -0
  45. package/dist/lsp/RenameProvider.js +6 -0
  46. package/dist/lsp/SemanticTokenProvider.d.ts +7 -0
  47. package/dist/lsp/SemanticTokenProvider.js +297 -0
  48. package/dist/lsp/index.d.ts +7 -0
  49. package/dist/lsp/index.js +7 -0
  50. package/dist/model/deployments-index.d.ts +60 -0
  51. package/dist/model/deployments-index.js +181 -0
  52. package/dist/model/fqn-computation.d.ts +3 -0
  53. package/dist/model/fqn-computation.js +72 -0
  54. package/dist/model/fqn-index.d.ts +25 -0
  55. package/dist/model/fqn-index.js +96 -0
  56. package/dist/model/index.d.ts +6 -0
  57. package/dist/model/index.js +6 -0
  58. package/dist/model/model-builder.d.ts +32 -0
  59. package/dist/model/model-builder.js +598 -0
  60. package/dist/model/model-locator.d.ts +23 -0
  61. package/dist/model/model-locator.js +126 -0
  62. package/dist/model/model-parser-where.d.ts +3 -0
  63. package/dist/model/model-parser-where.js +70 -0
  64. package/dist/model/model-parser.d.ts +292 -0
  65. package/dist/model/model-parser.js +72 -0
  66. package/dist/model/parser/Base.d.ts +28 -0
  67. package/dist/model/parser/Base.js +87 -0
  68. package/dist/model/parser/DeploymentModelParser.d.ts +33 -0
  69. package/dist/model/parser/DeploymentModelParser.js +162 -0
  70. package/dist/model/parser/DeploymentViewParser.d.ts +38 -0
  71. package/dist/model/parser/DeploymentViewParser.js +98 -0
  72. package/dist/model/parser/FqnRefParser.d.ts +29 -0
  73. package/dist/model/parser/FqnRefParser.js +108 -0
  74. package/dist/model/parser/GlobalsParser.d.ts +66 -0
  75. package/dist/model/parser/GlobalsParser.js +80 -0
  76. package/dist/model/parser/ModelParser.d.ts +27 -0
  77. package/dist/model/parser/ModelParser.js +122 -0
  78. package/dist/model/parser/PredicatesParser.d.ts +34 -0
  79. package/dist/model/parser/PredicatesParser.js +272 -0
  80. package/dist/model/parser/SpecificationParser.d.ts +27 -0
  81. package/dist/model/parser/SpecificationParser.js +120 -0
  82. package/dist/model/parser/ViewsParser.d.ts +64 -0
  83. package/dist/model/parser/ViewsParser.js +377 -0
  84. package/dist/model-change/ModelChanges.d.ts +15 -0
  85. package/dist/model-change/ModelChanges.js +89 -0
  86. package/dist/model-change/changeElementStyle.d.ts +16 -0
  87. package/dist/model-change/changeElementStyle.js +136 -0
  88. package/dist/model-change/changeViewLayout.d.ts +12 -0
  89. package/dist/model-change/changeViewLayout.js +32 -0
  90. package/dist/model-change/saveManualLayout.d.ts +11 -0
  91. package/dist/model-change/saveManualLayout.js +27 -0
  92. package/dist/module.d.ts +70 -0
  93. package/dist/module.js +162 -0
  94. package/dist/protocol.d.ts +38 -23
  95. package/dist/protocol.js +15 -0
  96. package/dist/references/index.d.ts +3 -0
  97. package/dist/references/index.js +3 -0
  98. package/dist/references/name-provider.d.ts +9 -0
  99. package/dist/references/name-provider.js +33 -0
  100. package/dist/references/scope-computation.d.ts +20 -0
  101. package/dist/references/scope-computation.js +281 -0
  102. package/dist/references/scope-provider.d.ts +16 -0
  103. package/dist/references/scope-provider.js +165 -0
  104. package/dist/shared/NodeKindProvider.d.ts +15 -0
  105. package/dist/shared/NodeKindProvider.js +108 -0
  106. package/dist/shared/WorkspaceManager.d.ts +18 -0
  107. package/dist/shared/WorkspaceManager.js +36 -0
  108. package/dist/shared/WorkspaceSymbolProvider.d.ts +3 -0
  109. package/dist/shared/WorkspaceSymbolProvider.js +3 -0
  110. package/dist/shared/index.d.ts +3 -0
  111. package/dist/shared/index.js +3 -0
  112. package/dist/test/index.d.ts +1 -0
  113. package/dist/test/index.js +1 -0
  114. package/dist/test/setup.d.ts +1 -0
  115. package/dist/test/setup.js +7 -0
  116. package/dist/test/testServices.d.ts +22 -0
  117. package/dist/test/testServices.js +119 -0
  118. package/dist/utils/elementRef.d.ts +11 -0
  119. package/dist/utils/elementRef.js +15 -0
  120. package/dist/utils/fqnRef.d.ts +8 -0
  121. package/dist/utils/fqnRef.js +46 -0
  122. package/dist/utils/index.d.ts +1 -0
  123. package/dist/utils/index.js +1 -0
  124. package/dist/utils/printDocs.d.ts +2 -0
  125. package/dist/utils/printDocs.js +1 -0
  126. package/dist/utils/stringHash.d.ts +1 -0
  127. package/dist/utils/stringHash.js +5 -0
  128. package/dist/validation/_shared.d.ts +3 -0
  129. package/dist/validation/_shared.js +22 -0
  130. package/dist/validation/deployment-checks.d.ts +6 -0
  131. package/dist/validation/deployment-checks.js +114 -0
  132. package/dist/validation/dynamic-view-rule.d.ts +4 -0
  133. package/dist/validation/dynamic-view-rule.js +17 -0
  134. package/dist/validation/dynamic-view-step.d.ts +4 -0
  135. package/dist/validation/dynamic-view-step.js +29 -0
  136. package/dist/validation/element.d.ts +4 -0
  137. package/dist/validation/element.js +49 -0
  138. package/dist/validation/index.d.ts +15 -0
  139. package/dist/validation/index.js +152 -0
  140. package/dist/validation/property-checks.d.ts +6 -0
  141. package/dist/validation/property-checks.js +39 -0
  142. package/dist/validation/relation.d.ts +5 -0
  143. package/dist/validation/relation.js +56 -0
  144. package/dist/validation/specification.d.ts +11 -0
  145. package/dist/validation/specification.js +136 -0
  146. package/dist/validation/view-predicates/element-with.d.ts +4 -0
  147. package/dist/validation/view-predicates/element-with.js +31 -0
  148. package/dist/validation/view-predicates/expanded-element.d.ts +4 -0
  149. package/dist/validation/view-predicates/expanded-element.js +12 -0
  150. package/dist/validation/view-predicates/expression-v2.d.ts +5 -0
  151. package/dist/validation/view-predicates/expression-v2.js +83 -0
  152. package/dist/validation/view-predicates/incoming.d.ts +4 -0
  153. package/dist/validation/view-predicates/incoming.js +16 -0
  154. package/dist/validation/view-predicates/index.d.ts +6 -0
  155. package/dist/validation/view-predicates/index.js +6 -0
  156. package/dist/validation/view-predicates/outgoing.d.ts +4 -0
  157. package/dist/validation/view-predicates/outgoing.js +16 -0
  158. package/dist/validation/view-predicates/relation-with.d.ts +4 -0
  159. package/dist/validation/view-predicates/relation-with.js +13 -0
  160. package/dist/validation/view.d.ts +4 -0
  161. package/dist/validation/view.js +23 -0
  162. package/dist/view-utils/assignNavigateTo.d.ts +2 -0
  163. package/dist/view-utils/assignNavigateTo.js +25 -0
  164. package/dist/view-utils/index.d.ts +2 -0
  165. package/dist/view-utils/index.js +2 -0
  166. package/dist/view-utils/manual-layout.d.ts +7 -0
  167. package/dist/view-utils/manual-layout.js +99 -0
  168. package/dist/view-utils/resolve-relative-paths.d.ts +2 -0
  169. package/dist/view-utils/resolve-relative-paths.js +78 -0
  170. package/dist/views/configurable-layouter.d.ts +7 -0
  171. package/dist/views/configurable-layouter.js +55 -0
  172. package/dist/views/index.d.ts +1 -0
  173. package/dist/views/index.js +1 -0
  174. package/dist/views/likec4-views.d.ts +26 -0
  175. package/dist/views/likec4-views.js +113 -0
  176. package/package.json +40 -54
  177. package/src/LikeC4FileSystem.ts +22 -21
  178. package/src/Rpc.ts +13 -7
  179. package/src/ast.ts +44 -133
  180. package/src/browser.ts +11 -11
  181. package/src/documentation/documentation-provider.ts +52 -0
  182. package/src/documentation/index.ts +1 -0
  183. package/src/generated/ast.ts +177 -177
  184. package/src/generated/grammar.ts +1 -1
  185. package/src/index.ts +13 -9
  186. package/src/like-c4.langium +37 -34
  187. package/src/logger.ts +34 -55
  188. package/src/lsp/CompletionProvider.ts +4 -4
  189. package/src/lsp/DocumentSymbolProvider.ts +110 -28
  190. package/src/lsp/HoverProvider.ts +5 -3
  191. package/src/lsp/SemanticTokenProvider.ts +2 -2
  192. package/src/model/deployments-index.ts +18 -14
  193. package/src/model/fqn-computation.ts +8 -8
  194. package/src/model/model-builder.ts +62 -60
  195. package/src/model/model-parser.ts +62 -1574
  196. package/src/model/parser/Base.ts +107 -0
  197. package/src/model/parser/DeploymentModelParser.ts +192 -0
  198. package/src/model/parser/DeploymentViewParser.ts +116 -0
  199. package/src/model/parser/FqnRefParser.ts +118 -0
  200. package/src/model/parser/GlobalsParser.ts +96 -0
  201. package/src/model/parser/ModelParser.ts +141 -0
  202. package/src/model/parser/PredicatesParser.ts +291 -0
  203. package/src/model/parser/SpecificationParser.ts +133 -0
  204. package/src/model/parser/ViewsParser.ts +428 -0
  205. package/src/module.ts +71 -25
  206. package/src/protocol.ts +29 -4
  207. package/src/references/scope-computation.ts +35 -35
  208. package/src/references/scope-provider.ts +13 -7
  209. package/src/utils/{deploymentRef.ts → fqnRef.ts} +27 -2
  210. package/src/validation/_shared.ts +0 -1
  211. package/src/validation/deployment-checks.ts +49 -62
  212. package/src/validation/dynamic-view-rule.ts +5 -4
  213. package/src/validation/dynamic-view-step.ts +23 -26
  214. package/src/validation/index.ts +100 -9
  215. package/src/validation/property-checks.ts +11 -10
  216. package/src/validation/specification.ts +38 -38
  217. package/src/validation/view-predicates/element-with.ts +6 -5
  218. package/src/validation/view-predicates/expanded-element.ts +6 -5
  219. package/src/validation/view-predicates/expression-v2.ts +101 -0
  220. package/src/validation/view-predicates/incoming.ts +6 -5
  221. package/src/validation/view-predicates/index.ts +1 -1
  222. package/src/validation/view-predicates/outgoing.ts +6 -5
  223. package/src/validation/view-predicates/relation-with.ts +6 -5
  224. package/src/validation/view.ts +5 -5
  225. package/src/view-utils/assignNavigateTo.ts +1 -1
  226. package/src/view-utils/manual-layout.ts +25 -0
  227. package/src/views/configurable-layouter.ts +65 -0
  228. package/src/views/index.ts +1 -0
  229. package/src/views/likec4-views.ts +139 -0
  230. package/dist/browser.cjs +0 -25
  231. package/dist/browser.d.cts +0 -23
  232. package/dist/browser.d.mts +0 -23
  233. package/dist/browser.mjs +0 -20
  234. package/dist/index.cjs +0 -53
  235. package/dist/index.d.cts +0 -34
  236. package/dist/index.d.mts +0 -34
  237. package/dist/index.mjs +0 -46
  238. package/dist/likec4lib.cjs +0 -1546
  239. package/dist/likec4lib.d.cts +0 -6
  240. package/dist/likec4lib.d.mts +0 -6
  241. package/dist/protocol.cjs +0 -25
  242. package/dist/protocol.d.cts +0 -48
  243. package/dist/protocol.d.mts +0 -48
  244. package/dist/protocol.mjs +0 -17
  245. package/dist/shared/language-server.CO_nmHiL.cjs +0 -7689
  246. package/dist/shared/language-server.Da6ey08o.d.cts +0 -1619
  247. package/dist/shared/language-server.De7S3e5Z.d.ts +0 -1619
  248. package/dist/shared/language-server.Dj4iDjtB.d.mts +0 -1619
  249. package/dist/shared/language-server.oO_9JoAG.mjs +0 -7666
  250. package/src/validation/view-predicates/deployments.ts +0 -56
@@ -0,0 +1,13 @@
1
+ import { startLanguageServer as startLanguim } from "langium/lsp";
2
+ import { BrowserMessageReader, BrowserMessageWriter, createConnection } from "vscode-languageserver/browser";
3
+ import { createLanguageServices } from "./module.js";
4
+ export { logger as lspLogger, setLogLevel } from "./logger.js";
5
+ export { createCustomLanguageServices, createLanguageServices, LikeC4Module } from "./module.js";
6
+ export function startLanguageServer() {
7
+ const messageReader = new BrowserMessageReader(self);
8
+ const messageWriter = new BrowserMessageWriter(self);
9
+ const connection = createConnection(messageReader, messageWriter);
10
+ const services = createLanguageServices({ connection });
11
+ startLanguim(services.shared);
12
+ return services;
13
+ }
@@ -0,0 +1,8 @@
1
+ import { type AstNode, type DocumentationProvider } from 'langium';
2
+ import type { LikeC4Services } from '../module';
3
+ export declare class LikeC4DocumentationProvider implements DocumentationProvider {
4
+ private parser;
5
+ private locator;
6
+ constructor(services: LikeC4Services);
7
+ getDocumentation(node: AstNode): string | undefined;
8
+ }
@@ -0,0 +1,46 @@
1
+ import { AstUtils } from "langium";
2
+ import { ast } from "../ast.js";
3
+ import { logWarnError } from "../logger.js";
4
+ export class LikeC4DocumentationProvider {
5
+ parser;
6
+ locator;
7
+ constructor(services) {
8
+ this.parser = services.likec4.ModelParser;
9
+ this.locator = services.likec4.ModelLocator;
10
+ }
11
+ getDocumentation(node) {
12
+ try {
13
+ if (ast.isDeploymentNode(node)) {
14
+ const doc = AstUtils.getDocument(node);
15
+ const el = this.parser.forDocument(doc).parseDeploymentNode(node);
16
+ const lines = [el.id];
17
+ if (el.title !== node.name) {
18
+ lines.push(" ", `**${el.title}**`);
19
+ }
20
+ return lines.join(" \n");
21
+ }
22
+ if (ast.isDeployedInstance(node)) {
23
+ const doc = AstUtils.getDocument(node);
24
+ const instance = this.parser.forDocument(doc).parseDeployedInstance(node);
25
+ const el = this.locator.getParsedElement(instance.element);
26
+ const lines = [instance.id, `_instance of_ ${instance.element}`];
27
+ if (el) {
28
+ lines.push(" ", `**${el.title}**`);
29
+ }
30
+ return lines.join(" \n");
31
+ }
32
+ if (ast.isElement(node)) {
33
+ const doc = AstUtils.getDocument(node);
34
+ const el = this.parser.forDocument(doc).parseElement(node);
35
+ if (!el) {
36
+ return;
37
+ }
38
+ const lines = [el.id, " ", `**${el.title}**`];
39
+ return lines.join(" \n");
40
+ }
41
+ } catch (e) {
42
+ logWarnError(e);
43
+ }
44
+ return;
45
+ }
46
+ }
@@ -0,0 +1 @@
1
+ export { LikeC4DocumentationProvider } from './documentation-provider';
@@ -0,0 +1 @@
1
+ export { LikeC4DocumentationProvider } from "./documentation-provider.js";
@@ -0,0 +1,27 @@
1
+ import { type AstNode } from 'langium';
2
+ import { AbstractFormatter } from 'langium/lsp';
3
+ export declare class LikeC4Formatter extends AbstractFormatter {
4
+ protected format(node: AstNode): void;
5
+ protected formatTags(node: AstNode): void;
6
+ protected formatRelation(node: AstNode): void;
7
+ protected removeIndentFromTopLevelStatements(node: AstNode): void;
8
+ protected indentContentInBraces(node: AstNode): void;
9
+ protected appendKeywordsWithSpace(node: AstNode): void;
10
+ protected formatView(node: AstNode): void;
11
+ protected formatLeafProperty(node: AstNode): void;
12
+ protected formatLinkProperty(node: AstNode): void;
13
+ protected formatNavigateToProperty(node: AstNode): void;
14
+ protected formatAutolayoutProperty(node: AstNode): void;
15
+ protected formatMetadataProperty(node: AstNode): void;
16
+ protected formatElementDeclaration(node: AstNode): void;
17
+ protected formatGlobals(node: AstNode): void;
18
+ protected formatSpecificationRule(node: AstNode): void;
19
+ protected formatWithPredicate(node: AstNode): void;
20
+ protected formatViewRuleGlobalStyle(node: AstNode): void;
21
+ protected formatViewRuleGroup(node: AstNode): void;
22
+ protected formatViewRuleStyle(node: AstNode): void;
23
+ protected formatWhereExpression(node: AstNode): void;
24
+ protected formatIncludeExcludeExpressions(node: AstNode): void;
25
+ private findPredicateExpressionRoot;
26
+ private on;
27
+ }
@@ -0,0 +1,261 @@
1
+ import { GrammarUtils } from "langium";
2
+ import { AbstractFormatter, Formatting } from "langium/lsp";
3
+ import { filter, isTruthy } from "remeda";
4
+ import * as ast from "../generated/ast.js";
5
+ import * as utils from "./utils.js";
6
+ const FormattingOptions = {
7
+ newLine: Formatting.newLine({ allowMore: true }),
8
+ oneSpace: Formatting.oneSpace(),
9
+ noSpace: Formatting.noSpace(),
10
+ indent: Formatting.indent({ allowMore: true }),
11
+ noIndent: Formatting.noIndent()
12
+ };
13
+ export class LikeC4Formatter extends AbstractFormatter {
14
+ format(node) {
15
+ this.removeIndentFromTopLevelStatements(node);
16
+ this.indentContentInBraces(node);
17
+ this.formatSpecificationRule(node);
18
+ this.formatGlobals(node);
19
+ this.formatElementDeclaration(node);
20
+ this.formatRelation(node);
21
+ this.formatMetadataProperty(node);
22
+ this.formatView(node);
23
+ this.formatViewRuleGroup(node);
24
+ this.formatViewRuleGlobalStyle(node);
25
+ this.formatIncludeExcludeExpressions(node);
26
+ this.formatWhereExpression(node);
27
+ this.formatAutolayoutProperty(node);
28
+ this.formatWithPredicate(node);
29
+ this.formatViewRuleStyle(node);
30
+ this.formatLeafProperty(node);
31
+ this.formatLinkProperty(node);
32
+ this.formatNavigateToProperty(node);
33
+ this.formatTags(node);
34
+ }
35
+ formatTags(node) {
36
+ this.on(node, ast.isTags, (n, f) => {
37
+ f.cst(GrammarUtils.findNodesForProperty(n.$cstNode, "values").slice(1)).prepend(FormattingOptions.oneSpace);
38
+ f.keywords(",").prepend(FormattingOptions.noSpace).append(FormattingOptions.oneSpace);
39
+ });
40
+ }
41
+ formatRelation(node) {
42
+ this.on(node, ast.isRelation, (n, f) => {
43
+ const sourceNodes = n?.source?.$cstNode ? [n?.source?.$cstNode] : [];
44
+ f.cst(sourceNodes).append(FormattingOptions.oneSpace);
45
+ f.keywords("]->").prepend(FormattingOptions.noSpace);
46
+ f.keywords("-[").append(FormattingOptions.noSpace);
47
+ f.nodes(...filter([
48
+ n.target,
49
+ n.tags
50
+ ], isTruthy)).prepend(FormattingOptions.oneSpace);
51
+ f.properties("title", "technology").prepend(FormattingOptions.oneSpace);
52
+ });
53
+ this.on(node, ast.isDynamicViewStep, (n, f) => {
54
+ f.keywords("->", "<-").surround(FormattingOptions.oneSpace);
55
+ const kind = f.property("kind");
56
+ kind.nodes[0]?.text.startsWith(".") && kind.surround(FormattingOptions.oneSpace);
57
+ f.keywords("]->").prepend(FormattingOptions.noSpace).append(FormattingOptions.oneSpace);
58
+ f.keywords("-[").prepend(FormattingOptions.oneSpace).append(FormattingOptions.noSpace);
59
+ f.properties("title").prepend(FormattingOptions.oneSpace);
60
+ });
61
+ this.on(node, ast.isDirectedRelationExpression)?.property("target").prepend(FormattingOptions.oneSpace);
62
+ this.on(node, ast.isOutgoingRelationExpression, (n, f) => {
63
+ f.property("from").append(FormattingOptions.oneSpace);
64
+ f.keywords("]->").prepend(FormattingOptions.noSpace);
65
+ f.keywords("-[").append(FormattingOptions.noSpace);
66
+ });
67
+ this.on(node, ast.isIncomingRelationExpression)?.keywords("->").append(FormattingOptions.oneSpace);
68
+ this.on(node, ast.isInOutRelationExpression)?.keyword("->").prepend(FormattingOptions.oneSpace);
69
+ }
70
+ removeIndentFromTopLevelStatements(node) {
71
+ if (ast.isModel(node) || ast.isSpecificationRule(node) || ast.isModelViews(node) || ast.isLikeC4Lib(node) || ast.isGlobals(node)) {
72
+ const formatter = this.getNodeFormatter(node);
73
+ formatter.keywords("specification", "model", "views", "likec4lib", "global").prepend(FormattingOptions.noIndent);
74
+ }
75
+ }
76
+ indentContentInBraces(node) {
77
+ if (ast.isLikeC4Lib(node) || ast.isSpecificationRule(node) || ast.isSpecificationElementKind(node) || ast.isSpecificationRelationshipKind(node) || ast.isGlobals(node) || ast.isGlobalStyle(node) || ast.isGlobalStyleGroup(node) || ast.isModel(node) || ast.isElementBody(node) || ast.isExtendElementBody(node) || ast.isRelationBody(node) || ast.isRelationStyleProperty(node) || ast.isMetadataBody(node) || ast.isModelViews(node) || ast.isElementViewBody(node) || ast.isDynamicViewBody(node) || ast.isViewRuleStyle(node) || ast.isViewRuleGroup(node) || ast.isCustomElementProperties(node) || ast.isCustomRelationProperties(node) || ast.isElementStyleProperty(node) || ast.isDynamicViewParallelSteps(node)) {
78
+ const formatter = this.getNodeFormatter(node);
79
+ const openBrace = formatter.keywords("{");
80
+ const closeBrace = formatter.keywords("}");
81
+ const interiorNodes = formatter.interior(openBrace, closeBrace);
82
+ let perviousNode = null;
83
+ for (const interiorNode of interiorNodes.nodes) {
84
+ if (!perviousNode || !utils.areOverlap(perviousNode, interiorNode)) {
85
+ formatter.cst([interiorNode]).prepend(FormattingOptions.indent);
86
+ }
87
+ perviousNode = interiorNode;
88
+ }
89
+ openBrace.prepend(FormattingOptions.noIndent).prepend(FormattingOptions.oneSpace);
90
+ closeBrace.prepend(FormattingOptions.noIndent).prepend(Formatting.newLine({ allowMore: true }));
91
+ }
92
+ }
93
+ appendKeywordsWithSpace(node) {
94
+ this.on(node, ast.isElementKind)?.keywords("element").append(FormattingOptions.oneSpace);
95
+ }
96
+ formatView(node) {
97
+ this.on(node, ast.isElementView, (n, f) => {
98
+ if (n.extends || n.viewOf || n.name) {
99
+ f.keywords("view").append(FormattingOptions.oneSpace);
100
+ }
101
+ f.keywords("of", "extends").surround(FormattingOptions.oneSpace);
102
+ });
103
+ this.on(node, ast.isDynamicView)?.keywords("dynamic", "view").append(FormattingOptions.oneSpace);
104
+ }
105
+ formatLeafProperty(node) {
106
+ if (ast.isElementStringProperty(node) || ast.isRelationStringProperty(node) || ast.isViewStringProperty(node) || ast.isNotationProperty(node) || ast.isSpecificationElementStringProperty(node) || ast.isSpecificationRelationshipStringProperty(node) || ast.isColorProperty(node) || ast.isLineProperty(node) || ast.isArrowProperty(node) || ast.isIconProperty(node) || ast.isShapeProperty(node) || ast.isBorderProperty(node) || ast.isOpacityProperty(node)) {
107
+ const formatter = this.getNodeFormatter(node);
108
+ const colon = formatter.keyword(":");
109
+ const propertyName = formatter.keywords(
110
+ "title",
111
+ "description",
112
+ "technology",
113
+ "notation",
114
+ "color",
115
+ "line",
116
+ "head",
117
+ "tail",
118
+ "icon",
119
+ "shape",
120
+ "border",
121
+ "opacity"
122
+ );
123
+ if (colon.nodes.length === 0) {
124
+ propertyName.append(FormattingOptions.oneSpace);
125
+ } else {
126
+ colon.prepend(FormattingOptions.noSpace).append(FormattingOptions.oneSpace);
127
+ }
128
+ formatter.keyword(";").prepend(FormattingOptions.noSpace).append(FormattingOptions.newLine);
129
+ }
130
+ }
131
+ formatLinkProperty(node) {
132
+ this.on(node, ast.isLinkProperty, (n, f) => {
133
+ f.keyword("link").append(FormattingOptions.oneSpace);
134
+ f.property("value").append(FormattingOptions.oneSpace);
135
+ f.keyword(":").prepend(FormattingOptions.noSpace).append(FormattingOptions.oneSpace);
136
+ f.keyword(";").prepend(FormattingOptions.noSpace).append(FormattingOptions.newLine);
137
+ });
138
+ }
139
+ formatNavigateToProperty(node) {
140
+ this.on(node, ast.isNavigateToProperty)?.property("key").append(FormattingOptions.oneSpace);
141
+ }
142
+ formatAutolayoutProperty(node) {
143
+ this.on(node, ast.isViewRuleAutoLayout, (n, f) => {
144
+ f.keyword("autoLayout").append(FormattingOptions.oneSpace);
145
+ f.property("rankSep").prepend(FormattingOptions.oneSpace);
146
+ f.property("nodeSep").prepend(FormattingOptions.oneSpace);
147
+ });
148
+ }
149
+ formatMetadataProperty(node) {
150
+ this.on(node, ast.isMetadataAttribute, (n, f) => {
151
+ f.property("key").append(FormattingOptions.oneSpace);
152
+ f.keyword(":").prepend(FormattingOptions.noSpace).append(FormattingOptions.oneSpace);
153
+ f.keyword(";").prepend(FormattingOptions.noSpace).append(FormattingOptions.newLine);
154
+ });
155
+ }
156
+ formatElementDeclaration(node) {
157
+ this.on(node, ast.isElement, (n, f) => {
158
+ const kind = GrammarUtils.findNodeForProperty(n.$cstNode, "kind");
159
+ const name = GrammarUtils.findNodeForProperty(n.$cstNode, "name");
160
+ if (name && kind) {
161
+ if (utils.compareRanges(name, kind) > 0) {
162
+ f.cst([kind]).append(FormattingOptions.oneSpace);
163
+ } else {
164
+ f.cst([name]).append(FormattingOptions.oneSpace);
165
+ f.cst([kind]).prepend(FormattingOptions.oneSpace);
166
+ }
167
+ }
168
+ f.properties("props").prepend(FormattingOptions.oneSpace);
169
+ });
170
+ }
171
+ formatGlobals(node) {
172
+ this.on(node, ast.isGlobalStyle, (n, f) => {
173
+ f.keyword("style").append(FormattingOptions.oneSpace);
174
+ f.property("id").append(FormattingOptions.oneSpace);
175
+ });
176
+ this.on(node, ast.isGlobalStyleGroup, (n, f) => {
177
+ f.keyword("styleGroup").append(FormattingOptions.oneSpace);
178
+ });
179
+ }
180
+ formatSpecificationRule(node) {
181
+ if (ast.isSpecificationElementKind(node) || ast.isSpecificationRelationshipKind(node) || ast.isSpecificationTag(node)) {
182
+ const formatter = this.getNodeFormatter(node);
183
+ formatter.keywords("element", "relationship", "tag").append(FormattingOptions.oneSpace);
184
+ }
185
+ if (ast.isSpecificationColor(node)) {
186
+ const formatter = this.getNodeFormatter(node);
187
+ formatter.keyword("color").append(FormattingOptions.oneSpace);
188
+ formatter.property("name").append(FormattingOptions.oneSpace);
189
+ }
190
+ }
191
+ formatWithPredicate(node) {
192
+ const formatter = this.getNodeFormatter(node);
193
+ if (ast.isElementPredicateWith(node) || ast.isRelationPredicateWith(node)) {
194
+ formatter.keyword("with").prepend(FormattingOptions.oneSpace);
195
+ }
196
+ }
197
+ formatViewRuleGlobalStyle(node) {
198
+ this.on(node, ast.isViewRuleGlobalStyle, (n, f) => {
199
+ f.keywords("global", "style").append(FormattingOptions.oneSpace);
200
+ });
201
+ }
202
+ formatViewRuleGroup(node) {
203
+ this.on(node, ast.isViewRuleGroup, (n, f) => {
204
+ f.keyword("group").append(FormattingOptions.oneSpace);
205
+ });
206
+ }
207
+ formatViewRuleStyle(node) {
208
+ this.on(node, ast.isViewRuleStyle)?.keyword("style").append(FormattingOptions.oneSpace);
209
+ this.on(node, ast.isElementExpressionsIterator)?.keyword(",").prepend(FormattingOptions.noSpace).append(FormattingOptions.oneSpace);
210
+ }
211
+ formatWhereExpression(node) {
212
+ if (ast.isRelationPredicateOrWhere(node) || ast.isElementPredicateOrWhere(node)) {
213
+ const formatter = this.getNodeFormatter(node);
214
+ formatter.keyword("where").append(FormattingOptions.oneSpace);
215
+ }
216
+ if (ast.isWhereRelationExpression(node) || ast.isWhereElementExpression(node)) {
217
+ const formatter = this.getNodeFormatter(node);
218
+ formatter.property("operator").surround(FormattingOptions.oneSpace);
219
+ }
220
+ if (ast.isWhereElementNegation(node) || ast.isWhereRelationNegation(node)) {
221
+ const formatter = this.getNodeFormatter(node);
222
+ formatter.keyword("not").append(FormattingOptions.oneSpace);
223
+ }
224
+ if (ast.isWhereElement(node) || ast.isWhereElementTag(node) || ast.isWhereElementKind(node) || ast.isWhereRelation(node) || ast.isWhereRelationTag(node) || ast.isWhereRelationKind(node)) {
225
+ const formatter = this.getNodeFormatter(node);
226
+ formatter.property("operator").surround(FormattingOptions.oneSpace);
227
+ formatter.property("not").surround(FormattingOptions.oneSpace);
228
+ }
229
+ }
230
+ formatIncludeExcludeExpressions(node) {
231
+ if (ast.isDynamicViewRule(node) || ast.isIncludePredicate(node) || ast.isExcludePredicate(node)) {
232
+ const formatter = this.getNodeFormatter(node);
233
+ if (!node.$cstNode || !utils.isMultiline(node.$cstNode)) {
234
+ formatter.keywords("include", "exclude").append(FormattingOptions.oneSpace);
235
+ }
236
+ }
237
+ if (ast.isDynamicViewPredicateIterator(node) || ast.isPredicates(node) || ast.isPredicates(node)) {
238
+ const formatter = this.getNodeFormatter(node);
239
+ const parent = this.findPredicateExpressionRoot(node);
240
+ const isMultiline = parent?.$cstNode && utils.isMultiline(parent?.$cstNode);
241
+ if (isMultiline) {
242
+ formatter.property("value").prepend(FormattingOptions.indent);
243
+ }
244
+ formatter.keyword(",").prepend(FormattingOptions.noSpace).append(isMultiline ? FormattingOptions.newLine : FormattingOptions.oneSpace);
245
+ }
246
+ }
247
+ findPredicateExpressionRoot(node) {
248
+ let parent = node.$container;
249
+ while (true) {
250
+ if (!parent || ast.isDynamicViewRule(parent) || ast.isIncludePredicate(parent) || ast.isExcludePredicate(parent)) {
251
+ return parent;
252
+ }
253
+ parent = parent.$container;
254
+ }
255
+ }
256
+ on(node, predicate, format) {
257
+ const formatter = predicate(node) ? this.getNodeFormatter(node) : void 0;
258
+ format && formatter && format(node, formatter);
259
+ return formatter;
260
+ }
261
+ }
@@ -0,0 +1,6 @@
1
+ import type { CstNode } from "langium";
2
+ import type { Position, Range } from "vscode-languageserver-types";
3
+ export declare function areOverlap(a: CstNode, b: CstNode): boolean;
4
+ export declare function compareRanges(a: CstNode, b: CstNode): number;
5
+ export declare function isInRagne(range: Range, pos: Position): boolean;
6
+ export declare function isMultiline(node: CstNode): boolean;
@@ -0,0 +1,15 @@
1
+ export function areOverlap(a, b) {
2
+ ;
3
+ [a, b] = compareRanges(a, b) > 0 ? [b, a] : [a, b];
4
+ return isInRagne(a.range, b.range.start);
5
+ }
6
+ export function compareRanges(a, b) {
7
+ const lineDiff = a.range.start.line - b.range.start.line;
8
+ return lineDiff !== 0 ? lineDiff : a.range.start.character - b.range.start.character;
9
+ }
10
+ export function isInRagne(range, pos) {
11
+ return !(pos.line < range.start.line || pos.line > range.end.line || pos.line == range.start.line && pos.character < range.start.character || pos.line == range.end.line && pos.character > range.end.character);
12
+ }
13
+ export function isMultiline(node) {
14
+ return node.range.start.line != node.range.end.line;
15
+ }