@likec4/language-server 1.47.0 → 1.48.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 (316) hide show
  1. package/LICENSE +1 -1
  2. package/browser/package.json +2 -2
  3. package/browser-worker/package.json +2 -2
  4. package/bundled/package.json +4 -0
  5. package/dist/LikeC4LanguageServices.d.mts +4 -0
  6. package/dist/LikeC4LanguageServices.mjs +3 -0
  7. package/dist/_chunks/ConfigurableLayouter.mjs +1956 -0
  8. package/dist/_chunks/LikeC4LanguageServices.d.mts +1978 -0
  9. package/dist/_chunks/LikeC4LanguageServices.mjs +725 -0
  10. package/dist/_chunks/ast.d.mts +1444 -0
  11. package/dist/_chunks/ast.mjs +2375 -0
  12. package/dist/_chunks/ast2.mjs +176 -0
  13. package/dist/_chunks/common-exports.mjs +0 -0
  14. package/dist/_chunks/filesystem.mjs +58 -0
  15. package/dist/_chunks/grammar.mjs +8 -0
  16. package/dist/_chunks/icons.mjs +5211 -0
  17. package/dist/_chunks/libs/@hono/node-server.mjs +436 -0
  18. package/dist/_chunks/libs/@msgpack/msgpack.mjs +805 -0
  19. package/dist/_chunks/libs/eventemitter3.mjs +243 -0
  20. package/dist/_chunks/libs/fast-equals.mjs +446 -0
  21. package/dist/_chunks/libs/hono.mjs +1829 -0
  22. package/dist/_chunks/libs/p-queue.mjs +449 -0
  23. package/dist/_chunks/libs/parse-ms.mjs +36 -0
  24. package/dist/_chunks/libs/picomatch.mjs +1673 -0
  25. package/dist/_chunks/libs/pretty-ms.mjs +80 -0
  26. package/dist/_chunks/libs/remeda.mjs +482 -0
  27. package/dist/_chunks/libs/strip-indent.mjs +15 -0
  28. package/dist/_chunks/libs/ufo.mjs +166 -0
  29. package/dist/_chunks/likec4lib.mjs +9 -0
  30. package/dist/_chunks/mcp.mjs +33 -0
  31. package/dist/_chunks/module.mjs +28 -0
  32. package/dist/_chunks/module2.mjs +6576 -0
  33. package/dist/_chunks/protocol.d.mts +311 -0
  34. package/dist/_chunks/protocol.mjs +78 -0
  35. package/dist/_chunks/rolldown-runtime.mjs +42 -0
  36. package/dist/ast.d.mts +4 -0
  37. package/dist/ast.mjs +4 -0
  38. package/dist/browser-worker.d.mts +1 -0
  39. package/dist/browser-worker.mjs +6 -0
  40. package/dist/browser.d.mts +11 -0
  41. package/dist/browser.mjs +27 -0
  42. package/dist/bundled.d.mts +28 -0
  43. package/dist/bundled.mjs +51 -4853
  44. package/dist/common-exports.d.mts +4 -0
  45. package/dist/common-exports.mjs +5 -0
  46. package/dist/filesystem/index.d.mts +4 -0
  47. package/dist/filesystem/index.mjs +3 -0
  48. package/dist/generated/ast.d.mts +2 -0
  49. package/dist/generated/ast.mjs +3 -0
  50. package/dist/generated/grammar.d.mts +6 -0
  51. package/dist/generated/grammar.mjs +3 -0
  52. package/dist/generated/module.d.mts +14 -0
  53. package/dist/generated/module.mjs +3 -0
  54. package/dist/generated-lib/icons.d.mts +4 -0
  55. package/dist/generated-lib/icons.mjs +3 -0
  56. package/dist/index.d.mts +4 -0
  57. package/dist/index.mjs +48 -0
  58. package/dist/likec4lib.d.mts +9 -0
  59. package/dist/likec4lib.mjs +4 -0
  60. package/dist/mcp/index.d.mts +4 -0
  61. package/dist/mcp/index.mjs +3 -0
  62. package/dist/module.d.mts +4 -0
  63. package/dist/module.mjs +3 -0
  64. package/dist/protocol.d.mts +2 -0
  65. package/dist/protocol.mjs +3 -0
  66. package/likec4lib/package.json +2 -2
  67. package/package.json +106 -63
  68. package/protocol/package.json +2 -2
  69. package/dist/LikeC4LanguageServices.d.ts +0 -115
  70. package/dist/LikeC4LanguageServices.js +0 -164
  71. package/dist/Rpc.d.ts +0 -9
  72. package/dist/Rpc.js +0 -276
  73. package/dist/ast.d.ts +0 -226
  74. package/dist/ast.js +0 -264
  75. package/dist/browser-worker.d.ts +0 -1
  76. package/dist/browser-worker.js +0 -4
  77. package/dist/browser.d.ts +0 -10
  78. package/dist/browser.js +0 -34
  79. package/dist/bundled.d.ts +0 -8
  80. package/dist/bundled.js +0 -44
  81. package/dist/documentation/documentation-provider.d.ts +0 -8
  82. package/dist/documentation/documentation-provider.js +0 -51
  83. package/dist/documentation/index.d.ts +0 -1
  84. package/dist/documentation/index.js +0 -1
  85. package/dist/empty.d.ts +0 -2
  86. package/dist/empty.js +0 -2
  87. package/dist/filesystem/ChokidarWatcher.d.ts +0 -19
  88. package/dist/filesystem/ChokidarWatcher.js +0 -133
  89. package/dist/filesystem/FileSystemWatcher.d.ts +0 -19
  90. package/dist/filesystem/FileSystemWatcher.js +0 -14
  91. package/dist/filesystem/LikeC4FileSystem.d.ts +0 -3
  92. package/dist/filesystem/LikeC4FileSystem.js +0 -140
  93. package/dist/filesystem/index.d.ts +0 -55
  94. package/dist/filesystem/index.js +0 -29
  95. package/dist/formatting/LikeC4Formatter.d.ts +0 -59
  96. package/dist/formatting/LikeC4Formatter.js +0 -637
  97. package/dist/formatting/utils.d.ts +0 -6
  98. package/dist/formatting/utils.js +0 -18
  99. package/dist/generated/ast.d.ts +0 -1411
  100. package/dist/generated/ast.js +0 -2207
  101. package/dist/generated/grammar.d.ts +0 -6
  102. package/dist/generated/grammar.js +0 -7
  103. package/dist/generated/module.d.ts +0 -14
  104. package/dist/generated/module.js +0 -27
  105. package/dist/generated-lib/icons.d.ts +0 -1
  106. package/dist/generated-lib/icons.js +0 -18
  107. package/dist/index.d.ts +0 -37
  108. package/dist/index.js +0 -54
  109. package/dist/likec4lib.d.ts +0 -6
  110. package/dist/likec4lib.js +0 -7
  111. package/dist/logger.d.ts +0 -17
  112. package/dist/logger.js +0 -81
  113. package/dist/lsp/CodeActionProvider.d.ts +0 -14
  114. package/dist/lsp/CodeActionProvider.js +0 -33
  115. package/dist/lsp/CodeLensProvider.d.ts +0 -9
  116. package/dist/lsp/CodeLensProvider.js +0 -44
  117. package/dist/lsp/CompletionProvider.d.ts +0 -13
  118. package/dist/lsp/CompletionProvider.js +0 -238
  119. package/dist/lsp/DocumentHighlightProvider.d.ts +0 -9
  120. package/dist/lsp/DocumentHighlightProvider.js +0 -10
  121. package/dist/lsp/DocumentLinkProvider.d.ts +0 -11
  122. package/dist/lsp/DocumentLinkProvider.js +0 -58
  123. package/dist/lsp/DocumentSymbolProvider.d.ts +0 -33
  124. package/dist/lsp/DocumentSymbolProvider.js +0 -317
  125. package/dist/lsp/HoverProvider.d.ts +0 -10
  126. package/dist/lsp/HoverProvider.js +0 -106
  127. package/dist/lsp/RenameProvider.d.ts +0 -5
  128. package/dist/lsp/RenameProvider.js +0 -6
  129. package/dist/lsp/SemanticTokenProvider.d.ts +0 -19
  130. package/dist/lsp/SemanticTokenProvider.js +0 -305
  131. package/dist/lsp/index.d.ts +0 -8
  132. package/dist/lsp/index.js +0 -9
  133. package/dist/mcp/MCPServerFactory.d.ts +0 -8
  134. package/dist/mcp/MCPServerFactory.js +0 -73
  135. package/dist/mcp/NoopLikeC4MCPServer.d.ts +0 -9
  136. package/dist/mcp/NoopLikeC4MCPServer.js +0 -17
  137. package/dist/mcp/interfaces.d.ts +0 -13
  138. package/dist/mcp/interfaces.js +0 -4
  139. package/dist/mcp/server/StdioLikeC4MCPServer.d.ts +0 -16
  140. package/dist/mcp/server/StdioLikeC4MCPServer.js +0 -51
  141. package/dist/mcp/server/StreamableLikeC4MCPServer.d.ts +0 -16
  142. package/dist/mcp/server/StreamableLikeC4MCPServer.js +0 -121
  143. package/dist/mcp/server/WithMCPServer.d.ts +0 -4
  144. package/dist/mcp/server/WithMCPServer.js +0 -54
  145. package/dist/mcp/tools/_common.d.ts +0 -88
  146. package/dist/mcp/tools/_common.js +0 -49
  147. package/dist/mcp/tools/find-relationships.d.ts +0 -202
  148. package/dist/mcp/tools/find-relationships.js +0 -150
  149. package/dist/mcp/tools/list-projects.d.ts +0 -194
  150. package/dist/mcp/tools/list-projects.js +0 -62
  151. package/dist/mcp/tools/open-view.d.ts +0 -200
  152. package/dist/mcp/tools/open-view.js +0 -52
  153. package/dist/mcp/tools/read-deployment.d.ts +0 -200
  154. package/dist/mcp/tools/read-deployment.js +0 -150
  155. package/dist/mcp/tools/read-element.d.ts +0 -200
  156. package/dist/mcp/tools/read-element.js +0 -218
  157. package/dist/mcp/tools/read-project-summary.d.ts +0 -198
  158. package/dist/mcp/tools/read-project-summary.js +0 -176
  159. package/dist/mcp/tools/read-view.d.ts +0 -200
  160. package/dist/mcp/tools/read-view.js +0 -203
  161. package/dist/mcp/tools/search-element.d.ts +0 -198
  162. package/dist/mcp/tools/search-element.js +0 -177
  163. package/dist/mcp/utils.d.ts +0 -18
  164. package/dist/mcp/utils.js +0 -48
  165. package/dist/model/builder/MergedExtends.d.ts +0 -13
  166. package/dist/model/builder/MergedExtends.js +0 -74
  167. package/dist/model/builder/MergedSpecification.d.ts +0 -32
  168. package/dist/model/builder/MergedSpecification.js +0 -175
  169. package/dist/model/builder/buildModel.d.ts +0 -16
  170. package/dist/model/builder/buildModel.js +0 -245
  171. package/dist/model/deployments-index.d.ts +0 -10
  172. package/dist/model/deployments-index.js +0 -102
  173. package/dist/model/fqn-index.d.ts +0 -61
  174. package/dist/model/fqn-index.js +0 -253
  175. package/dist/model/index.d.ts +0 -6
  176. package/dist/model/index.js +0 -6
  177. package/dist/model/model-builder.d.ts +0 -54
  178. package/dist/model/model-builder.js +0 -233
  179. package/dist/model/model-locator.d.ts +0 -39
  180. package/dist/model/model-locator.js +0 -240
  181. package/dist/model/model-parser-where.d.ts +0 -4
  182. package/dist/model/model-parser-where.js +0 -81
  183. package/dist/model/model-parser.d.ts +0 -645
  184. package/dist/model/model-parser.js +0 -133
  185. package/dist/model/parser/Base.d.ts +0 -69
  186. package/dist/model/parser/Base.js +0 -382
  187. package/dist/model/parser/DeploymentModelParser.d.ts +0 -71
  188. package/dist/model/parser/DeploymentModelParser.js +0 -176
  189. package/dist/model/parser/DeploymentViewParser.d.ts +0 -75
  190. package/dist/model/parser/DeploymentViewParser.js +0 -86
  191. package/dist/model/parser/FqnRefParser.d.ts +0 -66
  192. package/dist/model/parser/FqnRefParser.js +0 -382
  193. package/dist/model/parser/GlobalsParser.d.ts +0 -109
  194. package/dist/model/parser/GlobalsParser.js +0 -84
  195. package/dist/model/parser/ImportsParser.d.ts +0 -46
  196. package/dist/model/parser/ImportsParser.js +0 -24
  197. package/dist/model/parser/ModelParser.d.ts +0 -71
  198. package/dist/model/parser/ModelParser.js +0 -209
  199. package/dist/model/parser/PredicatesParser.d.ts +0 -75
  200. package/dist/model/parser/PredicatesParser.js +0 -45
  201. package/dist/model/parser/SpecificationParser.d.ts +0 -53
  202. package/dist/model/parser/SpecificationParser.js +0 -113
  203. package/dist/model/parser/ValueConverter.d.ts +0 -4
  204. package/dist/model/parser/ValueConverter.js +0 -12
  205. package/dist/model/parser/ViewsParser.d.ts +0 -112
  206. package/dist/model/parser/ViewsParser.js +0 -492
  207. package/dist/model-change/ModelChanges.d.ts +0 -18
  208. package/dist/model-change/ModelChanges.js +0 -129
  209. package/dist/model-change/changeElementStyle.d.ts +0 -16
  210. package/dist/model-change/changeElementStyle.js +0 -134
  211. package/dist/model-change/changeViewLayout.d.ts +0 -12
  212. package/dist/model-change/changeViewLayout.js +0 -28
  213. package/dist/model-change/removeManualLayoutV1.d.ts +0 -7
  214. package/dist/model-change/removeManualLayoutV1.js +0 -27
  215. package/dist/module.d.ts +0 -92
  216. package/dist/module.js +0 -143
  217. package/dist/protocol.d.ts +0 -289
  218. package/dist/protocol.js +0 -123
  219. package/dist/references/index.d.ts +0 -3
  220. package/dist/references/index.js +0 -3
  221. package/dist/references/name-provider.d.ts +0 -9
  222. package/dist/references/name-provider.js +0 -37
  223. package/dist/references/scope-computation.d.ts +0 -20
  224. package/dist/references/scope-computation.js +0 -288
  225. package/dist/references/scope-provider.d.ts +0 -40
  226. package/dist/references/scope-provider.js +0 -239
  227. package/dist/shared/NodeKindProvider.d.ts +0 -15
  228. package/dist/shared/NodeKindProvider.js +0 -57
  229. package/dist/shared/WorkspaceSymbolProvider.d.ts +0 -3
  230. package/dist/shared/WorkspaceSymbolProvider.js +0 -3
  231. package/dist/shared/index.d.ts +0 -2
  232. package/dist/shared/index.js +0 -2
  233. package/dist/test/index.d.ts +0 -1
  234. package/dist/test/index.js +0 -1
  235. package/dist/test/testServices.d.ts +0 -64
  236. package/dist/test/testServices.js +0 -210
  237. package/dist/utils/disposable.d.ts +0 -8
  238. package/dist/utils/disposable.js +0 -26
  239. package/dist/utils/elementRef.d.ts +0 -11
  240. package/dist/utils/elementRef.js +0 -33
  241. package/dist/utils/fqnRef.d.ts +0 -11
  242. package/dist/utils/fqnRef.js +0 -63
  243. package/dist/utils/index.d.ts +0 -11
  244. package/dist/utils/index.js +0 -35
  245. package/dist/utils/printDocs.d.ts +0 -2
  246. package/dist/utils/printDocs.js +0 -1
  247. package/dist/utils/projectId.d.ts +0 -4
  248. package/dist/utils/projectId.js +0 -16
  249. package/dist/utils/stringHash.d.ts +0 -1
  250. package/dist/utils/stringHash.js +0 -5
  251. package/dist/validation/DocumentValidator.d.ts +0 -11
  252. package/dist/validation/DocumentValidator.js +0 -17
  253. package/dist/validation/_shared.d.ts +0 -3
  254. package/dist/validation/_shared.js +0 -26
  255. package/dist/validation/deployment-checks.d.ts +0 -7
  256. package/dist/validation/deployment-checks.js +0 -140
  257. package/dist/validation/dynamic-view.d.ts +0 -6
  258. package/dist/validation/dynamic-view.js +0 -67
  259. package/dist/validation/element-ref.d.ts +0 -4
  260. package/dist/validation/element-ref.js +0 -12
  261. package/dist/validation/element.d.ts +0 -4
  262. package/dist/validation/element.js +0 -49
  263. package/dist/validation/imports.d.ts +0 -4
  264. package/dist/validation/imports.js +0 -46
  265. package/dist/validation/index.d.ts +0 -15
  266. package/dist/validation/index.js +0 -167
  267. package/dist/validation/property-checks.d.ts +0 -7
  268. package/dist/validation/property-checks.js +0 -108
  269. package/dist/validation/relation.d.ts +0 -6
  270. package/dist/validation/relation.js +0 -141
  271. package/dist/validation/specification.d.ts +0 -12
  272. package/dist/validation/specification.js +0 -190
  273. package/dist/validation/view-checks.d.ts +0 -4
  274. package/dist/validation/view-checks.js +0 -46
  275. package/dist/validation/view-predicates/fqn-expr-with.d.ts +0 -4
  276. package/dist/validation/view-predicates/fqn-expr-with.js +0 -43
  277. package/dist/validation/view-predicates/fqn-ref-expr.d.ts +0 -4
  278. package/dist/validation/view-predicates/fqn-ref-expr.js +0 -51
  279. package/dist/validation/view-predicates/incoming.d.ts +0 -4
  280. package/dist/validation/view-predicates/incoming.js +0 -16
  281. package/dist/validation/view-predicates/index.d.ts +0 -6
  282. package/dist/validation/view-predicates/index.js +0 -6
  283. package/dist/validation/view-predicates/outgoing.d.ts +0 -4
  284. package/dist/validation/view-predicates/outgoing.js +0 -20
  285. package/dist/validation/view-predicates/relation-expr.d.ts +0 -4
  286. package/dist/validation/view-predicates/relation-expr.js +0 -46
  287. package/dist/validation/view-predicates/relation-with.d.ts +0 -4
  288. package/dist/validation/view-predicates/relation-with.js +0 -16
  289. package/dist/validation/view.d.ts +0 -4
  290. package/dist/validation/view.js +0 -42
  291. package/dist/view-utils/assignNavigateTo.d.ts +0 -2
  292. package/dist/view-utils/assignNavigateTo.js +0 -27
  293. package/dist/view-utils/index.d.ts +0 -2
  294. package/dist/view-utils/index.js +0 -2
  295. package/dist/view-utils/manual-layout.d.ts +0 -13
  296. package/dist/view-utils/manual-layout.js +0 -149
  297. package/dist/views/ConfigurableLayouter.d.ts +0 -7
  298. package/dist/views/ConfigurableLayouter.js +0 -51
  299. package/dist/views/LikeC4ManualLayouts.d.ts +0 -42
  300. package/dist/views/LikeC4ManualLayouts.js +0 -209
  301. package/dist/views/LikeC4Views.d.ts +0 -89
  302. package/dist/views/LikeC4Views.js +0 -216
  303. package/dist/views/index.d.ts +0 -4
  304. package/dist/views/index.js +0 -11
  305. package/dist/workspace/AstNodeDescriptionProvider.d.ts +0 -7
  306. package/dist/workspace/AstNodeDescriptionProvider.js +0 -18
  307. package/dist/workspace/IndexManager.d.ts +0 -10
  308. package/dist/workspace/IndexManager.js +0 -26
  309. package/dist/workspace/LangiumDocuments.d.ts +0 -29
  310. package/dist/workspace/LangiumDocuments.js +0 -104
  311. package/dist/workspace/ProjectsManager.d.ts +0 -134
  312. package/dist/workspace/ProjectsManager.js +0 -610
  313. package/dist/workspace/WorkspaceManager.d.ts +0 -31
  314. package/dist/workspace/WorkspaceManager.js +0 -132
  315. package/dist/workspace/index.d.ts +0 -5
  316. package/dist/workspace/index.js +0 -5
