@likec4/language-server 1.43.0 → 1.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/package.json +1 -1
- package/browser-worker/package.json +1 -1
- package/dist/LikeC4LanguageServices.d.ts +12 -19
- package/dist/LikeC4LanguageServices.js +182 -0
- package/dist/Rpc.js +245 -0
- package/dist/ast.d.ts +5 -1
- package/dist/ast.js +253 -0
- package/dist/browser-worker.js +4 -0
- package/dist/browser.js +35 -0
- package/dist/bundled.js +42 -0
- package/dist/bundled.mjs +3542 -3896
- package/dist/documentation/documentation-provider.js +51 -0
- package/dist/documentation/index.js +1 -0
- package/dist/empty.js +2 -0
- package/dist/filesystem/ChokidarWatcher.js +97 -0
- package/dist/filesystem/FileSystemWatcher.js +14 -0
- package/dist/filesystem/LikeC4FileSystem.d.ts +1 -2
- package/dist/filesystem/LikeC4FileSystem.js +126 -0
- package/dist/filesystem/index.d.ts +26 -0
- package/dist/filesystem/index.js +29 -0
- package/dist/formatting/LikeC4Formatter.js +637 -0
- package/dist/formatting/utils.js +18 -0
- package/dist/generated/ast.js +2155 -0
- package/dist/generated/{grammar.mjs → grammar.js} +6 -2
- package/dist/generated/module.d.ts +6 -1
- package/dist/generated/module.js +27 -0
- package/dist/generated-lib/{icons.mjs → icons.js} +11 -7
- package/dist/index.d.ts +7 -0
- package/dist/index.js +53 -0
- package/dist/{likec4lib.mjs → likec4lib.js} +3 -3
- package/dist/logger.js +81 -0
- package/dist/lsp/CodeActionProvider.d.ts +14 -0
- package/dist/lsp/CodeActionProvider.js +33 -0
- package/dist/lsp/CodeLensProvider.js +44 -0
- package/dist/lsp/CompletionProvider.d.ts +3 -1
- package/dist/lsp/CompletionProvider.js +200 -0
- package/dist/lsp/DocumentHighlightProvider.js +10 -0
- package/dist/lsp/DocumentLinkProvider.js +58 -0
- package/dist/lsp/DocumentSymbolProvider.js +306 -0
- package/dist/lsp/HoverProvider.js +106 -0
- package/dist/lsp/RenameProvider.js +6 -0
- package/dist/lsp/SemanticTokenProvider.js +257 -0
- package/dist/lsp/index.d.ts +1 -0
- package/dist/lsp/index.js +9 -0
- package/dist/mcp/MCPServerFactory.js +73 -0
- package/dist/mcp/NoopLikeC4MCPServer.js +17 -0
- package/dist/mcp/interfaces.js +5 -0
- package/dist/mcp/server/StdioLikeC4MCPServer.js +47 -0
- package/dist/mcp/server/StreamableLikeC4MCPServer.js +145 -0
- package/dist/mcp/server/WithMCPServer.js +56 -0
- package/dist/mcp/tools/_common.d.ts +8 -7
- package/dist/mcp/tools/_common.js +49 -0
- package/dist/mcp/tools/find-relationships.d.ts +7 -8
- package/dist/mcp/tools/find-relationships.js +150 -0
- package/dist/mcp/tools/list-projects.d.ts +3 -3
- package/dist/mcp/tools/list-projects.js +62 -0
- package/dist/mcp/tools/open-view.d.ts +6 -7
- package/dist/mcp/tools/open-view.js +52 -0
- package/dist/mcp/tools/read-deployment.d.ts +6 -7
- package/dist/mcp/tools/read-deployment.js +132 -0
- package/dist/mcp/tools/read-element.d.ts +6 -7
- package/dist/mcp/tools/read-element.js +194 -0
- package/dist/mcp/tools/read-project-summary.d.ts +5 -6
- package/dist/mcp/tools/read-project-summary.js +176 -0
- package/dist/mcp/tools/read-view.d.ts +6 -7
- package/dist/mcp/tools/read-view.js +203 -0
- package/dist/mcp/tools/search-element.d.ts +3 -3
- package/dist/mcp/tools/search-element.js +177 -0
- package/dist/mcp/utils.d.ts +2 -2
- package/dist/mcp/utils.js +48 -0
- package/dist/model/builder/MergedExtends.js +74 -0
- package/dist/model/builder/MergedSpecification.js +175 -0
- package/dist/model/builder/buildModel.js +176 -0
- package/dist/model/deployments-index.js +102 -0
- package/dist/model/fqn-index.js +250 -0
- package/dist/model/index.js +6 -0
- package/dist/model/model-builder.d.ts +13 -11
- package/dist/model/model-builder.js +234 -0
- package/dist/model/model-locator.d.ts +6 -5
- package/dist/model/model-locator.js +240 -0
- package/dist/model/model-parser-where.js +81 -0
- package/dist/model/model-parser.d.ts +309 -304
- package/dist/model/model-parser.js +119 -0
- package/dist/model/parser/Base.d.ts +2 -2
- package/dist/model/parser/Base.js +367 -0
- package/dist/model/parser/DeploymentModelParser.d.ts +2 -2
- package/dist/model/parser/DeploymentModelParser.js +176 -0
- package/dist/model/parser/DeploymentViewParser.d.ts +3 -3
- package/dist/model/parser/DeploymentViewParser.js +86 -0
- package/dist/model/parser/FqnRefParser.d.ts +2 -2
- package/dist/model/parser/FqnRefParser.js +382 -0
- package/dist/model/parser/GlobalsParser.d.ts +6 -6
- package/dist/model/parser/GlobalsParser.js +84 -0
- package/dist/model/parser/ImportsParser.d.ts +11 -12
- package/dist/model/parser/ImportsParser.js +24 -0
- package/dist/model/parser/ModelParser.d.ts +2 -2
- package/dist/model/parser/ModelParser.js +165 -0
- package/dist/model/parser/PredicatesParser.d.ts +2 -2
- package/dist/model/parser/PredicatesParser.js +45 -0
- package/dist/model/parser/SpecificationParser.d.ts +2 -2
- package/dist/model/parser/SpecificationParser.js +109 -0
- package/dist/model/parser/ValueConverter.js +12 -0
- package/dist/model/parser/ViewsParser.d.ts +3 -3
- package/dist/model/parser/ViewsParser.js +477 -0
- package/dist/model-change/ModelChanges.d.ts +6 -3
- package/dist/model-change/ModelChanges.js +102 -0
- package/dist/model-change/changeElementStyle.js +134 -0
- package/dist/model-change/changeViewLayout.d.ts +2 -2
- package/dist/model-change/changeViewLayout.js +28 -0
- package/dist/model-change/removeManualLayoutV1.d.ts +7 -0
- package/dist/model-change/removeManualLayoutV1.js +27 -0
- package/dist/module.d.ts +10 -5
- package/dist/module.js +143 -0
- package/dist/protocol.d.ts +1 -17
- package/dist/protocol.js +114 -0
- package/dist/references/index.js +3 -0
- package/dist/references/name-provider.js +37 -0
- package/dist/references/scope-computation.js +288 -0
- package/dist/references/scope-provider.d.ts +3 -3
- package/dist/references/scope-provider.js +242 -0
- package/dist/shared/NodeKindProvider.js +57 -0
- package/dist/shared/{WorkspaceSymbolProvider.mjs → WorkspaceSymbolProvider.js} +1 -1
- package/dist/shared/index.js +2 -0
- package/dist/test/index.js +1 -0
- package/dist/test/testServices.d.ts +16 -16
- package/dist/test/testServices.js +210 -0
- package/dist/utils/disposable.js +26 -0
- package/dist/utils/elementRef.d.ts +1 -1
- package/dist/utils/elementRef.js +27 -0
- package/dist/utils/fqnRef.js +63 -0
- package/dist/utils/index.js +35 -0
- package/dist/utils/printDocs.js +1 -0
- package/dist/utils/projectId.js +16 -0
- package/dist/utils/stringHash.js +5 -0
- package/dist/validation/DocumentValidator.js +17 -0
- package/dist/validation/_shared.js +26 -0
- package/dist/validation/deployment-checks.js +140 -0
- package/dist/validation/dynamic-view.js +67 -0
- package/dist/validation/element-ref.js +12 -0
- package/dist/validation/element.js +49 -0
- package/dist/validation/imports.js +46 -0
- package/dist/validation/index.d.ts +1 -1
- package/dist/validation/index.js +157 -0
- package/dist/validation/property-checks.js +108 -0
- package/dist/validation/relation.js +55 -0
- package/dist/validation/specification.js +190 -0
- package/dist/validation/view-predicates/fqn-expr-with.js +43 -0
- package/dist/validation/view-predicates/fqn-ref-expr.js +51 -0
- package/dist/validation/view-predicates/incoming.js +16 -0
- package/dist/validation/view-predicates/index.js +6 -0
- package/dist/validation/view-predicates/outgoing.js +20 -0
- package/dist/validation/view-predicates/relation-expr.js +46 -0
- package/dist/validation/view-predicates/relation-with.js +16 -0
- package/dist/validation/view.d.ts +1 -1
- package/dist/validation/view.js +42 -0
- package/dist/view-utils/assignNavigateTo.js +27 -0
- package/dist/view-utils/index.d.ts +1 -0
- package/dist/view-utils/index.js +2 -0
- package/dist/view-utils/manual-layout.d.ts +6 -0
- package/dist/view-utils/manual-layout.js +151 -0
- package/dist/views/ConfigurableLayouter.js +51 -0
- package/dist/views/LikeC4ManualLayouts.d.ts +28 -0
- package/dist/views/LikeC4ManualLayouts.js +132 -0
- package/dist/views/{likec4-views.d.ts → LikeC4Views.d.ts} +9 -8
- package/dist/views/LikeC4Views.js +200 -0
- package/dist/views/index.d.ts +4 -1
- package/dist/views/index.js +11 -0
- package/dist/workspace/AstNodeDescriptionProvider.js +15 -0
- package/dist/workspace/IndexManager.js +21 -0
- package/dist/workspace/LangiumDocuments.d.ts +1 -1
- package/dist/workspace/LangiumDocuments.js +58 -0
- package/dist/workspace/ProjectsManager.d.ts +8 -3
- package/dist/workspace/ProjectsManager.js +373 -0
- package/dist/workspace/WorkspaceManager.d.ts +3 -2
- package/dist/workspace/WorkspaceManager.js +93 -0
- package/dist/workspace/index.js +5 -0
- package/likec4lib/package.json +1 -1
- package/package.json +25 -24
- package/protocol/package.json +1 -1
- package/dist/LikeC4LanguageServices.mjs +0 -197
- package/dist/Rpc.mjs +0 -296
- package/dist/ast.mjs +0 -221
- package/dist/browser-worker.mjs +0 -2
- package/dist/browser.mjs +0 -32
- package/dist/documentation/documentation-provider.mjs +0 -48
- package/dist/documentation/index.mjs +0 -1
- package/dist/empty.mjs +0 -1
- package/dist/filesystem/ChokidarWatcher.mjs +0 -68
- package/dist/filesystem/FileSystemWatcher.mjs +0 -11
- package/dist/filesystem/LikeC4FileSystem.mjs +0 -64
- package/dist/filesystem/index.mjs +0 -19
- package/dist/formatting/LikeC4Formatter.mjs +0 -511
- package/dist/formatting/utils.mjs +0 -15
- package/dist/generated/ast.mjs +0 -2150
- package/dist/generated/module.mjs +0 -23
- package/dist/index.mjs +0 -50
- package/dist/logger.mjs +0 -82
- package/dist/lsp/CodeLensProvider.mjs +0 -42
- package/dist/lsp/CompletionProvider.mjs +0 -208
- package/dist/lsp/DocumentHighlightProvider.mjs +0 -10
- package/dist/lsp/DocumentLinkProvider.mjs +0 -53
- package/dist/lsp/DocumentSymbolProvider.mjs +0 -287
- package/dist/lsp/HoverProvider.mjs +0 -104
- package/dist/lsp/RenameProvider.mjs +0 -6
- package/dist/lsp/SemanticTokenProvider.mjs +0 -276
- package/dist/lsp/index.mjs +0 -7
- package/dist/mcp/MCPServerFactory.mjs +0 -70
- package/dist/mcp/NoopLikeC4MCPServer.mjs +0 -17
- package/dist/mcp/interfaces.mjs +0 -4
- package/dist/mcp/server/StdioLikeC4MCPServer.mjs +0 -46
- package/dist/mcp/server/StreamableLikeC4MCPServer.mjs +0 -153
- package/dist/mcp/server/WithMCPServer.mjs +0 -58
- package/dist/mcp/tools/_common.mjs +0 -42
- package/dist/mcp/tools/find-relationships.mjs +0 -151
- package/dist/mcp/tools/list-projects.mjs +0 -62
- package/dist/mcp/tools/open-view.mjs +0 -52
- package/dist/mcp/tools/read-deployment.mjs +0 -130
- package/dist/mcp/tools/read-element.mjs +0 -198
- package/dist/mcp/tools/read-project-summary.mjs +0 -178
- package/dist/mcp/tools/read-view.mjs +0 -205
- package/dist/mcp/tools/search-element.mjs +0 -171
- package/dist/mcp/utils.mjs +0 -47
- package/dist/model/builder/MergedExtends.mjs +0 -76
- package/dist/model/builder/MergedSpecification.mjs +0 -205
- package/dist/model/builder/assignTagColors.d.ts +0 -7
- package/dist/model/builder/assignTagColors.mjs +0 -51
- package/dist/model/builder/buildModel.mjs +0 -226
- package/dist/model/deployments-index.mjs +0 -100
- package/dist/model/fqn-index.mjs +0 -243
- package/dist/model/index.mjs +0 -6
- package/dist/model/model-builder.mjs +0 -285
- package/dist/model/model-locator.mjs +0 -239
- package/dist/model/model-parser-where.mjs +0 -81
- package/dist/model/model-parser.mjs +0 -127
- package/dist/model/parser/Base.mjs +0 -376
- package/dist/model/parser/DeploymentModelParser.mjs +0 -212
- package/dist/model/parser/DeploymentViewParser.mjs +0 -95
- package/dist/model/parser/FqnRefParser.mjs +0 -398
- package/dist/model/parser/GlobalsParser.mjs +0 -82
- package/dist/model/parser/ImportsParser.mjs +0 -28
- package/dist/model/parser/ModelParser.mjs +0 -190
- package/dist/model/parser/PredicatesParser.mjs +0 -45
- package/dist/model/parser/SpecificationParser.mjs +0 -120
- package/dist/model/parser/ValueConverter.mjs +0 -12
- package/dist/model/parser/ViewsParser.mjs +0 -490
- package/dist/model-change/ModelChanges.mjs +0 -89
- package/dist/model-change/changeElementStyle.mjs +0 -143
- package/dist/model-change/changeViewLayout.mjs +0 -32
- package/dist/model-change/saveManualLayout.d.ts +0 -11
- package/dist/model-change/saveManualLayout.mjs +0 -27
- package/dist/module.mjs +0 -180
- package/dist/protocol.mjs +0 -65
- package/dist/references/index.mjs +0 -3
- package/dist/references/name-provider.mjs +0 -39
- package/dist/references/scope-computation.mjs +0 -312
- package/dist/references/scope-provider.mjs +0 -239
- package/dist/shared/NodeKindProvider.mjs +0 -110
- package/dist/shared/index.mjs +0 -2
- package/dist/test/index.mjs +0 -1
- package/dist/test/testServices.mjs +0 -200
- package/dist/utils/disposable.mjs +0 -25
- package/dist/utils/elementRef.mjs +0 -20
- package/dist/utils/fqnRef.mjs +0 -57
- package/dist/utils/index.mjs +0 -33
- package/dist/utils/printDocs.mjs +0 -1
- package/dist/utils/projectId.mjs +0 -16
- package/dist/utils/stringHash.mjs +0 -5
- package/dist/validation/DocumentValidator.mjs +0 -16
- package/dist/validation/_shared.mjs +0 -25
- package/dist/validation/deployment-checks.mjs +0 -146
- package/dist/validation/dynamic-view.mjs +0 -67
- package/dist/validation/element-ref.mjs +0 -12
- package/dist/validation/element.mjs +0 -50
- package/dist/validation/imports.mjs +0 -25
- package/dist/validation/index.mjs +0 -180
- package/dist/validation/property-checks.mjs +0 -107
- package/dist/validation/relation.mjs +0 -53
- package/dist/validation/specification.mjs +0 -173
- package/dist/validation/view-predicates/fqn-expr-with.mjs +0 -43
- package/dist/validation/view-predicates/fqn-ref-expr.mjs +0 -53
- package/dist/validation/view-predicates/incoming.mjs +0 -16
- package/dist/validation/view-predicates/index.mjs +0 -6
- package/dist/validation/view-predicates/outgoing.mjs +0 -20
- package/dist/validation/view-predicates/relation-expr.mjs +0 -39
- package/dist/validation/view-predicates/relation-with.mjs +0 -16
- package/dist/validation/view.mjs +0 -25
- package/dist/view-utils/assignNavigateTo.mjs +0 -25
- package/dist/view-utils/index.mjs +0 -1
- package/dist/view-utils/manual-layout.mjs +0 -99
- package/dist/views/configurable-layouter.mjs +0 -51
- package/dist/views/index.mjs +0 -1
- package/dist/views/likec4-views.mjs +0 -166
- package/dist/workspace/AstNodeDescriptionProvider.mjs +0 -17
- package/dist/workspace/IndexManager.mjs +0 -17
- package/dist/workspace/LangiumDocuments.mjs +0 -53
- package/dist/workspace/ProjectsManager.mjs +0 -360
- package/dist/workspace/WorkspaceManager.mjs +0 -83
- package/dist/workspace/index.mjs +0 -5
- /package/dist/views/{configurable-layouter.d.ts → ConfigurableLayouter.d.ts} +0 -0
|
@@ -9,15 +9,15 @@ export declare function GlobalsParser<TBase extends WithViewsParser>(B: TBase):
|
|
|
9
9
|
parseGlobalDynamicPredicateGroup(astRule: ast.GlobalDynamicPredicateGroup): c4.DynamicViewIncludeRule[];
|
|
10
10
|
parseGlobalStyleOrGroup(astRule: ast.GlobalStyle | ast.GlobalStyleGroup): c4.ElementViewRuleStyle[];
|
|
11
11
|
parseViews(): void;
|
|
12
|
-
parseElementView(astNode: ast.ElementView, additionalStyles:
|
|
12
|
+
parseElementView(astNode: ast.ElementView, additionalStyles: (c4.ViewRuleGlobalStyle | c4.ElementViewRuleStyle<c4.aux.Any>)[]): import("../../ast").ParsedAstElementView;
|
|
13
13
|
parseElementViewRule(astRule: ast.ViewRule): c4.ElementViewRule;
|
|
14
14
|
parseViewRulePredicate(astNode: ast.ViewRulePredicate): c4.ElementViewPredicate;
|
|
15
15
|
parseViewRuleGlobalPredicateRef(astRule: ast.ViewRuleGlobalPredicateRef | ast.DynamicViewGlobalPredicateRef): c4.ViewRuleGlobalPredicateRef;
|
|
16
|
-
parseViewRuleStyleOrGlobalRef(astRule: ast.ViewRuleStyleOrGlobalRef):
|
|
16
|
+
parseViewRuleStyleOrGlobalRef(astRule: ast.ViewRuleStyleOrGlobalRef): c4.ViewRuleGlobalStyle | c4.ElementViewRuleStyle<c4.aux.Any>;
|
|
17
17
|
parseViewRuleGroup(astNode: ast.ViewRuleGroup): c4.ElementViewRuleGroup;
|
|
18
18
|
parseViewRuleStyle(astRule: ast.ViewRuleStyle | ast.GlobalStyle): c4.ElementViewRuleStyle;
|
|
19
19
|
parseViewRuleGlobalStyle(astRule: ast.ViewRuleGlobalStyle): c4.ViewRuleGlobalStyle;
|
|
20
|
-
parseDynamicElementView(astNode: ast.DynamicView, additionalStyles:
|
|
20
|
+
parseDynamicElementView(astNode: ast.DynamicView, additionalStyles: (c4.ViewRuleGlobalStyle | c4.ElementViewRuleStyle<c4.aux.Any>)[]): import("../../ast").ParsedAstDynamicView;
|
|
21
21
|
parseDynamicViewRule(astRule: ast.DynamicViewRule): c4.DynamicViewRule;
|
|
22
22
|
parseDynamicViewIncludePredicate(astRule: ast.DynamicViewIncludePredicate): c4.DynamicViewIncludeRule;
|
|
23
23
|
parseDynamicParallelSteps(node: ast.DynamicViewParallelSteps): c4.DynamicStepsParallel;
|
|
@@ -60,14 +60,14 @@ export declare function GlobalsParser<TBase extends WithViewsParser>(B: TBase):
|
|
|
60
60
|
readonly doc: import("../../ast").ParsedLikeC4LangiumDocument;
|
|
61
61
|
get project(): import("../../workspace").Project;
|
|
62
62
|
resolveFqn(node: ast.FqnReferenceable): c4.Fqn;
|
|
63
|
-
getAstNodePath(node:
|
|
63
|
+
getAstNodePath(node: import("langium").AstNode): string;
|
|
64
64
|
getMetadata(metadataAstNode: ast.MetadataProperty | undefined): {
|
|
65
65
|
[key: string]: string | string[];
|
|
66
66
|
} | undefined;
|
|
67
67
|
parseMarkdownOrString(markdownOrString: ast.MarkdownOrString | undefined): c4.MarkdownOrString | undefined;
|
|
68
68
|
convertTags<E extends {
|
|
69
69
|
tags?: ast.Tags;
|
|
70
|
-
}>(withTags?: E | undefined):
|
|
70
|
+
}>(withTags?: E | undefined): c4.NonEmptyArray<c4.Tag<string>> | null;
|
|
71
71
|
parseTags<E extends {
|
|
72
72
|
tags?: ast.Tags;
|
|
73
73
|
}>(withTags?: E): c4.NonEmptyArray<c4.Tag> | null;
|
|
@@ -102,7 +102,7 @@ export declare function GlobalsParser<TBase extends WithViewsParser>(B: TBase):
|
|
|
102
102
|
parseDeploymentNode(astNode: ast.DeploymentNode): import("../../ast").ParsedAstDeployment.Node;
|
|
103
103
|
parseDeployedInstance(astNode: ast.DeployedInstance): import("../../ast").ParsedAstDeployment.Instance;
|
|
104
104
|
parseExtendDeployment(astNode: ast.ExtendDeployment): import("../../ast").ParsedAstExtend | null;
|
|
105
|
-
_resolveDeploymentRelationSource(node: ast.DeploymentRelation): c4;
|
|
105
|
+
_resolveDeploymentRelationSource(node: ast.DeploymentRelation): c4.FqnRef;
|
|
106
106
|
parseDeploymentRelation(astNode: ast.DeploymentRelation): import("../../ast").ParsedAstDeploymentRelation;
|
|
107
107
|
};
|
|
108
108
|
} & TBase;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { nonexhaustive } from '@likec4/core';
|
|
2
|
+
import { loggable } from '@likec4/log';
|
|
3
|
+
import { hasAtLeast, isTruthy } from 'remeda';
|
|
4
|
+
import { ast } from '../../ast';
|
|
5
|
+
import { serverLogger } from '../../logger';
|
|
6
|
+
const logger = serverLogger.getChild('GlobalsParser');
|
|
7
|
+
export function GlobalsParser(B) {
|
|
8
|
+
return class GlobalsParser extends B {
|
|
9
|
+
parseGlobals() {
|
|
10
|
+
const { parseResult, c4Globals } = this.doc;
|
|
11
|
+
const isValid = this.isValid;
|
|
12
|
+
const globals = parseResult.value.globals.filter(isValid);
|
|
13
|
+
const elRelPredicates = globals.flatMap(r => r.predicates.filter(isValid));
|
|
14
|
+
for (const predicate of elRelPredicates) {
|
|
15
|
+
try {
|
|
16
|
+
const globalPredicateId = predicate.name;
|
|
17
|
+
if (!isTruthy(globalPredicateId)) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (globalPredicateId in c4Globals.predicates) {
|
|
21
|
+
logger.warn(`Global predicate named "${globalPredicateId}" is already defined`);
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
this.parseAndStoreGlobalPredicateGroupOrDynamic(predicate, globalPredicateId, c4Globals);
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
logger.warn(loggable(e));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const styles = globals.flatMap(r => r.styles.filter(isValid));
|
|
31
|
+
for (const style of styles) {
|
|
32
|
+
try {
|
|
33
|
+
const globalStyleId = style.id.name;
|
|
34
|
+
if (!isTruthy(globalStyleId)) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (globalStyleId in c4Globals.styles) {
|
|
38
|
+
logger.warn(`Global style named "${globalStyleId}" is already defined`);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const styles = this.parseGlobalStyleOrGroup(style);
|
|
42
|
+
if (hasAtLeast(styles, 1)) {
|
|
43
|
+
c4Globals.styles[globalStyleId] = styles;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
logger.warn(loggable(e));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
parseAndStoreGlobalPredicateGroupOrDynamic(astRule, id, c4Globals) {
|
|
52
|
+
if (ast.isGlobalPredicateGroup(astRule)) {
|
|
53
|
+
const predicates = this.parseGlobalPredicateGroup(astRule);
|
|
54
|
+
if (hasAtLeast(predicates, 1)) {
|
|
55
|
+
c4Globals.predicates[id] = predicates;
|
|
56
|
+
}
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (ast.isGlobalDynamicPredicateGroup(astRule)) {
|
|
60
|
+
const predicates = this.parseGlobalDynamicPredicateGroup(astRule);
|
|
61
|
+
if (hasAtLeast(predicates, 1)) {
|
|
62
|
+
c4Globals.dynamicPredicates[id] = predicates;
|
|
63
|
+
}
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
nonexhaustive(astRule);
|
|
67
|
+
}
|
|
68
|
+
parseGlobalPredicateGroup(astRule) {
|
|
69
|
+
return astRule.predicates.map(p => this.parseViewRulePredicate(p));
|
|
70
|
+
}
|
|
71
|
+
parseGlobalDynamicPredicateGroup(astRule) {
|
|
72
|
+
return astRule.predicates.map(p => this.parseDynamicViewIncludePredicate(p));
|
|
73
|
+
}
|
|
74
|
+
parseGlobalStyleOrGroup(astRule) {
|
|
75
|
+
if (ast.isGlobalStyle(astRule)) {
|
|
76
|
+
return [this.parseViewRuleStyle(astRule)];
|
|
77
|
+
}
|
|
78
|
+
if (ast.isGlobalStyleGroup(astRule)) {
|
|
79
|
+
return astRule.styles.map(s => this.parseViewRuleStyle(s));
|
|
80
|
+
}
|
|
81
|
+
nonexhaustive(astRule);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type ProjectId } from '@likec4/core';
|
|
2
1
|
import type { ast } from '../../ast';
|
|
3
2
|
import type { Base } from './Base';
|
|
4
3
|
export declare function ImportsParser<TBase extends Base>(B: TBase): {
|
|
@@ -8,23 +7,23 @@ export declare function ImportsParser<TBase extends Base>(B: TBase): {
|
|
|
8
7
|
readonly services: import("../..").LikeC4Services;
|
|
9
8
|
readonly doc: import("../../ast").ParsedLikeC4LangiumDocument;
|
|
10
9
|
get project(): import("../../workspace").Project;
|
|
11
|
-
resolveFqn(node: ast.FqnReferenceable):
|
|
12
|
-
getAstNodePath(node:
|
|
10
|
+
resolveFqn(node: ast.FqnReferenceable): import("@likec4/core").Fqn;
|
|
11
|
+
getAstNodePath(node: import("langium").AstNode): string;
|
|
13
12
|
getMetadata(metadataAstNode: ast.MetadataProperty | undefined): {
|
|
14
13
|
[key: string]: string | string[];
|
|
15
14
|
} | undefined;
|
|
16
|
-
parseMarkdownOrString(markdownOrString: ast.MarkdownOrString | undefined):
|
|
15
|
+
parseMarkdownOrString(markdownOrString: ast.MarkdownOrString | undefined): import("@likec4/core").MarkdownOrString | undefined;
|
|
17
16
|
convertTags<E extends {
|
|
18
17
|
tags?: ast.Tags;
|
|
19
|
-
}>(withTags?: E | undefined):
|
|
18
|
+
}>(withTags?: E | undefined): import("@likec4/core").NonEmptyArray<import("@likec4/core").Tag<string>> | null;
|
|
20
19
|
parseTags<E extends {
|
|
21
20
|
tags?: ast.Tags;
|
|
22
|
-
}>(withTags?: E):
|
|
23
|
-
convertLinks(source?: ast.LinkProperty["$container"]):
|
|
24
|
-
parseLinks(source?: ast.LinkProperty["$container"]):
|
|
25
|
-
parseIconProperty(prop: ast.IconProperty | undefined):
|
|
21
|
+
}>(withTags?: E): import("@likec4/core").NonEmptyArray<import("@likec4/core").Tag> | null;
|
|
22
|
+
convertLinks(source?: ast.LinkProperty["$container"]): import("@likec4/core").Link[] | undefined;
|
|
23
|
+
parseLinks(source?: ast.LinkProperty["$container"]): import("@likec4/core").Link[] | undefined;
|
|
24
|
+
parseIconProperty(prop: ast.IconProperty | undefined): import("@likec4/core").IconUrl | undefined;
|
|
26
25
|
parseImageAlias(value: string): string | undefined;
|
|
27
|
-
parseColorLiteral(astNode: ast.ColorLiteral):
|
|
26
|
+
parseColorLiteral(astNode: ast.ColorLiteral): import("@likec4/core").ColorLiteral | undefined;
|
|
28
27
|
parseElementStyle(elementProps: Array<ast.ElementProperty> | ast.ElementStyleProperty | undefined): import("../../ast").ParsedElementStyle;
|
|
29
28
|
parseStyleProps(styleProps: Array<ast.StyleProperty> | undefined): import("../../ast").ParsedElementStyle;
|
|
30
29
|
parseBaseProps(props: {
|
|
@@ -39,8 +38,8 @@ export declare function ImportsParser<TBase extends Base>(B: TBase): {
|
|
|
39
38
|
technology?: string | undefined;
|
|
40
39
|
}): {
|
|
41
40
|
title?: string;
|
|
42
|
-
summary?:
|
|
43
|
-
description?:
|
|
41
|
+
summary?: import("@likec4/core").MarkdownOrString;
|
|
42
|
+
description?: import("@likec4/core").MarkdownOrString;
|
|
44
43
|
technology?: string;
|
|
45
44
|
};
|
|
46
45
|
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { nonNullable } from '@likec4/core';
|
|
2
|
+
import { loggable } from '@likec4/log';
|
|
3
|
+
import { serverLogger } from '../../logger';
|
|
4
|
+
const logger = serverLogger.getChild('ImportsParser');
|
|
5
|
+
export function ImportsParser(B) {
|
|
6
|
+
return class ImportsParser extends B {
|
|
7
|
+
parseImports() {
|
|
8
|
+
const imports = this.doc.parseResult.value.imports ?? [];
|
|
9
|
+
for (const importsFromPoject of imports) {
|
|
10
|
+
const project = importsFromPoject.project;
|
|
11
|
+
let imported = importsFromPoject.imports;
|
|
12
|
+
while (imported) {
|
|
13
|
+
try {
|
|
14
|
+
this.doc.c4Imports.set(project, this.resolveFqn(nonNullable(imported.imported.ref, `ElementRef is empty of imported: ${imported.imported.$refText}`)));
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
logger.warn(loggable(e));
|
|
18
|
+
}
|
|
19
|
+
imported = imported.prev;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -32,14 +32,14 @@ export declare function ModelParser<TBase extends WithExpressionV2>(B: TBase): {
|
|
|
32
32
|
readonly doc: import("../../ast").ParsedLikeC4LangiumDocument;
|
|
33
33
|
get project(): import("../../workspace").Project;
|
|
34
34
|
resolveFqn(node: ast.FqnReferenceable): c4.Fqn;
|
|
35
|
-
getAstNodePath(node:
|
|
35
|
+
getAstNodePath(node: import("langium").AstNode): string;
|
|
36
36
|
getMetadata(metadataAstNode: ast.MetadataProperty | undefined): {
|
|
37
37
|
[key: string]: string | string[];
|
|
38
38
|
} | undefined;
|
|
39
39
|
parseMarkdownOrString(markdownOrString: ast.MarkdownOrString | undefined): c4.MarkdownOrString | undefined;
|
|
40
40
|
convertTags<E extends {
|
|
41
41
|
tags?: ast.Tags;
|
|
42
|
-
}>(withTags?: E | undefined):
|
|
42
|
+
}>(withTags?: E | undefined): c4.NonEmptyArray<c4.Tag<string>> | null;
|
|
43
43
|
parseTags<E extends {
|
|
44
44
|
tags?: ast.Tags;
|
|
45
45
|
}>(withTags?: E): c4.NonEmptyArray<c4.Tag> | null;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { invariant, isNonEmptyArray, LinkedList, nonexhaustive, nonNullable } from '@likec4/core';
|
|
2
|
+
import { exact, FqnRef } from '@likec4/core/types';
|
|
3
|
+
import { loggable } from '@likec4/log';
|
|
4
|
+
import { filter, first, isDefined, isEmpty, isTruthy, map, mapToObj, pipe } from 'remeda';
|
|
5
|
+
import { ast, toRelationshipStyle, } from '../../ast';
|
|
6
|
+
import { logger as mainLogger } from '../../logger';
|
|
7
|
+
import { stringHash } from '../../utils/stringHash';
|
|
8
|
+
const logger = mainLogger.getChild('ModelParser');
|
|
9
|
+
function* streamModel(doc) {
|
|
10
|
+
const traverseStack = LinkedList.from(doc.parseResult.value.models.flatMap(m => m.elements));
|
|
11
|
+
const relations = [];
|
|
12
|
+
let el;
|
|
13
|
+
while ((el = traverseStack.shift())) {
|
|
14
|
+
if (ast.isRelation(el)) {
|
|
15
|
+
relations.push(el);
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if (el.body && el.body.elements && el.body.elements.length > 0) {
|
|
19
|
+
for (const child of el.body.elements) {
|
|
20
|
+
traverseStack.push(child);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
yield el;
|
|
24
|
+
}
|
|
25
|
+
yield* relations;
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
export function ModelParser(B) {
|
|
29
|
+
return class ModelParser extends B {
|
|
30
|
+
parseModel() {
|
|
31
|
+
const doc = this.doc;
|
|
32
|
+
for (const el of streamModel(doc)) {
|
|
33
|
+
try {
|
|
34
|
+
if (ast.isElement(el)) {
|
|
35
|
+
doc.c4Elements.push(this.parseElement(el));
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (ast.isRelation(el)) {
|
|
39
|
+
if (this.isValid(el)) {
|
|
40
|
+
doc.c4Relations.push(this.parseRelation(el));
|
|
41
|
+
}
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (ast.isExtendElement(el)) {
|
|
45
|
+
const parsed = this.parseExtendElement(el);
|
|
46
|
+
if (parsed) {
|
|
47
|
+
doc.c4ExtendElements.push(parsed);
|
|
48
|
+
}
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
nonexhaustive(el);
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
const astPath = this.getAstNodePath(el);
|
|
55
|
+
const error = loggable(e);
|
|
56
|
+
const message = e instanceof Error ? e.message : String(error);
|
|
57
|
+
logger.warn(`Error on {eltype}: ${message}\n document: {path}\n astpath: {astPath}\n${error}`, {
|
|
58
|
+
path: doc.uri.path,
|
|
59
|
+
eltype: el.$type,
|
|
60
|
+
astPath,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
parseElement(astNode) {
|
|
66
|
+
const isValid = this.isValid;
|
|
67
|
+
const id = this.resolveFqn(astNode);
|
|
68
|
+
const kind = nonNullable(astNode.kind.ref, 'Element kind is not resolved').name;
|
|
69
|
+
const tags = this.parseTags(astNode.body);
|
|
70
|
+
const style = this.parseElementStyle(astNode.body?.props);
|
|
71
|
+
const metadata = this.getMetadata(astNode.body?.props.find(ast.isMetadataProperty));
|
|
72
|
+
const astPath = this.getAstNodePath(astNode);
|
|
73
|
+
let [_title, _summary, _technology] = astNode.props ?? [];
|
|
74
|
+
const bodyProps = pipe(astNode.body?.props ?? [], filter(isValid), filter(ast.isElementStringProperty), mapToObj(p => [p.key, p.value]));
|
|
75
|
+
const { title, ...descAndTech } = this.parseBaseProps(bodyProps, {
|
|
76
|
+
title: _title,
|
|
77
|
+
summary: _summary,
|
|
78
|
+
technology: _technology,
|
|
79
|
+
});
|
|
80
|
+
const links = this.parseLinks(astNode.body);
|
|
81
|
+
return exact({
|
|
82
|
+
id,
|
|
83
|
+
kind,
|
|
84
|
+
astPath,
|
|
85
|
+
title: title ?? astNode.name,
|
|
86
|
+
metadata,
|
|
87
|
+
tags: tags ?? undefined,
|
|
88
|
+
...(links && isNonEmptyArray(links) && { links }),
|
|
89
|
+
...descAndTech,
|
|
90
|
+
style,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
parseExtendElement(astNode) {
|
|
94
|
+
const id = this.resolveFqn(astNode);
|
|
95
|
+
const tags = this.parseTags(astNode.body);
|
|
96
|
+
const metadata = this.getMetadata(astNode.body?.props.find(ast.isMetadataProperty));
|
|
97
|
+
const astPath = this.getAstNodePath(astNode);
|
|
98
|
+
const links = this.parseLinks(astNode.body) ?? [];
|
|
99
|
+
if (!tags && isEmpty(metadata ?? {}) && isEmpty(links)) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
return exact({
|
|
103
|
+
id,
|
|
104
|
+
astPath,
|
|
105
|
+
metadata,
|
|
106
|
+
tags,
|
|
107
|
+
links: isNonEmptyArray(links) ? links : null,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
_resolveRelationSource(node) {
|
|
111
|
+
if (isDefined(node.source)) {
|
|
112
|
+
const source = this.parseFqnRef(node.source);
|
|
113
|
+
invariant(FqnRef.isModelRef(source) || FqnRef.isImportRef(source), 'Relation source must be a model reference');
|
|
114
|
+
return source;
|
|
115
|
+
}
|
|
116
|
+
if (ast.isElementBody(node.$container)) {
|
|
117
|
+
return {
|
|
118
|
+
model: this.resolveFqn(node.$container.$container),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
if (ast.isExtendElementBody(node.$container)) {
|
|
122
|
+
return {
|
|
123
|
+
model: this.resolveFqn(node.$container.$container),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
throw new Error('RelationRefError: Invalid container for sourceless relation');
|
|
127
|
+
}
|
|
128
|
+
parseRelation(astNode) {
|
|
129
|
+
const isValid = this.isValid;
|
|
130
|
+
const source = this._resolveRelationSource(astNode);
|
|
131
|
+
const target = this.parseFqnRef(astNode.target);
|
|
132
|
+
invariant(FqnRef.isModelRef(target) || FqnRef.isImportRef(target), 'Target must be a model reference');
|
|
133
|
+
const tags = this.parseTags(astNode) ?? this.parseTags(astNode.body);
|
|
134
|
+
const links = this.parseLinks(astNode.body);
|
|
135
|
+
const kind = (astNode.kind ?? astNode.dotKind?.kind)?.ref?.name;
|
|
136
|
+
const metadata = this.getMetadata(astNode.body?.props.find(ast.isMetadataProperty));
|
|
137
|
+
const astPath = this.getAstNodePath(astNode);
|
|
138
|
+
const bodyProps = pipe(astNode.body?.props ?? [], filter(ast.isRelationStringProperty), filter(p => isTruthy(p.value)), mapToObj(p => [p.key, p.value]));
|
|
139
|
+
const navigateTo = pipe(astNode.body?.props ?? [], filter(ast.isRelationNavigateToProperty), map(p => p.value.view.ref?.name), filter(isTruthy), first());
|
|
140
|
+
const { title = '', description, technology } = this.parseBaseProps(bodyProps, {
|
|
141
|
+
// inline props
|
|
142
|
+
title: astNode.title,
|
|
143
|
+
description: astNode.description,
|
|
144
|
+
technology: astNode.technology,
|
|
145
|
+
});
|
|
146
|
+
const styleProp = astNode.body?.props.find(ast.isRelationStyleProperty);
|
|
147
|
+
const id = stringHash(astPath, source.model, target.model);
|
|
148
|
+
return exact({
|
|
149
|
+
id,
|
|
150
|
+
astPath,
|
|
151
|
+
source,
|
|
152
|
+
target,
|
|
153
|
+
title,
|
|
154
|
+
metadata,
|
|
155
|
+
kind,
|
|
156
|
+
tags: tags ?? undefined,
|
|
157
|
+
links: isNonEmptyArray(links) ? links : undefined,
|
|
158
|
+
navigateTo: navigateTo ? navigateTo : undefined,
|
|
159
|
+
description,
|
|
160
|
+
technology,
|
|
161
|
+
...toRelationshipStyle(styleProp?.props, isValid),
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}
|
|
@@ -37,14 +37,14 @@ export declare function PredicatesParser<TBase extends WithExpressionV2>(B: TBas
|
|
|
37
37
|
readonly doc: import("../../ast").ParsedLikeC4LangiumDocument;
|
|
38
38
|
get project(): import("../../workspace").Project;
|
|
39
39
|
resolveFqn(node: ast.FqnReferenceable): c4.Fqn;
|
|
40
|
-
getAstNodePath(node:
|
|
40
|
+
getAstNodePath(node: import("langium").AstNode): string;
|
|
41
41
|
getMetadata(metadataAstNode: ast.MetadataProperty | undefined): {
|
|
42
42
|
[key: string]: string | string[];
|
|
43
43
|
} | undefined;
|
|
44
44
|
parseMarkdownOrString(markdownOrString: ast.MarkdownOrString | undefined): c4.MarkdownOrString | undefined;
|
|
45
45
|
convertTags<E extends {
|
|
46
46
|
tags?: ast.Tags;
|
|
47
|
-
}>(withTags?: E | undefined):
|
|
47
|
+
}>(withTags?: E | undefined): c4.NonEmptyArray<c4.Tag<string>> | null;
|
|
48
48
|
parseTags<E extends {
|
|
49
49
|
tags?: ast.Tags;
|
|
50
50
|
}>(withTags?: E): c4.NonEmptyArray<c4.Tag> | null;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { nonexhaustive } from '@likec4/core';
|
|
2
|
+
import { ast } from '../../ast';
|
|
3
|
+
export function PredicatesParser(B) {
|
|
4
|
+
return class PredicatesParser extends B {
|
|
5
|
+
parsePredicate(astNode) {
|
|
6
|
+
return this.parseExpressionV2(astNode);
|
|
7
|
+
}
|
|
8
|
+
parseElementPredicate(astNode) {
|
|
9
|
+
if (ast.isFqnExprWith(astNode)) {
|
|
10
|
+
return this.parseFqnExprWith(astNode);
|
|
11
|
+
}
|
|
12
|
+
if (ast.isFqnExprOrWhere(astNode)) {
|
|
13
|
+
return this.parseFqnExprOrWhere(astNode);
|
|
14
|
+
}
|
|
15
|
+
nonexhaustive(astNode);
|
|
16
|
+
}
|
|
17
|
+
parseElementPredicateOrWhere(astNode) {
|
|
18
|
+
return this.parseFqnExprOrWhere(astNode);
|
|
19
|
+
}
|
|
20
|
+
parseElementExpression(astNode) {
|
|
21
|
+
return this.parseFqnExpr(astNode);
|
|
22
|
+
}
|
|
23
|
+
parseElementPredicateWhere(astNode) {
|
|
24
|
+
return this.parseFqnExprWhere(astNode);
|
|
25
|
+
}
|
|
26
|
+
parseElementPredicateWith(astNode) {
|
|
27
|
+
return this.parseFqnExprWith(astNode);
|
|
28
|
+
}
|
|
29
|
+
parseRelationPredicate(astNode) {
|
|
30
|
+
return this.parseRelationExprOrWith(astNode);
|
|
31
|
+
}
|
|
32
|
+
parseRelationPredicateOrWhere(astNode) {
|
|
33
|
+
return this.parseRelationExprOrWhere(astNode);
|
|
34
|
+
}
|
|
35
|
+
parseRelationPredicateWhere(astNode) {
|
|
36
|
+
return this.parseRelationExprWhere(astNode);
|
|
37
|
+
}
|
|
38
|
+
parseRelationPredicateWith(astNode) {
|
|
39
|
+
return this.parseRelationExprWith(astNode);
|
|
40
|
+
}
|
|
41
|
+
parseRelationExpression(astNode) {
|
|
42
|
+
return this.parseRelationExpr(astNode);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -15,14 +15,14 @@ export declare function SpecificationParser<TBase extends Base>(B: TBase): {
|
|
|
15
15
|
readonly doc: import("../../ast").ParsedLikeC4LangiumDocument;
|
|
16
16
|
get project(): import("../../workspace").Project;
|
|
17
17
|
resolveFqn(node: ast.FqnReferenceable): c4.Fqn;
|
|
18
|
-
getAstNodePath(node:
|
|
18
|
+
getAstNodePath(node: import("langium").AstNode): string;
|
|
19
19
|
getMetadata(metadataAstNode: ast.MetadataProperty | undefined): {
|
|
20
20
|
[key: string]: string | string[];
|
|
21
21
|
} | undefined;
|
|
22
22
|
parseMarkdownOrString(markdownOrString: ast.MarkdownOrString | undefined): c4.MarkdownOrString | undefined;
|
|
23
23
|
convertTags<E extends {
|
|
24
24
|
tags?: ast.Tags;
|
|
25
|
-
}>(withTags?: E | undefined):
|
|
25
|
+
}>(withTags?: E | undefined): c4.NonEmptyArray<c4.Tag<string>> | null;
|
|
26
26
|
parseTags<E extends {
|
|
27
27
|
tags?: ast.Tags;
|
|
28
28
|
}>(withTags?: E): c4.NonEmptyArray<c4.Tag> | null;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import * as c4 from '@likec4/core';
|
|
2
|
+
import { exact } from '@likec4/core';
|
|
3
|
+
import { nonNullable } from '@likec4/core/utils';
|
|
4
|
+
import { loggable } from '@likec4/log';
|
|
5
|
+
import { filter, isNonNullish, isNullish, isTruthy, mapToObj, omitBy, pipe } from 'remeda';
|
|
6
|
+
import { ast, parseMarkdownAsString, toRelationshipStyle } from '../../ast';
|
|
7
|
+
import { serverLogger } from '../../logger';
|
|
8
|
+
import { removeIndent } from './Base';
|
|
9
|
+
const logger = serverLogger.getChild('SpecificationParser');
|
|
10
|
+
export function SpecificationParser(B) {
|
|
11
|
+
return class SpecificationParser extends B {
|
|
12
|
+
parseSpecification() {
|
|
13
|
+
const { parseResult: { value: { specifications, }, }, c4Specification, } = this.doc;
|
|
14
|
+
const isValid = this.isValid;
|
|
15
|
+
for (const elementSpec of specifications.flatMap(s => s.elements.filter(isValid))) {
|
|
16
|
+
try {
|
|
17
|
+
Object.assign(c4Specification.elements, this.parseElementSpecificationNode(elementSpec));
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
logger.warn(loggable(e));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
for (const deploymentNodeSpec of specifications.flatMap(s => s.deploymentNodes.filter(isValid))) {
|
|
24
|
+
try {
|
|
25
|
+
Object.assign(c4Specification.deployments, this.parseElementSpecificationNode(deploymentNodeSpec));
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
logger.warn(loggable(e));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const relations_specs = specifications.flatMap(s => s.relationships.filter(this.isValid));
|
|
32
|
+
for (const { kind, props } of relations_specs) {
|
|
33
|
+
try {
|
|
34
|
+
const kindName = kind.name;
|
|
35
|
+
if (!isTruthy(kindName)) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (kindName in c4Specification.relationships) {
|
|
39
|
+
logger.warn(`Relationship kind "${kindName}" is already defined`);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const bodyProps = pipe(props.filter(ast.isSpecificationRelationshipStringProperty) ?? [], filter(p => this.isValid(p) && isNonNullish(p.value)), mapToObj(p => [p.key, removeIndent(parseMarkdownAsString(p.value))]), omitBy(isNullish));
|
|
43
|
+
c4Specification.relationships[kindName] = {
|
|
44
|
+
...bodyProps,
|
|
45
|
+
...toRelationshipStyle(props.filter(ast.isRelationshipStyleProperty), this.isValid),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
logger.warn(loggable(e));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const tags_specs = specifications.flatMap(s => s.tags.filter(this.isValid));
|
|
53
|
+
for (const tagSpec of tags_specs) {
|
|
54
|
+
try {
|
|
55
|
+
const tag = tagSpec.tag.name;
|
|
56
|
+
const astPath = this.getAstNodePath(tagSpec.tag);
|
|
57
|
+
const color = tagSpec.color && this.parseColorLiteral(tagSpec.color);
|
|
58
|
+
if (isTruthy(tag)) {
|
|
59
|
+
c4Specification.tags[tag] = {
|
|
60
|
+
astPath,
|
|
61
|
+
...(color ? { color } : {}),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
logger.warn(loggable(e));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const colors_specs = specifications.flatMap(s => s.colors.filter(isValid));
|
|
70
|
+
for (const { name, color } of colors_specs) {
|
|
71
|
+
try {
|
|
72
|
+
const colorName = name.name;
|
|
73
|
+
if (colorName in c4Specification.colors) {
|
|
74
|
+
logger.warn(`Custom color "${colorName}" is already defined`);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
c4Specification.colors[colorName] = {
|
|
78
|
+
color: nonNullable(this.parseColorLiteral(color), `Color "${colorName}" is not valid: ${color}`),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
logger.warn(loggable(e));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
parseElementSpecificationNode(specAst) {
|
|
87
|
+
const { kind, props } = specAst;
|
|
88
|
+
const kindName = kind.name;
|
|
89
|
+
if (!isTruthy(kindName)) {
|
|
90
|
+
throw new Error('DeploymentNodeKind name is not resolved');
|
|
91
|
+
}
|
|
92
|
+
const tags = this.parseTags(specAst);
|
|
93
|
+
const style = this.parseElementStyle(props.find(ast.isElementStyleProperty));
|
|
94
|
+
const links = this.parseLinks(specAst);
|
|
95
|
+
const bodyProps = pipe(props.filter(ast.isSpecificationElementStringProperty) ?? [], filter(p => this.isValid(p)), mapToObj(p => [p.key, p.value]));
|
|
96
|
+
const baseProps = this.parseBaseProps(bodyProps);
|
|
97
|
+
const notation = removeIndent(parseMarkdownAsString(bodyProps.notation));
|
|
98
|
+
return {
|
|
99
|
+
[kindName]: exact({
|
|
100
|
+
...baseProps,
|
|
101
|
+
notation,
|
|
102
|
+
tags: tags ?? undefined,
|
|
103
|
+
...(links && c4.isNonEmptyArray(links) && { links }),
|
|
104
|
+
style,
|
|
105
|
+
}),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DefaultValueConverter, ValueConverter } from 'langium';
|
|
2
|
+
export class LikeC4ValueConverter extends DefaultValueConverter {
|
|
3
|
+
runConverter(rule, input, cstNode) {
|
|
4
|
+
if (rule.name === 'MarkdownString') {
|
|
5
|
+
if ((input.startsWith('"""') && input.endsWith('"""')) || (input.startsWith(`'''`) && input.endsWith(`'''`))) {
|
|
6
|
+
input = input.slice(2, -2);
|
|
7
|
+
}
|
|
8
|
+
return ValueConverter.convertString(input);
|
|
9
|
+
}
|
|
10
|
+
return super.runConverter(rule, input, cstNode);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -62,14 +62,14 @@ export declare function ViewsParser<TBase extends WithPredicates & WithDeploymen
|
|
|
62
62
|
readonly doc: import("../../ast").ParsedLikeC4LangiumDocument;
|
|
63
63
|
get project(): import("../../workspace").Project;
|
|
64
64
|
resolveFqn(node: ast.FqnReferenceable): c4.Fqn;
|
|
65
|
-
getAstNodePath(node:
|
|
65
|
+
getAstNodePath(node: import("langium").AstNode): string;
|
|
66
66
|
getMetadata(metadataAstNode: ast.MetadataProperty | undefined): {
|
|
67
67
|
[key: string]: string | string[];
|
|
68
68
|
} | undefined;
|
|
69
69
|
parseMarkdownOrString(markdownOrString: ast.MarkdownOrString | undefined): c4.MarkdownOrString | undefined;
|
|
70
70
|
convertTags<E extends {
|
|
71
71
|
tags?: ast.Tags;
|
|
72
|
-
}>(withTags?: E | undefined):
|
|
72
|
+
}>(withTags?: E | undefined): c4.NonEmptyArray<c4.Tag<string>> | null;
|
|
73
73
|
parseTags<E extends {
|
|
74
74
|
tags?: ast.Tags;
|
|
75
75
|
}>(withTags?: E): c4.NonEmptyArray<c4.Tag> | null;
|
|
@@ -104,7 +104,7 @@ export declare function ViewsParser<TBase extends WithPredicates & WithDeploymen
|
|
|
104
104
|
parseDeploymentNode(astNode: ast.DeploymentNode): import("../../ast").ParsedAstDeployment.Node;
|
|
105
105
|
parseDeployedInstance(astNode: ast.DeployedInstance): import("../../ast").ParsedAstDeployment.Instance;
|
|
106
106
|
parseExtendDeployment(astNode: ast.ExtendDeployment): import("../../ast").ParsedAstExtend | null;
|
|
107
|
-
_resolveDeploymentRelationSource(node: ast.DeploymentRelation): c4;
|
|
107
|
+
_resolveDeploymentRelationSource(node: ast.DeploymentRelation): c4.FqnRef;
|
|
108
108
|
parseDeploymentRelation(astNode: ast.DeploymentRelation): import("../../ast").ParsedAstDeploymentRelation;
|
|
109
109
|
};
|
|
110
110
|
} & TBase;
|