@likec4/language-server 1.1.1 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/contrib/likec4.monarch.ts +4 -4
  2. package/contrib/likec4.tmLanguage.json +1 -1
  3. package/package.json +8 -10
  4. package/src/Rpc.ts +108 -0
  5. package/src/ast.ts +443 -0
  6. package/src/browser/index.ts +30 -0
  7. package/src/elementRef.ts +26 -0
  8. package/src/generated/ast.ts +1632 -0
  9. package/src/generated/grammar.ts +10 -0
  10. package/src/generated/module.ts +32 -0
  11. package/src/index.ts +4 -0
  12. package/src/like-c4.langium +395 -0
  13. package/src/logger.ts +54 -0
  14. package/src/lsp/CodeLensProvider.ts +51 -0
  15. package/src/lsp/DocumentHighlightProvider.ts +12 -0
  16. package/src/lsp/DocumentLinkProvider.test.ts +66 -0
  17. package/src/lsp/DocumentLinkProvider.ts +53 -0
  18. package/src/lsp/DocumentSymbolProvider.ts +201 -0
  19. package/src/lsp/HoverProvider.ts +58 -0
  20. package/{dist/lsp/SemanticTokenProvider.js → src/lsp/SemanticTokenProvider.ts} +58 -43
  21. package/src/lsp/index.ts +6 -0
  22. package/src/model/fqn-computation.ts +47 -0
  23. package/src/model/fqn-index.ts +161 -0
  24. package/src/model/index.ts +5 -0
  25. package/src/model/model-builder.ts +447 -0
  26. package/src/model/model-locator.ts +130 -0
  27. package/src/model/model-parser.ts +580 -0
  28. package/src/model-change/ModelChanges.ts +120 -0
  29. package/src/model-change/changeElementStyle.ts +176 -0
  30. package/src/model-change/changeViewLayout.ts +41 -0
  31. package/src/module.ts +197 -0
  32. package/src/node/index.ts +20 -0
  33. package/src/protocol.ts +87 -0
  34. package/src/references/index.ts +2 -0
  35. package/src/references/scope-computation.ts +142 -0
  36. package/src/references/scope-provider.ts +166 -0
  37. package/src/shared/NodeKindProvider.ts +67 -0
  38. package/src/shared/WorkspaceManager.ts +39 -0
  39. package/src/shared/WorkspaceSymbolProvider.ts +3 -0
  40. package/src/shared/index.ts +3 -0
  41. package/src/test/index.ts +1 -0
  42. package/src/test/testServices.ts +119 -0
  43. package/src/utils/index.ts +1 -0
  44. package/src/utils/printDocs.ts +3 -0
  45. package/src/utils/stringHash.ts +6 -0
  46. package/src/validation/dynamic-view-rule.ts +35 -0
  47. package/src/validation/dynamic-view-step.ts +39 -0
  48. package/src/validation/element.ts +52 -0
  49. package/{dist/validation/index.js → src/validation/index.ts} +25 -17
  50. package/src/validation/property-checks.ts +17 -0
  51. package/src/validation/relation.ts +57 -0
  52. package/src/validation/specification.ts +118 -0
  53. package/src/validation/view-predicates/custom-element-expr.ts +21 -0
  54. package/src/validation/view-predicates/expanded-element.ts +34 -0
  55. package/src/validation/view-predicates/incoming.ts +19 -0
  56. package/src/validation/view-predicates/index.ts +4 -0
  57. package/src/validation/view-predicates/outgoing.ts +19 -0
  58. package/src/validation/view.ts +26 -0
  59. package/src/view-utils/assignNavigateTo.ts +30 -0
  60. package/src/view-utils/index.ts +3 -0
  61. package/src/view-utils/resolve-extended-views.ts +57 -0
  62. package/src/view-utils/resolve-relative-paths.ts +84 -0
  63. package/dist/Rpc.d.ts +0 -10
  64. package/dist/Rpc.js +0 -98
  65. package/dist/ast.d.ts +0 -133
  66. package/dist/ast.js +0 -267
  67. package/dist/browser/index.d.ts +0 -9
  68. package/dist/browser/index.js +0 -16
  69. package/dist/elementRef.d.ts +0 -12
  70. package/dist/elementRef.js +0 -15
  71. package/dist/generated/ast.d.ts +0 -559
  72. package/dist/generated/ast.js +0 -868
  73. package/dist/generated/grammar.d.ts +0 -7
  74. package/dist/generated/grammar.js +0 -3
  75. package/dist/generated/module.d.ts +0 -14
  76. package/dist/generated/module.js +0 -22
  77. package/dist/index.d.ts +0 -5
  78. package/dist/index.js +0 -2
  79. package/dist/logger.d.ts +0 -12
  80. package/dist/logger.js +0 -51
  81. package/dist/lsp/CodeLensProvider.d.ts +0 -10
  82. package/dist/lsp/CodeLensProvider.js +0 -37
  83. package/dist/lsp/DocumentHighlightProvider.d.ts +0 -10
  84. package/dist/lsp/DocumentHighlightProvider.js +0 -10
  85. package/dist/lsp/DocumentLinkProvider.d.ts +0 -11
  86. package/dist/lsp/DocumentLinkProvider.js +0 -41
  87. package/dist/lsp/DocumentLinkProvider.test.d.ts +0 -2
  88. package/dist/lsp/DocumentLinkProvider.test.js +0 -54
  89. package/dist/lsp/DocumentSymbolProvider.d.ts +0 -22
  90. package/dist/lsp/DocumentSymbolProvider.js +0 -184
  91. package/dist/lsp/HoverProvider.d.ts +0 -10
  92. package/dist/lsp/HoverProvider.js +0 -36
  93. package/dist/lsp/SemanticTokenProvider.d.ts +0 -8
  94. package/dist/lsp/index.d.ts +0 -7
  95. package/dist/lsp/index.js +0 -6
  96. package/dist/model/fqn-computation.d.ts +0 -4
  97. package/dist/model/fqn-computation.js +0 -43
  98. package/dist/model/fqn-index.d.ts +0 -26
  99. package/dist/model/fqn-index.js +0 -114
  100. package/dist/model/index.d.ts +0 -6
  101. package/dist/model/index.js +0 -5
  102. package/dist/model/model-builder.d.ts +0 -20
  103. package/dist/model/model-builder.js +0 -352
  104. package/dist/model/model-locator.d.ts +0 -22
  105. package/dist/model/model-locator.js +0 -119
  106. package/dist/model/model-parser.d.ts +0 -27
  107. package/dist/model/model-parser.js +0 -410
  108. package/dist/model-change/ModelChanges.d.ts +0 -15
  109. package/dist/model-change/ModelChanges.js +0 -100
  110. package/dist/model-change/changeElementStyle.d.ts +0 -15
  111. package/dist/model-change/changeElementStyle.js +0 -141
  112. package/dist/model-change/changeViewLayout.d.ts +0 -13
  113. package/dist/model-change/changeViewLayout.js +0 -30
  114. package/dist/module.d.ts +0 -59
  115. package/dist/module.js +0 -121
  116. package/dist/node/index.d.ts +0 -6
  117. package/dist/node/index.js +0 -13
  118. package/dist/protocol.d.ts +0 -58
  119. package/dist/protocol.js +0 -14
  120. package/dist/references/index.d.ts +0 -3
  121. package/dist/references/index.js +0 -2
  122. package/dist/references/scope-computation.d.ts +0 -11
  123. package/dist/references/scope-computation.js +0 -108
  124. package/dist/references/scope-provider.d.ts +0 -18
  125. package/dist/references/scope-provider.js +0 -136
  126. package/dist/shared/NodeKindProvider.d.ts +0 -16
  127. package/dist/shared/NodeKindProvider.js +0 -58
  128. package/dist/shared/WorkspaceManager.d.ts +0 -17
  129. package/dist/shared/WorkspaceManager.js +0 -29
  130. package/dist/shared/WorkspaceSymbolProvider.d.ts +0 -4
  131. package/dist/shared/WorkspaceSymbolProvider.js +0 -3
  132. package/dist/shared/index.d.ts +0 -4
  133. package/dist/shared/index.js +0 -3
  134. package/dist/test/index.d.ts +0 -2
  135. package/dist/test/index.js +0 -1
  136. package/dist/test/testServices.d.ts +0 -23
  137. package/dist/test/testServices.js +0 -102
  138. package/dist/utils/index.d.ts +0 -2
  139. package/dist/utils/index.js +0 -1
  140. package/dist/utils/printDocs.d.ts +0 -3
  141. package/dist/utils/printDocs.js +0 -1
  142. package/dist/utils/stringHash.d.ts +0 -2
  143. package/dist/utils/stringHash.js +0 -5
  144. package/dist/validation/element.d.ts +0 -6
  145. package/dist/validation/element.js +0 -38
  146. package/dist/validation/index.d.ts +0 -3
  147. package/dist/validation/property-checks.d.ts +0 -5
  148. package/dist/validation/property-checks.js +0 -11
  149. package/dist/validation/relation.d.ts +0 -5
  150. package/dist/validation/relation.js +0 -50
  151. package/dist/validation/specification.d.ts +0 -10
  152. package/dist/validation/specification.js +0 -97
  153. package/dist/validation/view-predicates/custom-element-expr.d.ts +0 -5
  154. package/dist/validation/view-predicates/custom-element-expr.js +0 -16
  155. package/dist/validation/view-predicates/expanded-element.d.ts +0 -5
  156. package/dist/validation/view-predicates/expanded-element.js +0 -28
  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 -18
  165. package/dist/view-utils/assignNavigateTo.d.ts +0 -3
  166. package/dist/view-utils/assignNavigateTo.js +0 -23
  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 -76
  173. /package/{dist → src}/reset.d.ts +0 -0
