@likec4/language-server 1.47.0 → 1.49.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 (297) hide show
  1. package/browser/package.json +2 -2
  2. package/browser-worker/package.json +2 -2
  3. package/bundled/package.json +4 -0
  4. package/dist/THIRD-PARTY-LICENSES.md +178 -0
  5. package/dist/_chunks/ConfigurableLayouter.mjs +1 -0
  6. package/dist/_chunks/LikeC4FileSystem.mjs +3 -0
  7. package/dist/_chunks/LikeC4Views.mjs +34 -0
  8. package/dist/_chunks/ProjectsManager.mjs +1 -0
  9. package/dist/_chunks/WithMCPServer.mjs +481 -0
  10. package/dist/_chunks/icons.mjs +2 -0
  11. package/dist/_chunks/index.d.mts +3107 -0
  12. package/dist/_chunks/libs/@msgpack/msgpack.mjs +1 -0
  13. package/dist/_chunks/libs/eventemitter3.mjs +1 -0
  14. package/dist/_chunks/libs/fast-equals.mjs +1 -0
  15. package/dist/_chunks/libs/p-queue.mjs +1 -0
  16. package/dist/_chunks/libs/parse-ms.mjs +1 -0
  17. package/dist/_chunks/libs/picomatch.mjs +1 -0
  18. package/dist/_chunks/libs/pretty-ms.mjs +1 -0
  19. package/dist/_chunks/libs/remeda.mjs +1 -0
  20. package/dist/_chunks/libs/strip-indent.mjs +1 -0
  21. package/dist/_chunks/libs/ufo.mjs +1 -0
  22. package/dist/_chunks/logger.mjs +1 -0
  23. package/dist/_chunks/rolldown-runtime.mjs +1 -0
  24. package/dist/_chunks/utils.mjs +1 -0
  25. package/dist/browser/index.d.mts +10 -0
  26. package/dist/browser/index.mjs +1 -0
  27. package/dist/browser/worker.d.mts +1 -0
  28. package/dist/browser/worker.mjs +1 -0
  29. package/dist/bundled.d.mts +27 -0
  30. package/dist/bundled.mjs +1 -4853
  31. package/dist/filesystem/index.d.mts +2 -0
  32. package/dist/filesystem/index.mjs +1 -0
  33. package/dist/index.d.mts +39 -0
  34. package/dist/index.mjs +1 -0
  35. package/dist/likec4lib.d.mts +16 -0
  36. package/dist/likec4lib.mjs +1 -0
  37. package/dist/mcp/index.d.mts +2 -0
  38. package/dist/mcp/index.mjs +1 -0
  39. package/dist/module.d.mts +126 -0
  40. package/dist/module.mjs +1 -0
  41. package/dist/protocol.d.mts +315 -0
  42. package/dist/protocol.mjs +1 -0
  43. package/filesystem/package.json +4 -0
  44. package/likec4lib/package.json +2 -2
  45. package/mcp/package.json +4 -0
  46. package/module/package.json +4 -0
  47. package/package.json +128 -62
  48. package/protocol/package.json +2 -2
  49. package/LICENSE +0 -21
  50. package/dist/LikeC4LanguageServices.d.ts +0 -115
  51. package/dist/LikeC4LanguageServices.js +0 -164
  52. package/dist/Rpc.d.ts +0 -9
  53. package/dist/Rpc.js +0 -276
  54. package/dist/ast.d.ts +0 -226
  55. package/dist/ast.js +0 -264
  56. package/dist/browser-worker.d.ts +0 -1
  57. package/dist/browser-worker.js +0 -4
  58. package/dist/browser.d.ts +0 -10
  59. package/dist/browser.js +0 -34
  60. package/dist/bundled.d.ts +0 -8
  61. package/dist/bundled.js +0 -44
  62. package/dist/documentation/documentation-provider.d.ts +0 -8
  63. package/dist/documentation/documentation-provider.js +0 -51
  64. package/dist/documentation/index.d.ts +0 -1
  65. package/dist/documentation/index.js +0 -1
  66. package/dist/empty.d.ts +0 -2
  67. package/dist/empty.js +0 -2
  68. package/dist/filesystem/ChokidarWatcher.d.ts +0 -19
  69. package/dist/filesystem/ChokidarWatcher.js +0 -133
  70. package/dist/filesystem/FileSystemWatcher.d.ts +0 -19
  71. package/dist/filesystem/FileSystemWatcher.js +0 -14
  72. package/dist/filesystem/LikeC4FileSystem.d.ts +0 -3
  73. package/dist/filesystem/LikeC4FileSystem.js +0 -140
  74. package/dist/filesystem/index.d.ts +0 -55
  75. package/dist/filesystem/index.js +0 -29
  76. package/dist/formatting/LikeC4Formatter.d.ts +0 -59
  77. package/dist/formatting/LikeC4Formatter.js +0 -637
  78. package/dist/formatting/utils.d.ts +0 -6
  79. package/dist/formatting/utils.js +0 -18
  80. package/dist/generated/ast.d.ts +0 -1411
  81. package/dist/generated/ast.js +0 -2207
  82. package/dist/generated/grammar.d.ts +0 -6
  83. package/dist/generated/grammar.js +0 -7
  84. package/dist/generated/module.d.ts +0 -14
  85. package/dist/generated/module.js +0 -27
  86. package/dist/generated-lib/icons.d.ts +0 -1
  87. package/dist/generated-lib/icons.js +0 -18
  88. package/dist/index.d.ts +0 -37
  89. package/dist/index.js +0 -54
  90. package/dist/likec4lib.d.ts +0 -6
  91. package/dist/likec4lib.js +0 -7
  92. package/dist/logger.d.ts +0 -17
  93. package/dist/logger.js +0 -81
  94. package/dist/lsp/CodeActionProvider.d.ts +0 -14
  95. package/dist/lsp/CodeActionProvider.js +0 -33
  96. package/dist/lsp/CodeLensProvider.d.ts +0 -9
  97. package/dist/lsp/CodeLensProvider.js +0 -44
  98. package/dist/lsp/CompletionProvider.d.ts +0 -13
  99. package/dist/lsp/CompletionProvider.js +0 -238
  100. package/dist/lsp/DocumentHighlightProvider.d.ts +0 -9
  101. package/dist/lsp/DocumentHighlightProvider.js +0 -10
  102. package/dist/lsp/DocumentLinkProvider.d.ts +0 -11
  103. package/dist/lsp/DocumentLinkProvider.js +0 -58
  104. package/dist/lsp/DocumentSymbolProvider.d.ts +0 -33
  105. package/dist/lsp/DocumentSymbolProvider.js +0 -317
  106. package/dist/lsp/HoverProvider.d.ts +0 -10
  107. package/dist/lsp/HoverProvider.js +0 -106
  108. package/dist/lsp/RenameProvider.d.ts +0 -5
  109. package/dist/lsp/RenameProvider.js +0 -6
  110. package/dist/lsp/SemanticTokenProvider.d.ts +0 -19
  111. package/dist/lsp/SemanticTokenProvider.js +0 -305
  112. package/dist/lsp/index.d.ts +0 -8
  113. package/dist/lsp/index.js +0 -9
  114. package/dist/mcp/MCPServerFactory.d.ts +0 -8
  115. package/dist/mcp/MCPServerFactory.js +0 -73
  116. package/dist/mcp/NoopLikeC4MCPServer.d.ts +0 -9
  117. package/dist/mcp/NoopLikeC4MCPServer.js +0 -17
  118. package/dist/mcp/interfaces.d.ts +0 -13
  119. package/dist/mcp/interfaces.js +0 -4
  120. package/dist/mcp/server/StdioLikeC4MCPServer.d.ts +0 -16
  121. package/dist/mcp/server/StdioLikeC4MCPServer.js +0 -51
  122. package/dist/mcp/server/StreamableLikeC4MCPServer.d.ts +0 -16
  123. package/dist/mcp/server/StreamableLikeC4MCPServer.js +0 -121
  124. package/dist/mcp/server/WithMCPServer.d.ts +0 -4
  125. package/dist/mcp/server/WithMCPServer.js +0 -54
  126. package/dist/mcp/tools/_common.d.ts +0 -88
  127. package/dist/mcp/tools/_common.js +0 -49
  128. package/dist/mcp/tools/find-relationships.d.ts +0 -202
  129. package/dist/mcp/tools/find-relationships.js +0 -150
  130. package/dist/mcp/tools/list-projects.d.ts +0 -194
  131. package/dist/mcp/tools/list-projects.js +0 -62
  132. package/dist/mcp/tools/open-view.d.ts +0 -200
  133. package/dist/mcp/tools/open-view.js +0 -52
  134. package/dist/mcp/tools/read-deployment.d.ts +0 -200
  135. package/dist/mcp/tools/read-deployment.js +0 -150
  136. package/dist/mcp/tools/read-element.d.ts +0 -200
  137. package/dist/mcp/tools/read-element.js +0 -218
  138. package/dist/mcp/tools/read-project-summary.d.ts +0 -198
  139. package/dist/mcp/tools/read-project-summary.js +0 -176
  140. package/dist/mcp/tools/read-view.d.ts +0 -200
  141. package/dist/mcp/tools/read-view.js +0 -203
  142. package/dist/mcp/tools/search-element.d.ts +0 -198
  143. package/dist/mcp/tools/search-element.js +0 -177
  144. package/dist/mcp/utils.d.ts +0 -18
  145. package/dist/mcp/utils.js +0 -48
  146. package/dist/model/builder/MergedExtends.d.ts +0 -13
  147. package/dist/model/builder/MergedExtends.js +0 -74
  148. package/dist/model/builder/MergedSpecification.d.ts +0 -32
  149. package/dist/model/builder/MergedSpecification.js +0 -175
  150. package/dist/model/builder/buildModel.d.ts +0 -16
  151. package/dist/model/builder/buildModel.js +0 -245
  152. package/dist/model/deployments-index.d.ts +0 -10
  153. package/dist/model/deployments-index.js +0 -102
  154. package/dist/model/fqn-index.d.ts +0 -61
  155. package/dist/model/fqn-index.js +0 -253
  156. package/dist/model/index.d.ts +0 -6
  157. package/dist/model/index.js +0 -6
  158. package/dist/model/model-builder.d.ts +0 -54
  159. package/dist/model/model-builder.js +0 -233
  160. package/dist/model/model-locator.d.ts +0 -39
  161. package/dist/model/model-locator.js +0 -240
  162. package/dist/model/model-parser-where.d.ts +0 -4
  163. package/dist/model/model-parser-where.js +0 -81
  164. package/dist/model/model-parser.d.ts +0 -645
  165. package/dist/model/model-parser.js +0 -133
  166. package/dist/model/parser/Base.d.ts +0 -69
  167. package/dist/model/parser/Base.js +0 -382
  168. package/dist/model/parser/DeploymentModelParser.d.ts +0 -71
  169. package/dist/model/parser/DeploymentModelParser.js +0 -176
  170. package/dist/model/parser/DeploymentViewParser.d.ts +0 -75
  171. package/dist/model/parser/DeploymentViewParser.js +0 -86
  172. package/dist/model/parser/FqnRefParser.d.ts +0 -66
  173. package/dist/model/parser/FqnRefParser.js +0 -382
  174. package/dist/model/parser/GlobalsParser.d.ts +0 -109
  175. package/dist/model/parser/GlobalsParser.js +0 -84
  176. package/dist/model/parser/ImportsParser.d.ts +0 -46
  177. package/dist/model/parser/ImportsParser.js +0 -24
  178. package/dist/model/parser/ModelParser.d.ts +0 -71
  179. package/dist/model/parser/ModelParser.js +0 -209
  180. package/dist/model/parser/PredicatesParser.d.ts +0 -75
  181. package/dist/model/parser/PredicatesParser.js +0 -45
  182. package/dist/model/parser/SpecificationParser.d.ts +0 -53
  183. package/dist/model/parser/SpecificationParser.js +0 -113
  184. package/dist/model/parser/ValueConverter.d.ts +0 -4
  185. package/dist/model/parser/ValueConverter.js +0 -12
  186. package/dist/model/parser/ViewsParser.d.ts +0 -112
  187. package/dist/model/parser/ViewsParser.js +0 -492
  188. package/dist/model-change/ModelChanges.d.ts +0 -18
  189. package/dist/model-change/ModelChanges.js +0 -129
  190. package/dist/model-change/changeElementStyle.d.ts +0 -16
  191. package/dist/model-change/changeElementStyle.js +0 -134
  192. package/dist/model-change/changeViewLayout.d.ts +0 -12
  193. package/dist/model-change/changeViewLayout.js +0 -28
  194. package/dist/model-change/removeManualLayoutV1.d.ts +0 -7
  195. package/dist/model-change/removeManualLayoutV1.js +0 -27
  196. package/dist/module.d.ts +0 -92
  197. package/dist/module.js +0 -143
  198. package/dist/protocol.d.ts +0 -289
  199. package/dist/protocol.js +0 -123
  200. package/dist/references/index.d.ts +0 -3
  201. package/dist/references/index.js +0 -3
  202. package/dist/references/name-provider.d.ts +0 -9
  203. package/dist/references/name-provider.js +0 -37
  204. package/dist/references/scope-computation.d.ts +0 -20
  205. package/dist/references/scope-computation.js +0 -288
  206. package/dist/references/scope-provider.d.ts +0 -40
  207. package/dist/references/scope-provider.js +0 -239
  208. package/dist/shared/NodeKindProvider.d.ts +0 -15
  209. package/dist/shared/NodeKindProvider.js +0 -57
  210. package/dist/shared/WorkspaceSymbolProvider.d.ts +0 -3
  211. package/dist/shared/WorkspaceSymbolProvider.js +0 -3
  212. package/dist/shared/index.d.ts +0 -2
  213. package/dist/shared/index.js +0 -2
  214. package/dist/test/index.d.ts +0 -1
  215. package/dist/test/index.js +0 -1
  216. package/dist/test/testServices.d.ts +0 -64
  217. package/dist/test/testServices.js +0 -210
  218. package/dist/utils/disposable.d.ts +0 -8
  219. package/dist/utils/disposable.js +0 -26
  220. package/dist/utils/elementRef.d.ts +0 -11
  221. package/dist/utils/elementRef.js +0 -33
  222. package/dist/utils/fqnRef.d.ts +0 -11
  223. package/dist/utils/fqnRef.js +0 -63
  224. package/dist/utils/index.d.ts +0 -11
  225. package/dist/utils/index.js +0 -35
  226. package/dist/utils/printDocs.d.ts +0 -2
  227. package/dist/utils/printDocs.js +0 -1
  228. package/dist/utils/projectId.d.ts +0 -4
  229. package/dist/utils/projectId.js +0 -16
  230. package/dist/utils/stringHash.d.ts +0 -1
  231. package/dist/utils/stringHash.js +0 -5
  232. package/dist/validation/DocumentValidator.d.ts +0 -11
  233. package/dist/validation/DocumentValidator.js +0 -17
  234. package/dist/validation/_shared.d.ts +0 -3
  235. package/dist/validation/_shared.js +0 -26
  236. package/dist/validation/deployment-checks.d.ts +0 -7
  237. package/dist/validation/deployment-checks.js +0 -140
  238. package/dist/validation/dynamic-view.d.ts +0 -6
  239. package/dist/validation/dynamic-view.js +0 -67
  240. package/dist/validation/element-ref.d.ts +0 -4
  241. package/dist/validation/element-ref.js +0 -12
  242. package/dist/validation/element.d.ts +0 -4
  243. package/dist/validation/element.js +0 -49
  244. package/dist/validation/imports.d.ts +0 -4
  245. package/dist/validation/imports.js +0 -46
  246. package/dist/validation/index.d.ts +0 -15
  247. package/dist/validation/index.js +0 -167
  248. package/dist/validation/property-checks.d.ts +0 -7
  249. package/dist/validation/property-checks.js +0 -108
  250. package/dist/validation/relation.d.ts +0 -6
  251. package/dist/validation/relation.js +0 -141
  252. package/dist/validation/specification.d.ts +0 -12
  253. package/dist/validation/specification.js +0 -190
  254. package/dist/validation/view-checks.d.ts +0 -4
  255. package/dist/validation/view-checks.js +0 -46
  256. package/dist/validation/view-predicates/fqn-expr-with.d.ts +0 -4
  257. package/dist/validation/view-predicates/fqn-expr-with.js +0 -43
  258. package/dist/validation/view-predicates/fqn-ref-expr.d.ts +0 -4
  259. package/dist/validation/view-predicates/fqn-ref-expr.js +0 -51
  260. package/dist/validation/view-predicates/incoming.d.ts +0 -4
  261. package/dist/validation/view-predicates/incoming.js +0 -16
  262. package/dist/validation/view-predicates/index.d.ts +0 -6
  263. package/dist/validation/view-predicates/index.js +0 -6
  264. package/dist/validation/view-predicates/outgoing.d.ts +0 -4
  265. package/dist/validation/view-predicates/outgoing.js +0 -20
  266. package/dist/validation/view-predicates/relation-expr.d.ts +0 -4
  267. package/dist/validation/view-predicates/relation-expr.js +0 -46
  268. package/dist/validation/view-predicates/relation-with.d.ts +0 -4
  269. package/dist/validation/view-predicates/relation-with.js +0 -16
  270. package/dist/validation/view.d.ts +0 -4
  271. package/dist/validation/view.js +0 -42
  272. package/dist/view-utils/assignNavigateTo.d.ts +0 -2
  273. package/dist/view-utils/assignNavigateTo.js +0 -27
  274. package/dist/view-utils/index.d.ts +0 -2
  275. package/dist/view-utils/index.js +0 -2
  276. package/dist/view-utils/manual-layout.d.ts +0 -13
  277. package/dist/view-utils/manual-layout.js +0 -149
  278. package/dist/views/ConfigurableLayouter.d.ts +0 -7
  279. package/dist/views/ConfigurableLayouter.js +0 -51
  280. package/dist/views/LikeC4ManualLayouts.d.ts +0 -42
  281. package/dist/views/LikeC4ManualLayouts.js +0 -209
  282. package/dist/views/LikeC4Views.d.ts +0 -89
  283. package/dist/views/LikeC4Views.js +0 -216
  284. package/dist/views/index.d.ts +0 -4
  285. package/dist/views/index.js +0 -11
  286. package/dist/workspace/AstNodeDescriptionProvider.d.ts +0 -7
  287. package/dist/workspace/AstNodeDescriptionProvider.js +0 -18
  288. package/dist/workspace/IndexManager.d.ts +0 -10
  289. package/dist/workspace/IndexManager.js +0 -26
  290. package/dist/workspace/LangiumDocuments.d.ts +0 -29
  291. package/dist/workspace/LangiumDocuments.js +0 -104
  292. package/dist/workspace/ProjectsManager.d.ts +0 -134
  293. package/dist/workspace/ProjectsManager.js +0 -610
  294. package/dist/workspace/WorkspaceManager.d.ts +0 -31
  295. package/dist/workspace/WorkspaceManager.js +0 -132
  296. package/dist/workspace/index.d.ts +0 -5
  297. 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;