@likec4/language-server 1.18.0 → 1.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/LikeC4FileSystem.d.ts +13 -0
- package/dist/LikeC4FileSystem.js +27 -0
- package/dist/Rpc.d.ts +9 -0
- package/dist/Rpc.js +132 -0
- package/dist/ast.d.ts +200 -0
- package/dist/ast.js +276 -0
- package/dist/browser.d.ts +7 -20
- package/dist/browser.js +13 -0
- package/dist/documentation/documentation-provider.d.ts +8 -0
- package/dist/documentation/documentation-provider.js +46 -0
- package/dist/documentation/index.d.ts +1 -0
- package/dist/documentation/index.js +1 -0
- package/dist/formatting/LikeC4Formatter.d.ts +27 -0
- package/dist/formatting/LikeC4Formatter.js +261 -0
- package/dist/formatting/utils.d.ts +6 -0
- package/dist/formatting/utils.js +15 -0
- package/dist/generated/ast.d.ts +1242 -0
- package/dist/generated/ast.js +1945 -0
- package/dist/generated/grammar.d.ts +6 -0
- package/dist/generated/grammar.js +3 -0
- package/dist/generated/module.d.ts +9 -0
- package/dist/generated/module.js +23 -0
- package/dist/generated-lib/icons.d.ts +1 -0
- package/dist/{likec4lib.mjs → generated-lib/icons.js} +1 -6
- package/dist/index.d.ts +9 -31
- package/dist/index.js +14 -0
- package/dist/like-c4.langium +845 -0
- package/dist/likec4lib.d.ts +4 -6
- package/dist/likec4lib.js +4 -0
- package/dist/logger.d.ts +7 -0
- package/dist/logger.js +73 -0
- package/dist/lsp/CodeLensProvider.d.ts +9 -0
- package/dist/lsp/CodeLensProvider.js +40 -0
- package/dist/lsp/CompletionProvider.d.ts +6 -0
- package/dist/lsp/CompletionProvider.js +135 -0
- package/dist/lsp/DocumentHighlightProvider.d.ts +9 -0
- package/dist/lsp/DocumentHighlightProvider.js +10 -0
- package/dist/lsp/DocumentLinkProvider.d.ts +11 -0
- package/dist/lsp/DocumentLinkProvider.js +49 -0
- package/dist/lsp/DocumentSymbolProvider.d.ts +32 -0
- package/dist/lsp/DocumentSymbolProvider.js +274 -0
- package/dist/lsp/HoverProvider.d.ts +10 -0
- package/dist/lsp/HoverProvider.js +69 -0
- package/dist/lsp/RenameProvider.d.ts +5 -0
- package/dist/lsp/RenameProvider.js +6 -0
- package/dist/lsp/SemanticTokenProvider.d.ts +7 -0
- package/dist/lsp/SemanticTokenProvider.js +297 -0
- package/dist/lsp/index.d.ts +7 -0
- package/dist/lsp/index.js +7 -0
- package/dist/model/deployments-index.d.ts +60 -0
- package/dist/model/deployments-index.js +181 -0
- package/dist/model/fqn-computation.d.ts +3 -0
- package/dist/model/fqn-computation.js +72 -0
- package/dist/model/fqn-index.d.ts +25 -0
- package/dist/model/fqn-index.js +96 -0
- package/dist/model/index.d.ts +6 -0
- package/dist/model/index.js +6 -0
- package/dist/model/model-builder.d.ts +32 -0
- package/dist/model/model-builder.js +598 -0
- package/dist/model/model-locator.d.ts +23 -0
- package/dist/model/model-locator.js +126 -0
- package/dist/model/model-parser-where.d.ts +3 -0
- package/dist/model/model-parser-where.js +70 -0
- package/dist/model/model-parser.d.ts +292 -0
- package/dist/model/model-parser.js +72 -0
- package/dist/model/parser/Base.d.ts +28 -0
- package/dist/model/parser/Base.js +87 -0
- package/dist/model/parser/DeploymentModelParser.d.ts +33 -0
- package/dist/model/parser/DeploymentModelParser.js +162 -0
- package/dist/model/parser/DeploymentViewParser.d.ts +38 -0
- package/dist/model/parser/DeploymentViewParser.js +98 -0
- package/dist/model/parser/FqnRefParser.d.ts +29 -0
- package/dist/model/parser/FqnRefParser.js +108 -0
- package/dist/model/parser/GlobalsParser.d.ts +66 -0
- package/dist/model/parser/GlobalsParser.js +80 -0
- package/dist/model/parser/ModelParser.d.ts +27 -0
- package/dist/model/parser/ModelParser.js +122 -0
- package/dist/model/parser/PredicatesParser.d.ts +34 -0
- package/dist/model/parser/PredicatesParser.js +272 -0
- package/dist/model/parser/SpecificationParser.d.ts +27 -0
- package/dist/model/parser/SpecificationParser.js +120 -0
- package/dist/model/parser/ViewsParser.d.ts +64 -0
- package/dist/model/parser/ViewsParser.js +377 -0
- package/dist/model-change/ModelChanges.d.ts +15 -0
- package/dist/model-change/ModelChanges.js +89 -0
- package/dist/model-change/changeElementStyle.d.ts +16 -0
- package/dist/model-change/changeElementStyle.js +136 -0
- package/dist/model-change/changeViewLayout.d.ts +12 -0
- package/dist/model-change/changeViewLayout.js +32 -0
- package/dist/model-change/saveManualLayout.d.ts +11 -0
- package/dist/model-change/saveManualLayout.js +27 -0
- package/dist/module.d.ts +70 -0
- package/dist/module.js +162 -0
- package/dist/protocol.d.ts +38 -23
- package/dist/protocol.js +15 -0
- package/dist/references/index.d.ts +3 -0
- package/dist/references/index.js +3 -0
- package/dist/references/name-provider.d.ts +9 -0
- package/dist/references/name-provider.js +33 -0
- package/dist/references/scope-computation.d.ts +20 -0
- package/dist/references/scope-computation.js +281 -0
- package/dist/references/scope-provider.d.ts +16 -0
- package/dist/references/scope-provider.js +165 -0
- package/dist/shared/NodeKindProvider.d.ts +15 -0
- package/dist/shared/NodeKindProvider.js +108 -0
- package/dist/shared/WorkspaceManager.d.ts +18 -0
- package/dist/shared/WorkspaceManager.js +36 -0
- package/dist/shared/WorkspaceSymbolProvider.d.ts +3 -0
- package/dist/shared/WorkspaceSymbolProvider.js +3 -0
- package/dist/shared/index.d.ts +3 -0
- package/dist/shared/index.js +3 -0
- package/dist/test/index.d.ts +1 -0
- package/dist/test/index.js +1 -0
- package/dist/test/setup.d.ts +1 -0
- package/dist/test/setup.js +7 -0
- package/dist/test/testServices.d.ts +22 -0
- package/dist/test/testServices.js +119 -0
- package/dist/utils/elementRef.d.ts +11 -0
- package/dist/utils/elementRef.js +15 -0
- package/dist/utils/fqnRef.d.ts +8 -0
- package/dist/utils/fqnRef.js +46 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/printDocs.d.ts +2 -0
- package/dist/utils/printDocs.js +1 -0
- package/dist/utils/stringHash.d.ts +1 -0
- package/dist/utils/stringHash.js +5 -0
- package/dist/validation/_shared.d.ts +3 -0
- package/dist/validation/_shared.js +22 -0
- package/dist/validation/deployment-checks.d.ts +6 -0
- package/dist/validation/deployment-checks.js +114 -0
- package/dist/validation/dynamic-view-rule.d.ts +4 -0
- package/dist/validation/dynamic-view-rule.js +17 -0
- package/dist/validation/dynamic-view-step.d.ts +4 -0
- package/dist/validation/dynamic-view-step.js +29 -0
- package/dist/validation/element.d.ts +4 -0
- package/dist/validation/element.js +49 -0
- package/dist/validation/index.d.ts +15 -0
- package/dist/validation/index.js +152 -0
- package/dist/validation/property-checks.d.ts +6 -0
- package/dist/validation/property-checks.js +39 -0
- package/dist/validation/relation.d.ts +5 -0
- package/dist/validation/relation.js +56 -0
- package/dist/validation/specification.d.ts +11 -0
- package/dist/validation/specification.js +136 -0
- package/dist/validation/view-predicates/element-with.d.ts +4 -0
- package/dist/validation/view-predicates/element-with.js +31 -0
- package/dist/validation/view-predicates/expanded-element.d.ts +4 -0
- package/dist/validation/view-predicates/expanded-element.js +12 -0
- package/dist/validation/view-predicates/expression-v2.d.ts +5 -0
- package/dist/validation/view-predicates/expression-v2.js +83 -0
- package/dist/validation/view-predicates/incoming.d.ts +4 -0
- package/dist/validation/view-predicates/incoming.js +16 -0
- package/dist/validation/view-predicates/index.d.ts +6 -0
- package/dist/validation/view-predicates/index.js +6 -0
- package/dist/validation/view-predicates/outgoing.d.ts +4 -0
- package/dist/validation/view-predicates/outgoing.js +16 -0
- package/dist/validation/view-predicates/relation-with.d.ts +4 -0
- package/dist/validation/view-predicates/relation-with.js +13 -0
- package/dist/validation/view.d.ts +4 -0
- package/dist/validation/view.js +23 -0
- package/dist/view-utils/assignNavigateTo.d.ts +2 -0
- package/dist/view-utils/assignNavigateTo.js +25 -0
- package/dist/view-utils/index.d.ts +2 -0
- package/dist/view-utils/index.js +2 -0
- package/dist/view-utils/manual-layout.d.ts +7 -0
- package/dist/view-utils/manual-layout.js +99 -0
- package/dist/view-utils/resolve-relative-paths.d.ts +2 -0
- package/dist/view-utils/resolve-relative-paths.js +78 -0
- package/dist/views/configurable-layouter.d.ts +7 -0
- package/dist/views/configurable-layouter.js +55 -0
- package/dist/views/index.d.ts +1 -0
- package/dist/views/index.js +1 -0
- package/dist/views/likec4-views.d.ts +26 -0
- package/dist/views/likec4-views.js +113 -0
- package/package.json +40 -54
- package/src/LikeC4FileSystem.ts +22 -21
- package/src/Rpc.ts +13 -7
- package/src/ast.ts +44 -133
- package/src/browser.ts +11 -11
- package/src/documentation/documentation-provider.ts +52 -0
- package/src/documentation/index.ts +1 -0
- package/src/generated/ast.ts +177 -177
- package/src/generated/grammar.ts +1 -1
- package/src/index.ts +13 -9
- package/src/like-c4.langium +37 -34
- package/src/logger.ts +34 -55
- package/src/lsp/CompletionProvider.ts +4 -4
- package/src/lsp/DocumentSymbolProvider.ts +110 -28
- package/src/lsp/HoverProvider.ts +5 -3
- package/src/lsp/SemanticTokenProvider.ts +2 -2
- package/src/model/deployments-index.ts +18 -14
- package/src/model/fqn-computation.ts +8 -8
- package/src/model/model-builder.ts +62 -60
- package/src/model/model-parser.ts +62 -1574
- package/src/model/parser/Base.ts +107 -0
- package/src/model/parser/DeploymentModelParser.ts +192 -0
- package/src/model/parser/DeploymentViewParser.ts +116 -0
- package/src/model/parser/FqnRefParser.ts +118 -0
- package/src/model/parser/GlobalsParser.ts +96 -0
- package/src/model/parser/ModelParser.ts +141 -0
- package/src/model/parser/PredicatesParser.ts +291 -0
- package/src/model/parser/SpecificationParser.ts +133 -0
- package/src/model/parser/ViewsParser.ts +428 -0
- package/src/module.ts +71 -25
- package/src/protocol.ts +29 -4
- package/src/references/scope-computation.ts +35 -35
- package/src/references/scope-provider.ts +13 -7
- package/src/utils/{deploymentRef.ts → fqnRef.ts} +27 -2
- package/src/validation/_shared.ts +0 -1
- package/src/validation/deployment-checks.ts +49 -62
- package/src/validation/dynamic-view-rule.ts +5 -4
- package/src/validation/dynamic-view-step.ts +23 -26
- package/src/validation/index.ts +100 -9
- package/src/validation/property-checks.ts +11 -10
- package/src/validation/specification.ts +38 -38
- package/src/validation/view-predicates/element-with.ts +6 -5
- package/src/validation/view-predicates/expanded-element.ts +6 -5
- package/src/validation/view-predicates/expression-v2.ts +101 -0
- package/src/validation/view-predicates/incoming.ts +6 -5
- package/src/validation/view-predicates/index.ts +1 -1
- package/src/validation/view-predicates/outgoing.ts +6 -5
- package/src/validation/view-predicates/relation-with.ts +6 -5
- package/src/validation/view.ts +5 -5
- package/src/view-utils/assignNavigateTo.ts +1 -1
- package/src/view-utils/manual-layout.ts +25 -0
- package/src/views/configurable-layouter.ts +65 -0
- package/src/views/index.ts +1 -0
- package/src/views/likec4-views.ts +139 -0
- package/dist/browser.cjs +0 -25
- package/dist/browser.d.cts +0 -23
- package/dist/browser.d.mts +0 -23
- package/dist/browser.mjs +0 -20
- package/dist/index.cjs +0 -53
- package/dist/index.d.cts +0 -34
- package/dist/index.d.mts +0 -34
- package/dist/index.mjs +0 -46
- package/dist/likec4lib.cjs +0 -1546
- package/dist/likec4lib.d.cts +0 -6
- package/dist/likec4lib.d.mts +0 -6
- package/dist/protocol.cjs +0 -25
- package/dist/protocol.d.cts +0 -48
- package/dist/protocol.d.mts +0 -48
- package/dist/protocol.mjs +0 -17
- package/dist/shared/language-server.CO_nmHiL.cjs +0 -7689
- package/dist/shared/language-server.Da6ey08o.d.cts +0 -1619
- package/dist/shared/language-server.De7S3e5Z.d.ts +0 -1619
- package/dist/shared/language-server.Dj4iDjtB.d.mts +0 -1619
- package/dist/shared/language-server.oO_9JoAG.mjs +0 -7666
- package/src/validation/view-predicates/deployments.ts +0 -56
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { LikeC4LangiumDocument } from '../ast';
|
|
2
|
+
export declare function createTestServices(workspace?: string): {
|
|
3
|
+
services: any;
|
|
4
|
+
parse: (input: string, uri?: string) => Promise<LikeC4LangiumDocument>;
|
|
5
|
+
validate: (input: string | LikeC4LangiumDocument, uri?: string) => Promise<{
|
|
6
|
+
document: LikeC4LangiumDocument;
|
|
7
|
+
diagnostics: any[];
|
|
8
|
+
warnings: any[];
|
|
9
|
+
errors: any[];
|
|
10
|
+
}>;
|
|
11
|
+
validateAll: () => Promise<{
|
|
12
|
+
diagnostics: any;
|
|
13
|
+
errors: any;
|
|
14
|
+
warnings: any;
|
|
15
|
+
}>;
|
|
16
|
+
buildModel: () => Promise<any>;
|
|
17
|
+
resetState: () => Promise<void>;
|
|
18
|
+
format: (input: string | LikeC4LangiumDocument, uri?: string) => Promise<any>;
|
|
19
|
+
};
|
|
20
|
+
export type TestServices = ReturnType<typeof createTestServices>;
|
|
21
|
+
export type TestParseFn = TestServices['validate'];
|
|
22
|
+
export type TestValidateFn = TestServices['validate'];
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { DocumentState, EmptyFileSystem, TextDocument } from "langium";
|
|
2
|
+
import * as assert from "node:assert";
|
|
3
|
+
import stripIndent from "strip-indent";
|
|
4
|
+
import { DiagnosticSeverity } from "vscode-languageserver-types";
|
|
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 formatter = services.lsp.Formatter;
|
|
15
|
+
const workspaceFolder = {
|
|
16
|
+
name: "test",
|
|
17
|
+
uri: workspaceUri.toString()
|
|
18
|
+
};
|
|
19
|
+
let isInitialized = false;
|
|
20
|
+
let documentIndex = 1;
|
|
21
|
+
const parse = async (input, uri) => {
|
|
22
|
+
if (!isInitialized) {
|
|
23
|
+
await services.shared.workspace.WorkspaceLock.write(async (_cancelToken) => {
|
|
24
|
+
if (isInitialized) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
isInitialized = true;
|
|
28
|
+
services.shared.workspace.WorkspaceManager.initialize({
|
|
29
|
+
capabilities: {},
|
|
30
|
+
processId: null,
|
|
31
|
+
rootUri: null,
|
|
32
|
+
workspaceFolders: [workspaceFolder]
|
|
33
|
+
});
|
|
34
|
+
await services.shared.workspace.WorkspaceManager.initializeWorkspace([workspaceFolder]);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const docUri = Utils.resolvePath(
|
|
38
|
+
workspaceUri,
|
|
39
|
+
"./src/",
|
|
40
|
+
uri ?? `${documentIndex++}${metaData.fileExtensions[0]}`
|
|
41
|
+
);
|
|
42
|
+
const document = services.shared.workspace.LangiumDocumentFactory.fromString(
|
|
43
|
+
stripIndent(input),
|
|
44
|
+
docUri
|
|
45
|
+
);
|
|
46
|
+
langiumDocuments.addDocument(document);
|
|
47
|
+
await services.shared.workspace.WorkspaceLock.write(async (_cancelToken) => {
|
|
48
|
+
await documentBuilder.build([document], { validation: false });
|
|
49
|
+
});
|
|
50
|
+
return document;
|
|
51
|
+
};
|
|
52
|
+
const validate = async (input, uri) => {
|
|
53
|
+
const document = typeof input === "string" ? await parse(input, uri) : input;
|
|
54
|
+
await services.shared.workspace.WorkspaceLock.write(async (_cancelToken) => {
|
|
55
|
+
await documentBuilder.build([document], { validation: true });
|
|
56
|
+
});
|
|
57
|
+
const diagnostics = document.diagnostics ?? [];
|
|
58
|
+
const warnings = diagnostics.flatMap((d) => d.severity === DiagnosticSeverity.Warning ? d.message : []);
|
|
59
|
+
const errors = diagnostics.flatMap((d) => d.severity === DiagnosticSeverity.Error ? d.message : []);
|
|
60
|
+
return {
|
|
61
|
+
document,
|
|
62
|
+
diagnostics,
|
|
63
|
+
warnings,
|
|
64
|
+
errors
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
const format = async (input, uri) => {
|
|
68
|
+
const document = typeof input === "string" ? await parse(input, uri) : input;
|
|
69
|
+
await services.shared.workspace.WorkspaceLock.write(async (_cancelToken) => {
|
|
70
|
+
await documentBuilder.build([document], { validation: true });
|
|
71
|
+
});
|
|
72
|
+
const edits = await formatter?.formatDocument(
|
|
73
|
+
document,
|
|
74
|
+
{
|
|
75
|
+
options: { tabSize: 2, insertSpaces: true },
|
|
76
|
+
textDocument: { uri: document.uri.toString() }
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
return TextDocument.applyEdits(document.textDocument, edits ?? []);
|
|
80
|
+
};
|
|
81
|
+
const validateAll = async () => {
|
|
82
|
+
await services.shared.workspace.WorkspaceLock.write(async (_cancelToken) => {
|
|
83
|
+
const docs2 = langiumDocuments.all.toArray();
|
|
84
|
+
await documentBuilder.build(docs2, { validation: true });
|
|
85
|
+
});
|
|
86
|
+
await documentBuilder.waitUntil(DocumentState.Validated);
|
|
87
|
+
const docs = langiumDocuments.all.toArray();
|
|
88
|
+
assert.ok(docs.length > 0, "no documents to validate");
|
|
89
|
+
const diagnostics = docs.flatMap((doc) => doc.diagnostics ?? []);
|
|
90
|
+
const warnings = diagnostics.flatMap((d) => d.severity === DiagnosticSeverity.Warning ? d.message : []);
|
|
91
|
+
const errors = diagnostics.flatMap((d) => d.severity === DiagnosticSeverity.Error ? d.message : []);
|
|
92
|
+
return {
|
|
93
|
+
diagnostics,
|
|
94
|
+
errors,
|
|
95
|
+
warnings
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
const buildModel = async () => {
|
|
99
|
+
await validateAll();
|
|
100
|
+
const model = await modelBuilder.buildComputedModel();
|
|
101
|
+
if (!model) throw new Error("No model found");
|
|
102
|
+
return model;
|
|
103
|
+
};
|
|
104
|
+
const resetState = async () => {
|
|
105
|
+
await services.shared.workspace.WorkspaceLock.write(async (cancelToken) => {
|
|
106
|
+
const docs = langiumDocuments.all.toArray().map((doc) => doc.uri);
|
|
107
|
+
await documentBuilder.update([], docs, cancelToken);
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
return {
|
|
111
|
+
services,
|
|
112
|
+
parse,
|
|
113
|
+
validate,
|
|
114
|
+
validateAll,
|
|
115
|
+
buildModel,
|
|
116
|
+
resetState,
|
|
117
|
+
format
|
|
118
|
+
};
|
|
119
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type * as c4 from '@likec4/core';
|
|
2
|
+
import type { ast } from '../ast';
|
|
3
|
+
/**
|
|
4
|
+
* Returns referenced AST Element
|
|
5
|
+
*/
|
|
6
|
+
export declare function elementRef(node: ast.ElementRef | ast.FqnElementRef): any;
|
|
7
|
+
/**
|
|
8
|
+
* Returns FQN of FqnElementRef
|
|
9
|
+
* a.b.c.d - for c node returns a.b.c
|
|
10
|
+
*/
|
|
11
|
+
export declare function getFqnElementRef(node: ast.FqnElementRef): c4.Fqn;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function elementRef(node) {
|
|
2
|
+
return node.el.ref;
|
|
3
|
+
}
|
|
4
|
+
export function getFqnElementRef(node) {
|
|
5
|
+
const name = [node.el.$refText];
|
|
6
|
+
let parent = node.parent;
|
|
7
|
+
while (parent) {
|
|
8
|
+
name.push(parent.el.$refText);
|
|
9
|
+
parent = parent.parent;
|
|
10
|
+
}
|
|
11
|
+
if (name.length === 1) {
|
|
12
|
+
return name[0];
|
|
13
|
+
}
|
|
14
|
+
return name.reverse().join(".");
|
|
15
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ast } from '../ast';
|
|
2
|
+
export declare function instanceRef(deploymentRef: ast.FqnRef): ast.DeployedInstance | null;
|
|
3
|
+
export declare function deploymentNodeRef(deploymentRef: ast.FqnRef): ast.DeploymentNode | null;
|
|
4
|
+
export declare function isReferenceToLogicalModel(node: ast.FqnRef): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Returns true if node references deployment model
|
|
7
|
+
*/
|
|
8
|
+
export declare function isReferenceToDeploymentModel(node: ast.FqnRef): boolean;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { AstUtils } from "langium";
|
|
2
|
+
import { isNullish } from "remeda";
|
|
3
|
+
import { ast } from "../ast.js";
|
|
4
|
+
export function instanceRef(deploymentRef) {
|
|
5
|
+
let referenceable;
|
|
6
|
+
while (referenceable = deploymentRef.value?.ref) {
|
|
7
|
+
if (ast.isDeploymentNode(referenceable)) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
if (ast.isDeployedInstance(referenceable)) {
|
|
11
|
+
return referenceable;
|
|
12
|
+
}
|
|
13
|
+
if (isNullish(deploymentRef.parent)) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
deploymentRef = deploymentRef.parent;
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
export function deploymentNodeRef(deploymentRef) {
|
|
21
|
+
let referenceable = deploymentRef.value.ref ?? null;
|
|
22
|
+
if (!referenceable || ast.isDeploymentNode(referenceable)) {
|
|
23
|
+
return referenceable;
|
|
24
|
+
}
|
|
25
|
+
const artifact = instanceRef(deploymentRef);
|
|
26
|
+
return artifact ? AstUtils.getContainerOfType(artifact, ast.isDeploymentNode) ?? null : null;
|
|
27
|
+
}
|
|
28
|
+
export function isReferenceToLogicalModel(node) {
|
|
29
|
+
while (node.parent) {
|
|
30
|
+
node = node.parent;
|
|
31
|
+
}
|
|
32
|
+
return ast.isElement(node.value.ref);
|
|
33
|
+
}
|
|
34
|
+
export function isReferenceToDeploymentModel(node) {
|
|
35
|
+
let referenceable;
|
|
36
|
+
while (referenceable = node.value?.ref) {
|
|
37
|
+
if (ast.isDeploymentElement(referenceable)) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
if (isNullish(node.parent)) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
node = node.parent;
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './stringHash';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./stringHash.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const printDocs = (docs) => docs.map((d) => " - " + d.uri.toString(true)).join("\n");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function stringHash(...str: [string, ...string[]]): string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isPromise } from "remeda";
|
|
2
|
+
import { logWarnError } from "../logger.js";
|
|
3
|
+
export const RESERVED_WORDS = [
|
|
4
|
+
"this",
|
|
5
|
+
"it",
|
|
6
|
+
"self",
|
|
7
|
+
"super",
|
|
8
|
+
"likec4lib",
|
|
9
|
+
"global"
|
|
10
|
+
];
|
|
11
|
+
export function tryOrLog(fn) {
|
|
12
|
+
return async (node, accept, cancelToken) => {
|
|
13
|
+
try {
|
|
14
|
+
const result = fn(node, accept, cancelToken);
|
|
15
|
+
if (isPromise(result)) {
|
|
16
|
+
await result;
|
|
17
|
+
}
|
|
18
|
+
} catch (e) {
|
|
19
|
+
logWarnError(e);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ValidationCheck } from 'langium';
|
|
2
|
+
import { ast } from '../ast';
|
|
3
|
+
import type { LikeC4Services } from '../module';
|
|
4
|
+
export declare const deploymentNodeChecks: (services: LikeC4Services) => ValidationCheck<ast.DeploymentNode>;
|
|
5
|
+
export declare const deployedInstanceChecks: (services: LikeC4Services) => ValidationCheck<ast.DeployedInstance>;
|
|
6
|
+
export declare const deploymentRelationChecks: (services: LikeC4Services) => ValidationCheck<ast.DeploymentRelation>;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { FqnRef, isSameHierarchy, nonNullable } from "@likec4/core";
|
|
2
|
+
import { AstUtils } from "langium";
|
|
3
|
+
import { RESERVED_WORDS, tryOrLog } from "./_shared.js";
|
|
4
|
+
const { getDocument } = AstUtils;
|
|
5
|
+
export const deploymentNodeChecks = (services) => {
|
|
6
|
+
const DeploymentsIndex = services.likec4.DeploymentsIndex;
|
|
7
|
+
const Names = services.references.NameProvider;
|
|
8
|
+
return tryOrLog((el, accept) => {
|
|
9
|
+
const nodeName = Names.getName(el);
|
|
10
|
+
if (!nodeName) {
|
|
11
|
+
accept("error", "DeploymentNode must be named", {
|
|
12
|
+
node: el
|
|
13
|
+
});
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const range = nonNullable(Names.getNameNode(el), "name CstNode not found").range;
|
|
17
|
+
if (RESERVED_WORDS.includes(nodeName)) {
|
|
18
|
+
accept("error", `Reserved word: ${nodeName}`, {
|
|
19
|
+
node: el,
|
|
20
|
+
range
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
const fqnName = DeploymentsIndex.getFqn(el);
|
|
24
|
+
const withSameName = DeploymentsIndex.byFqn(fqnName).limit(2).toArray();
|
|
25
|
+
if (withSameName.length > 1) {
|
|
26
|
+
accept(
|
|
27
|
+
"error",
|
|
28
|
+
`Duplicate node name "${fqnName}"`,
|
|
29
|
+
{
|
|
30
|
+
node: el,
|
|
31
|
+
range
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
export const deployedInstanceChecks = (services) => {
|
|
38
|
+
const DeploymentsIndex = services.likec4.DeploymentsIndex;
|
|
39
|
+
const Names = services.references.NameProvider;
|
|
40
|
+
return tryOrLog((el, accept) => {
|
|
41
|
+
const artifactName = Names.getName(el);
|
|
42
|
+
if (!artifactName) {
|
|
43
|
+
accept("error", "Deployed instance must be named, unique inside node", {
|
|
44
|
+
node: el
|
|
45
|
+
});
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const range = nonNullable(Names.getNameNode(el), "name CstNode not found").range;
|
|
49
|
+
if (RESERVED_WORDS.includes(artifactName)) {
|
|
50
|
+
accept("error", `Reserved word: ${artifactName}`, {
|
|
51
|
+
node: el,
|
|
52
|
+
range
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
const fqnName = DeploymentsIndex.getFqn(el);
|
|
56
|
+
const withSameName = DeploymentsIndex.byFqn(fqnName).limit(2).toArray();
|
|
57
|
+
if (withSameName.length > 1) {
|
|
58
|
+
accept(
|
|
59
|
+
"error",
|
|
60
|
+
`Duplicate instance name "${fqnName}"`,
|
|
61
|
+
{
|
|
62
|
+
node: el,
|
|
63
|
+
range
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
export const deploymentRelationChecks = (services) => {
|
|
70
|
+
const ModelParser = services.likec4.ModelParser;
|
|
71
|
+
return tryOrLog((el, accept) => {
|
|
72
|
+
const source = el.source?.value?.ref;
|
|
73
|
+
if (!source) {
|
|
74
|
+
let sourceCstText = el.source?.$cstNode?.text ?? "";
|
|
75
|
+
accept("error", `DeploymentRelation source '${sourceCstText}' not resolved`, {
|
|
76
|
+
node: el,
|
|
77
|
+
property: "source"
|
|
78
|
+
});
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const target = el.target?.value?.ref;
|
|
82
|
+
if (!target) {
|
|
83
|
+
let targetCstText = el.target?.$cstNode?.text ?? "";
|
|
84
|
+
accept("error", `DeploymentRelation target '${targetCstText}' not resolved`, {
|
|
85
|
+
node: el,
|
|
86
|
+
property: "target"
|
|
87
|
+
});
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const doc = getDocument(el);
|
|
91
|
+
const parser = ModelParser.forDocument(doc);
|
|
92
|
+
const sourceFqnRef = parser.parseFqnRef(el.source);
|
|
93
|
+
if (FqnRef.isModelRef(sourceFqnRef)) {
|
|
94
|
+
accept("error", "DeploymentRelation must refer deployment element", {
|
|
95
|
+
node: el,
|
|
96
|
+
property: "source"
|
|
97
|
+
});
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const targetFqnRef = parser.parseFqnRef(el.target);
|
|
101
|
+
if (FqnRef.isModelRef(targetFqnRef)) {
|
|
102
|
+
accept("error", "DeploymentRelation must refer deployment element", {
|
|
103
|
+
node: el,
|
|
104
|
+
property: "target"
|
|
105
|
+
});
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (isSameHierarchy(sourceFqnRef.deployment, targetFqnRef.deployment)) {
|
|
109
|
+
accept("error", "Invalid parent-child relationship", {
|
|
110
|
+
node: el
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ast, elementExpressionFromPredicate } from "../ast.js";
|
|
2
|
+
import { tryOrLog } from "./_shared.js";
|
|
3
|
+
export const dynamicViewRulePredicate = (_services) => {
|
|
4
|
+
return tryOrLog((predicate, accept) => {
|
|
5
|
+
const expr = elementExpressionFromPredicate(predicate.value);
|
|
6
|
+
switch (true) {
|
|
7
|
+
case ast.isElementKindExpression(expr):
|
|
8
|
+
case ast.isElementTagExpression(expr):
|
|
9
|
+
case ast.isWildcardExpression(expr): {
|
|
10
|
+
accept("warning", `Predicate is ignored, as not supported in dynamic views`, {
|
|
11
|
+
node: predicate
|
|
12
|
+
});
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { isAncestor } from "@likec4/core";
|
|
2
|
+
import { elementRef } from "../utils/elementRef.js";
|
|
3
|
+
import { tryOrLog } from "./_shared.js";
|
|
4
|
+
export const dynamicViewStep = (services) => {
|
|
5
|
+
const fqnIndex = services.likec4.FqnIndex;
|
|
6
|
+
return tryOrLog((el, accept) => {
|
|
7
|
+
const sourceEl = elementRef(el.source);
|
|
8
|
+
const source = sourceEl && fqnIndex.getFqn(sourceEl);
|
|
9
|
+
if (!source) {
|
|
10
|
+
accept("error", "Source not found (not parsed/indexed yet)", {
|
|
11
|
+
node: el,
|
|
12
|
+
property: "source"
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
const targetEl = elementRef(el.target);
|
|
16
|
+
const target = targetEl && fqnIndex.getFqn(targetEl);
|
|
17
|
+
if (!target) {
|
|
18
|
+
accept("error", "Target not found (not parsed/indexed yet)", {
|
|
19
|
+
node: el,
|
|
20
|
+
property: "target"
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (source && target && (isAncestor(source, target) || isAncestor(target, source))) {
|
|
24
|
+
accept("error", "Invalid parent-child relationship", {
|
|
25
|
+
node: el
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { AstUtils } from "langium";
|
|
2
|
+
import { RESERVED_WORDS, tryOrLog } from "./_shared.js";
|
|
3
|
+
const { getDocument } = AstUtils;
|
|
4
|
+
export const elementChecks = (services) => {
|
|
5
|
+
const fqnIndex = services.likec4.FqnIndex;
|
|
6
|
+
const locator = services.workspace.AstNodeLocator;
|
|
7
|
+
return tryOrLog((el, accept) => {
|
|
8
|
+
const fqn = fqnIndex.getFqn(el);
|
|
9
|
+
if (!fqn) {
|
|
10
|
+
accept("error", "Not indexed element", {
|
|
11
|
+
node: el,
|
|
12
|
+
property: "name"
|
|
13
|
+
});
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (RESERVED_WORDS.includes(el.name)) {
|
|
17
|
+
accept("error", `Reserved word: ${el.name}`, {
|
|
18
|
+
node: el,
|
|
19
|
+
property: "name"
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const doc = getDocument(el);
|
|
23
|
+
const docUri = doc.uri;
|
|
24
|
+
const elPath = locator.getAstNodePath(el);
|
|
25
|
+
const withSameFqn = fqnIndex.byFqn(fqn).filter((v) => v.documentUri !== docUri || v.path !== elPath).head();
|
|
26
|
+
if (withSameFqn) {
|
|
27
|
+
const isAnotherDoc = withSameFqn.documentUri !== docUri;
|
|
28
|
+
accept(
|
|
29
|
+
"error",
|
|
30
|
+
`Duplicate element name ${el.name !== fqn ? el.name + " (" + fqn + ")" : el.name}`,
|
|
31
|
+
{
|
|
32
|
+
node: el,
|
|
33
|
+
property: "name",
|
|
34
|
+
...isAnotherDoc && {
|
|
35
|
+
relatedInformation: [
|
|
36
|
+
{
|
|
37
|
+
location: {
|
|
38
|
+
range: withSameFqn.nameSegment?.range ?? withSameFqn.selectionSegment?.range,
|
|
39
|
+
uri: withSameFqn.documentUri.toString()
|
|
40
|
+
},
|
|
41
|
+
message: `conflicting element`
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AstNode } from 'langium';
|
|
2
|
+
import { type LikeC4LangiumDocument, ast } from '../ast';
|
|
3
|
+
import type { LikeC4Services } from '../module';
|
|
4
|
+
type Guard<N extends AstNode> = (n: AstNode) => n is N;
|
|
5
|
+
type Guarded<G> = G extends Guard<infer N> ? N : never;
|
|
6
|
+
declare const isValidatableAstNode: (n: AstNode) => n is ast.DeployedInstance | ast.DeploymentNode | ast.DeploymentViewRulePredicate | ast.DeploymentViewRuleStyle | ast.ViewRuleAutoLayout | ast.DynamicViewGlobalPredicateRef | ast.DynamicViewIncludePredicate | ast.ViewRuleGlobalStyle | ast.ViewRuleStyle | ast.ElementDescedantsExpression | ast.ElementKindExpression | ast.ElementRef | ast.ElementTagExpression | ast.ExpandElementExpression | ast.WildcardExpression | ast.ElementPredicateWhere | ast.ElementPredicateWith | ast.ElementStringProperty | ast.ElementStyleProperty | ast.IconProperty | ast.LinkProperty | ast.MetadataBody | ast.FqnRefExpr | ast.DirectedRelationExpr | ast.InOutRelationExpr | ast.IncomingRelationExpr | ast.OutgoingRelationExpr | ast.Element | ast.ExtendElement | ast.DeploymentView | ast.DynamicView | ast.ElementView | ast.DirectedRelationExpression | ast.InOutRelationExpression | ast.IncomingRelationExpression | ast.OutgoingRelationExpression | ast.RelationPredicateWhere | ast.RelationPredicateWith | ast.RelationStringProperty | ast.ArrowProperty | ast.ColorProperty | ast.LineProperty | ast.MetadataAttribute | ast.NotationProperty | ast.NotesProperty | ast.SpecificationElementStringProperty | ast.SpecificationRelationshipStringProperty | ast.ViewStringProperty | ast.BorderProperty | ast.OpacityProperty | ast.ShapeProperty | ast.ViewRuleGlobalPredicateRef | ast.ViewRuleGroup | ast.ExcludePredicate | ast.IncludePredicate | ast.SpecificationRelationshipKind | ast.GlobalStyle | ast.SpecificationColor | ast.NavigateToProperty | ast.DynamicViewStep | ast.Tags | ast.DeploymentRelation | ast.SpecificationDeploymentNodeKind | ast.DynamicViewParallelSteps | ast.GlobalDynamicPredicateGroup | ast.DynamicViewPredicateIterator | ast.Relation | ast.SpecificationElementKind | ast.GlobalPredicateGroup | ast.Globals | ast.GlobalStyleGroup | ast.SpecificationRule | ast.SpecificationTag;
|
|
7
|
+
type ValidatableAstNode = Guarded<typeof isValidatableAstNode>;
|
|
8
|
+
export declare function checksFromDiagnostics(doc: LikeC4LangiumDocument): {
|
|
9
|
+
isValid: (n: ValidatableAstNode) => boolean;
|
|
10
|
+
invalidNodes: WeakSet<object>;
|
|
11
|
+
};
|
|
12
|
+
export type ChecksFromDiagnostics = ReturnType<typeof checksFromDiagnostics>;
|
|
13
|
+
export type IsValidFn = ChecksFromDiagnostics['isValid'];
|
|
14
|
+
export declare function registerValidationChecks(services: LikeC4Services): void;
|
|
15
|
+
export {};
|