@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,189 +0,0 @@
1
- import { nonexhaustive } from "@likec4/core";
2
- import { GrammarUtils } from "langium";
3
- import { filter, isEmpty, isTruthy, 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
- try {
43
- if (ast.isSpecificationElementKind(nd) || ast.isSpecificationRelationshipKind(nd)) {
44
- return this.getKindSymbol(nd);
45
- }
46
- if (ast.isSpecificationTag(nd)) {
47
- return this.getTagSymbol(nd);
48
- }
49
- } catch (e) {
50
- logError(e);
51
- return null;
52
- }
53
- nonexhaustive(nd);
54
- }),
55
- filter(isTruthy)
56
- );
57
- if (specSymbols.length === 0)
58
- return [];
59
- return [
60
- {
61
- kind: SymbolKind.Namespace,
62
- name: astSpec.name,
63
- range: cstModel.range,
64
- selectionRange: specKeywordNode.range,
65
- children: specSymbols
66
- }
67
- ];
68
- }
69
- getModelSymbol(astModel) {
70
- const cstModel = astModel.$cstNode;
71
- if (!cstModel)
72
- return [];
73
- const nameNode = GrammarUtils.findNodeForProperty(cstModel, "name");
74
- if (!nameNode)
75
- return [];
76
- return [
77
- {
78
- kind: this.symbolKind(astModel),
79
- name: astModel.name,
80
- range: cstModel.range,
81
- selectionRange: nameNode.range,
82
- children: astModel.elements.flatMap((e) => this.getElementsSymbol(e))
83
- }
84
- ];
85
- }
86
- getElementsSymbol(el) {
87
- try {
88
- if (ast.isExtendElement(el)) {
89
- return this.getExtendElementSymbol(el);
90
- }
91
- if (ast.isElement(el)) {
92
- return this.getElementSymbol(el);
93
- }
94
- } catch (e) {
95
- logError(e);
96
- }
97
- return [];
98
- }
99
- getExtendElementSymbol(astElement) {
100
- const cst = astElement.$cstNode;
101
- const nameNode = astElement.element.$cstNode;
102
- const body = astElement.body;
103
- if (!cst || !nameNode)
104
- return [];
105
- return [
106
- {
107
- kind: this.symbolKind(astElement),
108
- name: getFqnElementRef(astElement.element),
109
- range: cst.range,
110
- selectionRange: nameNode.range,
111
- children: body.elements.flatMap((e) => this.getElementsSymbol(e))
112
- }
113
- ];
114
- }
115
- getElementSymbol(astElement) {
116
- const cst = astElement.$cstNode;
117
- const nameNode = GrammarUtils.findNodeForProperty(cst, "name");
118
- if (!nameNode || !cst)
119
- return [];
120
- const name = astElement.name;
121
- const kind = astElement.kind.$refText;
122
- const detail = kind;
123
- return [
124
- {
125
- kind: this.symbolKind(astElement),
126
- name,
127
- range: cst.range,
128
- selectionRange: nameNode.range,
129
- detail,
130
- children: astElement.body?.elements.flatMap((e) => this.getElementsSymbol(e)) ?? []
131
- }
132
- ];
133
- }
134
- getModelViewsSymbol(astViews) {
135
- const cst = astViews.$cstNode;
136
- const nameNode = GrammarUtils.findNodeForProperty(cst, "name");
137
- if (!nameNode || !cst)
138
- return [];
139
- return [
140
- {
141
- kind: this.symbolKind(astViews),
142
- name: astViews.name,
143
- range: cst.range,
144
- selectionRange: nameNode.range,
145
- children: astViews.views.flatMap((e) => this.getViewSymbol(e))
146
- }
147
- ];
148
- }
149
- getKindSymbol(astKind) {
150
- if (!astKind.$cstNode || !astKind.kind.$cstNode || isEmpty(astKind.kind.name))
151
- return null;
152
- return {
153
- kind: this.symbolKind(astKind),
154
- name: astKind.kind.name,
155
- range: astKind.$cstNode.range,
156
- selectionRange: astKind.kind.$cstNode.range
157
- };
158
- }
159
- getTagSymbol(astTag) {
160
- if (!astTag.$cstNode || !astTag.tag.$cstNode || isEmpty(astTag.tag.name))
161
- return null;
162
- return {
163
- kind: this.symbolKind(astTag),
164
- name: "#" + astTag.tag.name,
165
- range: astTag.$cstNode.range,
166
- selectionRange: astTag.tag.$cstNode.range
167
- };
168
- }
169
- getViewSymbol(astView) {
170
- const cst = astView?.$cstNode;
171
- if (!cst)
172
- return [];
173
- const nameNode = astView.name ? GrammarUtils.findNodeForProperty(cst, "name") : null;
174
- if (!nameNode)
175
- return [];
176
- return [
177
- {
178
- kind: this.symbolKind(astView),
179
- name: nameNode.text,
180
- range: cst.range,
181
- selectionRange: nameNode.range,
182
- children: []
183
- }
184
- ];
185
- }
186
- symbolKind(node) {
187
- return this.nodeKindProvider.getSymbolKind(node);
188
- }
189
- }
@@ -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