@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,136 +0,0 @@
1
- import {
2
- AstUtils,
3
- CstUtils,
4
- DefaultScopeProvider,
5
- DONE_RESULT,
6
- EMPTY_STREAM,
7
- GrammarUtils,
8
- stream,
9
- StreamImpl,
10
- StreamScope
11
- } from "langium";
12
- import { ast } from "../ast.js";
13
- import { elementRef, getFqnElementRef } from "../elementRef.js";
14
- import { logError } from "../logger.js";
15
- const { findNodeForProperty } = GrammarUtils;
16
- const { toDocumentSegment } = CstUtils;
17
- const { getDocument } = AstUtils;
18
- function toAstNodeDescription(entry) {
19
- const $cstNode = findNodeForProperty(entry.el.$cstNode, "name");
20
- return {
21
- documentUri: entry.doc.uri,
22
- name: entry.name,
23
- ...entry.el.$cstNode && {
24
- selectionSegment: toDocumentSegment(entry.el.$cstNode)
25
- },
26
- ...$cstNode && {
27
- nameSegment: toDocumentSegment($cstNode)
28
- },
29
- path: entry.path,
30
- type: ast.Element
31
- };
32
- }
33
- export class LikeC4ScopeProvider extends DefaultScopeProvider {
34
- fqnIndex;
35
- constructor(services) {
36
- super(services);
37
- this.fqnIndex = services.likec4.FqnIndex;
38
- }
39
- directChildrenOf(parent) {
40
- return this.fqnIndex.directChildrenOf(parent).map(toAstNodeDescription);
41
- }
42
- // we need lazy resolving here
43
- uniqueDescedants(of) {
44
- return new StreamImpl(
45
- () => {
46
- const element = of();
47
- const fqn = element && this.fqnIndex.getFqn(element);
48
- if (fqn) {
49
- return this.fqnIndex.uniqueDescedants(fqn).map(toAstNodeDescription).iterator();
50
- }
51
- return null;
52
- },
53
- (iterator) => {
54
- if (iterator) {
55
- return iterator.next();
56
- }
57
- return DONE_RESULT;
58
- }
59
- );
60
- }
61
- scopeElementRef(ref) {
62
- return this.uniqueDescedants(() => ref.el.ref);
63
- }
64
- scopeExtendElement({ element }) {
65
- return stream([element.el.$nodeDescription]).nonNullable().concat(this.uniqueDescedants(() => elementRef(element)));
66
- }
67
- scopeElementView({ viewOf, extends: ext }) {
68
- if (viewOf) {
69
- return stream([viewOf.el.$nodeDescription]).nonNullable().concat(this.uniqueDescedants(() => elementRef(viewOf)));
70
- }
71
- if (ext) {
72
- return stream([ext]).flatMap((v) => {
73
- const view = v.view.ref;
74
- return view ? this.scopeElementView(view) : EMPTY_STREAM;
75
- });
76
- }
77
- return EMPTY_STREAM;
78
- }
79
- getScope(context) {
80
- const referenceType = this.reflection.getReferenceType(context);
81
- try {
82
- const container = context.container;
83
- if (ast.isFqnElementRef(container) && context.property === "el") {
84
- const parent = container.parent;
85
- if (!parent) {
86
- return this.getGlobalScope(referenceType);
87
- }
88
- return new StreamScope(this.directChildrenOf(getFqnElementRef(parent)));
89
- }
90
- if (ast.isElementRef(container) && context.property === "el") {
91
- const parent = container.parent;
92
- if (parent) {
93
- return new StreamScope(this.scopeElementRef(parent));
94
- }
95
- }
96
- return this.computeScope(context);
97
- } catch (e) {
98
- logError(e);
99
- return this.getGlobalScope(referenceType);
100
- }
101
- }
102
- computeScope(context) {
103
- const referenceType = this.reflection.getReferenceType(context);
104
- const scopes = [];
105
- const doc = getDocument(context.container);
106
- const precomputed = doc.precomputedScopes;
107
- if (precomputed) {
108
- const byReferenceType = (desc) => this.reflection.isSubtype(desc.type, referenceType);
109
- let container = context.container;
110
- while (container) {
111
- const elements = precomputed.get(container).filter(byReferenceType);
112
- if (elements.length > 0) {
113
- scopes.push(stream(elements));
114
- }
115
- if (referenceType === ast.Element) {
116
- if (ast.isExtendElementBody(container)) {
117
- scopes.push(this.scopeExtendElement(container.$container));
118
- }
119
- if (ast.isElementViewBody(container)) {
120
- scopes.push(this.scopeElementView(container.$container));
121
- }
122
- }
123
- container = container.$container;
124
- }
125
- }
126
- return scopes.reduceRight((outerScope, elements) => {
127
- return this.createScope(elements, outerScope);
128
- }, this.getGlobalScope(referenceType));
129
- }
130
- /**
131
- * Create a global scope filtered for the given reference type.
132
- */
133
- getGlobalScope(referenceType) {
134
- return new StreamScope(this.indexManager.allElements(referenceType));
135
- }
136
- }
@@ -1,16 +0,0 @@
1
- import { type AstNode, type AstNodeDescription } from 'langium';
2
- import type { LangiumSharedServices, NodeKindProvider as LspNodeKindProvider } from 'langium/lsp';
3
- import { CompletionItemKind, SymbolKind } from 'vscode-languageserver-protocol';
4
- export declare class NodeKindProvider implements LspNodeKindProvider {
5
- private services;
6
- constructor(services: LangiumSharedServices);
7
- /**
8
- * Returns a `SymbolKind` as used by `WorkspaceSymbolProvider` or `DocumentSymbolProvider`.
9
- */
10
- getSymbolKind(node: AstNode | AstNodeDescription): SymbolKind;
11
- /**
12
- * Returns a `CompletionItemKind` as used by the `CompletionProvider`.
13
- */
14
- getCompletionItemKind(node: AstNode | AstNodeDescription): CompletionItemKind;
15
- }
16
- //# sourceMappingURL=NodeKindProvider.d.ts.map
@@ -1,60 +0,0 @@
1
- import { CompletionItemKind, SymbolKind } from "vscode-languageserver-protocol";
2
- import { ast } from "../ast.js";
3
- export class NodeKindProvider {
4
- constructor(services) {
5
- this.services = services;
6
- }
7
- /**
8
- * Returns a `SymbolKind` as used by `WorkspaceSymbolProvider` or `DocumentSymbolProvider`.
9
- */
10
- // prettier-ignore
11
- getSymbolKind(node) {
12
- const hasType = (type) => "type" in node && this.services.AstReflection.isSubtype(node.type, type);
13
- switch (true) {
14
- case (ast.isElement(node) || hasType(ast.Element) || (ast.isExtendElement(node) || hasType(ast.ExtendElement))): {
15
- return SymbolKind.Constructor;
16
- }
17
- case (ast.isModel(node) || ast.isModelViews(node) || ast.isSpecificationRule(node) || hasType(ast.Model) || hasType(ast.ModelViews) || hasType(ast.SpecificationRule)): {
18
- return SymbolKind.Namespace;
19
- }
20
- case (ast.isLikeC4View(node) || hasType(ast.LikeC4View)): {
21
- return SymbolKind.Class;
22
- }
23
- case (ast.isTag(node) || hasType(ast.Tag) || (ast.isSpecificationTag(node) || hasType(ast.SpecificationTag))): {
24
- return SymbolKind.EnumMember;
25
- }
26
- case (ast.isRelationshipKind(node) || hasType(ast.RelationshipKind) || (ast.isSpecificationRelationshipKind(node) || hasType(ast.SpecificationRelationshipKind))): {
27
- return SymbolKind.Event;
28
- }
29
- case (ast.isElementKind(node) || hasType(ast.ElementKind) || (ast.isSpecificationElementKind(node) || hasType(ast.SpecificationElementKind))): {
30
- return SymbolKind.TypeParameter;
31
- }
32
- }
33
- return SymbolKind.Constant;
34
- }
35
- /**
36
- * Returns a `CompletionItemKind` as used by the `CompletionProvider`.
37
- */
38
- getCompletionItemKind(node) {
39
- switch (this.getSymbolKind(node)) {
40
- case SymbolKind.Constructor:
41
- return CompletionItemKind.Constructor;
42
- case SymbolKind.Namespace:
43
- return CompletionItemKind.Module;
44
- case SymbolKind.Class:
45
- return CompletionItemKind.Class;
46
- case SymbolKind.Enum:
47
- return CompletionItemKind.Enum;
48
- case SymbolKind.EnumMember:
49
- return CompletionItemKind.EnumMember;
50
- case SymbolKind.TypeParameter:
51
- return CompletionItemKind.TypeParameter;
52
- case SymbolKind.Interface:
53
- return CompletionItemKind.Interface;
54
- case SymbolKind.Event:
55
- return CompletionItemKind.Event;
56
- default:
57
- return CompletionItemKind.Reference;
58
- }
59
- }
60
- }
@@ -1,17 +0,0 @@
1
- /// <reference types="node" />
2
- import type { LangiumDocument } from 'langium';
3
- import { DefaultWorkspaceManager } from 'langium';
4
- import type { WorkspaceFolder } from 'vscode-languageserver';
5
- import { URI } from 'vscode-uri';
6
- export declare class LikeC4WorkspaceManager extends DefaultWorkspaceManager {
7
- /**
8
- * Load all additional documents that shall be visible in the context of the given workspace
9
- * folders and add them to the collector. This can be used to include built-in libraries of
10
- * your language, which can be either loaded from provided files or constructed in memory.
11
- */
12
- protected loadAdditionalDocuments(_folders: WorkspaceFolder[], _collector: (document: LangiumDocument) => void): Promise<void>;
13
- workspace(): WorkspaceFolder | null;
14
- get workspaceUri(): URI;
15
- get workspaceURL(): import("url").URL;
16
- }
17
- //# sourceMappingURL=WorkspaceManager.d.ts.map
@@ -1,29 +0,0 @@
1
- import { hasAtLeast, invariant } from "@likec4/core";
2
- import { DefaultWorkspaceManager } from "langium";
3
- import { URI } from "vscode-uri";
4
- export class LikeC4WorkspaceManager extends DefaultWorkspaceManager {
5
- /**
6
- * Load all additional documents that shall be visible in the context of the given workspace
7
- * folders and add them to the collector. This can be used to include built-in libraries of
8
- * your language, which can be either loaded from provided files or constructed in memory.
9
- */
10
- loadAdditionalDocuments(_folders, _collector) {
11
- return Promise.resolve();
12
- }
13
- workspace() {
14
- if (this.folders && hasAtLeast(this.folders, 1)) {
15
- return this.folders[0];
16
- }
17
- return null;
18
- }
19
- get workspaceUri() {
20
- const workspace = this.workspace();
21
- invariant(workspace, "Workspace not initialized");
22
- return URI.parse(workspace.uri);
23
- }
24
- get workspaceURL() {
25
- const workspace = this.workspace();
26
- invariant(workspace, "Workspace not initialized");
27
- return new URL(workspace.uri);
28
- }
29
- }
@@ -1,4 +0,0 @@
1
- import { DefaultWorkspaceSymbolProvider } from 'langium/lsp';
2
- export declare class WorkspaceSymbolProvider extends DefaultWorkspaceSymbolProvider {
3
- }
4
- //# sourceMappingURL=WorkspaceSymbolProvider.d.ts.map
@@ -1,3 +0,0 @@
1
- import { DefaultWorkspaceSymbolProvider } from "langium/lsp";
2
- export class WorkspaceSymbolProvider extends DefaultWorkspaceSymbolProvider {
3
- }
@@ -1,4 +0,0 @@
1
- export * from './NodeKindProvider';
2
- export * from './WorkspaceManager';
3
- export * from './WorkspaceSymbolProvider';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1,3 +0,0 @@
1
- export * from "./NodeKindProvider.js";
2
- export * from "./WorkspaceManager.js";
3
- export * from "./WorkspaceSymbolProvider.js";
@@ -1,2 +0,0 @@
1
- export * from './testServices';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- export * from "./testServices.js";
@@ -1,23 +0,0 @@
1
- import { type Diagnostic } from 'vscode-languageserver-protocol';
2
- import type { LikeC4LangiumDocument } from '../ast';
3
- export declare function createTestServices(workspace?: string): {
4
- services: import("../module").LikeC4Services;
5
- parse: (input: string, uri?: string) => Promise<LikeC4LangiumDocument>;
6
- validate: (input: string | LikeC4LangiumDocument, uri?: string) => Promise<{
7
- document: LikeC4LangiumDocument;
8
- diagnostics: (Diagnostic & import("langium").DiagnosticInfo<import("../ast").LikeC4AstNode>)[];
9
- warnings: string[];
10
- errors: string[];
11
- }>;
12
- validateAll: () => Promise<{
13
- diagnostics: Diagnostic[];
14
- errors: string[];
15
- warnings: string[];
16
- }>;
17
- buildModel: () => Promise<import("@likec4/core").LikeC4ComputedModel>;
18
- resetState: () => Promise<void>;
19
- };
20
- export type TestServices = ReturnType<typeof createTestServices>;
21
- export type TestParseFn = TestServices['validate'];
22
- export type TestValidateFn = TestServices['validate'];
23
- //# sourceMappingURL=testServices.d.ts.map
@@ -1,102 +0,0 @@
1
- import { DocumentState, EmptyFileSystem } from "langium";
2
- import * as assert from "node:assert";
3
- import stripIndent from "strip-indent";
4
- import { DiagnosticSeverity } from "vscode-languageserver-protocol";
5
- import { URI, Utils } from "vscode-uri";
6
- import { createLanguageServices } from "../module.js";
7
- export function createTestServices(workspace = "file:///test/workspace") {
8
- const services = createLanguageServices(EmptyFileSystem).likec4;
9
- const metaData = services.LanguageMetaData;
10
- const langiumDocuments = services.shared.workspace.LangiumDocuments;
11
- const documentBuilder = services.shared.workspace.DocumentBuilder;
12
- const modelBuilder = services.likec4.ModelBuilder;
13
- const workspaceUri = URI.parse(workspace);
14
- const workspaceFolder = {
15
- name: "test",
16
- uri: workspaceUri.toString()
17
- };
18
- let isInitialized = false;
19
- let documentIndex = 1;
20
- const parse = async (input, uri) => {
21
- if (!isInitialized) {
22
- await services.shared.workspace.WorkspaceLock.write(async (_cancelToken) => {
23
- if (isInitialized) {
24
- return;
25
- }
26
- isInitialized = true;
27
- await services.shared.workspace.WorkspaceManager.initializeWorkspace([workspaceFolder]);
28
- Object.assign(services.shared.workspace.WorkspaceManager, {
29
- folders: [workspaceFolder]
30
- });
31
- });
32
- }
33
- const docUri = Utils.resolvePath(
34
- workspaceUri,
35
- "./src/",
36
- uri ?? `${documentIndex++}${metaData.fileExtensions[0]}`
37
- );
38
- const document = services.shared.workspace.LangiumDocumentFactory.fromString(
39
- stripIndent(input),
40
- docUri
41
- );
42
- langiumDocuments.addDocument(document);
43
- await services.shared.workspace.WorkspaceLock.write(async (_cancelToken) => {
44
- await documentBuilder.build([document], { validation: false });
45
- });
46
- return document;
47
- };
48
- const validate = async (input, uri) => {
49
- const document = typeof input === "string" ? await parse(input, uri) : input;
50
- await services.shared.workspace.WorkspaceLock.write(async (_cancelToken) => {
51
- await documentBuilder.build([document], { validation: true });
52
- });
53
- const diagnostics = document.diagnostics ?? [];
54
- const warnings = diagnostics.flatMap((d) => d.severity === DiagnosticSeverity.Warning ? d.message : []);
55
- const errors = diagnostics.flatMap((d) => d.severity === DiagnosticSeverity.Error ? d.message : []);
56
- return {
57
- document,
58
- diagnostics,
59
- warnings,
60
- errors
61
- };
62
- };
63
- let previousPromise = Promise.resolve();
64
- const validateAll = async () => {
65
- await services.shared.workspace.WorkspaceLock.write(async (_cancelToken) => {
66
- const docs2 = langiumDocuments.all.toArray();
67
- await documentBuilder.build(docs2, { validation: true });
68
- });
69
- await documentBuilder.waitUntil(DocumentState.Validated);
70
- const docs = langiumDocuments.all.toArray();
71
- assert.ok(docs.length > 0, "no documents to validate");
72
- const diagnostics = docs.flatMap((doc) => doc.diagnostics ?? []);
73
- const warnings = diagnostics.flatMap((d) => d.severity === DiagnosticSeverity.Warning ? d.message : []);
74
- const errors = diagnostics.flatMap((d) => d.severity === DiagnosticSeverity.Error ? d.message : []);
75
- return {
76
- diagnostics,
77
- errors,
78
- warnings
79
- };
80
- };
81
- const buildModel = async () => {
82
- await validateAll();
83
- const model = await modelBuilder.buildComputedModel();
84
- if (!model)
85
- throw new Error("No model found");
86
- return model;
87
- };
88
- const resetState = async () => {
89
- await services.shared.workspace.WorkspaceLock.write(async (cancelToken) => {
90
- const docs = langiumDocuments.all.toArray().map((doc) => doc.uri);
91
- await documentBuilder.update([], docs, cancelToken);
92
- });
93
- };
94
- return {
95
- services,
96
- parse,
97
- validate,
98
- validateAll,
99
- buildModel,
100
- resetState
101
- };
102
- }
@@ -1,2 +0,0 @@
1
- export * from './stringHash';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- export * from "./stringHash.js";
@@ -1,3 +0,0 @@
1
- import type { LangiumDocument } from 'langium';
2
- export declare const printDocs: (docs: LangiumDocument[]) => string;
3
- //# sourceMappingURL=printDocs.d.ts.map
@@ -1 +0,0 @@
1
- export const printDocs = (docs) => docs.map((d) => " - " + d.uri.toString(true)).join("\n");
@@ -1,2 +0,0 @@
1
- export declare function stringHash(...str: [string, ...string[]]): string;
2
- //# sourceMappingURL=stringHash.d.ts.map
@@ -1,5 +0,0 @@
1
- import hash from "string-hash";
2
- export function stringHash(...str) {
3
- var s = str.length > 1 ? str.join(":::") : str[0];
4
- return hash(s).toString(36);
5
- }
@@ -1,5 +0,0 @@
1
- import type { ValidationCheck } from 'langium';
2
- import { ast } from '../ast';
3
- import type { LikeC4Services } from '../module';
4
- export declare const dynamicViewRulePredicate: (_services: LikeC4Services) => ValidationCheck<ast.DynamicViewRulePredicate>;
5
- //# sourceMappingURL=dynamic-view-rule.d.ts.map
@@ -1,5 +0,0 @@
1
- import type { ValidationCheck } from 'langium';
2
- import { ast } from '../ast';
3
- import type { LikeC4Services } from '../module';
4
- export declare const dynamicViewStep: (services: LikeC4Services) => ValidationCheck<ast.DynamicViewStep>;
5
- //# sourceMappingURL=dynamic-view-step.d.ts.map
@@ -1,33 +0,0 @@
1
- import { isAncestor } from "@likec4/core";
2
- import { elementRef } from "../elementRef.js";
3
- import { logError } from "../logger.js";
4
- export const dynamicViewStep = (services) => {
5
- const fqnIndex = services.likec4.FqnIndex;
6
- return (el, accept) => {
7
- try {
8
- const sourceEl = elementRef(el.source);
9
- const source = sourceEl && fqnIndex.getFqn(sourceEl);
10
- if (!source) {
11
- accept("error", "Source not found (not parsed/indexed yet)", {
12
- node: el,
13
- property: "source"
14
- });
15
- }
16
- const targetEl = elementRef(el.target);
17
- const target = targetEl && fqnIndex.getFqn(targetEl);
18
- if (!target) {
19
- accept("error", "Target not found (not parsed/indexed yet)", {
20
- node: el,
21
- property: "target"
22
- });
23
- }
24
- if (source && target && (isAncestor(source, target) || isAncestor(target, source))) {
25
- accept("error", "Invalid parent-child relationship", {
26
- node: el
27
- });
28
- }
29
- } catch (e) {
30
- logError(e);
31
- }
32
- };
33
- };
@@ -1,6 +0,0 @@
1
- /// <reference types="react" />
2
- import { type ValidationCheck } from 'langium';
3
- import type { ast } from '../ast';
4
- import type { LikeC4Services } from '../module';
5
- export declare const elementChecks: (services: LikeC4Services) => ValidationCheck<ast.Element>;
6
- //# sourceMappingURL=element.d.ts.map
@@ -1,38 +0,0 @@
1
- import { AstUtils } from "langium";
2
- const { getDocument } = AstUtils;
3
- export const elementChecks = (services) => {
4
- const fqnIndex = services.likec4.FqnIndex;
5
- return (el, accept) => {
6
- const fqn = fqnIndex.getFqn(el);
7
- if (!fqn) {
8
- accept("error", "Not indexed element", {
9
- node: el,
10
- property: "name"
11
- });
12
- return;
13
- }
14
- const withSameFqn = fqnIndex.byFqn(fqn).filter((v) => v.el !== el).head();
15
- if (withSameFqn) {
16
- const isAnotherDoc = withSameFqn.doc.uri !== getDocument(el).uri;
17
- accept(
18
- "error",
19
- `Duplicate element name ${el.name !== fqn ? el.name + " (" + fqn + ")" : el.name}`,
20
- {
21
- node: el,
22
- property: "name",
23
- ...isAnotherDoc && {
24
- relatedInformation: [
25
- {
26
- location: {
27
- range: withSameFqn.el.$cstNode.range,
28
- uri: withSameFqn.doc.uri.toString()
29
- },
30
- message: `conflicting element`
31
- }
32
- ]
33
- }
34
- }
35
- );
36
- }
37
- };
38
- };
@@ -1,3 +0,0 @@
1
- import type { LikeC4Services } from '../module';
2
- export declare function registerValidationChecks(services: LikeC4Services): void;
3
- //# sourceMappingURL=index.d.ts.map
@@ -1,5 +0,0 @@
1
- import type { ValidationCheck } from 'langium';
2
- import type { ast } from '../ast';
3
- import type { LikeC4Services } from '../module';
4
- export declare const opacityPropertyRuleChecks: (_: LikeC4Services) => ValidationCheck<ast.OpacityProperty>;
5
- //# sourceMappingURL=property-checks.d.ts.map
@@ -1,11 +0,0 @@
1
- export const opacityPropertyRuleChecks = (_) => {
2
- return (node, accept) => {
3
- const opacity = parseFloat(node.value);
4
- if (isNaN(opacity) || opacity < 0 || opacity > 100) {
5
- accept("warning", `Value ignored, must be between 0% and 100%`, {
6
- node,
7
- property: "value"
8
- });
9
- }
10
- };
11
- };
@@ -1,5 +0,0 @@
1
- import type { ValidationCheck } from 'langium';
2
- import { ast } from '../ast';
3
- import type { LikeC4Services } from '../module';
4
- export declare const relationChecks: (services: LikeC4Services) => ValidationCheck<ast.Relation>;
5
- //# sourceMappingURL=relation.d.ts.map
@@ -1,50 +0,0 @@
1
- import { isSameHierarchy } from "@likec4/core";
2
- import { ast } from "../ast.js";
3
- import { elementRef } from "../elementRef.js";
4
- import { logError } from "../logger.js";
5
- export const relationChecks = (services) => {
6
- const fqnIndex = services.likec4.FqnIndex;
7
- return (el, accept) => {
8
- try {
9
- const targetEl = elementRef(el.target);
10
- const target = targetEl && fqnIndex.getFqn(targetEl);
11
- if (!target) {
12
- accept("error", "Target not found (not parsed/indexed yet)", {
13
- node: el,
14
- property: "target"
15
- });
16
- }
17
- let sourceEl;
18
- if (ast.isExplicitRelation(el)) {
19
- sourceEl = elementRef(el.source);
20
- if (!sourceEl) {
21
- return accept("error", "Source not found (not parsed/indexed yet)", {
22
- node: el,
23
- property: "source"
24
- });
25
- }
26
- } else {
27
- sourceEl = el.$container.$container;
28
- }
29
- const source = fqnIndex.getFqn(sourceEl);
30
- if (!source) {
31
- accept("error", "Source not found (not parsed/indexed yet)", {
32
- node: el
33
- });
34
- }
35
- if (source && target && isSameHierarchy(source, target)) {
36
- accept("error", "Invalid parent-child relationship", {
37
- node: el
38
- });
39
- }
40
- if (el.tags?.value && el.body?.tags?.value) {
41
- accept("error", "Relation cannot have tags in both header and body", {
42
- node: el,
43
- property: "tags"
44
- });
45
- }
46
- } catch (e) {
47
- logError(e);
48
- }
49
- };
50
- };
@@ -1,10 +0,0 @@
1
- import { type ValidationCheck } from 'langium';
2
- import { ast } from '../ast';
3
- import type { LikeC4Services } from '../module';
4
- export declare const specificationRuleChecks: (_: LikeC4Services) => ValidationCheck<ast.SpecificationRule>;
5
- export declare const modelRuleChecks: (_: LikeC4Services) => ValidationCheck<ast.Model>;
6
- export declare const modelViewsChecks: (_: LikeC4Services) => ValidationCheck<ast.ModelViews>;
7
- export declare const elementKindChecks: (services: LikeC4Services) => ValidationCheck<ast.ElementKind>;
8
- export declare const tagChecks: (services: LikeC4Services) => ValidationCheck<ast.Tag>;
9
- export declare const relationshipChecks: (services: LikeC4Services) => ValidationCheck<ast.RelationshipKind>;
10
- //# sourceMappingURL=specification.d.ts.map