@@ -1,184 +0,0 @@
1
- import { nonexhaustive } from "@likec4/core";
2
- import { GrammarUtils } from "langium";
3
- import { compact, isEmpty, map, pipe } from "remeda";
4
- import { SymbolKind } from "vscode-languageserver-protocol";
5
- import { ast } from "../ast.js";
6
- import { getFqnElementRef } from "../elementRef.js";
7
- import { logError } from "../logger.js";
8
- export class LikeC4DocumentSymbolProvider {
9
- constructor(services) {
10
- this.services = services;
11
- this.nodeKindProvider = services.shared.lsp.NodeKindProvider;
12
- }
13
- nodeKindProvider;
14
- getSymbols({
15
- parseResult: {
16
- value: { specifications, models, views }
17
- }
18
- }) {
19
- return [
20
- ...specifications.map((s) => () => this.getSpecSymbol(s)),
21
- ...models.map((s) => () => this.getModelSymbol(s)),
22
- ...views.map((s) => () => this.getModelViewsSymbol(s))
23
- ].flatMap((fn) => {
24
- try {
25
- return fn() ?? [];
26
- } catch (e) {
27
- logError(e);
28
- return [];
29
- }
30
- });
31
- }
32
- getSpecSymbol(astSpec) {
33
- const cstModel = astSpec?.$cstNode;
34
- if (!cstModel)
35
- return [];
36
- const specKeywordNode = GrammarUtils.findNodeForProperty(cstModel, "name");
37
- if (!specKeywordNode)
38
- return [];
39
- const specSymbols = pipe(
40
- [...astSpec.elements, ...astSpec.tags, ...astSpec.relationships],
41
- map((nd) => {
42
- if (ast.isSpecificationElementKind(nd) || ast.isSpecificationRelationshipKind(nd)) {
43
- return this.getKindSymbol(nd);
44
- }
45
- if (ast.isSpecificationTag(nd)) {
46
- return this.getTagSymbol(nd);
47
- }
48
- nonexhaustive(nd);
49
- }),
50
- compact
51
- );
52
- if (specSymbols.length === 0)
53
- return [];
54
- return [
55
- {
56
- kind: SymbolKind.Namespace,
57
- name: astSpec.name,
58
- range: cstModel.range,
59
- selectionRange: specKeywordNode.range,
60
- children: specSymbols
61
- }
62
- ];
63
- }
64
- getModelSymbol(astModel) {
65
- const cstModel = astModel.$cstNode;
66
- if (!cstModel)
67
- return [];
68
- const nameNode = GrammarUtils.findNodeForProperty(cstModel, "name");
69
- if (!nameNode)
70
- return [];
71
- return [
72
- {
73
- kind: this.symbolKind(astModel),
74
- name: astModel.name,
75
- range: cstModel.range,
76
- selectionRange: nameNode.range,
77
- children: astModel.elements.flatMap((e) => this.getElementsSymbol(e))
78
- }
79
- ];
80
- }
81
- getElementsSymbol(el) {
82
- try {
83
- if (ast.isExtendElement(el)) {
84
- return this.getExtendElementSymbol(el);
85
- }
86
- if (ast.isElement(el)) {
87
- return this.getElementSymbol(el);
88
- }
89
- } catch (e) {
90
- logError(e);
91
- }
92
- return [];
93
- }
94
- getExtendElementSymbol(astElement) {
95
- const cst = astElement.$cstNode;
96
- const nameNode = astElement.element.$cstNode;
97
- const body = astElement.body;
98
- if (!cst || !nameNode)
99
- return [];
100
- return [
101
- {
102
- kind: this.symbolKind(astElement),
103
- name: getFqnElementRef(astElement.element),
104
- range: cst.range,
105
- selectionRange: nameNode.range,
106
- children: body.elements.flatMap((e) => this.getElementsSymbol(e))
107
- }
108
- ];
109
- }
110
- getElementSymbol(astElement) {
111
- const cst = astElement.$cstNode;
112
- const nameNode = GrammarUtils.findNodeForProperty(cst, "name");
113
- if (!nameNode || !cst)
114
- return [];
115
- const name = astElement.name;
116
- const kind = astElement.kind.$refText;
117
- const detail = kind;
118
- return [
119
- {
120
- kind: this.symbolKind(astElement),
121
- name,
122
- range: cst.range,
123
- selectionRange: nameNode.range,
124
- detail,
125
- children: astElement.body?.elements.flatMap((e) => this.getElementsSymbol(e)) ?? []
126
- }
127
- ];
128
- }
129
- getModelViewsSymbol(astViews) {
130
- const cst = astViews.$cstNode;
131
- const nameNode = GrammarUtils.findNodeForProperty(cst, "name");
132
- if (!nameNode || !cst)
133
- return [];
134
- return [
135
- {
136
- kind: this.symbolKind(astViews),
137
- name: astViews.name,
138
- range: cst.range,
139
- selectionRange: nameNode.range,
140
- children: astViews.views.flatMap((e) => this.getElementViewSymbol(e))
141
- }
142
- ];
143
- }
144
- getKindSymbol(astKind) {
145
- if (!astKind.$cstNode || !astKind.kind.$cstNode || isEmpty(astKind.kind.name))
146
- return null;
147
- return {
148
- kind: this.symbolKind(astKind),
149
- name: astKind.kind.name,
150
- range: astKind.$cstNode.range,
151
- selectionRange: astKind.kind.$cstNode.range
152
- };
153
- }
154
- getTagSymbol(astTag) {
155
- if (!astTag.$cstNode || !astTag.tag.$cstNode || isEmpty(astTag.tag.name))
156
- return null;
157
- return {
158
- kind: this.symbolKind(astTag),
159
- name: "#" + astTag.tag.name,
160
- range: astTag.$cstNode.range,
161
- selectionRange: astTag.tag.$cstNode.range
162
- };
163
- }
164
- getElementViewSymbol(astView) {
165
- const cst = astView?.$cstNode;
166
- if (!cst)
167
- return [];
168
- const nameNode = astView.name ? GrammarUtils.findNodeForProperty(cst, "name") : null;
169
- if (!nameNode)
170
- return [];
171
- return [
172
- {
173
- kind: this.symbolKind(astView),
174
- name: nameNode.text,
175
- range: cst.range,
176
- selectionRange: nameNode.range,
177
- children: []
178
- }
179
- ];
180
- }
181
- symbolKind(node) {
182
- return this.nodeKindProvider.getSymbolKind(node);
183
- }
184
- }
@@ -1,10 +0,0 @@
1
- import { type AstNode, type MaybePromise } from 'langium';
2
- import { AstNodeHoverProvider } from 'langium/lsp';
3
- import type { Hover } from 'vscode-languageserver-protocol';
4
- import type { LikeC4Services } from '../module';
5
- export declare class LikeC4HoverProvider extends AstNodeHoverProvider {
6
- private locator;
7
- constructor(services: LikeC4Services);
8
- protected getAstNodeHoverContent(node: AstNode): MaybePromise<Hover | undefined>;
9
- }
10
- //# sourceMappingURL=HoverProvider.d.ts.map
@@ -1,36 +0,0 @@
1
- import { AstNodeHoverProvider } from "langium/lsp";
2
- import stripIndent from "strip-indent";
3
- import { ast } from "../ast.js";
4
- export class LikeC4HoverProvider extends AstNodeHoverProvider {
5
- locator;
6
- constructor(services) {
7
- super(services);
8
- this.locator = services.likec4.ModelLocator;
9
- }
10
- getAstNodeHoverContent(node) {
11
- if (ast.isTag(node)) {
12
- return {
13
- contents: {
14
- kind: "markdown",
15
- value: stripIndent(`
16
- tag: \`${node.name}\`
17
- `)
18
- }
19
- };
20
- }
21
- if (ast.isElement(node)) {
22
- const el = this.locator.getParsedElement(node);
23
- if (!el) {
24
- return;
25
- }
26
- const lines = [el.id, `### ${el.title}`, "`" + el.kind + "` "];
27
- return {
28
- contents: {
29
- kind: "markdown",
30
- value: lines.join("\n")
31
- }
32
- };
33
- }
34
- return;
35
- }
36
- }
@@ -1,8 +0,0 @@
1
- import type { AstNode } from 'langium';
2
- import { AbstractSemanticTokenProvider, type SemanticTokenAcceptor } from 'langium/lsp';
3
- export declare class LikeC4SemanticTokenProvider extends AbstractSemanticTokenProvider {
4
- protected highlightElement(node: AstNode, acceptor: SemanticTokenAcceptor): void | undefined | 'prune';
5
- private highlightAstElement;
6
- private highlightView;
7
- }
8
- //# sourceMappingURL=SemanticTokenProvider.d.ts.map
@@ -1,7 +0,0 @@
1
- export * from './CodeLensProvider';
2
- export * from './DocumentHighlightProvider';
3
- export * from './DocumentLinkProvider';
4
- export * from './DocumentSymbolProvider';
5
- export * from './HoverProvider';
6
- export * from './SemanticTokenProvider';
7
- //# sourceMappingURL=index.d.ts.map
package/dist/lsp/index.js DELETED
@@ -1,6 +0,0 @@
1
- export * from "./CodeLensProvider.js";
2
- export * from "./DocumentHighlightProvider.js";
3
- export * from "./DocumentLinkProvider.js";
4
- export * from "./DocumentSymbolProvider.js";
5
- export * from "./HoverProvider.js";
6
- export * from "./SemanticTokenProvider.js";
@@ -1,4 +0,0 @@
1
- import { type LikeC4LangiumDocument } from '../ast';
2
- import type { LikeC4Services } from '../module';
3
- export declare function computeDocumentFqn(document: LikeC4LangiumDocument, services: LikeC4Services): void;
4
- //# sourceMappingURL=fqn-computation.d.ts.map
@@ -1,43 +0,0 @@
1
- import { AsFqn, nonexhaustive } from "@likec4/core";
2
- import { MultiMap } from "langium";
3
- import { isEmpty, isNullish as isNil } from "remeda";
4
- import { ast, ElementOps } from "../ast.js";
5
- import { getFqnElementRef } from "../elementRef.js";
6
- export function computeDocumentFqn(document, services) {
7
- const c4fqns = document.c4fqns = new MultiMap();
8
- const elements = document.parseResult.value.models.flatMap((m) => m.elements);
9
- if (elements.length === 0) {
10
- return;
11
- }
12
- const locator = services.workspace.AstNodeLocator;
13
- const traverseStack = elements.map((el) => [el, null]);
14
- let pair;
15
- while (pair = traverseStack.shift()) {
16
- const [el, parent] = pair;
17
- if (ast.isRelation(el)) {
18
- continue;
19
- }
20
- if (ast.isExtendElement(el)) {
21
- if (!isNil(el.body) && !isEmpty(el.body.elements)) {
22
- const fqn = getFqnElementRef(el.element);
23
- el.body.elements.forEach((child) => traverseStack.push([child, fqn]));
24
- }
25
- continue;
26
- }
27
- if (ast.isElement(el)) {
28
- const fqn = AsFqn(el.name, parent);
29
- const path = locator.getAstNodePath(el);
30
- c4fqns.add(fqn, {
31
- el: new WeakRef(el),
32
- path,
33
- name: el.name
34
- });
35
- ElementOps.writeId(el, fqn);
36
- if (!isNil(el.body) && !isEmpty(el.body.elements)) {
37
- el.body.elements.forEach((child) => traverseStack.push([child, fqn]));
38
- }
39
- continue;
40
- }
41
- nonexhaustive(el);
42
- }
43
- }
@@ -1,26 +0,0 @@
1
- import type { Fqn } from '@likec4/core';
2
- import type { LangiumDocuments, Stream } from 'langium';
3
- import type { ast, FqnIndexedDocument } from '../ast';
4
- import type { LikeC4Services } from '../module';
5
- export interface FqnIndexEntry {
6
- fqn: Fqn;
7
- name: string;
8
- el: ast.Element;
9
- doc: FqnIndexedDocument;
10
- path: string;
11
- }
12
- export declare class FqnIndex {
13
- private services;
14
- protected langiumDocuments: LangiumDocuments;
15
- constructor(services: LikeC4Services);
16
- get documents(): Stream<FqnIndexedDocument>;
17
- private entries;
18
- getFqn(el: ast.Element): Fqn | null;
19
- byFqn(fqn: Fqn): Stream<FqnIndexEntry>;
20
- directChildrenOf(parent: Fqn): Stream<FqnIndexEntry>;
21
- /**
22
- * Returns descedant elements with unique names in the scope
23
- */
24
- uniqueDescedants(parent: Fqn): Stream<FqnIndexEntry>;
25
- }
26
- //# sourceMappingURL=fqn-index.d.ts.map
@@ -1,114 +0,0 @@
1
- import { nameFromFqn, parentFqn } from "@likec4/core";
2
- import { DocumentState, DONE_RESULT, MultiMap, stream, StreamImpl } from "langium";
3
- import { ElementOps, isFqnIndexedDocument, isLikeC4LangiumDocument } from "../ast.js";
4
- import { logError, logger } from "../logger.js";
5
- import { printDocs } from "../utils/printDocs.js";
6
- import { computeDocumentFqn } from "./fqn-computation.js";
7
- const True = () => true;
8
- export class FqnIndex {
9
- constructor(services) {
10
- this.services = services;
11
- this.langiumDocuments = services.shared.workspace.LangiumDocuments;
12
- services.shared.workspace.DocumentBuilder.onBuildPhase(
13
- DocumentState.IndexedContent,
14
- async (docs, _cancelToken) => {
15
- logger.debug(`[FqnIndex] onIndexedContent ${docs.length}:
16
- ` + printDocs(docs));
17
- for (const doc of docs) {
18
- if (isLikeC4LangiumDocument(doc)) {
19
- delete doc.c4fqns;
20
- delete doc.c4Elements;
21
- delete doc.c4Specification;
22
- delete doc.c4Relations;
23
- delete doc.c4Views;
24
- try {
25
- computeDocumentFqn(doc, services);
26
- } catch (e) {
27
- logError(e);
28
- }
29
- }
30
- }
31
- return Promise.resolve();
32
- }
33
- );
34
- logger.debug(`[FqnIndex] Created`);
35
- }
36
- langiumDocuments;
37
- get documents() {
38
- return this.langiumDocuments.all.filter(isFqnIndexedDocument);
39
- }
40
- entries(filterByFqn = True) {
41
- return this.documents.flatMap(
42
- (doc) => doc.c4fqns.entries().flatMap(([fqn, entry]) => {
43
- if (filterByFqn(fqn)) {
44
- const el = entry.el.deref();
45
- if (el) {
46
- return { ...entry, fqn, el, doc };
47
- }
48
- }
49
- return [];
50
- })
51
- );
52
- }
53
- getFqn(el) {
54
- return ElementOps.readId(el) ?? null;
55
- }
56
- byFqn(fqn) {
57
- return this.documents.flatMap((doc) => {
58
- return doc.c4fqns.get(fqn).flatMap((entry) => {
59
- const el = entry.el.deref();
60
- if (el) {
61
- return { fqn, el, doc, path: entry.path, name: entry.name };
62
- }
63
- return [];
64
- });
65
- });
66
- }
67
- directChildrenOf(parent) {
68
- return stream([parent]).flatMap((_parent) => {
69
- const children = this.entries((fqn) => parentFqn(fqn) === _parent).map((entry) => [entry.name, entry]).toArray();
70
- if (children.length === 0) {
71
- return [];
72
- }
73
- return new MultiMap(children).entriesGroupedByKey().flatMap(([_name, descrs]) => descrs.length === 1 ? descrs : []).iterator();
74
- });
75
- }
76
- /**
77
- * Returns descedant elements with unique names in the scope
78
- */
79
- uniqueDescedants(parent) {
80
- return new StreamImpl(
81
- () => {
82
- const prefix = `${parent}.`;
83
- const childrenNames = /* @__PURE__ */ new Set();
84
- const descedants = [];
85
- const nested = new MultiMap();
86
- this.entries((f) => f.startsWith(prefix)).forEach((e) => {
87
- const name = nameFromFqn(e.fqn);
88
- const entry = { ...e, name };
89
- if (parentFqn(e.fqn) === parent) {
90
- childrenNames.add(name);
91
- nested.add(name, entry);
92
- } else {
93
- descedants.push(entry);
94
- }
95
- });
96
- if (nested.size + descedants.length === 0) {
97
- return null;
98
- }
99
- for (const descedant of descedants) {
100
- if (!childrenNames.has(descedant.name)) {
101
- nested.add(descedant.name, descedant);
102
- }
103
- }
104
- return nested.entriesGroupedByKey().flatMap(([_name, descrs]) => descrs.length === 1 ? descrs : []).iterator();
105
- },
106
- (iterator) => {
107
- if (iterator) {
108
- return iterator.next();
109
- }
110
- return DONE_RESULT;
111
- }
112
- );
113
- }
114
- }
@@ -1,6 +0,0 @@
1
- export * from './fqn-computation';
2
- export * from './fqn-index';
3
- export * from './model-builder';
4
- export * from './model-locator';
5
- export * from './model-parser';
6
- //# sourceMappingURL=index.d.ts.map
@@ -1,5 +0,0 @@
1
- export * from "./fqn-computation.js";
2
- export * from "./fqn-index.js";
3
- export * from "./model-builder.js";
4
- export * from "./model-locator.js";
5
- export * from "./model-parser.js";
@@ -1,20 +0,0 @@
1
- import { type c4, type ViewID } from '@likec4/core';
2
- import type { URI } from 'langium';
3
- import { type CancellationToken, Disposable } from 'vscode-languageserver';
4
- import type { LikeC4Services } from '../module';
5
- type ModelParsedListener = (docs: URI[]) => void;
6
- export declare class LikeC4ModelBuilder {
7
- private services;
8
- private langiumDocuments;
9
- private listeners;
10
- constructor(services: LikeC4Services);
11
- buildModel(cancelToken?: CancellationToken): Promise<c4.LikeC4Model | null>;
12
- private previousViews;
13
- buildComputedModel(cancelToken?: CancellationToken): Promise<c4.LikeC4ComputedModel | null>;
14
- computeView(viewId: ViewID, cancelToken?: CancellationToken): Promise<c4.ComputedView | null>;
15
- onModelParsed(callback: ModelParsedListener): Disposable;
16
- private documents;
17
- private notifyListeners;
18
- }
19
- export {};
20
- //# sourceMappingURL=model-builder.d.ts.map