@likec4/language-server 1.2.0 → 1.2.2

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 (173) hide show
  1. package/package.json +8 -10
  2. package/src/Rpc.ts +108 -0
  3. package/src/ast.ts +443 -0
  4. package/src/browser/index.ts +30 -0
  5. package/src/elementRef.ts +26 -0
  6. package/src/generated/ast.ts +1632 -0
  7. package/src/generated/grammar.ts +10 -0
  8. package/src/generated/module.ts +32 -0
  9. package/src/index.ts +4 -0
  10. package/src/like-c4.langium +395 -0
  11. package/src/logger.ts +54 -0
  12. package/src/lsp/CodeLensProvider.ts +51 -0
  13. package/src/lsp/DocumentHighlightProvider.ts +12 -0
  14. package/src/lsp/DocumentLinkProvider.test.ts +66 -0
  15. package/src/lsp/DocumentLinkProvider.ts +53 -0
  16. package/src/lsp/DocumentSymbolProvider.ts +201 -0
  17. package/src/lsp/HoverProvider.ts +58 -0
  18. package/{dist/lsp/SemanticTokenProvider.js → src/lsp/SemanticTokenProvider.ts} +57 -42
  19. package/src/lsp/index.ts +6 -0
  20. package/src/model/fqn-computation.ts +47 -0
  21. package/src/model/fqn-index.ts +161 -0
  22. package/src/model/index.ts +5 -0
  23. package/src/model/model-builder.ts +447 -0
  24. package/src/model/model-locator.ts +130 -0
  25. package/src/model/model-parser.ts +580 -0
  26. package/src/model-change/ModelChanges.ts +120 -0
  27. package/src/model-change/changeElementStyle.ts +176 -0
  28. package/src/model-change/changeViewLayout.ts +41 -0
  29. package/src/module.ts +197 -0
  30. package/src/node/index.ts +20 -0
  31. package/src/protocol.ts +87 -0
  32. package/src/references/index.ts +2 -0
  33. package/src/references/scope-computation.ts +142 -0
  34. package/src/references/scope-provider.ts +166 -0
  35. package/src/shared/NodeKindProvider.ts +67 -0
  36. package/src/shared/WorkspaceManager.ts +39 -0
  37. package/src/shared/WorkspaceSymbolProvider.ts +3 -0
  38. package/src/shared/index.ts +3 -0
  39. package/src/test/index.ts +1 -0
  40. package/src/test/testServices.ts +119 -0
  41. package/src/utils/index.ts +1 -0
  42. package/src/utils/printDocs.ts +3 -0
  43. package/src/utils/stringHash.ts +6 -0
  44. package/{dist/validation/dynamic-view-rule.js → src/validation/dynamic-view-rule.ts} +14 -11
  45. package/src/validation/dynamic-view-step.ts +39 -0
  46. package/src/validation/element.ts +52 -0
  47. package/{dist/validation/index.js → src/validation/index.ts} +22 -18
  48. package/src/validation/property-checks.ts +17 -0
  49. package/src/validation/relation.ts +57 -0
  50. package/src/validation/specification.ts +118 -0
  51. package/src/validation/view-predicates/custom-element-expr.ts +21 -0
  52. package/{dist/validation/view-predicates/expanded-element.js → src/validation/view-predicates/expanded-element.ts} +18 -13
  53. package/src/validation/view-predicates/incoming.ts +19 -0
  54. package/src/validation/view-predicates/index.ts +4 -0
  55. package/src/validation/view-predicates/outgoing.ts +19 -0
  56. package/src/validation/view.ts +26 -0
  57. package/src/view-utils/assignNavigateTo.ts +30 -0
  58. package/src/view-utils/index.ts +3 -0
  59. package/src/view-utils/resolve-extended-views.ts +57 -0
  60. package/src/view-utils/resolve-relative-paths.ts +84 -0
  61. package/dist/Rpc.d.ts +0 -10
  62. package/dist/Rpc.js +0 -98
  63. package/dist/ast.d.ts +0 -149
  64. package/dist/ast.js +0 -271
  65. package/dist/browser/index.d.ts +0 -9
  66. package/dist/browser/index.js +0 -16
  67. package/dist/elementRef.d.ts +0 -12
  68. package/dist/elementRef.js +0 -15
  69. package/dist/generated/ast.d.ts +0 -615
  70. package/dist/generated/ast.js +0 -957
  71. package/dist/generated/grammar.d.ts +0 -7
  72. package/dist/generated/grammar.js +0 -3
  73. package/dist/generated/module.d.ts +0 -14
  74. package/dist/generated/module.js +0 -22
  75. package/dist/index.d.ts +0 -5
  76. package/dist/index.js +0 -2
  77. package/dist/logger.d.ts +0 -12
  78. package/dist/logger.js +0 -51
  79. package/dist/lsp/CodeLensProvider.d.ts +0 -10
  80. package/dist/lsp/CodeLensProvider.js +0 -40
  81. package/dist/lsp/DocumentHighlightProvider.d.ts +0 -10
  82. package/dist/lsp/DocumentHighlightProvider.js +0 -10
  83. package/dist/lsp/DocumentLinkProvider.d.ts +0 -11
  84. package/dist/lsp/DocumentLinkProvider.js +0 -41
  85. package/dist/lsp/DocumentLinkProvider.test.d.ts +0 -2
  86. package/dist/lsp/DocumentLinkProvider.test.js +0 -54
  87. package/dist/lsp/DocumentSymbolProvider.d.ts +0 -22
  88. package/dist/lsp/DocumentSymbolProvider.js +0 -189
  89. package/dist/lsp/HoverProvider.d.ts +0 -10
  90. package/dist/lsp/HoverProvider.js +0 -36
  91. package/dist/lsp/SemanticTokenProvider.d.ts +0 -8
  92. package/dist/lsp/index.d.ts +0 -7
  93. package/dist/lsp/index.js +0 -6
  94. package/dist/model/fqn-computation.d.ts +0 -4
  95. package/dist/model/fqn-computation.js +0 -43
  96. package/dist/model/fqn-index.d.ts +0 -26
  97. package/dist/model/fqn-index.js +0 -114
  98. package/dist/model/index.d.ts +0 -6
  99. package/dist/model/index.js +0 -5
  100. package/dist/model/model-builder.d.ts +0 -20
  101. package/dist/model/model-builder.js +0 -365
  102. package/dist/model/model-locator.d.ts +0 -22
  103. package/dist/model/model-locator.js +0 -115
  104. package/dist/model/model-parser.d.ts +0 -29
  105. package/dist/model/model-parser.js +0 -520
  106. package/dist/model-change/ModelChanges.d.ts +0 -16
  107. package/dist/model-change/ModelChanges.js +0 -106
  108. package/dist/model-change/changeElementStyle.d.ts +0 -18
  109. package/dist/model-change/changeElementStyle.js +0 -141
  110. package/dist/model-change/changeViewLayout.d.ts +0 -13
  111. package/dist/model-change/changeViewLayout.js +0 -29
  112. package/dist/module.d.ts +0 -59
  113. package/dist/module.js +0 -121
  114. package/dist/node/index.d.ts +0 -6
  115. package/dist/node/index.js +0 -13
  116. package/dist/protocol.d.ts +0 -58
  117. package/dist/protocol.js +0 -14
  118. package/dist/references/index.d.ts +0 -3
  119. package/dist/references/index.js +0 -2
  120. package/dist/references/scope-computation.d.ts +0 -11
  121. package/dist/references/scope-computation.js +0 -111
  122. package/dist/references/scope-provider.d.ts +0 -18
  123. package/dist/references/scope-provider.js +0 -136
  124. package/dist/shared/NodeKindProvider.d.ts +0 -16
  125. package/dist/shared/NodeKindProvider.js +0 -60
  126. package/dist/shared/WorkspaceManager.d.ts +0 -17
  127. package/dist/shared/WorkspaceManager.js +0 -29
  128. package/dist/shared/WorkspaceSymbolProvider.d.ts +0 -4
  129. package/dist/shared/WorkspaceSymbolProvider.js +0 -3
  130. package/dist/shared/index.d.ts +0 -4
  131. package/dist/shared/index.js +0 -3
  132. package/dist/test/index.d.ts +0 -2
  133. package/dist/test/index.js +0 -1
  134. package/dist/test/testServices.d.ts +0 -23
  135. package/dist/test/testServices.js +0 -102
  136. package/dist/utils/index.d.ts +0 -2
  137. package/dist/utils/index.js +0 -1
  138. package/dist/utils/printDocs.d.ts +0 -3
  139. package/dist/utils/printDocs.js +0 -1
  140. package/dist/utils/stringHash.d.ts +0 -2
  141. package/dist/utils/stringHash.js +0 -5
  142. package/dist/validation/dynamic-view-rule.d.ts +0 -5
  143. package/dist/validation/dynamic-view-step.d.ts +0 -5
  144. package/dist/validation/dynamic-view-step.js +0 -33
  145. package/dist/validation/element.d.ts +0 -6
  146. package/dist/validation/element.js +0 -38
  147. package/dist/validation/index.d.ts +0 -3
  148. package/dist/validation/property-checks.d.ts +0 -5
  149. package/dist/validation/property-checks.js +0 -11
  150. package/dist/validation/relation.d.ts +0 -5
  151. package/dist/validation/relation.js +0 -50
  152. package/dist/validation/specification.d.ts +0 -10
  153. package/dist/validation/specification.js +0 -97
  154. package/dist/validation/view-predicates/custom-element-expr.d.ts +0 -5
  155. package/dist/validation/view-predicates/custom-element-expr.js +0 -16
  156. package/dist/validation/view-predicates/expanded-element.d.ts +0 -5
  157. package/dist/validation/view-predicates/incoming.d.ts +0 -5
  158. package/dist/validation/view-predicates/incoming.js +0 -14
  159. package/dist/validation/view-predicates/index.d.ts +0 -5
  160. package/dist/validation/view-predicates/index.js +0 -4
  161. package/dist/validation/view-predicates/outgoing.d.ts +0 -5
  162. package/dist/validation/view-predicates/outgoing.js +0 -14
  163. package/dist/validation/view.d.ts +0 -5
  164. package/dist/validation/view.js +0 -16
  165. package/dist/view-utils/assignNavigateTo.d.ts +0 -3
  166. package/dist/view-utils/assignNavigateTo.js +0 -24
  167. package/dist/view-utils/index.d.ts +0 -4
  168. package/dist/view-utils/index.js +0 -3
  169. package/dist/view-utils/resolve-extended-views.d.ts +0 -7
  170. package/dist/view-utils/resolve-extended-views.js +0 -41
  171. package/dist/view-utils/resolve-relative-paths.d.ts +0 -3
  172. package/dist/view-utils/resolve-relative-paths.js +0 -75
  173. /package/{dist → src}/reset.d.ts +0 -0