@@ -1,133 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- //
3
- // Copyright (c) 2023-2025 Denis Davydkov
4
- // Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
5
- //
6
- // Portions of this file have been modified by NVIDIA CORPORATION & AFFILIATES.
7
- import { DefaultWeakMap, invariant, MultiMap } from '@likec4/core/utils';
8
- import { DocumentState, UriUtils } from 'langium';
9
- import { pipe } from 'remeda';
10
- import { DiagnosticSeverity } from 'vscode-languageserver-types';
11
- import { isLikeC4LangiumDocument } from '../ast';
12
- import { logger as rootLogger, logWarnError } from '../logger';
13
- import { BaseParser } from './parser/Base';
14
- import { DeploymentModelParser } from './parser/DeploymentModelParser';
15
- import { DeploymentViewParser } from './parser/DeploymentViewParser';
16
- import { ExpressionV2Parser } from './parser/FqnRefParser';
17
- import { GlobalsParser } from './parser/GlobalsParser';
18
- import { ImportsParser } from './parser/ImportsParser';
19
- import { ModelParser } from './parser/ModelParser';
20
- import { PredicatesParser } from './parser/PredicatesParser';
21
- import { SpecificationParser } from './parser/SpecificationParser';
22
- import { ViewsParser } from './parser/ViewsParser';
23
- const DocumentParserFromMixins = pipe(BaseParser, ExpressionV2Parser, ImportsParser, ModelParser, DeploymentModelParser, DeploymentViewParser, PredicatesParser, SpecificationParser, ViewsParser, GlobalsParser);
24
- export class DocumentParser extends DocumentParserFromMixins {
25
- }
26
- const logger = rootLogger.getChild('ModelParser');
27
- export class LikeC4ModelParser {
28
- services;
29
- cachedParsers = new DefaultWeakMap((doc) => this.createParser(doc));
30
- constructor(services) {
31
- this.services = services;
32
- services.shared.workspace.DocumentBuilder.onDocumentPhase(DocumentState.Linked, async (doc) => {
33
- if (this.cachedParsers.has(doc)) {
34
- logger.trace('Linked: clear cached parser {projectId} document {doc}', {
35
- projectId: doc.likec4ProjectId,
36
- doc: UriUtils.basename(doc.uri),
37
- });
38
- this.cachedParsers.delete(doc);
39
- }
40
- });
41
- services.shared.workspace.DocumentBuilder.onBuildPhase(DocumentState.Linked, async (docs) => {
42
- for (const doc of docs) {
43
- if (services.shared.workspace.ProjectsManager.isExcluded(doc)) {
44
- continue;
45
- }
46
- try {
47
- // Force create parser for linked document (if not yet created)
48
- this.parse(doc);
49
- }
50
- catch (error) {
51
- logWarnError(error);
52
- }
53
- }
54
- });
55
- // We need to clean up cached parser when document is validated and has errors
56
- // Because after that parser takes into account validation results
57
- services.shared.workspace.DocumentBuilder.onDocumentPhase(DocumentState.Validated, async (doc) => {
58
- if (doc.diagnostics?.some(d => d.severity === DiagnosticSeverity.Error) && this.cachedParsers.has(doc)) {
59
- logger.trace('Validated: clear cached parser {projectId} document {doc} because of errors', {
60
- projectId: doc.likec4ProjectId,
61
- doc: UriUtils.basename(doc.uri),
62
- });
63
- this.cachedParsers.delete(doc);
64
- }
65
- });
66
- }
67
- documents(projectId) {
68
- return this.services.shared.workspace.LangiumDocuments.projectDocuments(projectId).map(d => this.parse(d));
69
- }
70
- parse(doc) {
71
- const parser = this.forDocument(doc);
72
- return parser.doc;
73
- }
74
- forDocument(doc) {
75
- return this.cachedParsers.get(doc);
76
- }
77
- createParser(doc) {
78
- invariant(isLikeC4LangiumDocument(doc), `Document ${doc.uri.toString()} is not a LikeC4 document`);
79
- const docbasename = UriUtils.basename(doc.uri);
80
- if (doc.likec4ProjectId) {
81
- logger.trace(`create parser {projectId} document {doc}`, {
82
- projectId: doc.likec4ProjectId,
83
- doc: docbasename,
84
- });
85
- }
86
- else {
87
- logger.warn(`create parser for document without project {doc}`, { doc: doc.uri.fsPath });
88
- }
89
- if (doc.state < DocumentState.Linked) {
90
- logger.warn(`Document {doc} is not linked, state is {state}`, {
91
- doc: docbasename,
92
- state: doc.state,
93
- });
94
- }
95
- const props = {
96
- c4Specification: {
97
- tags: {},
98
- elements: {},
99
- relationships: {},
100
- colors: {},
101
- deployments: {},
102
- },
103
- c4Elements: [],
104
- c4ExtendElements: [],
105
- c4ExtendDeployments: [],
106
- c4ExtendRelations: [],
107
- c4Relations: [],
108
- c4Deployments: [],
109
- c4DeploymentRelations: [],
110
- c4Globals: {
111
- predicates: {},
112
- dynamicPredicates: {},
113
- styles: {},
114
- },
115
- c4Views: [],
116
- c4Imports: new MultiMap(Set),
117
- };
118
- doc = Object.assign(doc, props);
119
- const parser = new DocumentParser(this.services, doc);
120
- try {
121
- parser.parseSpecification();
122
- parser.parseImports();
123
- parser.parseModel();
124
- parser.parseGlobals();
125
- parser.parseDeployment();
126
- parser.parseViews();
127
- }
128
- catch (error) {
129
- throw new Error(`Error parsing document ${doc.uri.fsPath}`, { cause: error });
130
- }
131
- return parser;
132
- }
133
- }
@@ -1,69 +0,0 @@
1
- import type * as c4 from '@likec4/core';
2
- import { type MarkdownOrString } from '@likec4/core';
3
- import type { AstNode } from 'langium';
4
- import { type ParsedElementStyle, type ParsedLikeC4LangiumDocument, ast } from '../../ast';
5
- import type { LikeC4Services } from '../../module';
6
- import { type IsValidFn } from '../../validation';
7
- import type { Project } from '../../workspace/ProjectsManager';
8
- export type GConstructor<T = {}> = new (...args: any[]) => T;
9
- export declare function toSingleLine(str: string): string;
10
- export declare function toSingleLine(str: string | undefined | null): string | undefined;
11
- export declare function toSingleLine(str: ast.MarkdownOrString): MarkdownOrString;
12
- export declare function toSingleLine(str: ast.MarkdownOrString | undefined | null): MarkdownOrString | undefined;
13
- export declare function toSingleLine(str: ast.MarkdownOrString | string): MarkdownOrString | string;
14
- export declare function toSingleLine(str: ast.MarkdownOrString | string | undefined | null): MarkdownOrString | string | undefined;
15
- export declare function removeIndent(str: string): string;
16
- export declare function removeIndent(str: string | undefined): string | undefined;
17
- export declare function removeIndent(str: ast.MarkdownOrString): MarkdownOrString;
18
- export declare function removeIndent(str: ast.MarkdownOrString | undefined): MarkdownOrString | undefined;
19
- export declare function removeIndent(str: ast.MarkdownOrString | string): MarkdownOrString | string;
20
- export type Base = GConstructor<BaseParser>;
21
- export declare class BaseParser {
22
- readonly services: LikeC4Services;
23
- readonly doc: ParsedLikeC4LangiumDocument;
24
- isValid: IsValidFn;
25
- constructor(services: LikeC4Services, doc: ParsedLikeC4LangiumDocument);
26
- get project(): Project;
27
- resolveFqn(node: ast.FqnReferenceable): c4.Fqn;
28
- getAstNodePath(node: AstNode): string;
29
- getMetadata(metadataAstNode: ast.MetadataProperty | undefined): {
30
- [key: string]: string | string[];
31
- } | undefined;
32
- parseMarkdownOrString(markdownOrString: ast.MarkdownOrString | undefined): c4.MarkdownOrString | undefined;
33
- convertTags<E extends {
34
- tags?: ast.Tags;
35
- }>(withTags?: E): c4.NonEmptyArray<c4.Tag<string>> | null;
36
- parseTags<E extends {
37
- tags?: ast.Tags;
38
- }>(withTags?: E): c4.NonEmptyArray<c4.Tag> | null;
39
- convertLinks(source?: ast.LinkProperty['$container']): c4.Link[] | undefined;
40
- parseLinks(source?: ast.LinkProperty['$container']): c4.Link[] | undefined;
41
- parseIconProperty(prop: ast.IconProperty | undefined): c4.IconUrl | undefined;
42
- parseImageAlias(value: string): string | undefined;
43
- parseColorLiteral(astNode: ast.ColorLiteral): c4.ColorLiteral | undefined;
44
- parseElementStyle(elementProps: Array<ast.ElementProperty> | ast.ElementStyleProperty | undefined): ParsedElementStyle;
45
- parseStyleProps(styleProps: Array<ast.StyleProperty> | undefined): ParsedElementStyle;
46
- /**
47
- * Parse base properties: title, description and technology
48
- *
49
- * @param props - body properties (inside '{...}')
50
- * @param override - optional, inline properties (right on the node)
51
- * have higher priority and override body properties
52
- */
53
- parseBaseProps(props: {
54
- title?: ast.MarkdownOrString | undefined;
55
- summary?: ast.MarkdownOrString | undefined;
56
- description?: ast.MarkdownOrString | undefined;
57
- technology?: ast.MarkdownOrString | undefined;
58
- }, override?: {
59
- title?: string | undefined;
60
- summary?: string | undefined;
61
- description?: string | undefined;
62
- technology?: string | undefined;
63
- }): {
64
- title?: string;
65
- summary?: c4.MarkdownOrString;
66
- description?: c4.MarkdownOrString;
67
- technology?: string;
68
- };
69
- }
@@ -1,382 +0,0 @@
1
- import { exact, GlobalFqn, isNonEmptyArray, memoizeProp, nonexhaustive, nonNullable, } from '@likec4/core';
2
- import { filter, flatMap, groupBy, isArray, isBoolean, isEmpty, isNumber, isString, isTruthy, mapValues, pipe, unique, } from 'remeda';
3
- import { dedent } from 'strip-indent';
4
- import { hasLeadingSlash, hasProtocol, isRelative, joinRelativeURL, joinURL } from 'ufo';
5
- import { ast, parseAstOpacityProperty, parseAstPercent, parseAstSizeValue, parseMarkdownAsString, toColor, } from '../../ast';
6
- import { serverLogger } from '../../logger';
7
- import { projectIdFrom } from '../../utils';
8
- import { readStrictFqn } from '../../utils/elementRef';
9
- import { checksFromDiagnostics } from '../../validation';
10
- const logger = serverLogger.getChild('BaseParser');
11
- export function toSingleLine(str) {
12
- if (str === null || str === undefined) {
13
- return undefined;
14
- }
15
- const without = removeIndent(str);
16
- if (isString(without)) {
17
- return without.split('\n').join(' ');
18
- }
19
- if ('md' in without) {
20
- return {
21
- md: without.md.split('\n').join(' '),
22
- };
23
- }
24
- return {
25
- txt: without.txt.split('\n').join(' '),
26
- };
27
- }
28
- // export function removeIndent(str: ast.MarkdownOrString | string): MarkdownOrString | string
29
- export function removeIndent(str) {
30
- if (str === null || str === undefined) {
31
- return undefined;
32
- }
33
- switch (true) {
34
- case isString(str):
35
- return dedent(str).trim();
36
- case ast.isMarkdownOrString(str) && isTruthy(str.markdown):
37
- return {
38
- md: dedent(str.markdown).trim(),
39
- };
40
- case ast.isMarkdownOrString(str) && isTruthy(str.text):
41
- return {
42
- txt: dedent(str.text).trim(),
43
- };
44
- default:
45
- return undefined;
46
- }
47
- }
48
- export class BaseParser {
49
- services;
50
- doc;
51
- isValid;
52
- constructor(services, doc) {
53
- this.services = services;
54
- this.doc = doc;
55
- // do nothing
56
- this.isValid = checksFromDiagnostics(doc).isValid;
57
- }
58
- get project() {
59
- return memoizeProp(this, 'project', () => this.services.shared.workspace.ProjectsManager.getProject(this.doc));
60
- }
61
- resolveFqn(node) {
62
- if (ast.isImported(node)) {
63
- const project = projectIdFrom(node);
64
- const fqn = this.resolveFqn(nonNullable(node.imported.ref, `FqnRef is empty of imported: ${node.$cstNode?.text}`));
65
- this.doc.c4Imports.set(project, fqn);
66
- return GlobalFqn(project, fqn);
67
- }
68
- if (ast.isExtendElement(node)) {
69
- return readStrictFqn(node.element);
70
- }
71
- if (ast.isExtendDeployment(node)) {
72
- return readStrictFqn(node.deploymentNode);
73
- }
74
- if (ast.isDeploymentElement(node)) {
75
- return this.services.likec4.DeploymentsIndex.getFqn(node);
76
- }
77
- return this.services.likec4.FqnIndex.getFqn(node);
78
- }
79
- getAstNodePath(node) {
80
- return this.services.workspace.AstNodeLocator.getAstNodePath(node);
81
- }
82
- getMetadata(metadataAstNode) {
83
- if (!metadataAstNode || !this.isValid(metadataAstNode) || isEmpty(metadataAstNode.props)) {
84
- return undefined;
85
- }
86
- // Helper function to extract string values from MetadataValue
87
- const extractValues = (value) => {
88
- if (ast.isMarkdownOrString(value)) {
89
- const mdOrStr = removeIndent(value);
90
- if (!mdOrStr)
91
- return [];
92
- // Handle both string and MarkdownOrString types
93
- if (typeof mdOrStr === 'string') {
94
- return isTruthy(mdOrStr) ? [mdOrStr] : [];
95
- }
96
- else {
97
- // MarkdownOrString object with txt or md property
98
- const strValue = mdOrStr.md || mdOrStr.txt;
99
- return isTruthy(strValue) ? [strValue] : [];
100
- }
101
- }
102
- else if (ast.isMetadataArray(value)) {
103
- return value.values
104
- .map(v => removeIndent(v))
105
- .map(v => {
106
- if (typeof v === 'string') {
107
- return v;
108
- }
109
- else {
110
- // MarkdownOrString object
111
- return v.md || v.txt;
112
- }
113
- })
114
- .filter(isTruthy);
115
- }
116
- return [];
117
- };
118
- // Transform metadata attributes into key-value pairs
119
- const keyValuePairs = pipe(metadataAstNode.props, flatMap(p => extractValues(p.value).map(v => [p.key, v])), filter(([_, value]) => isTruthy(value)));
120
- if (isEmpty(keyValuePairs)) {
121
- return undefined;
122
- }
123
- // Group by key to handle duplicate keys
124
- const groupedData = pipe(keyValuePairs, groupBy(([key]) => key), mapValues(pairs => pairs.map(([_, value]) => value)));
125
- // Convert to final format: single values as string, multiple values as string[]
126
- const data = {};
127
- for (const [key, values] of Object.entries(groupedData)) {
128
- if (values && values.length > 0) {
129
- data[key] = values.length === 1 ? values[0] : values;
130
- }
131
- }
132
- return isEmpty(data) ? undefined : data;
133
- }
134
- parseMarkdownOrString(markdownOrString) {
135
- if (ast.isMarkdownOrString(markdownOrString)) {
136
- return removeIndent(markdownOrString);
137
- }
138
- return undefined;
139
- }
140
- convertTags(withTags) {
141
- return this.parseTags(withTags);
142
- }
143
- parseTags(withTags) {
144
- let iter = withTags?.tags;
145
- if (!iter) {
146
- return null;
147
- }
148
- let tags = [];
149
- while (iter) {
150
- try {
151
- if (this.isValid(iter)) {
152
- const values = iter.values.map(t => t.tag.ref?.name).filter(isTruthy);
153
- if (values.length > 0) {
154
- tags.push(...values);
155
- }
156
- }
157
- }
158
- catch {
159
- // ignore
160
- }
161
- iter = iter.prev;
162
- }
163
- return isNonEmptyArray(tags) ? unique(tags) : null;
164
- }
165
- convertLinks(source) {
166
- return this.parseLinks(source);
167
- }
168
- parseLinks(source) {
169
- if (!source?.props || source.props.length === 0) {
170
- return undefined;
171
- }
172
- return pipe(source.props, filter(ast.isLinkProperty), flatMap(p => {
173
- if (!this.isValid(p)) {
174
- return [];
175
- }
176
- const url = p.value;
177
- if (isTruthy(url)) {
178
- const title = isTruthy(p.title) ? toSingleLine(p.title) : undefined;
179
- const relative = this.services.lsp.DocumentLinkProvider.relativeLink(this.doc, url);
180
- return {
181
- url,
182
- ...(title && { title }),
183
- ...(relative && relative !== url && { relative }),
184
- };
185
- }
186
- return [];
187
- }));
188
- }
189
- parseIconProperty(prop) {
190
- if (!prop || !this.isValid(prop)) {
191
- return undefined;
192
- }
193
- const { libicon, value } = prop;
194
- switch (true) {
195
- case !!libicon: {
196
- const name = libicon.ref?.name;
197
- if (!name) {
198
- logger.warn(`Library icon ${libicon.$refText} is not a valid library icon`);
199
- return undefined;
200
- }
201
- return name;
202
- }
203
- case value && value === 'none': {
204
- return value;
205
- }
206
- case value && hasProtocol(value): {
207
- if (value.startsWith('file:')) {
208
- logger.warn(`Icon property '${value}' used the 'file' protocol which is not supported`);
209
- return undefined;
210
- }
211
- return value;
212
- }
213
- case value && value.startsWith('@'): {
214
- return this.parseImageAlias(value);
215
- }
216
- case value && isRelative(value): {
217
- return joinRelativeURL(this.doc.uri.toString(), '../', value);
218
- }
219
- case value && hasLeadingSlash(value): {
220
- return joinURL(this.project.folderUri.toString(), value);
221
- }
222
- default: {
223
- logger.warn(`Icon property '${value}' is not a valid URL, library icon, image alias or 'none'`);
224
- return undefined;
225
- }
226
- }
227
- }
228
- parseImageAlias(value) {
229
- // Extract the alias name (e.g., '@infra' from '@infra/backend.svg')
230
- const slashIndex = value.indexOf('/');
231
- const aliasName = slashIndex > 0 ? value.substring(0, slashIndex) : value;
232
- const remainingPath = slashIndex > 0 ? value.substring(slashIndex + 1) : '';
233
- // Get imageAliases from project config, or use default '@' -> './images' mapping
234
- const imageAliases = { '@': './images', ...this.project.config.imageAliases };
235
- // Look up the alias path
236
- const aliasPath = imageAliases[aliasName];
237
- if (!aliasPath) {
238
- logger.warn(`Image alias "${aliasName}" not found in project configuration`);
239
- return undefined;
240
- }
241
- // Combine the alias path with the remaining path
242
- const fullPath = remainingPath ? joinURL(aliasPath, remainingPath) : aliasPath;
243
- // Make it relative to the **project root**, not the current document.
244
- return joinURL(this.project.folderUri.toString(), fullPath);
245
- }
246
- parseColorLiteral(astNode) {
247
- if (!this.isValid(astNode)) {
248
- return undefined;
249
- }
250
- if (ast.isHexColor(astNode)) {
251
- return `#${astNode.hex}`;
252
- }
253
- if (ast.isRGBAColor(astNode)) {
254
- let alpha = isNumber(astNode.alpha) ? astNode.alpha : undefined;
255
- if (isString(astNode.alpha)) {
256
- alpha = parseAstPercent(astNode.alpha) / 100;
257
- }
258
- if (alpha !== undefined) {
259
- return `rgba(${astNode.red},${astNode.green},${astNode.blue},${alpha})`;
260
- }
261
- return `rgb(${astNode.red},${astNode.green},${astNode.blue})`;
262
- }
263
- nonexhaustive(astNode);
264
- }
265
- parseElementStyle(elementProps) {
266
- if (!elementProps) {
267
- return {};
268
- }
269
- if (isArray(elementProps)) {
270
- const style = this.parseStyleProps(elementProps.find(ast.isElementStyleProperty)?.props);
271
- // Property on element has higher priority than from style
272
- try {
273
- const iconProp = this.parseIconProperty(elementProps.find(ast.isIconProperty));
274
- if (iconProp) {
275
- style.icon = iconProp;
276
- }
277
- }
278
- catch (err) {
279
- logger.warn('Failed to parse icon property on element', { err });
280
- }
281
- return style;
282
- }
283
- return this.parseStyleProps(elementProps.props);
284
- }
285
- parseStyleProps(styleProps) {
286
- const result = {};
287
- if (!styleProps || styleProps.length === 0) {
288
- return result;
289
- }
290
- for (const prop of styleProps) {
291
- if (!this.isValid(prop)) {
292
- continue;
293
- }
294
- try {
295
- switch (true) {
296
- case ast.isBorderProperty(prop): {
297
- if (isTruthy(prop.value)) {
298
- result.border = prop.value;
299
- }
300
- break;
301
- }
302
- case ast.isColorProperty(prop): {
303
- const color = toColor(prop);
304
- if (isTruthy(color)) {
305
- result.color = color;
306
- }
307
- break;
308
- }
309
- case ast.isShapeProperty(prop): {
310
- if (isTruthy(prop.value)) {
311
- result.shape = prop.value;
312
- }
313
- break;
314
- }
315
- case ast.isIconProperty(prop): {
316
- const icon = this.parseIconProperty(prop);
317
- if (isTruthy(icon)) {
318
- result.icon = icon;
319
- }
320
- break;
321
- }
322
- case ast.isOpacityProperty(prop): {
323
- result.opacity = parseAstOpacityProperty(prop);
324
- break;
325
- }
326
- case ast.isMultipleProperty(prop): {
327
- result.multiple = isBoolean(prop.value) ? prop.value : false;
328
- break;
329
- }
330
- case ast.isShapeSizeProperty(prop): {
331
- if (isTruthy(prop.value)) {
332
- result.size = parseAstSizeValue(prop);
333
- }
334
- break;
335
- }
336
- case ast.isPaddingSizeProperty(prop): {
337
- if (isTruthy(prop.value)) {
338
- result.padding = parseAstSizeValue(prop);
339
- }
340
- break;
341
- }
342
- case ast.isTextSizeProperty(prop): {
343
- if (isTruthy(prop.value)) {
344
- result.textSize = parseAstSizeValue(prop);
345
- }
346
- break;
347
- }
348
- default:
349
- nonexhaustive(prop);
350
- }
351
- }
352
- catch (err) {
353
- logger.warn('Failed to parse style property', { err });
354
- }
355
- }
356
- return exact(result);
357
- }
358
- /**
359
- * Parse base properties: title, description and technology
360
- *
361
- * @param props - body properties (inside '{...}')
362
- * @param override - optional, inline properties (right on the node)
363
- * have higher priority and override body properties
364
- */
365
- parseBaseProps(props, override) {
366
- const title = removeIndent(override?.title ?? parseMarkdownAsString(props.title));
367
- const description = override?.description
368
- ? { txt: removeIndent(override.description) }
369
- : this.parseMarkdownOrString(props.description);
370
- const summary = override?.summary
371
- ? { txt: removeIndent(override.summary) }
372
- : this.parseMarkdownOrString(props.summary);
373
- const technology = toSingleLine(override?.technology) ??
374
- removeIndent(parseMarkdownAsString(props.technology));
375
- return exact({
376
- title,
377
- summary,
378
- description,
379
- technology,
380
- });
381
- }
382
- }
@@ -1,71 +0,0 @@
1
- import type * as c4 from '@likec4/core';
2
- import { FqnRef } from '@likec4/core';
3
- import { type ParsedAstDeployment, type ParsedAstDeploymentRelation, type ParsedAstExtend, ast } from '../../ast';
4
- import type { WithExpressionV2 } from './FqnRefParser';
5
- export type WithDeploymentModel = ReturnType<typeof DeploymentModelParser>;
6
- export declare function DeploymentModelParser<TBase extends WithExpressionV2>(B: TBase): {
7
- new (...args: any[]): {
8
- parseDeployment(): void;
9
- parseDeploymentNode(astNode: ast.DeploymentNode): ParsedAstDeployment.Node;
10
- parseDeployedInstance(astNode: ast.DeployedInstance): ParsedAstDeployment.Instance;
11
- parseExtendDeployment(astNode: ast.ExtendDeployment): ParsedAstExtend | null;
12
- _resolveDeploymentRelationSource(node: ast.DeploymentRelation): FqnRef;
13
- parseDeploymentRelation(astNode: ast.DeploymentRelation): ParsedAstDeploymentRelation;
14
- parseFqnRef(astNode: ast.FqnRef): c4.FqnRef;
15
- parseExpressionV2(astNode: ast.ExpressionV2): c4.Expression;
16
- parseFqnExprOrWith(astNode: ast.FqnExprOrWith): c4.FqnExpr.Any;
17
- parseFqnExprWith(astNode: ast.FqnExprWith): c4.FqnExpr.Custom;
18
- parseFqnExprOrWhere(astNode: ast.FqnExprOrWhere): c4.FqnExpr.OrWhere;
19
- parseFqnExprWhere(astNode: ast.FqnExprWhere): c4.FqnExpr.Where;
20
- parseFqnExpr(astNode: ast.FqnExpr): c4.FqnExpr;
21
- parseFqnRefExpr(astNode: ast.FqnRefExpr): c4.FqnExpr.NonWildcard;
22
- parseFqnExpressions(astNode: ast.FqnExpressions): c4.FqnExpr[];
23
- parseRelationExprOrWith(astNode: ast.RelationExprOrWith): c4.RelationExpr.Any;
24
- parseRelationExprWith(astNode: ast.RelationExprWith): c4.RelationExpr.Custom;
25
- parseCustomRelationProperties(custom: ast.CustomRelationProperties | undefined): import("type-fest").Except<c4.RelationExpr.Custom["customRelation"], "expr">;
26
- parseRelationExprOrWhere(astNode: ast.RelationExprOrWhere): c4.RelationExpr.OrWhere;
27
- parseRelationExprWhere(astNode: ast.RelationExprWhere): c4.RelationExpr.Where;
28
- parseRelationExpr(astNode: ast.RelationExpr): c4.RelationExpr.OrWhere;
29
- parseInlineKindCondition(astNode: ast.OutgoingRelationExpr): c4.WhereOperator | null;
30
- wrapInWhere(expr: c4.RelationExpr, condition: c4.WhereOperator | null): c4.RelationExpr.OrWhere;
31
- isValid: import("../../validation").IsValidFn;
32
- readonly services: import("../..").LikeC4Services;
33
- readonly doc: import("../../ast").ParsedLikeC4LangiumDocument;
34
- get project(): import("../../workspace").Project;
35
- resolveFqn(node: ast.FqnReferenceable): c4.Fqn;
36
- getAstNodePath(node: import("langium").AstNode): string;
37
- getMetadata(metadataAstNode: ast.MetadataProperty | undefined): {
38
- [key: string]: string | string[];
39
- } | undefined;
40
- parseMarkdownOrString(markdownOrString: ast.MarkdownOrString | undefined): c4.MarkdownOrString | undefined;
41
- convertTags<E extends {
42
- tags?: ast.Tags;
43
- }>(withTags?: E | undefined): c4.NonEmptyArray<c4.Tag<string>> | null;
44
- parseTags<E extends {
45
- tags?: ast.Tags;
46
- }>(withTags?: E): c4.NonEmptyArray<c4.Tag> | null;
47
- convertLinks(source?: ast.LinkProperty["$container"]): c4.Link[] | undefined;
48
- parseLinks(source?: ast.LinkProperty["$container"]): c4.Link[] | undefined;
49
- parseIconProperty(prop: ast.IconProperty | undefined): c4.IconUrl | undefined;
50
- parseImageAlias(value: string): string | undefined;
51
- parseColorLiteral(astNode: ast.ColorLiteral): c4.ColorLiteral | undefined;
52
- parseElementStyle(elementProps: Array<ast.ElementProperty> | ast.ElementStyleProperty | undefined): import("../../ast").ParsedElementStyle;
53
- parseStyleProps(styleProps: Array<ast.StyleProperty> | undefined): import("../../ast").ParsedElementStyle;
54
- parseBaseProps(props: {
55
- title?: ast.MarkdownOrString | undefined;
56
- summary?: ast.MarkdownOrString | undefined;
57
- description?: ast.MarkdownOrString | undefined;
58
- technology?: ast.MarkdownOrString | undefined;
59
- }, override?: {
60
- title?: string | undefined;
61
- summary?: string | undefined;
62
- description?: string | undefined;
63
- technology?: string | undefined;
64
- }): {
65
- title?: string;
66
- summary?: c4.MarkdownOrString;
67
- description?: c4.MarkdownOrString;
68
- technology?: string;
69
- };
70
- };
71
- } & TBase;