@@ -1,365 +0,0 @@
1
- import {
2
- compareByFqnHierarchically,
3
- isElementView,
4
- isStrictElementView,
5
- parentFqn
6
- } from "@likec4/core";
7
- import { computeDynamicView, computeView, LikeC4ModelGraph } from "@likec4/graph";
8
- import { deepEqual as eq } from "fast-equals";
9
- import { DocumentState, interruptAndCheck } from "langium";
10
- import {
11
- filter,
12
- find,
13
- flatMap,
14
- forEach,
15
- isNullish,
16
- isTruthy,
17
- map,
18
- mapToObj,
19
- pipe,
20
- prop,
21
- reduce,
22
- sort,
23
- values
24
- } from "remeda";
25
- import { Disposable } from "vscode-languageserver";
26
- import { isParsedLikeC4LangiumDocument } from "../ast.js";
27
- import { logError, logger, logWarnError } from "../logger.js";
28
- import { printDocs } from "../utils/printDocs.js";
29
- import { assignNavigateTo, resolveRelativePaths, resolveRulesExtendedViews } from "../view-utils/index.js";
30
- function buildModel(services, docs) {
31
- const c4Specification = {
32
- kinds: {},
33
- relationships: {}
34
- };
35
- forEach(map(docs, prop("c4Specification")), (spec) => {
36
- Object.assign(c4Specification.kinds, spec.kinds);
37
- Object.assign(c4Specification.relationships, spec.relationships);
38
- });
39
- const resolveLinks = (doc, links) => {
40
- return links.map((l) => services.lsp.DocumentLinkProvider.resolveLink(doc, l));
41
- };
42
- const toModelElement = (doc) => {
43
- return ({
44
- tags,
45
- links,
46
- style: {
47
- color,
48
- shape,
49
- icon,
50
- opacity,
51
- border
52
- },
53
- id,
54
- kind,
55
- title,
56
- description,
57
- technology
58
- }) => {
59
- try {
60
- const __kind = c4Specification.kinds[kind];
61
- if (!__kind) {
62
- logger.warn(`No kind '${kind}' found for ${id}`);
63
- return null;
64
- }
65
- color ??= __kind.color;
66
- shape ??= __kind.shape;
67
- icon ??= __kind.icon;
68
- opacity ??= __kind.opacity;
69
- border ??= __kind.border;
70
- return {
71
- ...color && { color },
72
- ...shape && { shape },
73
- ...icon && { icon },
74
- style: {
75
- ...border && { border },
76
- ...opacity && { opacity }
77
- },
78
- links: links ? resolveLinks(doc, links) : null,
79
- tags: tags ?? null,
80
- technology: technology ?? null,
81
- description: description ?? null,
82
- title,
83
- kind,
84
- id
85
- };
86
- } catch (e) {
87
- logWarnError(e);
88
- }
89
- return null;
90
- };
91
- };
92
- const elements = pipe(
93
- docs,
94
- flatMap((d) => d.c4Elements.map(toModelElement(d))),
95
- filter(isTruthy),
96
- sort(compareByFqnHierarchically),
97
- reduce(
98
- (acc, el) => {
99
- const parent = parentFqn(el.id);
100
- if (parent && isNullish(acc[parent])) {
101
- logWarnError(`No parent found for ${el.id}`);
102
- return acc;
103
- }
104
- if (el.id in acc) {
105
- logWarnError(`Duplicate element id: ${el.id}`);
106
- return acc;
107
- }
108
- acc[el.id] = el;
109
- return acc;
110
- },
111
- {}
112
- )
113
- );
114
- const toModelRelation = (doc) => {
115
- return ({
116
- astPath,
117
- source,
118
- target,
119
- kind,
120
- links,
121
- id,
122
- ...model
123
- }) => {
124
- if (isNullish(elements[source]) || isNullish(elements[target])) {
125
- return null;
126
- }
127
- if (!!kind && kind in c4Specification.relationships) {
128
- return {
129
- ...links && { links: resolveLinks(doc, links) },
130
- ...c4Specification.relationships[kind],
131
- ...model,
132
- source,
133
- target,
134
- kind,
135
- id
136
- };
137
- }
138
- return {
139
- ...links && { links: resolveLinks(doc, links) },
140
- ...model,
141
- source,
142
- target,
143
- id
144
- };
145
- };
146
- };
147
- const relations = pipe(
148
- flatMap(docs, (d) => map(d.c4Relations, toModelRelation(d))),
149
- filter(isTruthy),
150
- mapToObj((r) => [r.id, r])
151
- );
152
- const toC4View = (doc) => {
153
- const docUri = doc.uri.toString();
154
- return (parsedAstView) => {
155
- let {
156
- id,
157
- title,
158
- description,
159
- tags,
160
- links,
161
- // ignore this property
162
- astPath: _ignore,
163
- // model should include discriminant __
164
- ...model
165
- } = parsedAstView;
166
- if (parsedAstView.__ === "element" && isNullish(title) && "viewOf" in parsedAstView) {
167
- title ??= elements[parsedAstView.viewOf]?.title ?? null;
168
- }
169
- if (isNullish(title) && id === "index") {
170
- title = "Landscape view";
171
- }
172
- return {
173
- id,
174
- title,
175
- description,
176
- tags,
177
- links: links ? resolveLinks(doc, links) : null,
178
- docUri,
179
- ...model
180
- };
181
- };
182
- };
183
- const views = pipe(
184
- docs,
185
- flatMap((d) => map(d.c4Views, toC4View(d))),
186
- resolveRelativePaths,
187
- mapToObj((v) => [v.id, v]),
188
- resolveRulesExtendedViews
189
- );
190
- if (!("index" in views)) {
191
- views["index"] = {
192
- __: "element",
193
- id: "index",
194
- title: "Landscape",
195
- description: null,
196
- tags: null,
197
- links: null,
198
- rules: [
199
- {
200
- include: [
201
- {
202
- wildcard: true
203
- }
204
- ]
205
- }
206
- ]
207
- };
208
- }
209
- return {
210
- elements,
211
- relations,
212
- views
213
- };
214
- }
215
- const RAW_MODEL_CACHE = "LikeC4RawModel";
216
- const MODEL_CACHE = "LikeC4Model";
217
- export class LikeC4ModelBuilder {
218
- constructor(services) {
219
- this.services = services;
220
- this.langiumDocuments = services.shared.workspace.LangiumDocuments;
221
- const parser = services.likec4.ModelParser;
222
- services.shared.workspace.DocumentBuilder.onUpdate((changed, deleted) => {
223
- if (deleted.length > 0) {
224
- this.notifyListeners(deleted);
225
- }
226
- });
227
- services.shared.workspace.DocumentBuilder.onBuildPhase(
228
- DocumentState.Validated,
229
- async (docs, _cancelToken) => {
230
- let parsed = [];
231
- logger.debug(`[ModelBuilder] onValidated (${docs.length} docs)
232
- ${printDocs(docs)}`);
233
- for (const doc of parser.parse(docs)) {
234
- parsed.push(doc.uri);
235
- }
236
- if (parsed.length > 0) {
237
- this.notifyListeners(parsed);
238
- }
239
- return await Promise.resolve();
240
- }
241
- );
242
- logger.debug(`[ModelBuilder] Created`);
243
- }
244
- langiumDocuments;
245
- listeners = [];
246
- async buildModel(cancelToken) {
247
- return await this.services.shared.workspace.WorkspaceLock.read(async () => {
248
- if (cancelToken) {
249
- await interruptAndCheck(cancelToken);
250
- }
251
- const cache = this.services.WorkspaceCache;
252
- return cache.get(RAW_MODEL_CACHE, () => {
253
- const docs = this.documents();
254
- if (docs.length === 0) {
255
- logger.debug("[ModelBuilder] No documents to build model from");
256
- return null;
257
- }
258
- logger.debug(`[ModelBuilder] buildModel from ${docs.length} docs:
259
- ${printDocs(docs)}`);
260
- return buildModel(this.services, docs);
261
- });
262
- });
263
- }
264
- previousViews = {};
265
- async buildComputedModel(cancelToken) {
266
- const model = await this.buildModel(cancelToken);
267
- if (!model) {
268
- return null;
269
- }
270
- return await this.services.shared.workspace.WorkspaceLock.read(async () => {
271
- if (cancelToken) {
272
- await interruptAndCheck(cancelToken);
273
- }
274
- const cache = this.services.WorkspaceCache;
275
- const viewsCache = this.services.WorkspaceCache;
276
- return cache.get(MODEL_CACHE, () => {
277
- const index = new LikeC4ModelGraph(model);
278
- const allViews = [];
279
- for (const view of values(model.views)) {
280
- const result = isElementView(view) ? computeView(view, index) : computeDynamicView(view, index);
281
- if (!result.isSuccess) {
282
- logWarnError(result.error);
283
- continue;
284
- }
285
- allViews.push(result.view);
286
- }
287
- assignNavigateTo(allViews);
288
- const views = mapToObj(allViews, (v) => {
289
- const previous = this.previousViews[v.id];
290
- const view = previous && eq(v, previous) ? previous : v;
291
- viewsCache.set(computedViewKey(v.id), view);
292
- return [v.id, view];
293
- });
294
- this.previousViews = { ...views };
295
- return {
296
- elements: model.elements,
297
- relations: model.relations,
298
- views
299
- };
300
- });
301
- });
302
- }
303
- async computeView(viewId, cancelToken) {
304
- const model = await this.buildModel(cancelToken);
305
- const view = model?.views[viewId];
306
- if (!view) {
307
- logger.warn(`[ModelBuilder] Cannot find view ${viewId}`);
308
- return null;
309
- }
310
- return await this.services.shared.workspace.WorkspaceLock.read(async () => {
311
- if (cancelToken) {
312
- await interruptAndCheck(cancelToken);
313
- }
314
- const cache = this.services.WorkspaceCache;
315
- return cache.get(computedViewKey(viewId), () => {
316
- const index = new LikeC4ModelGraph(model);
317
- const result = isElementView(view) ? computeView(view, index) : computeDynamicView(view, index);
318
- if (!result.isSuccess) {
319
- logError(result.error);
320
- return null;
321
- }
322
- const allElementViews = values(model.views).filter(
323
- (v) => isStrictElementView(v) && v.id !== viewId
324
- );
325
- let computedView = result.view;
326
- computedView.nodes.forEach((node) => {
327
- if (!node.navigateTo) {
328
- const navigateTo = find(allElementViews, (v) => v.viewOf === node.id);
329
- if (navigateTo) {
330
- node.navigateTo = navigateTo.id;
331
- }
332
- }
333
- });
334
- const previous = this.previousViews[viewId];
335
- computedView = previous && eq(computedView, previous) ? previous : computedView;
336
- this.previousViews[viewId] = computedView;
337
- return computedView;
338
- });
339
- });
340
- }
341
- onModelParsed(callback) {
342
- this.listeners.push(callback);
343
- return Disposable.create(() => {
344
- const index = this.listeners.indexOf(callback);
345
- if (index >= 0) {
346
- this.listeners.splice(index, 1);
347
- }
348
- });
349
- }
350
- documents() {
351
- return this.langiumDocuments.all.filter(isParsedLikeC4LangiumDocument).toArray();
352
- }
353
- notifyListeners(docs) {
354
- for (const listener of this.listeners) {
355
- try {
356
- listener(docs);
357
- } catch (e) {
358
- logError(e);
359
- }
360
- }
361
- }
362
- }
363
- function computedViewKey(viewId) {
364
- return `computed-view-${viewId}`;
365
- }
@@ -1,22 +0,0 @@
1
- import type { likec4 as c4 } from '@likec4/core';
2
- import type { Location } from 'vscode-languageserver-protocol';
3
- import type { ParsedAstElement } from '../ast';
4
- import { ast } from '../ast';
5
- import type { LikeC4Services } from '../module';
6
- export declare class LikeC4ModelLocator {
7
- private services;
8
- private fqnIndex;
9
- private langiumDocuments;
10
- constructor(services: LikeC4Services);
11
- private documents;
12
- getParsedElement(astNode: ast.Element): ParsedAstElement | null;
13
- locateElement(fqn: c4.Fqn, property?: string): Location | null;
14
- locateRelation(relationId: c4.RelationID): Location | null;
15
- locateViewAst(viewId: c4.ViewID): {
16
- doc: import("../ast").ParsedLikeC4LangiumDocument;
17
- view: import("../ast").ParsedAstView;
18
- viewAst: ast.LikeC4View;
19
- } | null;
20
- locateView(viewId: c4.ViewID): Location | null;
21
- }
22
- //# sourceMappingURL=model-locator.d.ts.map
@@ -1,115 +0,0 @@
1
- import { AstUtils, GrammarUtils } from "langium";
2
- import { ast, isParsedLikeC4LangiumDocument } from "../ast.js";
3
- const { findNodeForKeyword, findNodeForProperty } = GrammarUtils;
4
- const { getDocument } = AstUtils;
5
- export class LikeC4ModelLocator {
6
- constructor(services) {
7
- this.services = services;
8
- this.fqnIndex = services.likec4.FqnIndex;
9
- this.langiumDocuments = services.shared.workspace.LangiumDocuments;
10
- }
11
- fqnIndex;
12
- langiumDocuments;
13
- documents() {
14
- return this.langiumDocuments.all.filter(isParsedLikeC4LangiumDocument);
15
- }
16
- getParsedElement(astNode) {
17
- const fqn = this.fqnIndex.getFqn(astNode);
18
- if (!fqn)
19
- return null;
20
- const doc = getDocument(astNode);
21
- if (!isParsedLikeC4LangiumDocument(doc)) {
22
- return null;
23
- }
24
- return doc.c4Elements.find((e) => e.id === fqn) ?? null;
25
- }
26
- locateElement(fqn, property = "name") {
27
- const entry = this.fqnIndex.byFqn(fqn).head();
28
- if (!entry) {
29
- return null;
30
- }
31
- const propertyNode = findNodeForProperty(entry.el.$cstNode, property) ?? entry.el.$cstNode;
32
- if (!propertyNode) {
33
- return null;
34
- }
35
- return {
36
- uri: entry.doc.uri.toString(),
37
- range: propertyNode.range
38
- };
39
- }
40
- locateRelation(relationId) {
41
- for (const doc of this.documents()) {
42
- const relation = doc.c4Relations.find((r) => r.id === relationId);
43
- if (!relation) {
44
- continue;
45
- }
46
- const node = this.services.workspace.AstNodeLocator.getAstNode(
47
- doc.parseResult.value,
48
- relation.astPath
49
- );
50
- if (!ast.isRelation(node)) {
51
- continue;
52
- }
53
- if (node.title) {
54
- const targetNode2 = findNodeForProperty(node.$cstNode, "title");
55
- if (targetNode2) {
56
- return {
57
- uri: doc.uri.toString(),
58
- range: targetNode2.range
59
- };
60
- }
61
- }
62
- let targetNode = node.kind ? findNodeForProperty(node.$cstNode, "kind") : findNodeForKeyword(node.$cstNode, "->");
63
- targetNode ??= findNodeForProperty(node.$cstNode, "target");
64
- if (!targetNode) {
65
- return null;
66
- }
67
- return {
68
- uri: doc.uri.toString(),
69
- range: targetNode.range
70
- };
71
- }
72
- return null;
73
- }
74
- locateViewAst(viewId) {
75
- for (const doc of this.documents()) {
76
- const view = doc.c4Views.find((r) => r.id === viewId);
77
- if (!view) {
78
- continue;
79
- }
80
- const viewAst = this.services.workspace.AstNodeLocator.getAstNode(
81
- doc.parseResult.value,
82
- view.astPath
83
- );
84
- if (ast.isLikeC4View(viewAst)) {
85
- return {
86
- doc,
87
- view,
88
- viewAst
89
- };
90
- }
91
- }
92
- return null;
93
- }
94
- locateView(viewId) {
95
- const res = this.locateViewAst(viewId);
96
- if (!res) {
97
- return null;
98
- }
99
- const node = res.viewAst;
100
- let targetNode = node.$cstNode;
101
- if (node.name) {
102
- targetNode = findNodeForProperty(node.$cstNode, "name") ?? targetNode;
103
- } else if ("viewOf" in node) {
104
- targetNode = findNodeForProperty(node.$cstNode, "viewOf") ?? targetNode;
105
- }
106
- targetNode ??= findNodeForKeyword(node.$cstNode, "view");
107
- if (!targetNode) {
108
- return null;
109
- }
110
- return {
111
- uri: res.doc.uri.toString(),
112
- range: targetNode.range
113
- };
114
- }
115
- }
@@ -1,29 +0,0 @@
1
- import { type c4 } from '@likec4/core';
2
- import type { LangiumDocument } from 'langium';
3
- import type { FqnIndexedDocument, ParsedLikeC4LangiumDocument } from '../ast';
4
- import { ast } from '../ast';
5
- import type { LikeC4Services } from '../module';
6
- export type ModelParsedListener = () => void;
7
- export declare class LikeC4ModelParser {
8
- private services;
9
- private fqnIndex;
10
- constructor(services: LikeC4Services);
11
- parse(doc: LangiumDocument | LangiumDocument[]): ParsedLikeC4LangiumDocument[];
12
- protected parseLikeC4Document(_doc: FqnIndexedDocument): ParsedLikeC4LangiumDocument;
13
- private parseSpecification;
14
- private parseModel;
15
- private parseElement;
16
- private parseRelation;
17
- private parseViews;
18
- private parseElementExpr;
19
- private parseCustomElementExpr;
20
- private parsePredicateExpr;
21
- private parseViewRule;
22
- private parseDynamicStep;
23
- private parseElementView;
24
- private parseDynamicElementView;
25
- protected resolveFqn(node: ast.Element | ast.ExtendElement): c4.Fqn;
26
- private getAstNodePath;
27
- private convertTags;
28
- }
29
- //# sourceMappingURL=model-parser.d.ts.map