@zenstackhq/language 3.0.0-beta.3 → 3.0.0-beta.30
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/index.cjs +1701 -301
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +89 -20
- package/dist/index.d.ts +89 -20
- package/dist/index.js +1652 -256
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +122 -28
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +7 -6
- package/dist/utils.d.ts +7 -6
- package/dist/utils.js +115 -23
- package/dist/utils.js.map +1 -1
- package/package.json +11 -11
- package/res/stdlib.zmodel +56 -77
package/dist/index.cjs
CHANGED
|
@@ -31,24 +31,30 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
// src/index.ts
|
|
32
32
|
var src_exports = {};
|
|
33
33
|
__export(src_exports, {
|
|
34
|
-
|
|
34
|
+
ZModelCodeGenerator: () => ZModelCodeGenerator,
|
|
35
35
|
ZModelLanguageMetaData: () => ZModelLanguageMetaData,
|
|
36
36
|
ZModelLanguageModule: () => ZModelLanguageModule,
|
|
37
37
|
ZModelSharedModule: () => ZModelSharedModule,
|
|
38
38
|
createZModelLanguageServices: () => createZModelLanguageServices,
|
|
39
39
|
createZModelServices: () => createZModelServices,
|
|
40
|
+
formatDocument: () => formatDocument,
|
|
40
41
|
loadDocument: () => loadDocument
|
|
41
42
|
});
|
|
42
43
|
module.exports = __toCommonJS(src_exports);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
var
|
|
46
|
-
var
|
|
47
|
-
var
|
|
44
|
+
|
|
45
|
+
// src/document.ts
|
|
46
|
+
var import_langium14 = require("langium");
|
|
47
|
+
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
48
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
49
|
+
var import_node_url4 = require("url");
|
|
48
50
|
|
|
49
51
|
// src/generated/ast.ts
|
|
50
52
|
var langium = __toESM(require("langium"), 1);
|
|
51
53
|
var AbstractDeclaration = "AbstractDeclaration";
|
|
54
|
+
function isAbstractDeclaration(item) {
|
|
55
|
+
return reflection.isInstance(item, AbstractDeclaration);
|
|
56
|
+
}
|
|
57
|
+
__name(isAbstractDeclaration, "isAbstractDeclaration");
|
|
52
58
|
var ConfigExpr = "ConfigExpr";
|
|
53
59
|
var Expression = "Expression";
|
|
54
60
|
function isExpression(item) {
|
|
@@ -75,6 +81,10 @@ function isAttribute(item) {
|
|
|
75
81
|
}
|
|
76
82
|
__name(isAttribute, "isAttribute");
|
|
77
83
|
var AttributeArg = "AttributeArg";
|
|
84
|
+
function isAttributeArg(item) {
|
|
85
|
+
return reflection.isInstance(item, AttributeArg);
|
|
86
|
+
}
|
|
87
|
+
__name(isAttributeArg, "isAttributeArg");
|
|
78
88
|
var AttributeParam = "AttributeParam";
|
|
79
89
|
var AttributeParamType = "AttributeParamType";
|
|
80
90
|
var BinaryExpr = "BinaryExpr";
|
|
@@ -93,6 +103,10 @@ function isConfigArrayExpr(item) {
|
|
|
93
103
|
}
|
|
94
104
|
__name(isConfigArrayExpr, "isConfigArrayExpr");
|
|
95
105
|
var ConfigField = "ConfigField";
|
|
106
|
+
function isConfigField(item) {
|
|
107
|
+
return reflection.isInstance(item, ConfigField);
|
|
108
|
+
}
|
|
109
|
+
__name(isConfigField, "isConfigField");
|
|
96
110
|
var ConfigInvocationArg = "ConfigInvocationArg";
|
|
97
111
|
var ConfigInvocationExpr = "ConfigInvocationExpr";
|
|
98
112
|
var DataField = "DataField";
|
|
@@ -137,10 +151,22 @@ function isEnumField(item) {
|
|
|
137
151
|
__name(isEnumField, "isEnumField");
|
|
138
152
|
var FieldInitializer = "FieldInitializer";
|
|
139
153
|
var FunctionDecl = "FunctionDecl";
|
|
154
|
+
function isFunctionDecl(item) {
|
|
155
|
+
return reflection.isInstance(item, FunctionDecl);
|
|
156
|
+
}
|
|
157
|
+
__name(isFunctionDecl, "isFunctionDecl");
|
|
140
158
|
var FunctionParam = "FunctionParam";
|
|
141
159
|
var FunctionParamType = "FunctionParamType";
|
|
142
160
|
var GeneratorDecl = "GeneratorDecl";
|
|
161
|
+
function isGeneratorDecl(item) {
|
|
162
|
+
return reflection.isInstance(item, GeneratorDecl);
|
|
163
|
+
}
|
|
164
|
+
__name(isGeneratorDecl, "isGeneratorDecl");
|
|
143
165
|
var InternalAttribute = "InternalAttribute";
|
|
166
|
+
function isInternalAttribute(item) {
|
|
167
|
+
return reflection.isInstance(item, InternalAttribute);
|
|
168
|
+
}
|
|
169
|
+
__name(isInternalAttribute, "isInternalAttribute");
|
|
144
170
|
var InvocationExpr = "InvocationExpr";
|
|
145
171
|
function isInvocationExpr(item) {
|
|
146
172
|
return reflection.isInstance(item, InvocationExpr);
|
|
@@ -157,6 +183,10 @@ function isModel(item) {
|
|
|
157
183
|
}
|
|
158
184
|
__name(isModel, "isModel");
|
|
159
185
|
var ModelImport = "ModelImport";
|
|
186
|
+
function isModelImport(item) {
|
|
187
|
+
return reflection.isInstance(item, ModelImport);
|
|
188
|
+
}
|
|
189
|
+
__name(isModelImport, "isModelImport");
|
|
160
190
|
var NullExpr = "NullExpr";
|
|
161
191
|
function isNullExpr(item) {
|
|
162
192
|
return reflection.isInstance(item, NullExpr);
|
|
@@ -178,6 +208,10 @@ function isPlugin(item) {
|
|
|
178
208
|
}
|
|
179
209
|
__name(isPlugin, "isPlugin");
|
|
180
210
|
var PluginField = "PluginField";
|
|
211
|
+
function isPluginField(item) {
|
|
212
|
+
return reflection.isInstance(item, PluginField);
|
|
213
|
+
}
|
|
214
|
+
__name(isPluginField, "isPluginField");
|
|
181
215
|
var Procedure = "Procedure";
|
|
182
216
|
var ProcedureParam = "ProcedureParam";
|
|
183
217
|
var ReferenceArg = "ReferenceArg";
|
|
@@ -1044,6 +1078,26 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
|
|
|
1044
1078
|
};
|
|
1045
1079
|
var reflection = new ZModelAstReflection();
|
|
1046
1080
|
|
|
1081
|
+
// src/ast.ts
|
|
1082
|
+
var BinaryExprOperatorPriority = {
|
|
1083
|
+
//LogicalExpr
|
|
1084
|
+
"||": 1,
|
|
1085
|
+
"&&": 1,
|
|
1086
|
+
//EqualityExpr
|
|
1087
|
+
"==": 2,
|
|
1088
|
+
"!=": 2,
|
|
1089
|
+
//ComparisonExpr
|
|
1090
|
+
">": 3,
|
|
1091
|
+
"<": 3,
|
|
1092
|
+
">=": 3,
|
|
1093
|
+
"<=": 3,
|
|
1094
|
+
in: 4,
|
|
1095
|
+
//CollectionPredicateExpr
|
|
1096
|
+
"^": 5,
|
|
1097
|
+
"?": 5,
|
|
1098
|
+
"!": 5
|
|
1099
|
+
};
|
|
1100
|
+
|
|
1047
1101
|
// src/constants.ts
|
|
1048
1102
|
var SUPPORTED_PROVIDERS = [
|
|
1049
1103
|
"sqlite",
|
|
@@ -1074,8 +1128,11 @@ var ExpressionContext = /* @__PURE__ */ function(ExpressionContext2) {
|
|
|
1074
1128
|
}({});
|
|
1075
1129
|
|
|
1076
1130
|
// src/module.ts
|
|
1077
|
-
var
|
|
1078
|
-
var
|
|
1131
|
+
var import_langium13 = require("langium");
|
|
1132
|
+
var import_lsp5 = require("langium/lsp");
|
|
1133
|
+
var import_node = require("langium/node");
|
|
1134
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
1135
|
+
var import_node_url3 = require("url");
|
|
1079
1136
|
|
|
1080
1137
|
// src/generated/grammar.ts
|
|
1081
1138
|
var import_langium = require("langium");
|
|
@@ -5136,15 +5193,13 @@ var ZModelGeneratedModule = {
|
|
|
5136
5193
|
parser: {}
|
|
5137
5194
|
};
|
|
5138
5195
|
|
|
5139
|
-
// src/validators/attribute-application-validator.ts
|
|
5140
|
-
var import_langium3 = require("langium");
|
|
5141
|
-
var import_pluralize = __toESM(require("pluralize"), 1);
|
|
5142
|
-
|
|
5143
5196
|
// src/utils.ts
|
|
5144
|
-
var import_common_helpers = require("@zenstackhq/common-helpers");
|
|
5145
5197
|
var import_langium2 = require("langium");
|
|
5146
5198
|
var import_node_fs = __toESM(require("fs"), 1);
|
|
5147
|
-
var
|
|
5199
|
+
var import_node_module = require("module");
|
|
5200
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
5201
|
+
var import_node_url = require("url");
|
|
5202
|
+
var import_meta = {};
|
|
5148
5203
|
function hasAttribute(decl, name) {
|
|
5149
5204
|
return !!getAttribute(decl, name);
|
|
5150
5205
|
}
|
|
@@ -5224,10 +5279,6 @@ function isRelationshipField(field) {
|
|
|
5224
5279
|
return isDataModel(field.type.reference?.ref);
|
|
5225
5280
|
}
|
|
5226
5281
|
__name(isRelationshipField, "isRelationshipField");
|
|
5227
|
-
function isFutureExpr(node) {
|
|
5228
|
-
return isInvocationExpr(node) && node.function.ref?.name === "future" && isFromStdlib(node.function.ref);
|
|
5229
|
-
}
|
|
5230
|
-
__name(isFutureExpr, "isFutureExpr");
|
|
5231
5282
|
function isDelegateModel(node) {
|
|
5232
5283
|
return isDataModel(node) && hasAttribute(node, "@@delegate");
|
|
5233
5284
|
}
|
|
@@ -5245,8 +5296,14 @@ function getRecursiveBases(decl, includeDelegate = true, seen = /* @__PURE__ */
|
|
|
5245
5296
|
return result;
|
|
5246
5297
|
}
|
|
5247
5298
|
seen.add(decl);
|
|
5248
|
-
|
|
5249
|
-
|
|
5299
|
+
const bases = [
|
|
5300
|
+
...decl.mixins,
|
|
5301
|
+
...isDataModel(decl) && decl.baseModel ? [
|
|
5302
|
+
decl.baseModel
|
|
5303
|
+
] : []
|
|
5304
|
+
];
|
|
5305
|
+
bases.forEach((base) => {
|
|
5306
|
+
const baseDecl = decl.$container.declarations.find((d) => (isTypeDef(d) || isDataModel(d)) && d.name === base.$refText);
|
|
5250
5307
|
if (baseDecl) {
|
|
5251
5308
|
if (!includeDelegate && isDelegateModel(baseDecl)) {
|
|
5252
5309
|
return;
|
|
@@ -5369,6 +5426,10 @@ function getArray(expr) {
|
|
|
5369
5426
|
return isArrayExpr(expr) || isConfigArrayExpr(expr) ? expr.items : void 0;
|
|
5370
5427
|
}
|
|
5371
5428
|
__name(getArray, "getArray");
|
|
5429
|
+
function getAttributeArg(attr, name) {
|
|
5430
|
+
return attr.args.find((arg) => arg.$resolvedParam?.name === name)?.value;
|
|
5431
|
+
}
|
|
5432
|
+
__name(getAttributeArg, "getAttributeArg");
|
|
5372
5433
|
function getFunctionExpressionContext(funcDecl) {
|
|
5373
5434
|
const funcAllowedContext = [];
|
|
5374
5435
|
const funcAttr = funcDecl.attributes.find((attr) => attr.decl.$refText === "@@@expressionContext");
|
|
@@ -5386,7 +5447,7 @@ function getFunctionExpressionContext(funcDecl) {
|
|
|
5386
5447
|
}
|
|
5387
5448
|
__name(getFunctionExpressionContext, "getFunctionExpressionContext");
|
|
5388
5449
|
function isCheckInvocation(node) {
|
|
5389
|
-
return isInvocationExpr(node) && node.function.ref?.name === "check"
|
|
5450
|
+
return isInvocationExpr(node) && node.function.ref?.name === "check";
|
|
5390
5451
|
}
|
|
5391
5452
|
__name(isCheckInvocation, "isCheckInvocation");
|
|
5392
5453
|
function resolveTransitiveImports(documents, model) {
|
|
@@ -5436,9 +5497,9 @@ function resolveImportUri(imp) {
|
|
|
5436
5497
|
return void 0;
|
|
5437
5498
|
}
|
|
5438
5499
|
const doc = import_langium2.AstUtils.getDocument(imp);
|
|
5439
|
-
const dir =
|
|
5500
|
+
const dir = import_node_path.default.dirname(doc.uri.fsPath);
|
|
5440
5501
|
const importPath = imp.path.endsWith(".zmodel") ? imp.path : `${imp.path}.zmodel`;
|
|
5441
|
-
return import_langium2.URI.file(
|
|
5502
|
+
return import_langium2.URI.file(import_node_path.default.resolve(dir, importPath));
|
|
5442
5503
|
}
|
|
5443
5504
|
__name(resolveImportUri, "resolveImportUri");
|
|
5444
5505
|
function getDataModelAndTypeDefs(model, includeIgnored = false) {
|
|
@@ -5456,17 +5517,17 @@ function getAllDeclarationsIncludingImports(documents, model) {
|
|
|
5456
5517
|
}
|
|
5457
5518
|
__name(getAllDeclarationsIncludingImports, "getAllDeclarationsIncludingImports");
|
|
5458
5519
|
function getAuthDecl(decls) {
|
|
5459
|
-
let authModel = decls.find((
|
|
5520
|
+
let authModel = decls.find((d) => hasAttribute(d, "@@auth"));
|
|
5460
5521
|
if (!authModel) {
|
|
5461
|
-
authModel = decls.find((
|
|
5522
|
+
authModel = decls.find((d) => d.name === "User");
|
|
5462
5523
|
}
|
|
5463
5524
|
return authModel;
|
|
5464
5525
|
}
|
|
5465
5526
|
__name(getAuthDecl, "getAuthDecl");
|
|
5466
|
-
function
|
|
5467
|
-
return isInvocationExpr(node) && node.function.ref?.name === "
|
|
5527
|
+
function isBeforeInvocation(node) {
|
|
5528
|
+
return isInvocationExpr(node) && node.function.ref?.name === "before";
|
|
5468
5529
|
}
|
|
5469
|
-
__name(
|
|
5530
|
+
__name(isBeforeInvocation, "isBeforeInvocation");
|
|
5470
5531
|
function isCollectionPredicate(node) {
|
|
5471
5532
|
return isBinaryExpr(node) && [
|
|
5472
5533
|
"?",
|
|
@@ -5521,12 +5582,14 @@ function getAllFields(decl, includeIgnored = false, seen = /* @__PURE__ */ new S
|
|
|
5521
5582
|
seen.add(decl);
|
|
5522
5583
|
const fields = [];
|
|
5523
5584
|
for (const mixin of decl.mixins) {
|
|
5524
|
-
|
|
5525
|
-
|
|
5585
|
+
if (mixin.ref) {
|
|
5586
|
+
fields.push(...getAllFields(mixin.ref, includeIgnored, seen));
|
|
5587
|
+
}
|
|
5526
5588
|
}
|
|
5527
5589
|
if (isDataModel(decl) && decl.baseModel) {
|
|
5528
|
-
|
|
5529
|
-
|
|
5590
|
+
if (decl.baseModel.ref) {
|
|
5591
|
+
fields.push(...getAllFields(decl.baseModel.ref, includeIgnored, seen));
|
|
5592
|
+
}
|
|
5530
5593
|
}
|
|
5531
5594
|
fields.push(...decl.fields.filter((f) => includeIgnored || !hasAttribute(f, "@ignore")));
|
|
5532
5595
|
return fields;
|
|
@@ -5539,17 +5602,29 @@ function getAllAttributes(decl, seen = /* @__PURE__ */ new Set()) {
|
|
|
5539
5602
|
seen.add(decl);
|
|
5540
5603
|
const attributes = [];
|
|
5541
5604
|
for (const mixin of decl.mixins) {
|
|
5542
|
-
|
|
5543
|
-
|
|
5605
|
+
if (mixin.ref) {
|
|
5606
|
+
attributes.push(...getAllAttributes(mixin.ref, seen));
|
|
5607
|
+
}
|
|
5544
5608
|
}
|
|
5545
5609
|
if (isDataModel(decl) && decl.baseModel) {
|
|
5546
|
-
|
|
5547
|
-
|
|
5610
|
+
if (decl.baseModel.ref) {
|
|
5611
|
+
const attrs = getAllAttributes(decl.baseModel.ref, seen).filter((attr) => !isNonInheritableAttribute(attr));
|
|
5612
|
+
attributes.push(...attrs);
|
|
5613
|
+
}
|
|
5548
5614
|
}
|
|
5549
5615
|
attributes.push(...decl.attributes);
|
|
5550
5616
|
return attributes;
|
|
5551
5617
|
}
|
|
5552
5618
|
__name(getAllAttributes, "getAllAttributes");
|
|
5619
|
+
function isNonInheritableAttribute(attr) {
|
|
5620
|
+
const attrName = attr.decl.ref?.name ?? attr.decl.$refText;
|
|
5621
|
+
return [
|
|
5622
|
+
"@@map",
|
|
5623
|
+
"@@unique",
|
|
5624
|
+
"@@index"
|
|
5625
|
+
].includes(attrName);
|
|
5626
|
+
}
|
|
5627
|
+
__name(isNonInheritableAttribute, "isNonInheritableAttribute");
|
|
5553
5628
|
function getDocument(node) {
|
|
5554
5629
|
const rootNode = findRootNode(node);
|
|
5555
5630
|
const result = rootNode.$document;
|
|
@@ -5559,6 +5634,71 @@ function getDocument(node) {
|
|
|
5559
5634
|
return result;
|
|
5560
5635
|
}
|
|
5561
5636
|
__name(getDocument, "getDocument");
|
|
5637
|
+
function getPluginDocuments(model, schemaPath) {
|
|
5638
|
+
const result = [];
|
|
5639
|
+
for (const decl of model.declarations.filter(isPlugin)) {
|
|
5640
|
+
const providerField = decl.fields.find((f) => f.name === "provider");
|
|
5641
|
+
if (!providerField) {
|
|
5642
|
+
continue;
|
|
5643
|
+
}
|
|
5644
|
+
const provider = getLiteral(providerField.value);
|
|
5645
|
+
if (!provider) {
|
|
5646
|
+
continue;
|
|
5647
|
+
}
|
|
5648
|
+
let pluginModelFile;
|
|
5649
|
+
let providerPath = import_node_path.default.resolve(import_node_path.default.dirname(schemaPath), provider);
|
|
5650
|
+
if (import_node_fs.default.existsSync(providerPath)) {
|
|
5651
|
+
if (import_node_fs.default.statSync(providerPath).isDirectory()) {
|
|
5652
|
+
providerPath = import_node_path.default.join(providerPath, "index.js");
|
|
5653
|
+
}
|
|
5654
|
+
pluginModelFile = import_node_path.default.resolve(import_node_path.default.dirname(providerPath), PLUGIN_MODULE_NAME);
|
|
5655
|
+
if (!import_node_fs.default.existsSync(pluginModelFile)) {
|
|
5656
|
+
pluginModelFile = findUp([
|
|
5657
|
+
PLUGIN_MODULE_NAME
|
|
5658
|
+
], import_node_path.default.dirname(providerPath));
|
|
5659
|
+
}
|
|
5660
|
+
}
|
|
5661
|
+
if (!pluginModelFile) {
|
|
5662
|
+
if (typeof import_meta.resolve === "function") {
|
|
5663
|
+
try {
|
|
5664
|
+
const resolvedUrl = import_meta.resolve(`${provider}/${PLUGIN_MODULE_NAME}`);
|
|
5665
|
+
pluginModelFile = (0, import_node_url.fileURLToPath)(resolvedUrl);
|
|
5666
|
+
} catch {
|
|
5667
|
+
}
|
|
5668
|
+
}
|
|
5669
|
+
}
|
|
5670
|
+
if (!pluginModelFile) {
|
|
5671
|
+
try {
|
|
5672
|
+
const require2 = (0, import_node_module.createRequire)((0, import_node_url.pathToFileURL)(schemaPath));
|
|
5673
|
+
pluginModelFile = require2.resolve(`${provider}/${PLUGIN_MODULE_NAME}`);
|
|
5674
|
+
} catch {
|
|
5675
|
+
}
|
|
5676
|
+
}
|
|
5677
|
+
if (pluginModelFile && import_node_fs.default.existsSync(pluginModelFile)) {
|
|
5678
|
+
result.push(pluginModelFile);
|
|
5679
|
+
}
|
|
5680
|
+
}
|
|
5681
|
+
return result;
|
|
5682
|
+
}
|
|
5683
|
+
__name(getPluginDocuments, "getPluginDocuments");
|
|
5684
|
+
function findUp(names, cwd = process.cwd(), multiple = false, result = []) {
|
|
5685
|
+
if (!names.some((name) => !!name)) {
|
|
5686
|
+
return void 0;
|
|
5687
|
+
}
|
|
5688
|
+
const target = names.find((name) => import_node_fs.default.existsSync(import_node_path.default.join(cwd, name)));
|
|
5689
|
+
if (multiple === false && target) {
|
|
5690
|
+
return import_node_path.default.join(cwd, target);
|
|
5691
|
+
}
|
|
5692
|
+
if (target) {
|
|
5693
|
+
result.push(import_node_path.default.join(cwd, target));
|
|
5694
|
+
}
|
|
5695
|
+
const up = import_node_path.default.resolve(cwd, "..");
|
|
5696
|
+
if (up === cwd) {
|
|
5697
|
+
return multiple && result.length > 0 ? result : void 0;
|
|
5698
|
+
}
|
|
5699
|
+
return findUp(names, up, multiple, result);
|
|
5700
|
+
}
|
|
5701
|
+
__name(findUp, "findUp");
|
|
5562
5702
|
function findRootNode(node) {
|
|
5563
5703
|
while (node.$container) {
|
|
5564
5704
|
node = node.$container;
|
|
@@ -5568,6 +5708,9 @@ function findRootNode(node) {
|
|
|
5568
5708
|
__name(findRootNode, "findRootNode");
|
|
5569
5709
|
|
|
5570
5710
|
// src/validators/attribute-application-validator.ts
|
|
5711
|
+
var import_common_helpers = require("@zenstackhq/common-helpers");
|
|
5712
|
+
var import_langium3 = require("langium");
|
|
5713
|
+
var import_pluralize = __toESM(require("pluralize"), 1);
|
|
5571
5714
|
function _ts_decorate(decorators, target, key, desc) {
|
|
5572
5715
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5573
5716
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -5681,6 +5824,7 @@ var AttributeApplicationValidator = class {
|
|
|
5681
5824
|
});
|
|
5682
5825
|
}
|
|
5683
5826
|
}
|
|
5827
|
+
// TODO: design a way to let plugin register validation
|
|
5684
5828
|
_checkModelLevelPolicy(attr, accept) {
|
|
5685
5829
|
const kind = getStringLiteral(attr.args[0]?.value);
|
|
5686
5830
|
if (!kind) {
|
|
@@ -5693,11 +5837,61 @@ var AttributeApplicationValidator = class {
|
|
|
5693
5837
|
"create",
|
|
5694
5838
|
"read",
|
|
5695
5839
|
"update",
|
|
5840
|
+
"post-update",
|
|
5696
5841
|
"delete",
|
|
5697
5842
|
"all"
|
|
5698
5843
|
], attr, accept);
|
|
5699
|
-
|
|
5844
|
+
if ((kind === "create" || kind === "all") && attr.args[1]?.value) {
|
|
5845
|
+
this.rejectNonOwnedRelationInExpression(attr.args[1].value, accept);
|
|
5846
|
+
}
|
|
5847
|
+
if (kind !== "post-update" && attr.args[1]?.value) {
|
|
5848
|
+
const beforeCall = import_langium3.AstUtils.streamAst(attr.args[1]?.value).find(isBeforeInvocation);
|
|
5849
|
+
if (beforeCall) {
|
|
5850
|
+
accept("error", `"before()" is only allowed in "post-update" policy rules`, {
|
|
5851
|
+
node: beforeCall
|
|
5852
|
+
});
|
|
5853
|
+
}
|
|
5854
|
+
}
|
|
5700
5855
|
}
|
|
5856
|
+
rejectNonOwnedRelationInExpression(expr, accept) {
|
|
5857
|
+
const contextModel = import_langium3.AstUtils.getContainerOfType(expr, isDataModel);
|
|
5858
|
+
if (!contextModel) {
|
|
5859
|
+
return;
|
|
5860
|
+
}
|
|
5861
|
+
if (import_langium3.AstUtils.streamAst(expr).some((node) => {
|
|
5862
|
+
if (!isDataFieldReference(node)) {
|
|
5863
|
+
return false;
|
|
5864
|
+
}
|
|
5865
|
+
if (node.target.ref?.$container !== contextModel) {
|
|
5866
|
+
return false;
|
|
5867
|
+
}
|
|
5868
|
+
const field = node.target.ref;
|
|
5869
|
+
if (!isRelationshipField(field)) {
|
|
5870
|
+
return false;
|
|
5871
|
+
}
|
|
5872
|
+
if (isAuthOrAuthMemberAccess(node)) {
|
|
5873
|
+
return false;
|
|
5874
|
+
}
|
|
5875
|
+
const startNode = isCollectionPredicate(node.$container) && node.$container.left === node ? node.$container : node;
|
|
5876
|
+
const collectionPredicate = import_langium3.AstUtils.getContainerOfType(startNode.$container, isCollectionPredicate);
|
|
5877
|
+
if (collectionPredicate && isAuthOrAuthMemberAccess(collectionPredicate.left)) {
|
|
5878
|
+
return false;
|
|
5879
|
+
}
|
|
5880
|
+
const relationAttr = field.attributes.find((attr) => attr.decl.ref?.name === "@relation");
|
|
5881
|
+
if (!relationAttr) {
|
|
5882
|
+
return true;
|
|
5883
|
+
}
|
|
5884
|
+
if (!relationAttr.args.some((arg) => arg.name === "fields")) {
|
|
5885
|
+
return true;
|
|
5886
|
+
}
|
|
5887
|
+
return false;
|
|
5888
|
+
})) {
|
|
5889
|
+
accept("error", `non-owned relation fields are not allowed in "create" rules`, {
|
|
5890
|
+
node: expr
|
|
5891
|
+
});
|
|
5892
|
+
}
|
|
5893
|
+
}
|
|
5894
|
+
// TODO: design a way to let plugin register validation
|
|
5701
5895
|
_checkFieldLevelPolicy(attr, accept) {
|
|
5702
5896
|
const kind = getStringLiteral(attr.args[0]?.value);
|
|
5703
5897
|
if (!kind) {
|
|
@@ -5712,8 +5906,8 @@ var AttributeApplicationValidator = class {
|
|
|
5712
5906
|
"all"
|
|
5713
5907
|
], attr, accept);
|
|
5714
5908
|
const expr = attr.args[1]?.value;
|
|
5715
|
-
if (expr && import_langium3.AstUtils.streamAst(expr).some((node) =>
|
|
5716
|
-
accept("error", `"
|
|
5909
|
+
if (expr && import_langium3.AstUtils.streamAst(expr).some((node) => isBeforeInvocation(node))) {
|
|
5910
|
+
accept("error", `"before()" is not allowed in field-level policy rules`, {
|
|
5717
5911
|
node: expr
|
|
5718
5912
|
});
|
|
5719
5913
|
}
|
|
@@ -5725,7 +5919,6 @@ var AttributeApplicationValidator = class {
|
|
|
5725
5919
|
});
|
|
5726
5920
|
}
|
|
5727
5921
|
}
|
|
5728
|
-
this.rejectEncryptedFields(attr, accept);
|
|
5729
5922
|
}
|
|
5730
5923
|
_checkValidate(attr, accept) {
|
|
5731
5924
|
const condition = attr.args[0]?.value;
|
|
@@ -5735,8 +5928,9 @@ var AttributeApplicationValidator = class {
|
|
|
5735
5928
|
});
|
|
5736
5929
|
}
|
|
5737
5930
|
}
|
|
5738
|
-
|
|
5739
|
-
const fields = attr
|
|
5931
|
+
_checkConstraint(attr, accept) {
|
|
5932
|
+
const fields = getAttributeArg(attr, "fields");
|
|
5933
|
+
const attrName = attr.decl.ref?.name;
|
|
5740
5934
|
if (!fields) {
|
|
5741
5935
|
accept("error", `expects an array of field references`, {
|
|
5742
5936
|
node: attr.args[0]
|
|
@@ -5745,7 +5939,7 @@ var AttributeApplicationValidator = class {
|
|
|
5745
5939
|
}
|
|
5746
5940
|
if (isArrayExpr(fields)) {
|
|
5747
5941
|
if (fields.items.length === 0) {
|
|
5748
|
-
accept("error",
|
|
5942
|
+
accept("error", `\`${attrName}\` expects at least one field reference`, {
|
|
5749
5943
|
node: fields
|
|
5750
5944
|
});
|
|
5751
5945
|
return;
|
|
@@ -5764,7 +5958,7 @@ var AttributeApplicationValidator = class {
|
|
|
5764
5958
|
return;
|
|
5765
5959
|
}
|
|
5766
5960
|
if (item.target.ref.$container !== attr.$container && isDelegateModel(item.target.ref.$container)) {
|
|
5767
|
-
accept("error", `Cannot use fields inherited from a polymorphic base model in
|
|
5961
|
+
accept("error", `Cannot use fields inherited from a polymorphic base model in \`${attrName}\``, {
|
|
5768
5962
|
node: item
|
|
5769
5963
|
});
|
|
5770
5964
|
}
|
|
@@ -5775,14 +5969,23 @@ var AttributeApplicationValidator = class {
|
|
|
5775
5969
|
});
|
|
5776
5970
|
}
|
|
5777
5971
|
}
|
|
5778
|
-
|
|
5779
|
-
|
|
5780
|
-
|
|
5781
|
-
|
|
5782
|
-
|
|
5972
|
+
_checkSchema(attr, accept) {
|
|
5973
|
+
const schemaName = getStringLiteral(attr.args[0]?.value);
|
|
5974
|
+
(0, import_common_helpers.invariant)(schemaName, `@@schema expects a string literal`);
|
|
5975
|
+
const zmodel = import_langium3.AstUtils.getContainerOfType(attr, isModel);
|
|
5976
|
+
const datasource = zmodel.declarations.find(isDataSource);
|
|
5977
|
+
if (datasource) {
|
|
5978
|
+
let found = false;
|
|
5979
|
+
const schemas = datasource.fields.find((f) => f.name === "schemas");
|
|
5980
|
+
if (schemas && isConfigArrayExpr(schemas.value)) {
|
|
5981
|
+
found = schemas.value.items.some((item) => isLiteralExpr(item) && item.value === schemaName);
|
|
5982
|
+
}
|
|
5983
|
+
if (!found) {
|
|
5984
|
+
accept("error", `Schema "${schemaName}" is not defined in the datasource`, {
|
|
5985
|
+
node: attr
|
|
5783
5986
|
});
|
|
5784
5987
|
}
|
|
5785
|
-
}
|
|
5988
|
+
}
|
|
5786
5989
|
}
|
|
5787
5990
|
validatePolicyKinds(kind, candidates, attr, accept) {
|
|
5788
5991
|
const items = kind.split(",").map((x) => x.trim());
|
|
@@ -5826,15 +6029,25 @@ _ts_decorate([
|
|
|
5826
6029
|
_ts_metadata("design:returntype", void 0)
|
|
5827
6030
|
], AttributeApplicationValidator.prototype, "_checkValidate", null);
|
|
5828
6031
|
_ts_decorate([
|
|
5829
|
-
check("@@unique"),
|
|
5830
6032
|
check("@@id"),
|
|
6033
|
+
check("@@index"),
|
|
6034
|
+
check("@@unique"),
|
|
6035
|
+
_ts_metadata("design:type", Function),
|
|
6036
|
+
_ts_metadata("design:paramtypes", [
|
|
6037
|
+
typeof AttributeApplication === "undefined" ? Object : AttributeApplication,
|
|
6038
|
+
typeof ValidationAcceptor === "undefined" ? Object : ValidationAcceptor
|
|
6039
|
+
]),
|
|
6040
|
+
_ts_metadata("design:returntype", void 0)
|
|
6041
|
+
], AttributeApplicationValidator.prototype, "_checkConstraint", null);
|
|
6042
|
+
_ts_decorate([
|
|
6043
|
+
check("@@schema"),
|
|
5831
6044
|
_ts_metadata("design:type", Function),
|
|
5832
6045
|
_ts_metadata("design:paramtypes", [
|
|
5833
6046
|
typeof AttributeApplication === "undefined" ? Object : AttributeApplication,
|
|
5834
6047
|
typeof ValidationAcceptor === "undefined" ? Object : ValidationAcceptor
|
|
5835
6048
|
]),
|
|
5836
6049
|
_ts_metadata("design:returntype", void 0)
|
|
5837
|
-
], AttributeApplicationValidator.prototype, "
|
|
6050
|
+
], AttributeApplicationValidator.prototype, "_checkSchema", null);
|
|
5838
6051
|
function assignableToAttributeParam(arg, param, attr) {
|
|
5839
6052
|
const argResolvedType = arg.$resolvedType;
|
|
5840
6053
|
if (!argResolvedType) {
|
|
@@ -5844,6 +6057,10 @@ function assignableToAttributeParam(arg, param, attr) {
|
|
|
5844
6057
|
let dstIsArray = param.type.array;
|
|
5845
6058
|
if (dstType === "ContextType") {
|
|
5846
6059
|
if (isDataField(attr.$container)) {
|
|
6060
|
+
const dstIsTypedJson = hasAttribute(attr.$container, "@json");
|
|
6061
|
+
if (dstIsTypedJson && attr.decl.ref?.name === "@default") {
|
|
6062
|
+
return argResolvedType.decl === "String";
|
|
6063
|
+
}
|
|
5847
6064
|
dstIsArray = attr.$container.type.array;
|
|
5848
6065
|
}
|
|
5849
6066
|
}
|
|
@@ -5935,6 +6152,9 @@ function isValidAttributeTarget(attrDecl, targetDecl) {
|
|
|
5935
6152
|
case "TypeDefField":
|
|
5936
6153
|
allowed = allowed || isTypeDef(targetDecl.type.reference?.ref);
|
|
5937
6154
|
break;
|
|
6155
|
+
case "ListField":
|
|
6156
|
+
allowed = allowed || !isDataModel(targetDecl.type.reference?.ref) && targetDecl.type.array;
|
|
6157
|
+
break;
|
|
5938
6158
|
default:
|
|
5939
6159
|
break;
|
|
5940
6160
|
}
|
|
@@ -6202,7 +6422,7 @@ var DataModelValidator = class {
|
|
|
6202
6422
|
if (!thisRelation.valid) {
|
|
6203
6423
|
return;
|
|
6204
6424
|
}
|
|
6205
|
-
if (this.isFieldInheritedFromDelegateModel(field)) {
|
|
6425
|
+
if (this.isFieldInheritedFromDelegateModel(field, contextModel)) {
|
|
6206
6426
|
return;
|
|
6207
6427
|
}
|
|
6208
6428
|
if (this.isSelfRelation(field)) {
|
|
@@ -6325,8 +6545,8 @@ var DataModelValidator = class {
|
|
|
6325
6545
|
}
|
|
6326
6546
|
}
|
|
6327
6547
|
// checks if the given field is inherited directly or indirectly from a delegate model
|
|
6328
|
-
isFieldInheritedFromDelegateModel(field) {
|
|
6329
|
-
return isDelegateModel(field.$container);
|
|
6548
|
+
isFieldInheritedFromDelegateModel(field, contextModel) {
|
|
6549
|
+
return field.$container !== contextModel && isDelegateModel(field.$container);
|
|
6330
6550
|
}
|
|
6331
6551
|
validateInherits(model, accept) {
|
|
6332
6552
|
if (!model.baseModel) {
|
|
@@ -6385,7 +6605,6 @@ var DataSourceValidator = class {
|
|
|
6385
6605
|
validateDuplicatedDeclarations(ds, ds.fields, accept);
|
|
6386
6606
|
this.validateProvider(ds, accept);
|
|
6387
6607
|
this.validateUrl(ds, accept);
|
|
6388
|
-
this.validateRelationMode(ds, accept);
|
|
6389
6608
|
}
|
|
6390
6609
|
validateProvider(ds, accept) {
|
|
6391
6610
|
const provider = ds.fields.find((f) => f.name === "provider");
|
|
@@ -6395,16 +6614,52 @@ var DataSourceValidator = class {
|
|
|
6395
6614
|
});
|
|
6396
6615
|
return;
|
|
6397
6616
|
}
|
|
6398
|
-
const
|
|
6399
|
-
if (!
|
|
6617
|
+
const providerValue = getStringLiteral(provider.value);
|
|
6618
|
+
if (!providerValue) {
|
|
6400
6619
|
accept("error", '"provider" must be set to a string literal', {
|
|
6401
6620
|
node: provider.value
|
|
6402
6621
|
});
|
|
6403
|
-
} else if (!SUPPORTED_PROVIDERS.includes(
|
|
6404
|
-
accept("error", `Provider "${
|
|
6622
|
+
} else if (!SUPPORTED_PROVIDERS.includes(providerValue)) {
|
|
6623
|
+
accept("error", `Provider "${providerValue}" is not supported. Choose from ${SUPPORTED_PROVIDERS.map((p) => '"' + p + '"').join(" | ")}.`, {
|
|
6405
6624
|
node: provider.value
|
|
6406
6625
|
});
|
|
6407
6626
|
}
|
|
6627
|
+
const defaultSchemaField = ds.fields.find((f) => f.name === "defaultSchema");
|
|
6628
|
+
let defaultSchemaValue;
|
|
6629
|
+
if (defaultSchemaField) {
|
|
6630
|
+
if (providerValue !== "postgresql") {
|
|
6631
|
+
accept("error", '"defaultSchema" is only supported for "postgresql" provider', {
|
|
6632
|
+
node: defaultSchemaField
|
|
6633
|
+
});
|
|
6634
|
+
}
|
|
6635
|
+
defaultSchemaValue = getStringLiteral(defaultSchemaField.value);
|
|
6636
|
+
if (!defaultSchemaValue) {
|
|
6637
|
+
accept("error", '"defaultSchema" must be a string literal', {
|
|
6638
|
+
node: defaultSchemaField.value
|
|
6639
|
+
});
|
|
6640
|
+
}
|
|
6641
|
+
}
|
|
6642
|
+
const schemasField = ds.fields.find((f) => f.name === "schemas");
|
|
6643
|
+
if (schemasField) {
|
|
6644
|
+
if (providerValue !== "postgresql") {
|
|
6645
|
+
accept("error", '"schemas" is only supported for "postgresql" provider', {
|
|
6646
|
+
node: schemasField
|
|
6647
|
+
});
|
|
6648
|
+
}
|
|
6649
|
+
const schemasValue = schemasField.value;
|
|
6650
|
+
if (!isConfigArrayExpr(schemasValue) || !schemasValue.items.every((e) => isLiteralExpr(e) && typeof getStringLiteral(e) === "string")) {
|
|
6651
|
+
accept("error", '"schemas" must be an array of string literals', {
|
|
6652
|
+
node: schemasField
|
|
6653
|
+
});
|
|
6654
|
+
} else if (
|
|
6655
|
+
// validate `defaultSchema` is included in `schemas`
|
|
6656
|
+
defaultSchemaValue && !schemasValue.items.some((e) => getStringLiteral(e) === defaultSchemaValue)
|
|
6657
|
+
) {
|
|
6658
|
+
accept("error", `"${defaultSchemaValue}" must be included in the "schemas" array`, {
|
|
6659
|
+
node: schemasField
|
|
6660
|
+
});
|
|
6661
|
+
}
|
|
6662
|
+
}
|
|
6408
6663
|
}
|
|
6409
6664
|
validateUrl(ds, accept) {
|
|
6410
6665
|
const urlField = ds.fields.find((f) => f.name === "url");
|
|
@@ -6418,20 +6673,6 @@ var DataSourceValidator = class {
|
|
|
6418
6673
|
});
|
|
6419
6674
|
}
|
|
6420
6675
|
}
|
|
6421
|
-
validateRelationMode(ds, accept) {
|
|
6422
|
-
const field = ds.fields.find((f) => f.name === "relationMode");
|
|
6423
|
-
if (field) {
|
|
6424
|
-
const val = getStringLiteral(field.value);
|
|
6425
|
-
if (!val || ![
|
|
6426
|
-
"foreignKeys",
|
|
6427
|
-
"prisma"
|
|
6428
|
-
].includes(val)) {
|
|
6429
|
-
accept("error", '"relationMode" must be set to "foreignKeys" or "prisma"', {
|
|
6430
|
-
node: field.value
|
|
6431
|
-
});
|
|
6432
|
-
}
|
|
6433
|
-
}
|
|
6434
|
-
}
|
|
6435
6676
|
};
|
|
6436
6677
|
|
|
6437
6678
|
// src/validators/enum-validator.ts
|
|
@@ -6484,11 +6725,21 @@ var ExpressionValidator = class {
|
|
|
6484
6725
|
}
|
|
6485
6726
|
}
|
|
6486
6727
|
switch (expr.$type) {
|
|
6728
|
+
case "MemberAccessExpr":
|
|
6729
|
+
this.validateMemberAccessExpr(expr, accept);
|
|
6730
|
+
break;
|
|
6487
6731
|
case "BinaryExpr":
|
|
6488
6732
|
this.validateBinaryExpr(expr, accept);
|
|
6489
6733
|
break;
|
|
6490
6734
|
}
|
|
6491
6735
|
}
|
|
6736
|
+
validateMemberAccessExpr(expr, accept) {
|
|
6737
|
+
if (isBeforeInvocation(expr.operand) && isDataModel(expr.$resolvedType?.decl)) {
|
|
6738
|
+
accept("error", "relation fields cannot be accessed from `before()`", {
|
|
6739
|
+
node: expr
|
|
6740
|
+
});
|
|
6741
|
+
}
|
|
6742
|
+
}
|
|
6492
6743
|
validateBinaryExpr(expr, accept) {
|
|
6493
6744
|
switch (expr.operator) {
|
|
6494
6745
|
case "in": {
|
|
@@ -6541,23 +6792,25 @@ var ExpressionValidator = class {
|
|
|
6541
6792
|
"Any"
|
|
6542
6793
|
];
|
|
6543
6794
|
}
|
|
6544
|
-
|
|
6795
|
+
const leftResolvedDecl = expr.left.$resolvedType?.decl;
|
|
6796
|
+
const rightResolvedDecl = expr.right.$resolvedType?.decl;
|
|
6797
|
+
if (leftResolvedDecl && (typeof leftResolvedDecl !== "string" || !supportedShapes.includes(leftResolvedDecl))) {
|
|
6545
6798
|
accept("error", `invalid operand type for "${expr.operator}" operator`, {
|
|
6546
6799
|
node: expr.left
|
|
6547
6800
|
});
|
|
6548
6801
|
return;
|
|
6549
6802
|
}
|
|
6550
|
-
if (typeof
|
|
6803
|
+
if (rightResolvedDecl && (typeof rightResolvedDecl !== "string" || !supportedShapes.includes(rightResolvedDecl))) {
|
|
6551
6804
|
accept("error", `invalid operand type for "${expr.operator}" operator`, {
|
|
6552
6805
|
node: expr.right
|
|
6553
6806
|
});
|
|
6554
6807
|
return;
|
|
6555
6808
|
}
|
|
6556
|
-
if (
|
|
6809
|
+
if (leftResolvedDecl === "DateTime" && rightResolvedDecl && rightResolvedDecl !== "DateTime") {
|
|
6557
6810
|
accept("error", "incompatible operand types", {
|
|
6558
6811
|
node: expr
|
|
6559
6812
|
});
|
|
6560
|
-
} else if (
|
|
6813
|
+
} else if (rightResolvedDecl === "DateTime" && leftResolvedDecl && leftResolvedDecl !== "DateTime") {
|
|
6561
6814
|
accept("error", "incompatible operand types", {
|
|
6562
6815
|
node: expr
|
|
6563
6816
|
});
|
|
@@ -6597,11 +6850,11 @@ var ExpressionValidator = class {
|
|
|
6597
6850
|
});
|
|
6598
6851
|
}
|
|
6599
6852
|
if (isDataFieldReference(expr.left) && (isThisExpr(expr.right) || isDataFieldReference(expr.right))) {
|
|
6600
|
-
accept("error", "comparison between
|
|
6853
|
+
accept("error", "comparison between models is not supported", {
|
|
6601
6854
|
node: expr
|
|
6602
6855
|
});
|
|
6603
6856
|
} else if (isDataFieldReference(expr.right) && (isThisExpr(expr.left) || isDataFieldReference(expr.left))) {
|
|
6604
|
-
accept("error", "comparison between
|
|
6857
|
+
accept("error", "comparison between models is not supported", {
|
|
6605
6858
|
node: expr
|
|
6606
6859
|
});
|
|
6607
6860
|
}
|
|
@@ -6691,41 +6944,39 @@ var FunctionInvocationValidator = class {
|
|
|
6691
6944
|
if (!this.validateArgs(funcDecl, expr.args, accept)) {
|
|
6692
6945
|
return;
|
|
6693
6946
|
}
|
|
6694
|
-
|
|
6695
|
-
|
|
6696
|
-
|
|
6697
|
-
|
|
6698
|
-
|
|
6699
|
-
|
|
6700
|
-
break;
|
|
6701
|
-
}
|
|
6702
|
-
curr = curr.$container;
|
|
6947
|
+
let curr = expr.$container;
|
|
6948
|
+
let containerAttribute;
|
|
6949
|
+
while (curr) {
|
|
6950
|
+
if (isDataModelAttribute(curr) || isDataFieldAttribute(curr)) {
|
|
6951
|
+
containerAttribute = curr;
|
|
6952
|
+
break;
|
|
6703
6953
|
}
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6954
|
+
curr = curr.$container;
|
|
6955
|
+
}
|
|
6956
|
+
const exprContext = this.getExpressionContext(containerAttribute);
|
|
6957
|
+
const funcAllowedContext = getFunctionExpressionContext(funcDecl);
|
|
6958
|
+
if (exprContext && !funcAllowedContext.includes(exprContext)) {
|
|
6959
|
+
accept("error", `function "${funcDecl.name}" is not allowed in the current context: ${exprContext}`, {
|
|
6960
|
+
node: expr
|
|
6961
|
+
});
|
|
6962
|
+
return;
|
|
6963
|
+
}
|
|
6964
|
+
const allCasing = [
|
|
6965
|
+
"original",
|
|
6966
|
+
"upper",
|
|
6967
|
+
"lower",
|
|
6968
|
+
"capitalize",
|
|
6969
|
+
"uncapitalize"
|
|
6970
|
+
];
|
|
6971
|
+
if ([
|
|
6972
|
+
"currentModel",
|
|
6973
|
+
"currentOperation"
|
|
6974
|
+
].includes(funcDecl.name)) {
|
|
6975
|
+
const arg = getLiteral(expr.args[0]?.value);
|
|
6976
|
+
if (arg && !allCasing.includes(arg)) {
|
|
6977
|
+
accept("error", `argument must be one of: ${allCasing.map((c) => '"' + c + '"').join(", ")}`, {
|
|
6978
|
+
node: expr.args[0]
|
|
6709
6979
|
});
|
|
6710
|
-
return;
|
|
6711
|
-
}
|
|
6712
|
-
const allCasing = [
|
|
6713
|
-
"original",
|
|
6714
|
-
"upper",
|
|
6715
|
-
"lower",
|
|
6716
|
-
"capitalize",
|
|
6717
|
-
"uncapitalize"
|
|
6718
|
-
];
|
|
6719
|
-
if ([
|
|
6720
|
-
"currentModel",
|
|
6721
|
-
"currentOperation"
|
|
6722
|
-
].includes(funcDecl.name)) {
|
|
6723
|
-
const arg = getLiteral(expr.args[0]?.value);
|
|
6724
|
-
if (arg && !allCasing.includes(arg)) {
|
|
6725
|
-
accept("error", `argument must be one of: ${allCasing.map((c) => '"' + c + '"').join(", ")}`, {
|
|
6726
|
-
node: expr.args[0]
|
|
6727
|
-
});
|
|
6728
|
-
}
|
|
6729
6980
|
}
|
|
6730
6981
|
}
|
|
6731
6982
|
const checker = invocationCheckers.get(expr.function.$refText);
|
|
@@ -6733,6 +6984,18 @@ var FunctionInvocationValidator = class {
|
|
|
6733
6984
|
checker.value.call(this, expr, accept);
|
|
6734
6985
|
}
|
|
6735
6986
|
}
|
|
6987
|
+
getExpressionContext(containerAttribute) {
|
|
6988
|
+
if (!containerAttribute) {
|
|
6989
|
+
return void 0;
|
|
6990
|
+
}
|
|
6991
|
+
if (this.isValidationAttribute(containerAttribute)) {
|
|
6992
|
+
return ExpressionContext.ValidationRule;
|
|
6993
|
+
}
|
|
6994
|
+
return (0, import_ts_pattern.match)(containerAttribute?.decl.$refText).with("@default", () => ExpressionContext.DefaultValue).with(import_ts_pattern.P.union("@@allow", "@@deny", "@allow", "@deny"), () => ExpressionContext.AccessPolicy).with("@@index", () => ExpressionContext.Index).otherwise(() => void 0);
|
|
6995
|
+
}
|
|
6996
|
+
isValidationAttribute(attr) {
|
|
6997
|
+
return !!attr.decl.ref?.attributes.some((attr2) => attr2.decl.$refText === "@@@validation");
|
|
6998
|
+
}
|
|
6736
6999
|
validateArgs(funcDecl, args, accept) {
|
|
6737
7000
|
let success = true;
|
|
6738
7001
|
for (let i = 0; i < funcDecl.params.length; i++) {
|
|
@@ -6793,6 +7056,51 @@ var FunctionInvocationValidator = class {
|
|
|
6793
7056
|
}
|
|
6794
7057
|
return true;
|
|
6795
7058
|
}
|
|
7059
|
+
_checkAuth(expr, accept) {
|
|
7060
|
+
if (!expr.$resolvedType) {
|
|
7061
|
+
accept("error", 'cannot resolve `auth()` - make sure you have a model or type with `@auth` attribute or named "User"', {
|
|
7062
|
+
node: expr
|
|
7063
|
+
});
|
|
7064
|
+
}
|
|
7065
|
+
}
|
|
7066
|
+
_checkLength(expr, accept) {
|
|
7067
|
+
const msg = "argument must be a string or list field";
|
|
7068
|
+
const fieldArg = expr.args[0].value;
|
|
7069
|
+
if (!isDataFieldReference(fieldArg)) {
|
|
7070
|
+
accept("error", msg, {
|
|
7071
|
+
node: expr.args[0]
|
|
7072
|
+
});
|
|
7073
|
+
return;
|
|
7074
|
+
}
|
|
7075
|
+
if (isDataModel(fieldArg.$resolvedType?.decl)) {
|
|
7076
|
+
accept("error", msg, {
|
|
7077
|
+
node: expr.args[0]
|
|
7078
|
+
});
|
|
7079
|
+
return;
|
|
7080
|
+
}
|
|
7081
|
+
if (!fieldArg.$resolvedType?.array && fieldArg.$resolvedType?.decl !== "String") {
|
|
7082
|
+
accept("error", msg, {
|
|
7083
|
+
node: expr.args[0]
|
|
7084
|
+
});
|
|
7085
|
+
}
|
|
7086
|
+
}
|
|
7087
|
+
_checkRegex(expr, accept) {
|
|
7088
|
+
const regex = expr.args[1]?.value;
|
|
7089
|
+
if (!isStringLiteral(regex)) {
|
|
7090
|
+
accept("error", "second argument must be a string literal", {
|
|
7091
|
+
node: expr.args[1]
|
|
7092
|
+
});
|
|
7093
|
+
return;
|
|
7094
|
+
}
|
|
7095
|
+
try {
|
|
7096
|
+
new RegExp(regex.value);
|
|
7097
|
+
} catch (e) {
|
|
7098
|
+
accept("error", "invalid regular expression: " + e.message, {
|
|
7099
|
+
node: expr.args[1]
|
|
7100
|
+
});
|
|
7101
|
+
}
|
|
7102
|
+
}
|
|
7103
|
+
// TODO: move this to policy plugin
|
|
6796
7104
|
_checkCheck(expr, accept) {
|
|
6797
7105
|
let valid = true;
|
|
6798
7106
|
const fieldArg = expr.args[0].value;
|
|
@@ -6864,6 +7172,33 @@ var FunctionInvocationValidator = class {
|
|
|
6864
7172
|
}
|
|
6865
7173
|
}
|
|
6866
7174
|
};
|
|
7175
|
+
_ts_decorate2([
|
|
7176
|
+
func("auth"),
|
|
7177
|
+
_ts_metadata2("design:type", Function),
|
|
7178
|
+
_ts_metadata2("design:paramtypes", [
|
|
7179
|
+
typeof InvocationExpr === "undefined" ? Object : InvocationExpr,
|
|
7180
|
+
typeof ValidationAcceptor === "undefined" ? Object : ValidationAcceptor
|
|
7181
|
+
]),
|
|
7182
|
+
_ts_metadata2("design:returntype", void 0)
|
|
7183
|
+
], FunctionInvocationValidator.prototype, "_checkAuth", null);
|
|
7184
|
+
_ts_decorate2([
|
|
7185
|
+
func("length"),
|
|
7186
|
+
_ts_metadata2("design:type", Function),
|
|
7187
|
+
_ts_metadata2("design:paramtypes", [
|
|
7188
|
+
typeof InvocationExpr === "undefined" ? Object : InvocationExpr,
|
|
7189
|
+
typeof ValidationAcceptor === "undefined" ? Object : ValidationAcceptor
|
|
7190
|
+
]),
|
|
7191
|
+
_ts_metadata2("design:returntype", void 0)
|
|
7192
|
+
], FunctionInvocationValidator.prototype, "_checkLength", null);
|
|
7193
|
+
_ts_decorate2([
|
|
7194
|
+
func("regex"),
|
|
7195
|
+
_ts_metadata2("design:type", Function),
|
|
7196
|
+
_ts_metadata2("design:paramtypes", [
|
|
7197
|
+
typeof InvocationExpr === "undefined" ? Object : InvocationExpr,
|
|
7198
|
+
typeof ValidationAcceptor === "undefined" ? Object : ValidationAcceptor
|
|
7199
|
+
]),
|
|
7200
|
+
_ts_metadata2("design:returntype", void 0)
|
|
7201
|
+
], FunctionInvocationValidator.prototype, "_checkRegex", null);
|
|
6867
7202
|
_ts_decorate2([
|
|
6868
7203
|
func("check"),
|
|
6869
7204
|
_ts_metadata2("design:type", Function),
|
|
@@ -6954,6 +7289,7 @@ function registerValidationChecks(services) {
|
|
|
6954
7289
|
const checks = {
|
|
6955
7290
|
Model: validator.checkModel,
|
|
6956
7291
|
DataSource: validator.checkDataSource,
|
|
7292
|
+
GeneratorDecl: validator.checkGenerator,
|
|
6957
7293
|
DataModel: validator.checkDataModel,
|
|
6958
7294
|
TypeDef: validator.checkTypeDef,
|
|
6959
7295
|
Enum: validator.checkEnum,
|
|
@@ -6973,51 +7309,1045 @@ var ZModelValidator = class {
|
|
|
6973
7309
|
constructor(services) {
|
|
6974
7310
|
this.services = services;
|
|
6975
7311
|
}
|
|
6976
|
-
shouldCheck(node) {
|
|
6977
|
-
let doc;
|
|
6978
|
-
let currNode = node;
|
|
6979
|
-
while (currNode) {
|
|
6980
|
-
if (currNode.$document) {
|
|
6981
|
-
doc = currNode.$document;
|
|
6982
|
-
break;
|
|
6983
|
-
}
|
|
6984
|
-
currNode = currNode.$container;
|
|
6985
|
-
}
|
|
6986
|
-
return doc?.parseResult.lexerErrors.length === 0 && doc?.parseResult.parserErrors.length === 0;
|
|
6987
|
-
}
|
|
6988
7312
|
checkModel(node, accept) {
|
|
6989
|
-
|
|
7313
|
+
new SchemaValidator(this.services.shared.workspace.LangiumDocuments).validate(node, accept);
|
|
6990
7314
|
}
|
|
6991
7315
|
checkDataSource(node, accept) {
|
|
6992
|
-
|
|
7316
|
+
new DataSourceValidator().validate(node, accept);
|
|
7317
|
+
}
|
|
7318
|
+
checkGenerator(node, accept) {
|
|
7319
|
+
accept("warning", '"generator" is not used by ZenStack and should be removed.', {
|
|
7320
|
+
node
|
|
7321
|
+
});
|
|
6993
7322
|
}
|
|
6994
7323
|
checkDataModel(node, accept) {
|
|
6995
|
-
|
|
7324
|
+
new DataModelValidator().validate(node, accept);
|
|
6996
7325
|
}
|
|
6997
7326
|
checkTypeDef(node, accept) {
|
|
6998
|
-
|
|
7327
|
+
new TypeDefValidator().validate(node, accept);
|
|
6999
7328
|
}
|
|
7000
7329
|
checkEnum(node, accept) {
|
|
7001
|
-
|
|
7330
|
+
new EnumValidator().validate(node, accept);
|
|
7002
7331
|
}
|
|
7003
7332
|
checkAttribute(node, accept) {
|
|
7004
|
-
|
|
7333
|
+
new AttributeValidator().validate(node, accept);
|
|
7005
7334
|
}
|
|
7006
7335
|
checkExpression(node, accept) {
|
|
7007
|
-
|
|
7336
|
+
new ExpressionValidator().validate(node, accept);
|
|
7008
7337
|
}
|
|
7009
7338
|
checkFunctionInvocation(node, accept) {
|
|
7010
|
-
|
|
7339
|
+
new FunctionInvocationValidator().validate(node, accept);
|
|
7011
7340
|
}
|
|
7012
7341
|
checkFunctionDecl(node, accept) {
|
|
7013
|
-
|
|
7342
|
+
new FunctionDeclValidator().validate(node, accept);
|
|
7014
7343
|
}
|
|
7015
7344
|
};
|
|
7016
7345
|
|
|
7017
|
-
// src/zmodel-
|
|
7346
|
+
// src/zmodel-comment-provider.ts
|
|
7018
7347
|
var import_langium7 = require("langium");
|
|
7019
7348
|
var import_ts_pattern2 = require("ts-pattern");
|
|
7020
|
-
var
|
|
7349
|
+
var ZModelCommentProvider = class extends import_langium7.DefaultCommentProvider {
|
|
7350
|
+
static {
|
|
7351
|
+
__name(this, "ZModelCommentProvider");
|
|
7352
|
+
}
|
|
7353
|
+
getComment(node) {
|
|
7354
|
+
let comment = super.getComment(node);
|
|
7355
|
+
if (!comment) {
|
|
7356
|
+
comment = (0, import_ts_pattern2.match)(node).when(isDataModel, (d) => `/**
|
|
7357
|
+
* Model *${d.name}*
|
|
7358
|
+
*/`).when(isTypeDef, (d) => `/**
|
|
7359
|
+
* Type *${d.name}*
|
|
7360
|
+
*/`).when(isEnum, (e) => `/**
|
|
7361
|
+
* Enum *${e.name}*
|
|
7362
|
+
*/`).when(isEnumField, (f) => `/**
|
|
7363
|
+
* Value of enum *${f.$container?.name}*
|
|
7364
|
+
*/`).when(isDataField, (f) => `/**
|
|
7365
|
+
* Field of *${f.$container?.name}*
|
|
7366
|
+
*/`).when(isFunctionDecl, (f) => `/**
|
|
7367
|
+
* Function *${f.name}*
|
|
7368
|
+
*/`).otherwise(() => "");
|
|
7369
|
+
}
|
|
7370
|
+
return comment;
|
|
7371
|
+
}
|
|
7372
|
+
};
|
|
7373
|
+
|
|
7374
|
+
// src/zmodel-completion-provider.ts
|
|
7375
|
+
var import_lsp = require("langium/lsp");
|
|
7376
|
+
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
7377
|
+
var import_ts_pattern3 = require("ts-pattern");
|
|
7378
|
+
var import_vscode_languageserver = require("vscode-languageserver");
|
|
7379
|
+
|
|
7380
|
+
// src/zmodel-code-generator.ts
|
|
7381
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
7382
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
7383
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
7384
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
7385
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7386
|
+
}
|
|
7387
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
7388
|
+
function _ts_metadata3(k, v) {
|
|
7389
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
7390
|
+
}
|
|
7391
|
+
__name(_ts_metadata3, "_ts_metadata");
|
|
7392
|
+
var generationHandlers = /* @__PURE__ */ new Map();
|
|
7393
|
+
function gen(name) {
|
|
7394
|
+
return function(_target, _propertyKey, descriptor) {
|
|
7395
|
+
if (!generationHandlers.get(name)) {
|
|
7396
|
+
generationHandlers.set(name, descriptor);
|
|
7397
|
+
}
|
|
7398
|
+
return descriptor;
|
|
7399
|
+
};
|
|
7400
|
+
}
|
|
7401
|
+
__name(gen, "gen");
|
|
7402
|
+
var ZModelCodeGenerator = class {
|
|
7403
|
+
static {
|
|
7404
|
+
__name(this, "ZModelCodeGenerator");
|
|
7405
|
+
}
|
|
7406
|
+
options;
|
|
7407
|
+
constructor(options) {
|
|
7408
|
+
this.options = {
|
|
7409
|
+
binaryExprNumberOfSpaces: options?.binaryExprNumberOfSpaces ?? 1,
|
|
7410
|
+
unaryExprNumberOfSpaces: options?.unaryExprNumberOfSpaces ?? 0,
|
|
7411
|
+
indent: options?.indent ?? 4,
|
|
7412
|
+
quote: options?.quote ?? "single"
|
|
7413
|
+
};
|
|
7414
|
+
}
|
|
7415
|
+
/**
|
|
7416
|
+
* Generates ZModel source code from AST.
|
|
7417
|
+
*/
|
|
7418
|
+
generate(ast) {
|
|
7419
|
+
const handler = generationHandlers.get(ast.$type);
|
|
7420
|
+
if (!handler) {
|
|
7421
|
+
throw new Error(`No generation handler found for ${ast.$type}`);
|
|
7422
|
+
}
|
|
7423
|
+
return handler.value.call(this, ast);
|
|
7424
|
+
}
|
|
7425
|
+
_generateModel(ast) {
|
|
7426
|
+
return ast.declarations.map((d) => this.generate(d)).join("\n\n");
|
|
7427
|
+
}
|
|
7428
|
+
_generateDataSource(ast) {
|
|
7429
|
+
return `datasource ${ast.name} {
|
|
7430
|
+
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
7431
|
+
}`;
|
|
7432
|
+
}
|
|
7433
|
+
_generateEnum(ast) {
|
|
7434
|
+
return `enum ${ast.name} {
|
|
7435
|
+
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
7436
|
+
}`;
|
|
7437
|
+
}
|
|
7438
|
+
_generateEnumField(ast) {
|
|
7439
|
+
return `${ast.name}${ast.attributes.length > 0 ? " " + ast.attributes.map((x) => this.generate(x)).join(" ") : ""}`;
|
|
7440
|
+
}
|
|
7441
|
+
_generateGenerator(ast) {
|
|
7442
|
+
return `generator ${ast.name} {
|
|
7443
|
+
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
7444
|
+
}`;
|
|
7445
|
+
}
|
|
7446
|
+
_generateConfigField(ast) {
|
|
7447
|
+
return `${ast.name} = ${this.generate(ast.value)}`;
|
|
7448
|
+
}
|
|
7449
|
+
_generateConfigArrayExpr(ast) {
|
|
7450
|
+
return `[${ast.items.map((x) => this.generate(x)).join(", ")}]`;
|
|
7451
|
+
}
|
|
7452
|
+
_generateConfigInvocationExpr(ast) {
|
|
7453
|
+
if (ast.args.length === 0) {
|
|
7454
|
+
return ast.name;
|
|
7455
|
+
} else {
|
|
7456
|
+
return `${ast.name}(${ast.args.map((x) => (x.name ? x.name + ": " : "") + this.generate(x.value)).join(", ")})`;
|
|
7457
|
+
}
|
|
7458
|
+
}
|
|
7459
|
+
_generatePlugin(ast) {
|
|
7460
|
+
return `plugin ${ast.name} {
|
|
7461
|
+
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
7462
|
+
}`;
|
|
7463
|
+
}
|
|
7464
|
+
_generatePluginField(ast) {
|
|
7465
|
+
return `${ast.name} = ${this.generate(ast.value)}`;
|
|
7466
|
+
}
|
|
7467
|
+
_generateDataModel(ast) {
|
|
7468
|
+
return `${ast.isView ? "view" : "model"} ${ast.name}${ast.mixins.length > 0 ? " mixes " + ast.mixins.map((x) => x.$refText).join(", ") : ""} {
|
|
7469
|
+
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}${ast.attributes.length > 0 ? "\n\n" + ast.attributes.map((x) => this.indent + this.generate(x)).join("\n") : ""}
|
|
7470
|
+
}`;
|
|
7471
|
+
}
|
|
7472
|
+
_generateDataField(ast) {
|
|
7473
|
+
return `${ast.name} ${this.fieldType(ast.type)}${ast.attributes.length > 0 ? " " + ast.attributes.map((x) => this.generate(x)).join(" ") : ""}`;
|
|
7474
|
+
}
|
|
7475
|
+
fieldType(type) {
|
|
7476
|
+
const baseType = type.type ? type.type : type.$type == "DataFieldType" && type.unsupported ? "Unsupported(" + this.generate(type.unsupported.value) + ")" : type.reference?.$refText;
|
|
7477
|
+
return `${baseType}${type.array ? "[]" : ""}${type.optional ? "?" : ""}`;
|
|
7478
|
+
}
|
|
7479
|
+
_generateDataModelAttribute(ast) {
|
|
7480
|
+
return this.attribute(ast);
|
|
7481
|
+
}
|
|
7482
|
+
_generateDataFieldAttribute(ast) {
|
|
7483
|
+
return this.attribute(ast);
|
|
7484
|
+
}
|
|
7485
|
+
attribute(ast) {
|
|
7486
|
+
const args = ast.args.length ? `(${ast.args.map((x) => this.generate(x)).join(", ")})` : "";
|
|
7487
|
+
return `${ast.decl.$refText}${args}`;
|
|
7488
|
+
}
|
|
7489
|
+
_generateAttributeArg(ast) {
|
|
7490
|
+
if (ast.name) {
|
|
7491
|
+
return `${ast.name}: ${this.generate(ast.value)}`;
|
|
7492
|
+
} else {
|
|
7493
|
+
return this.generate(ast.value);
|
|
7494
|
+
}
|
|
7495
|
+
}
|
|
7496
|
+
_generateObjectExpr(ast) {
|
|
7497
|
+
return `{ ${ast.fields.map((field) => this.objectField(field)).join(", ")} }`;
|
|
7498
|
+
}
|
|
7499
|
+
objectField(field) {
|
|
7500
|
+
return `${field.name}: ${this.generate(field.value)}`;
|
|
7501
|
+
}
|
|
7502
|
+
_generateArrayExpr(ast) {
|
|
7503
|
+
return `[${ast.items.map((item) => this.generate(item)).join(", ")}]`;
|
|
7504
|
+
}
|
|
7505
|
+
_generateLiteralExpr(ast) {
|
|
7506
|
+
return this.options.quote === "single" ? `'${ast.value}'` : `"${ast.value}"`;
|
|
7507
|
+
}
|
|
7508
|
+
_generateNumberLiteral(ast) {
|
|
7509
|
+
return ast.value.toString();
|
|
7510
|
+
}
|
|
7511
|
+
_generateBooleanLiteral(ast) {
|
|
7512
|
+
return ast.value.toString();
|
|
7513
|
+
}
|
|
7514
|
+
_generateUnaryExpr(ast) {
|
|
7515
|
+
return `${ast.operator}${this.unaryExprSpace}${this.generate(ast.operand)}`;
|
|
7516
|
+
}
|
|
7517
|
+
_generateBinaryExpr(ast) {
|
|
7518
|
+
const operator = ast.operator;
|
|
7519
|
+
const isCollectionPredicate2 = this.isCollectionPredicateOperator(operator);
|
|
7520
|
+
const rightExpr = this.generate(ast.right);
|
|
7521
|
+
const { left: isLeftParenthesis, right: isRightParenthesis } = this.isParenthesesNeededForBinaryExpr(ast);
|
|
7522
|
+
return `${isLeftParenthesis ? "(" : ""}${this.generate(ast.left)}${isLeftParenthesis ? ")" : ""}${isCollectionPredicate2 ? "" : this.binaryExprSpace}${operator}${isCollectionPredicate2 ? "" : this.binaryExprSpace}${isRightParenthesis ? "(" : ""}${isCollectionPredicate2 ? `[${rightExpr}]` : rightExpr}${isRightParenthesis ? ")" : ""}`;
|
|
7523
|
+
}
|
|
7524
|
+
_generateReferenceExpr(ast) {
|
|
7525
|
+
const args = ast.args.length ? `(${ast.args.map((x) => this.generate(x)).join(", ")})` : "";
|
|
7526
|
+
return `${ast.target.$refText}${args}`;
|
|
7527
|
+
}
|
|
7528
|
+
_generateReferenceArg(ast) {
|
|
7529
|
+
return `${ast.name}:${this.generate(ast.value)}`;
|
|
7530
|
+
}
|
|
7531
|
+
_generateMemberExpr(ast) {
|
|
7532
|
+
return `${this.generate(ast.operand)}.${ast.member.$refText}`;
|
|
7533
|
+
}
|
|
7534
|
+
_generateInvocationExpr(ast) {
|
|
7535
|
+
return `${ast.function.$refText}(${ast.args.map((x) => this.argument(x)).join(", ")})`;
|
|
7536
|
+
}
|
|
7537
|
+
_generateNullExpr() {
|
|
7538
|
+
return "null";
|
|
7539
|
+
}
|
|
7540
|
+
_generateThisExpr() {
|
|
7541
|
+
return "this";
|
|
7542
|
+
}
|
|
7543
|
+
_generateAttribute(ast) {
|
|
7544
|
+
return `attribute ${ast.name}(${ast.params.map((x) => this.generate(x)).join(", ")})`;
|
|
7545
|
+
}
|
|
7546
|
+
_generateAttributeParam(ast) {
|
|
7547
|
+
return `${ast.default ? "_ " : ""}${ast.name}: ${this.generate(ast.type)}`;
|
|
7548
|
+
}
|
|
7549
|
+
_generateAttributeParamType(ast) {
|
|
7550
|
+
return `${ast.type ?? ast.reference?.$refText}${ast.array ? "[]" : ""}${ast.optional ? "?" : ""}`;
|
|
7551
|
+
}
|
|
7552
|
+
_generateFunctionDecl(ast) {
|
|
7553
|
+
return `function ${ast.name}(${ast.params.map((x) => this.generate(x)).join(", ")}) ${ast.returnType ? ": " + this.generate(ast.returnType) : ""} {}`;
|
|
7554
|
+
}
|
|
7555
|
+
_generateFunctionParam(ast) {
|
|
7556
|
+
return `${ast.name}: ${this.generate(ast.type)}`;
|
|
7557
|
+
}
|
|
7558
|
+
_generateFunctionParamType(ast) {
|
|
7559
|
+
return `${ast.type ?? ast.reference?.$refText}${ast.array ? "[]" : ""}`;
|
|
7560
|
+
}
|
|
7561
|
+
_generateTypeDef(ast) {
|
|
7562
|
+
return `type ${ast.name} {
|
|
7563
|
+
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}${ast.attributes.length > 0 ? "\n\n" + ast.attributes.map((x) => this.indent + this.generate(x)).join("\n") : ""}
|
|
7564
|
+
}`;
|
|
7565
|
+
}
|
|
7566
|
+
argument(ast) {
|
|
7567
|
+
return this.generate(ast.value);
|
|
7568
|
+
}
|
|
7569
|
+
get binaryExprSpace() {
|
|
7570
|
+
return " ".repeat(this.options.binaryExprNumberOfSpaces);
|
|
7571
|
+
}
|
|
7572
|
+
get unaryExprSpace() {
|
|
7573
|
+
return " ".repeat(this.options.unaryExprNumberOfSpaces);
|
|
7574
|
+
}
|
|
7575
|
+
get indent() {
|
|
7576
|
+
return " ".repeat(this.options.indent);
|
|
7577
|
+
}
|
|
7578
|
+
isParenthesesNeededForBinaryExpr(ast) {
|
|
7579
|
+
const result = {
|
|
7580
|
+
left: false,
|
|
7581
|
+
right: false
|
|
7582
|
+
};
|
|
7583
|
+
const operator = ast.operator;
|
|
7584
|
+
const isCollectionPredicate2 = this.isCollectionPredicateOperator(operator);
|
|
7585
|
+
const currentPriority = BinaryExprOperatorPriority[operator];
|
|
7586
|
+
if (ast.left.$type === BinaryExpr && BinaryExprOperatorPriority[ast.left["operator"]] < currentPriority) {
|
|
7587
|
+
result.left = true;
|
|
7588
|
+
}
|
|
7589
|
+
if (!isCollectionPredicate2 && ast.right.$type === BinaryExpr && BinaryExprOperatorPriority[ast.right["operator"]] <= currentPriority) {
|
|
7590
|
+
result.right = true;
|
|
7591
|
+
}
|
|
7592
|
+
return result;
|
|
7593
|
+
}
|
|
7594
|
+
isCollectionPredicateOperator(op) {
|
|
7595
|
+
return [
|
|
7596
|
+
"?",
|
|
7597
|
+
"!",
|
|
7598
|
+
"^"
|
|
7599
|
+
].includes(op);
|
|
7600
|
+
}
|
|
7601
|
+
};
|
|
7602
|
+
_ts_decorate3([
|
|
7603
|
+
gen(Model),
|
|
7604
|
+
_ts_metadata3("design:type", Function),
|
|
7605
|
+
_ts_metadata3("design:paramtypes", [
|
|
7606
|
+
typeof Model === "undefined" ? Object : Model
|
|
7607
|
+
]),
|
|
7608
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7609
|
+
], ZModelCodeGenerator.prototype, "_generateModel", null);
|
|
7610
|
+
_ts_decorate3([
|
|
7611
|
+
gen(DataSource),
|
|
7612
|
+
_ts_metadata3("design:type", Function),
|
|
7613
|
+
_ts_metadata3("design:paramtypes", [
|
|
7614
|
+
typeof DataSource === "undefined" ? Object : DataSource
|
|
7615
|
+
]),
|
|
7616
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7617
|
+
], ZModelCodeGenerator.prototype, "_generateDataSource", null);
|
|
7618
|
+
_ts_decorate3([
|
|
7619
|
+
gen(Enum),
|
|
7620
|
+
_ts_metadata3("design:type", Function),
|
|
7621
|
+
_ts_metadata3("design:paramtypes", [
|
|
7622
|
+
typeof Enum === "undefined" ? Object : Enum
|
|
7623
|
+
]),
|
|
7624
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7625
|
+
], ZModelCodeGenerator.prototype, "_generateEnum", null);
|
|
7626
|
+
_ts_decorate3([
|
|
7627
|
+
gen(EnumField),
|
|
7628
|
+
_ts_metadata3("design:type", Function),
|
|
7629
|
+
_ts_metadata3("design:paramtypes", [
|
|
7630
|
+
typeof EnumField === "undefined" ? Object : EnumField
|
|
7631
|
+
]),
|
|
7632
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7633
|
+
], ZModelCodeGenerator.prototype, "_generateEnumField", null);
|
|
7634
|
+
_ts_decorate3([
|
|
7635
|
+
gen(GeneratorDecl),
|
|
7636
|
+
_ts_metadata3("design:type", Function),
|
|
7637
|
+
_ts_metadata3("design:paramtypes", [
|
|
7638
|
+
typeof GeneratorDecl === "undefined" ? Object : GeneratorDecl
|
|
7639
|
+
]),
|
|
7640
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7641
|
+
], ZModelCodeGenerator.prototype, "_generateGenerator", null);
|
|
7642
|
+
_ts_decorate3([
|
|
7643
|
+
gen(ConfigField),
|
|
7644
|
+
_ts_metadata3("design:type", Function),
|
|
7645
|
+
_ts_metadata3("design:paramtypes", [
|
|
7646
|
+
typeof ConfigField === "undefined" ? Object : ConfigField
|
|
7647
|
+
]),
|
|
7648
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7649
|
+
], ZModelCodeGenerator.prototype, "_generateConfigField", null);
|
|
7650
|
+
_ts_decorate3([
|
|
7651
|
+
gen(ConfigArrayExpr),
|
|
7652
|
+
_ts_metadata3("design:type", Function),
|
|
7653
|
+
_ts_metadata3("design:paramtypes", [
|
|
7654
|
+
typeof ConfigArrayExpr === "undefined" ? Object : ConfigArrayExpr
|
|
7655
|
+
]),
|
|
7656
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7657
|
+
], ZModelCodeGenerator.prototype, "_generateConfigArrayExpr", null);
|
|
7658
|
+
_ts_decorate3([
|
|
7659
|
+
gen(ConfigInvocationExpr),
|
|
7660
|
+
_ts_metadata3("design:type", Function),
|
|
7661
|
+
_ts_metadata3("design:paramtypes", [
|
|
7662
|
+
typeof ConfigInvocationExpr === "undefined" ? Object : ConfigInvocationExpr
|
|
7663
|
+
]),
|
|
7664
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7665
|
+
], ZModelCodeGenerator.prototype, "_generateConfigInvocationExpr", null);
|
|
7666
|
+
_ts_decorate3([
|
|
7667
|
+
gen(Plugin),
|
|
7668
|
+
_ts_metadata3("design:type", Function),
|
|
7669
|
+
_ts_metadata3("design:paramtypes", [
|
|
7670
|
+
typeof Plugin === "undefined" ? Object : Plugin
|
|
7671
|
+
]),
|
|
7672
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7673
|
+
], ZModelCodeGenerator.prototype, "_generatePlugin", null);
|
|
7674
|
+
_ts_decorate3([
|
|
7675
|
+
gen(PluginField),
|
|
7676
|
+
_ts_metadata3("design:type", Function),
|
|
7677
|
+
_ts_metadata3("design:paramtypes", [
|
|
7678
|
+
typeof PluginField === "undefined" ? Object : PluginField
|
|
7679
|
+
]),
|
|
7680
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7681
|
+
], ZModelCodeGenerator.prototype, "_generatePluginField", null);
|
|
7682
|
+
_ts_decorate3([
|
|
7683
|
+
gen(DataModel),
|
|
7684
|
+
_ts_metadata3("design:type", Function),
|
|
7685
|
+
_ts_metadata3("design:paramtypes", [
|
|
7686
|
+
typeof DataModel === "undefined" ? Object : DataModel
|
|
7687
|
+
]),
|
|
7688
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7689
|
+
], ZModelCodeGenerator.prototype, "_generateDataModel", null);
|
|
7690
|
+
_ts_decorate3([
|
|
7691
|
+
gen(DataField),
|
|
7692
|
+
_ts_metadata3("design:type", Function),
|
|
7693
|
+
_ts_metadata3("design:paramtypes", [
|
|
7694
|
+
typeof DataField === "undefined" ? Object : DataField
|
|
7695
|
+
]),
|
|
7696
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7697
|
+
], ZModelCodeGenerator.prototype, "_generateDataField", null);
|
|
7698
|
+
_ts_decorate3([
|
|
7699
|
+
gen(DataModelAttribute),
|
|
7700
|
+
_ts_metadata3("design:type", Function),
|
|
7701
|
+
_ts_metadata3("design:paramtypes", [
|
|
7702
|
+
typeof DataModelAttribute === "undefined" ? Object : DataModelAttribute
|
|
7703
|
+
]),
|
|
7704
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7705
|
+
], ZModelCodeGenerator.prototype, "_generateDataModelAttribute", null);
|
|
7706
|
+
_ts_decorate3([
|
|
7707
|
+
gen(DataFieldAttribute),
|
|
7708
|
+
_ts_metadata3("design:type", Function),
|
|
7709
|
+
_ts_metadata3("design:paramtypes", [
|
|
7710
|
+
typeof DataFieldAttribute === "undefined" ? Object : DataFieldAttribute
|
|
7711
|
+
]),
|
|
7712
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7713
|
+
], ZModelCodeGenerator.prototype, "_generateDataFieldAttribute", null);
|
|
7714
|
+
_ts_decorate3([
|
|
7715
|
+
gen(AttributeArg),
|
|
7716
|
+
_ts_metadata3("design:type", Function),
|
|
7717
|
+
_ts_metadata3("design:paramtypes", [
|
|
7718
|
+
typeof AttributeArg === "undefined" ? Object : AttributeArg
|
|
7719
|
+
]),
|
|
7720
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7721
|
+
], ZModelCodeGenerator.prototype, "_generateAttributeArg", null);
|
|
7722
|
+
_ts_decorate3([
|
|
7723
|
+
gen(ObjectExpr),
|
|
7724
|
+
_ts_metadata3("design:type", Function),
|
|
7725
|
+
_ts_metadata3("design:paramtypes", [
|
|
7726
|
+
typeof ObjectExpr === "undefined" ? Object : ObjectExpr
|
|
7727
|
+
]),
|
|
7728
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7729
|
+
], ZModelCodeGenerator.prototype, "_generateObjectExpr", null);
|
|
7730
|
+
_ts_decorate3([
|
|
7731
|
+
gen(ArrayExpr),
|
|
7732
|
+
_ts_metadata3("design:type", Function),
|
|
7733
|
+
_ts_metadata3("design:paramtypes", [
|
|
7734
|
+
typeof ArrayExpr === "undefined" ? Object : ArrayExpr
|
|
7735
|
+
]),
|
|
7736
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7737
|
+
], ZModelCodeGenerator.prototype, "_generateArrayExpr", null);
|
|
7738
|
+
_ts_decorate3([
|
|
7739
|
+
gen(StringLiteral),
|
|
7740
|
+
_ts_metadata3("design:type", Function),
|
|
7741
|
+
_ts_metadata3("design:paramtypes", [
|
|
7742
|
+
typeof LiteralExpr === "undefined" ? Object : LiteralExpr
|
|
7743
|
+
]),
|
|
7744
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7745
|
+
], ZModelCodeGenerator.prototype, "_generateLiteralExpr", null);
|
|
7746
|
+
_ts_decorate3([
|
|
7747
|
+
gen(NumberLiteral),
|
|
7748
|
+
_ts_metadata3("design:type", Function),
|
|
7749
|
+
_ts_metadata3("design:paramtypes", [
|
|
7750
|
+
typeof NumberLiteral === "undefined" ? Object : NumberLiteral
|
|
7751
|
+
]),
|
|
7752
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7753
|
+
], ZModelCodeGenerator.prototype, "_generateNumberLiteral", null);
|
|
7754
|
+
_ts_decorate3([
|
|
7755
|
+
gen(BooleanLiteral),
|
|
7756
|
+
_ts_metadata3("design:type", Function),
|
|
7757
|
+
_ts_metadata3("design:paramtypes", [
|
|
7758
|
+
typeof BooleanLiteral === "undefined" ? Object : BooleanLiteral
|
|
7759
|
+
]),
|
|
7760
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7761
|
+
], ZModelCodeGenerator.prototype, "_generateBooleanLiteral", null);
|
|
7762
|
+
_ts_decorate3([
|
|
7763
|
+
gen(UnaryExpr),
|
|
7764
|
+
_ts_metadata3("design:type", Function),
|
|
7765
|
+
_ts_metadata3("design:paramtypes", [
|
|
7766
|
+
typeof UnaryExpr === "undefined" ? Object : UnaryExpr
|
|
7767
|
+
]),
|
|
7768
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7769
|
+
], ZModelCodeGenerator.prototype, "_generateUnaryExpr", null);
|
|
7770
|
+
_ts_decorate3([
|
|
7771
|
+
gen(BinaryExpr),
|
|
7772
|
+
_ts_metadata3("design:type", Function),
|
|
7773
|
+
_ts_metadata3("design:paramtypes", [
|
|
7774
|
+
typeof BinaryExpr === "undefined" ? Object : BinaryExpr
|
|
7775
|
+
]),
|
|
7776
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7777
|
+
], ZModelCodeGenerator.prototype, "_generateBinaryExpr", null);
|
|
7778
|
+
_ts_decorate3([
|
|
7779
|
+
gen(ReferenceExpr),
|
|
7780
|
+
_ts_metadata3("design:type", Function),
|
|
7781
|
+
_ts_metadata3("design:paramtypes", [
|
|
7782
|
+
typeof ReferenceExpr === "undefined" ? Object : ReferenceExpr
|
|
7783
|
+
]),
|
|
7784
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7785
|
+
], ZModelCodeGenerator.prototype, "_generateReferenceExpr", null);
|
|
7786
|
+
_ts_decorate3([
|
|
7787
|
+
gen(ReferenceArg),
|
|
7788
|
+
_ts_metadata3("design:type", Function),
|
|
7789
|
+
_ts_metadata3("design:paramtypes", [
|
|
7790
|
+
typeof ReferenceArg === "undefined" ? Object : ReferenceArg
|
|
7791
|
+
]),
|
|
7792
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7793
|
+
], ZModelCodeGenerator.prototype, "_generateReferenceArg", null);
|
|
7794
|
+
_ts_decorate3([
|
|
7795
|
+
gen(MemberAccessExpr),
|
|
7796
|
+
_ts_metadata3("design:type", Function),
|
|
7797
|
+
_ts_metadata3("design:paramtypes", [
|
|
7798
|
+
typeof MemberAccessExpr === "undefined" ? Object : MemberAccessExpr
|
|
7799
|
+
]),
|
|
7800
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7801
|
+
], ZModelCodeGenerator.prototype, "_generateMemberExpr", null);
|
|
7802
|
+
_ts_decorate3([
|
|
7803
|
+
gen(InvocationExpr),
|
|
7804
|
+
_ts_metadata3("design:type", Function),
|
|
7805
|
+
_ts_metadata3("design:paramtypes", [
|
|
7806
|
+
typeof InvocationExpr === "undefined" ? Object : InvocationExpr
|
|
7807
|
+
]),
|
|
7808
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7809
|
+
], ZModelCodeGenerator.prototype, "_generateInvocationExpr", null);
|
|
7810
|
+
_ts_decorate3([
|
|
7811
|
+
gen(NullExpr),
|
|
7812
|
+
_ts_metadata3("design:type", Function),
|
|
7813
|
+
_ts_metadata3("design:paramtypes", []),
|
|
7814
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7815
|
+
], ZModelCodeGenerator.prototype, "_generateNullExpr", null);
|
|
7816
|
+
_ts_decorate3([
|
|
7817
|
+
gen(ThisExpr),
|
|
7818
|
+
_ts_metadata3("design:type", Function),
|
|
7819
|
+
_ts_metadata3("design:paramtypes", []),
|
|
7820
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7821
|
+
], ZModelCodeGenerator.prototype, "_generateThisExpr", null);
|
|
7822
|
+
_ts_decorate3([
|
|
7823
|
+
gen(Attribute),
|
|
7824
|
+
_ts_metadata3("design:type", Function),
|
|
7825
|
+
_ts_metadata3("design:paramtypes", [
|
|
7826
|
+
typeof Attribute === "undefined" ? Object : Attribute
|
|
7827
|
+
]),
|
|
7828
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7829
|
+
], ZModelCodeGenerator.prototype, "_generateAttribute", null);
|
|
7830
|
+
_ts_decorate3([
|
|
7831
|
+
gen(AttributeParam),
|
|
7832
|
+
_ts_metadata3("design:type", Function),
|
|
7833
|
+
_ts_metadata3("design:paramtypes", [
|
|
7834
|
+
typeof AttributeParam === "undefined" ? Object : AttributeParam
|
|
7835
|
+
]),
|
|
7836
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7837
|
+
], ZModelCodeGenerator.prototype, "_generateAttributeParam", null);
|
|
7838
|
+
_ts_decorate3([
|
|
7839
|
+
gen(AttributeParamType),
|
|
7840
|
+
_ts_metadata3("design:type", Function),
|
|
7841
|
+
_ts_metadata3("design:paramtypes", [
|
|
7842
|
+
typeof AttributeParamType === "undefined" ? Object : AttributeParamType
|
|
7843
|
+
]),
|
|
7844
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7845
|
+
], ZModelCodeGenerator.prototype, "_generateAttributeParamType", null);
|
|
7846
|
+
_ts_decorate3([
|
|
7847
|
+
gen(FunctionDecl),
|
|
7848
|
+
_ts_metadata3("design:type", Function),
|
|
7849
|
+
_ts_metadata3("design:paramtypes", [
|
|
7850
|
+
typeof FunctionDecl === "undefined" ? Object : FunctionDecl
|
|
7851
|
+
]),
|
|
7852
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7853
|
+
], ZModelCodeGenerator.prototype, "_generateFunctionDecl", null);
|
|
7854
|
+
_ts_decorate3([
|
|
7855
|
+
gen(FunctionParam),
|
|
7856
|
+
_ts_metadata3("design:type", Function),
|
|
7857
|
+
_ts_metadata3("design:paramtypes", [
|
|
7858
|
+
typeof FunctionParam === "undefined" ? Object : FunctionParam
|
|
7859
|
+
]),
|
|
7860
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7861
|
+
], ZModelCodeGenerator.prototype, "_generateFunctionParam", null);
|
|
7862
|
+
_ts_decorate3([
|
|
7863
|
+
gen(FunctionParamType),
|
|
7864
|
+
_ts_metadata3("design:type", Function),
|
|
7865
|
+
_ts_metadata3("design:paramtypes", [
|
|
7866
|
+
typeof FunctionParamType === "undefined" ? Object : FunctionParamType
|
|
7867
|
+
]),
|
|
7868
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7869
|
+
], ZModelCodeGenerator.prototype, "_generateFunctionParamType", null);
|
|
7870
|
+
_ts_decorate3([
|
|
7871
|
+
gen(TypeDef),
|
|
7872
|
+
_ts_metadata3("design:type", Function),
|
|
7873
|
+
_ts_metadata3("design:paramtypes", [
|
|
7874
|
+
typeof TypeDef === "undefined" ? Object : TypeDef
|
|
7875
|
+
]),
|
|
7876
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7877
|
+
], ZModelCodeGenerator.prototype, "_generateTypeDef", null);
|
|
7878
|
+
|
|
7879
|
+
// src/zmodel-completion-provider.ts
|
|
7880
|
+
var ZModelCompletionProvider = class extends import_lsp.DefaultCompletionProvider {
|
|
7881
|
+
static {
|
|
7882
|
+
__name(this, "ZModelCompletionProvider");
|
|
7883
|
+
}
|
|
7884
|
+
services;
|
|
7885
|
+
constructor(services) {
|
|
7886
|
+
super(services), this.services = services;
|
|
7887
|
+
}
|
|
7888
|
+
completionOptions = {
|
|
7889
|
+
triggerCharacters: [
|
|
7890
|
+
"@",
|
|
7891
|
+
"(",
|
|
7892
|
+
",",
|
|
7893
|
+
"."
|
|
7894
|
+
]
|
|
7895
|
+
};
|
|
7896
|
+
async getCompletion(document, params) {
|
|
7897
|
+
try {
|
|
7898
|
+
return await super.getCompletion(document, params);
|
|
7899
|
+
} catch (e) {
|
|
7900
|
+
console.error("Completion error:", e.message);
|
|
7901
|
+
return void 0;
|
|
7902
|
+
}
|
|
7903
|
+
}
|
|
7904
|
+
completionFor(context, next, acceptor) {
|
|
7905
|
+
if (isDataModelAttribute(context.node) || isDataFieldAttribute(context.node)) {
|
|
7906
|
+
const completions = this.getCompletionFromHint(context.node);
|
|
7907
|
+
if (completions) {
|
|
7908
|
+
completions.forEach((c) => acceptor(context, c));
|
|
7909
|
+
return;
|
|
7910
|
+
}
|
|
7911
|
+
}
|
|
7912
|
+
return super.completionFor(context, next, acceptor);
|
|
7913
|
+
}
|
|
7914
|
+
getCompletionFromHint(contextNode) {
|
|
7915
|
+
const unfilledParams = this.getUnfilledAttributeParams(contextNode);
|
|
7916
|
+
const nextParam = unfilledParams[0];
|
|
7917
|
+
if (!nextParam) {
|
|
7918
|
+
return void 0;
|
|
7919
|
+
}
|
|
7920
|
+
const hintAttr = getAttribute(nextParam, "@@@completionHint");
|
|
7921
|
+
if (hintAttr) {
|
|
7922
|
+
const hint = hintAttr.args[0];
|
|
7923
|
+
if (hint?.value) {
|
|
7924
|
+
if (isArrayExpr(hint.value)) {
|
|
7925
|
+
return hint.value.items.map((item) => {
|
|
7926
|
+
return {
|
|
7927
|
+
label: `${item.value}`,
|
|
7928
|
+
kind: import_vscode_languageserver.CompletionItemKind.Value,
|
|
7929
|
+
detail: "Parameter",
|
|
7930
|
+
sortText: "0"
|
|
7931
|
+
};
|
|
7932
|
+
});
|
|
7933
|
+
}
|
|
7934
|
+
}
|
|
7935
|
+
}
|
|
7936
|
+
return void 0;
|
|
7937
|
+
}
|
|
7938
|
+
// TODO: this doesn't work when the file contains parse errors
|
|
7939
|
+
getUnfilledAttributeParams(contextNode) {
|
|
7940
|
+
try {
|
|
7941
|
+
const params = contextNode.decl.ref?.params;
|
|
7942
|
+
if (params) {
|
|
7943
|
+
const args = contextNode.args;
|
|
7944
|
+
let unfilledParams = [
|
|
7945
|
+
...params
|
|
7946
|
+
];
|
|
7947
|
+
args.forEach((arg) => {
|
|
7948
|
+
if (arg.name) {
|
|
7949
|
+
unfilledParams = unfilledParams.filter((p) => p.name !== arg.name);
|
|
7950
|
+
} else {
|
|
7951
|
+
unfilledParams.shift();
|
|
7952
|
+
}
|
|
7953
|
+
});
|
|
7954
|
+
return unfilledParams;
|
|
7955
|
+
}
|
|
7956
|
+
} catch {
|
|
7957
|
+
}
|
|
7958
|
+
return [];
|
|
7959
|
+
}
|
|
7960
|
+
completionForCrossReference(context, crossRef, acceptor) {
|
|
7961
|
+
if (crossRef.property === "member" && !isMemberAccessExpr(context.node)) {
|
|
7962
|
+
return;
|
|
7963
|
+
}
|
|
7964
|
+
const customAcceptor = /* @__PURE__ */ __name((context2, item) => {
|
|
7965
|
+
if (item.insertText?.startsWith("@@@") || item.label?.startsWith("@@@")) {
|
|
7966
|
+
return;
|
|
7967
|
+
}
|
|
7968
|
+
if ("nodeDescription" in item) {
|
|
7969
|
+
const node = this.getAstNode(item.nodeDescription);
|
|
7970
|
+
if (!node) {
|
|
7971
|
+
return;
|
|
7972
|
+
}
|
|
7973
|
+
if ((isEnum(node) || isEnumField(node)) && isFromStdlib(node)) {
|
|
7974
|
+
return;
|
|
7975
|
+
}
|
|
7976
|
+
if ((isDataModelAttribute(context2.node) || isDataFieldAttribute(context2.node)) && !this.filterAttributeApplicationCompletion(context2.node, node)) {
|
|
7977
|
+
return;
|
|
7978
|
+
}
|
|
7979
|
+
}
|
|
7980
|
+
acceptor(context2, item);
|
|
7981
|
+
}, "customAcceptor");
|
|
7982
|
+
return super.completionForCrossReference(context, crossRef, customAcceptor);
|
|
7983
|
+
}
|
|
7984
|
+
completionForKeyword(context, keyword, acceptor) {
|
|
7985
|
+
const customAcceptor = /* @__PURE__ */ __name((context2, item) => {
|
|
7986
|
+
if (!this.filterKeywordForContext(context2, keyword.value)) {
|
|
7987
|
+
return;
|
|
7988
|
+
}
|
|
7989
|
+
acceptor(context2, item);
|
|
7990
|
+
}, "customAcceptor");
|
|
7991
|
+
return super.completionForKeyword(context, keyword, customAcceptor);
|
|
7992
|
+
}
|
|
7993
|
+
filterKeywordForContext(context, keyword) {
|
|
7994
|
+
if (isInvocationExpr(context.node)) {
|
|
7995
|
+
return [
|
|
7996
|
+
"true",
|
|
7997
|
+
"false",
|
|
7998
|
+
"null",
|
|
7999
|
+
"this"
|
|
8000
|
+
].includes(keyword);
|
|
8001
|
+
} else if (isDataModelAttribute(context.node) || isDataFieldAttribute(context.node)) {
|
|
8002
|
+
const exprContext = this.getAttributeContextType(context.node);
|
|
8003
|
+
if (exprContext === "DefaultValue") {
|
|
8004
|
+
return [
|
|
8005
|
+
"true",
|
|
8006
|
+
"false",
|
|
8007
|
+
"null"
|
|
8008
|
+
].includes(keyword);
|
|
8009
|
+
} else {
|
|
8010
|
+
return [
|
|
8011
|
+
"true",
|
|
8012
|
+
"false",
|
|
8013
|
+
"null",
|
|
8014
|
+
"this"
|
|
8015
|
+
].includes(keyword);
|
|
8016
|
+
}
|
|
8017
|
+
} else {
|
|
8018
|
+
return true;
|
|
8019
|
+
}
|
|
8020
|
+
}
|
|
8021
|
+
filterAttributeApplicationCompletion(contextNode, node) {
|
|
8022
|
+
const attrContextType = this.getAttributeContextType(contextNode);
|
|
8023
|
+
if (isFunctionDecl(node) && attrContextType) {
|
|
8024
|
+
const funcExprContextAttr = getAttribute(node, "@@@expressionContext");
|
|
8025
|
+
if (funcExprContextAttr && funcExprContextAttr.args[0]) {
|
|
8026
|
+
const arg = funcExprContextAttr.args[0];
|
|
8027
|
+
if (isArrayExpr(arg.value)) {
|
|
8028
|
+
return arg.value.items.some((item) => isEnumFieldReference(item) && item.target.$refText === attrContextType);
|
|
8029
|
+
}
|
|
8030
|
+
}
|
|
8031
|
+
return false;
|
|
8032
|
+
}
|
|
8033
|
+
if (isDataField(node)) {
|
|
8034
|
+
return attrContextType !== "DefaultValue";
|
|
8035
|
+
}
|
|
8036
|
+
return true;
|
|
8037
|
+
}
|
|
8038
|
+
getAttributeContextType(node) {
|
|
8039
|
+
return (0, import_ts_pattern3.match)(node.decl.$refText).with("@default", () => "DefaultValue").with(import_ts_pattern3.P.union("@@allow", "@allow", "@@deny", "@deny"), () => "AccessPolicy").with("@@validate", () => "ValidationRule").otherwise(() => void 0);
|
|
8040
|
+
}
|
|
8041
|
+
createReferenceCompletionItem(nodeDescription) {
|
|
8042
|
+
const node = this.getAstNode(nodeDescription);
|
|
8043
|
+
const documentation = this.getNodeDocumentation(node);
|
|
8044
|
+
return (0, import_ts_pattern3.match)(node).when(isDataModel, () => ({
|
|
8045
|
+
nodeDescription,
|
|
8046
|
+
kind: import_vscode_languageserver.CompletionItemKind.Class,
|
|
8047
|
+
detail: "Model",
|
|
8048
|
+
sortText: "1",
|
|
8049
|
+
documentation
|
|
8050
|
+
})).when(isTypeDef, () => ({
|
|
8051
|
+
nodeDescription,
|
|
8052
|
+
kind: import_vscode_languageserver.CompletionItemKind.Class,
|
|
8053
|
+
detail: "Type",
|
|
8054
|
+
sortText: "1",
|
|
8055
|
+
documentation
|
|
8056
|
+
})).when(isDataField, () => ({
|
|
8057
|
+
nodeDescription,
|
|
8058
|
+
kind: import_vscode_languageserver.CompletionItemKind.Field,
|
|
8059
|
+
detail: "Field",
|
|
8060
|
+
sortText: "0",
|
|
8061
|
+
documentation
|
|
8062
|
+
})).when(isEnum, () => ({
|
|
8063
|
+
nodeDescription,
|
|
8064
|
+
kind: import_vscode_languageserver.CompletionItemKind.Class,
|
|
8065
|
+
detail: "Enum",
|
|
8066
|
+
sortText: "1",
|
|
8067
|
+
documentation
|
|
8068
|
+
})).when(isEnumField, (d) => {
|
|
8069
|
+
const container = d.$container;
|
|
8070
|
+
return {
|
|
8071
|
+
nodeDescription,
|
|
8072
|
+
kind: import_vscode_languageserver.CompletionItemKind.Enum,
|
|
8073
|
+
detail: `Value of enum "${container.name}"`,
|
|
8074
|
+
sortText: "1",
|
|
8075
|
+
documentation
|
|
8076
|
+
};
|
|
8077
|
+
}).when(isFunctionDecl, () => ({
|
|
8078
|
+
nodeDescription,
|
|
8079
|
+
insertText: this.getFunctionInsertText(nodeDescription),
|
|
8080
|
+
kind: import_vscode_languageserver.CompletionItemKind.Function,
|
|
8081
|
+
detail: "Function",
|
|
8082
|
+
sortText: "1",
|
|
8083
|
+
documentation
|
|
8084
|
+
})).when(isAttribute, () => ({
|
|
8085
|
+
nodeDescription,
|
|
8086
|
+
insertText: this.getAttributeInsertText(nodeDescription),
|
|
8087
|
+
kind: import_vscode_languageserver.CompletionItemKind.Property,
|
|
8088
|
+
detail: "Attribute",
|
|
8089
|
+
sortText: "1",
|
|
8090
|
+
documentation
|
|
8091
|
+
})).otherwise(() => ({
|
|
8092
|
+
nodeDescription,
|
|
8093
|
+
kind: import_vscode_languageserver.CompletionItemKind.Reference,
|
|
8094
|
+
detail: nodeDescription.type,
|
|
8095
|
+
sortText: "2",
|
|
8096
|
+
documentation
|
|
8097
|
+
}));
|
|
8098
|
+
}
|
|
8099
|
+
getFunctionInsertText(nodeDescription) {
|
|
8100
|
+
const node = this.getAstNode(nodeDescription);
|
|
8101
|
+
if (isFunctionDecl(node)) {
|
|
8102
|
+
if (node.params.some((p) => !p.optional)) {
|
|
8103
|
+
return nodeDescription.name;
|
|
8104
|
+
}
|
|
8105
|
+
}
|
|
8106
|
+
return `${nodeDescription.name}()`;
|
|
8107
|
+
}
|
|
8108
|
+
getAttributeInsertText(nodeDescription) {
|
|
8109
|
+
const node = this.getAstNode(nodeDescription);
|
|
8110
|
+
if (isAttribute(node)) {
|
|
8111
|
+
if (node.name === "@relation") {
|
|
8112
|
+
return `${nodeDescription.name}(fields: [], references: [])`;
|
|
8113
|
+
}
|
|
8114
|
+
}
|
|
8115
|
+
return nodeDescription.name;
|
|
8116
|
+
}
|
|
8117
|
+
getAstNode(nodeDescription) {
|
|
8118
|
+
let node = nodeDescription.node;
|
|
8119
|
+
if (!node) {
|
|
8120
|
+
const doc = this.getOrCreateDocumentSync(nodeDescription);
|
|
8121
|
+
if (!doc) {
|
|
8122
|
+
return void 0;
|
|
8123
|
+
}
|
|
8124
|
+
node = this.services.workspace.AstNodeLocator.getAstNode(doc.parseResult.value, nodeDescription.path);
|
|
8125
|
+
if (!node) {
|
|
8126
|
+
return void 0;
|
|
8127
|
+
}
|
|
8128
|
+
}
|
|
8129
|
+
return node;
|
|
8130
|
+
}
|
|
8131
|
+
getOrCreateDocumentSync(nodeDescription) {
|
|
8132
|
+
let doc = this.services.shared.workspace.LangiumDocuments.getDocument(nodeDescription.documentUri);
|
|
8133
|
+
if (!doc) {
|
|
8134
|
+
try {
|
|
8135
|
+
const content = import_node_fs2.default.readFileSync(nodeDescription.documentUri.fsPath, "utf-8");
|
|
8136
|
+
doc = this.services.shared.workspace.LangiumDocuments.createDocument(nodeDescription.documentUri, content);
|
|
8137
|
+
} catch {
|
|
8138
|
+
console.warn("Failed to read or create document:", nodeDescription.documentUri);
|
|
8139
|
+
return void 0;
|
|
8140
|
+
}
|
|
8141
|
+
}
|
|
8142
|
+
return doc;
|
|
8143
|
+
}
|
|
8144
|
+
getNodeDocumentation(node) {
|
|
8145
|
+
if (!node) {
|
|
8146
|
+
return void 0;
|
|
8147
|
+
}
|
|
8148
|
+
const md = this.commentsToMarkdown(node);
|
|
8149
|
+
return {
|
|
8150
|
+
kind: "markdown",
|
|
8151
|
+
value: md
|
|
8152
|
+
};
|
|
8153
|
+
}
|
|
8154
|
+
commentsToMarkdown(node) {
|
|
8155
|
+
const md = this.services.documentation.DocumentationProvider.getDocumentation(node) ?? "";
|
|
8156
|
+
const zModelGenerator = new ZModelCodeGenerator();
|
|
8157
|
+
const docs = [];
|
|
8158
|
+
try {
|
|
8159
|
+
(0, import_ts_pattern3.match)(node).when(isAttribute, (attr) => {
|
|
8160
|
+
docs.push("```prisma", zModelGenerator.generate(attr), "```");
|
|
8161
|
+
}).when(isFunctionDecl, (func2) => {
|
|
8162
|
+
docs.push("```ts", zModelGenerator.generate(func2), "```");
|
|
8163
|
+
}).when(isDataModel, (model) => {
|
|
8164
|
+
docs.push("```prisma", `model ${model.name} { ... }`, "```");
|
|
8165
|
+
}).when(isEnum, (enumDecl) => {
|
|
8166
|
+
docs.push("```prisma", zModelGenerator.generate(enumDecl), "```");
|
|
8167
|
+
}).when(isDataField, (field) => {
|
|
8168
|
+
docs.push(`${field.name}: ${field.type.type ?? field.type.reference?.$refText}`);
|
|
8169
|
+
}).otherwise((ast) => {
|
|
8170
|
+
const name = ast.name;
|
|
8171
|
+
if (name) {
|
|
8172
|
+
docs.push(name);
|
|
8173
|
+
}
|
|
8174
|
+
});
|
|
8175
|
+
} catch {
|
|
8176
|
+
}
|
|
8177
|
+
if (md) {
|
|
8178
|
+
docs.push("___", md);
|
|
8179
|
+
}
|
|
8180
|
+
return docs.join("\n");
|
|
8181
|
+
}
|
|
8182
|
+
};
|
|
8183
|
+
|
|
8184
|
+
// src/zmodel-definition.ts
|
|
8185
|
+
var import_lsp2 = require("langium/lsp");
|
|
8186
|
+
var import_vscode_languageserver2 = require("vscode-languageserver");
|
|
8187
|
+
var ZModelDefinitionProvider = class extends import_lsp2.DefaultDefinitionProvider {
|
|
8188
|
+
static {
|
|
8189
|
+
__name(this, "ZModelDefinitionProvider");
|
|
8190
|
+
}
|
|
8191
|
+
documents;
|
|
8192
|
+
constructor(services) {
|
|
8193
|
+
super(services);
|
|
8194
|
+
this.documents = services.shared.workspace.LangiumDocuments;
|
|
8195
|
+
}
|
|
8196
|
+
collectLocationLinks(sourceCstNode, _params) {
|
|
8197
|
+
if (isModelImport(sourceCstNode.astNode)) {
|
|
8198
|
+
const importedModel = resolveImport(this.documents, sourceCstNode.astNode);
|
|
8199
|
+
if (importedModel?.$document) {
|
|
8200
|
+
const targetObject = importedModel;
|
|
8201
|
+
const selectionRange = this.nameProvider.getNameNode(targetObject)?.range ?? import_vscode_languageserver2.Range.create(0, 0, 0, 0);
|
|
8202
|
+
const previewRange = targetObject.$cstNode?.range ?? import_vscode_languageserver2.Range.create(0, 0, 0, 0);
|
|
8203
|
+
return [
|
|
8204
|
+
import_vscode_languageserver2.LocationLink.create(importedModel.$document.uri.toString(), previewRange, selectionRange, sourceCstNode.range)
|
|
8205
|
+
];
|
|
8206
|
+
}
|
|
8207
|
+
return void 0;
|
|
8208
|
+
}
|
|
8209
|
+
return super.collectLocationLinks(sourceCstNode, _params);
|
|
8210
|
+
}
|
|
8211
|
+
};
|
|
8212
|
+
|
|
8213
|
+
// src/zmodel-document-builder.ts
|
|
8214
|
+
var import_langium8 = require("langium");
|
|
8215
|
+
var ZModelDocumentBuilder = class extends import_langium8.DefaultDocumentBuilder {
|
|
8216
|
+
static {
|
|
8217
|
+
__name(this, "ZModelDocumentBuilder");
|
|
8218
|
+
}
|
|
8219
|
+
constructor(services) {
|
|
8220
|
+
super(services);
|
|
8221
|
+
let validationOptions = this.updateBuildOptions.validation;
|
|
8222
|
+
const stopFlags = {
|
|
8223
|
+
stopAfterLinkingErrors: true,
|
|
8224
|
+
stopAfterLexingErrors: true,
|
|
8225
|
+
stopAfterParsingErrors: true
|
|
8226
|
+
};
|
|
8227
|
+
if (validationOptions === true) {
|
|
8228
|
+
validationOptions = stopFlags;
|
|
8229
|
+
} else if (typeof validationOptions === "object") {
|
|
8230
|
+
validationOptions = {
|
|
8231
|
+
...validationOptions,
|
|
8232
|
+
...stopFlags
|
|
8233
|
+
};
|
|
8234
|
+
}
|
|
8235
|
+
this.updateBuildOptions = {
|
|
8236
|
+
...this.updateBuildOptions,
|
|
8237
|
+
validation: validationOptions
|
|
8238
|
+
};
|
|
8239
|
+
}
|
|
8240
|
+
};
|
|
8241
|
+
|
|
8242
|
+
// src/zmodel-documentation-provider.ts
|
|
8243
|
+
var import_langium9 = require("langium");
|
|
8244
|
+
var ZModelDocumentationProvider = class extends import_langium9.JSDocDocumentationProvider {
|
|
8245
|
+
static {
|
|
8246
|
+
__name(this, "ZModelDocumentationProvider");
|
|
8247
|
+
}
|
|
8248
|
+
getDocumentation(node) {
|
|
8249
|
+
if ("comments" in node && Array.isArray(node.comments) && node.comments.length > 0) {
|
|
8250
|
+
return node.comments.map((c) => c.replace(/^[/]*\s*/, "")).join("\n");
|
|
8251
|
+
}
|
|
8252
|
+
return super.getDocumentation(node);
|
|
8253
|
+
}
|
|
8254
|
+
};
|
|
8255
|
+
|
|
8256
|
+
// src/zmodel-formatter.ts
|
|
8257
|
+
var import_lsp3 = require("langium/lsp");
|
|
8258
|
+
var ZModelFormatter = class extends import_lsp3.AbstractFormatter {
|
|
8259
|
+
static {
|
|
8260
|
+
__name(this, "ZModelFormatter");
|
|
8261
|
+
}
|
|
8262
|
+
formatOptions;
|
|
8263
|
+
configurationProvider;
|
|
8264
|
+
constructor(services) {
|
|
8265
|
+
super();
|
|
8266
|
+
this.configurationProvider = services.shared.workspace.ConfigurationProvider;
|
|
8267
|
+
}
|
|
8268
|
+
format(node) {
|
|
8269
|
+
const formatter = this.getNodeFormatter(node);
|
|
8270
|
+
if (isDataField(node)) {
|
|
8271
|
+
if (isDataModel(node.$container) || isTypeDef(node.$container)) {
|
|
8272
|
+
const dataModel = node.$container;
|
|
8273
|
+
const compareFn = /* @__PURE__ */ __name((a, b) => b - a, "compareFn");
|
|
8274
|
+
const maxNameLength = dataModel.fields.map((x) => x.name.length).sort(compareFn)[0] ?? 0;
|
|
8275
|
+
const maxTypeLength = dataModel.fields.map(this.getFieldTypeLength).sort(compareFn)[0] ?? 0;
|
|
8276
|
+
formatter.property("type").prepend(import_lsp3.Formatting.spaces(maxNameLength - node.name.length + 1));
|
|
8277
|
+
if (node.attributes.length > 0) {
|
|
8278
|
+
formatter.node(node.attributes[0]).prepend(import_lsp3.Formatting.spaces(maxTypeLength - this.getFieldTypeLength(node) + 1));
|
|
8279
|
+
formatter.nodes(...node.attributes.slice(1)).prepend(import_lsp3.Formatting.oneSpace());
|
|
8280
|
+
}
|
|
8281
|
+
} else {
|
|
8282
|
+
formatter.property("type").prepend(import_lsp3.Formatting.oneSpace());
|
|
8283
|
+
if (node.attributes.length > 0) {
|
|
8284
|
+
formatter.properties("attributes").prepend(import_lsp3.Formatting.oneSpace());
|
|
8285
|
+
}
|
|
8286
|
+
}
|
|
8287
|
+
} else if (isDataFieldAttribute(node)) {
|
|
8288
|
+
formatter.keyword("(").surround(import_lsp3.Formatting.noSpace());
|
|
8289
|
+
formatter.keyword(")").prepend(import_lsp3.Formatting.noSpace());
|
|
8290
|
+
formatter.keyword(",").append(import_lsp3.Formatting.oneSpace());
|
|
8291
|
+
if (node.args.length > 1) {
|
|
8292
|
+
formatter.nodes(...node.args.slice(1)).prepend(import_lsp3.Formatting.oneSpace());
|
|
8293
|
+
}
|
|
8294
|
+
} else if (isAttributeArg(node)) {
|
|
8295
|
+
formatter.keyword(":").prepend(import_lsp3.Formatting.noSpace());
|
|
8296
|
+
formatter.keyword(":").append(import_lsp3.Formatting.oneSpace());
|
|
8297
|
+
} else if (isAbstractDeclaration(node)) {
|
|
8298
|
+
const bracesOpen = formatter.keyword("{");
|
|
8299
|
+
const bracesClose = formatter.keyword("}");
|
|
8300
|
+
formatter.interior(bracesOpen, bracesClose).prepend(import_lsp3.Formatting.indent({
|
|
8301
|
+
allowMore: true
|
|
8302
|
+
}));
|
|
8303
|
+
bracesOpen.prepend(import_lsp3.Formatting.oneSpace());
|
|
8304
|
+
bracesClose.prepend(import_lsp3.Formatting.newLine());
|
|
8305
|
+
} else if (isModel(node)) {
|
|
8306
|
+
const model = node;
|
|
8307
|
+
const nodes = formatter.nodes(...model.declarations);
|
|
8308
|
+
nodes.prepend(import_lsp3.Formatting.noIndent());
|
|
8309
|
+
}
|
|
8310
|
+
}
|
|
8311
|
+
formatDocument(document, params) {
|
|
8312
|
+
this.formatOptions = params.options;
|
|
8313
|
+
this.configurationProvider.getConfiguration(ZModelLanguageMetaData.languageId, "format").then((config) => {
|
|
8314
|
+
if (config) {
|
|
8315
|
+
}
|
|
8316
|
+
});
|
|
8317
|
+
return super.formatDocument(document, params);
|
|
8318
|
+
}
|
|
8319
|
+
getFormatOptions() {
|
|
8320
|
+
return this.formatOptions;
|
|
8321
|
+
}
|
|
8322
|
+
getIndent() {
|
|
8323
|
+
return 1;
|
|
8324
|
+
}
|
|
8325
|
+
getFieldTypeLength(field) {
|
|
8326
|
+
let length;
|
|
8327
|
+
if (field.type.type) {
|
|
8328
|
+
length = field.type.type.length;
|
|
8329
|
+
} else if (field.type.reference) {
|
|
8330
|
+
length = field.type.reference.$refText.length;
|
|
8331
|
+
} else if (isDataField(field) && field.type.unsupported) {
|
|
8332
|
+
const name = `Unsupported("${field.type.unsupported.value.value}")`;
|
|
8333
|
+
length = name.length;
|
|
8334
|
+
} else {
|
|
8335
|
+
length = 1;
|
|
8336
|
+
}
|
|
8337
|
+
if (field.type.optional) {
|
|
8338
|
+
length += 1;
|
|
8339
|
+
}
|
|
8340
|
+
if (field.type.array) {
|
|
8341
|
+
length += 2;
|
|
8342
|
+
}
|
|
8343
|
+
return length;
|
|
8344
|
+
}
|
|
8345
|
+
};
|
|
8346
|
+
|
|
8347
|
+
// src/zmodel-linker.ts
|
|
8348
|
+
var import_langium10 = require("langium");
|
|
8349
|
+
var import_ts_pattern4 = require("ts-pattern");
|
|
8350
|
+
var ZModelLinker = class extends import_langium10.DefaultLinker {
|
|
7021
8351
|
static {
|
|
7022
8352
|
__name(this, "ZModelLinker");
|
|
7023
8353
|
}
|
|
@@ -7027,31 +8357,29 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
|
|
|
7027
8357
|
this.descriptions = services.workspace.AstNodeDescriptionProvider;
|
|
7028
8358
|
}
|
|
7029
8359
|
//#region Reference linking
|
|
7030
|
-
async link(document, cancelToken =
|
|
8360
|
+
async link(document, cancelToken = import_langium10.Cancellation.CancellationToken.None) {
|
|
7031
8361
|
if (document.parseResult.lexerErrors?.length > 0 || document.parseResult.parserErrors?.length > 0) {
|
|
7032
8362
|
return;
|
|
7033
8363
|
}
|
|
7034
|
-
for (const node of
|
|
7035
|
-
await (0,
|
|
8364
|
+
for (const node of import_langium10.AstUtils.streamContents(document.parseResult.value)) {
|
|
8365
|
+
await (0, import_langium10.interruptAndCheck)(cancelToken);
|
|
7036
8366
|
this.resolve(node, document);
|
|
7037
8367
|
}
|
|
7038
|
-
document.state =
|
|
8368
|
+
document.state = import_langium10.DocumentState.Linked;
|
|
7039
8369
|
}
|
|
7040
|
-
linkReference(
|
|
7041
|
-
|
|
8370
|
+
linkReference(refInfo, document, extraScopes) {
|
|
8371
|
+
const defaultRef = refInfo.reference;
|
|
8372
|
+
if (defaultRef._ref) {
|
|
8373
|
+
return;
|
|
8374
|
+
}
|
|
8375
|
+
if (this.resolveFromScopeProviders(refInfo.reference, document, extraScopes)) {
|
|
7042
8376
|
return;
|
|
7043
8377
|
}
|
|
7044
|
-
|
|
7045
|
-
this.doLink({
|
|
7046
|
-
reference,
|
|
7047
|
-
container,
|
|
7048
|
-
property
|
|
7049
|
-
}, document);
|
|
8378
|
+
this.doLink(refInfo, document);
|
|
7050
8379
|
}
|
|
7051
8380
|
//#endregion
|
|
7052
8381
|
//#region Expression type resolving
|
|
7053
|
-
resolveFromScopeProviders(
|
|
7054
|
-
const reference = node[property];
|
|
8382
|
+
resolveFromScopeProviders(reference, document, providers) {
|
|
7055
8383
|
for (const provider of providers) {
|
|
7056
8384
|
const target = provider(reference.$refText);
|
|
7057
8385
|
if (target) {
|
|
@@ -7180,12 +8508,16 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
|
|
|
7180
8508
|
}
|
|
7181
8509
|
}
|
|
7182
8510
|
resolveInvocation(node, document, extraScopes) {
|
|
7183
|
-
this.linkReference(
|
|
8511
|
+
this.linkReference({
|
|
8512
|
+
reference: node.function,
|
|
8513
|
+
container: node,
|
|
8514
|
+
property: "function"
|
|
8515
|
+
}, document, extraScopes);
|
|
7184
8516
|
node.args.forEach((arg) => this.resolve(arg, document, extraScopes));
|
|
7185
8517
|
if (node.function.ref) {
|
|
7186
8518
|
const funcDecl = node.function.ref;
|
|
7187
8519
|
if (isAuthInvocation(node)) {
|
|
7188
|
-
const allDecls = getAllLoadedAndReachableDataModelsAndTypeDefs(this.langiumDocuments(),
|
|
8520
|
+
const allDecls = getAllLoadedAndReachableDataModelsAndTypeDefs(this.langiumDocuments(), import_langium10.AstUtils.getContainerOfType(node, isDataModel));
|
|
7189
8521
|
const authDecl = getAuthDecl(allDecls);
|
|
7190
8522
|
if (authDecl) {
|
|
7191
8523
|
node.$resolvedType = {
|
|
@@ -7193,7 +8525,7 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
|
|
|
7193
8525
|
nullable: true
|
|
7194
8526
|
};
|
|
7195
8527
|
}
|
|
7196
|
-
} else if (
|
|
8528
|
+
} else if (isBeforeInvocation(node)) {
|
|
7197
8529
|
node.$resolvedType = {
|
|
7198
8530
|
decl: getContainingDataModel(node)
|
|
7199
8531
|
};
|
|
@@ -7203,7 +8535,7 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
|
|
|
7203
8535
|
}
|
|
7204
8536
|
}
|
|
7205
8537
|
resolveLiteral(node) {
|
|
7206
|
-
const type = (0,
|
|
8538
|
+
const type = (0, import_ts_pattern4.match)(node).when(isStringLiteral, () => "String").when(isBooleanLiteral, () => "Boolean").when(isNumberLiteral, () => "Int").exhaustive();
|
|
7207
8539
|
if (type) {
|
|
7208
8540
|
this.resolveToBuiltinTypeOrDecl(node, type);
|
|
7209
8541
|
}
|
|
@@ -7257,7 +8589,7 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
|
|
|
7257
8589
|
if (isArrayExpr(node.value)) {
|
|
7258
8590
|
node.value.items.forEach((item) => {
|
|
7259
8591
|
if (isReferenceExpr(item)) {
|
|
7260
|
-
const resolved2 = this.resolveFromScopeProviders(item
|
|
8592
|
+
const resolved2 = this.resolveFromScopeProviders(item.target, document, [
|
|
7261
8593
|
scopeProvider
|
|
7262
8594
|
]);
|
|
7263
8595
|
if (resolved2) {
|
|
@@ -7271,7 +8603,7 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
|
|
|
7271
8603
|
this.resolveToBuiltinTypeOrDecl(node.value, node.value.items[0].$resolvedType.decl, true);
|
|
7272
8604
|
}
|
|
7273
8605
|
} else if (isReferenceExpr(node.value)) {
|
|
7274
|
-
const resolved2 = this.resolveFromScopeProviders(node.value
|
|
8606
|
+
const resolved2 = this.resolveFromScopeProviders(node.value.target, document, [
|
|
7275
8607
|
scopeProvider
|
|
7276
8608
|
]);
|
|
7277
8609
|
if (resolved2) {
|
|
@@ -7323,14 +8655,10 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
|
|
|
7323
8655
|
this.resolveDefault(node, document, scopes);
|
|
7324
8656
|
}
|
|
7325
8657
|
resolveDefault(node, document, extraScopes) {
|
|
7326
|
-
|
|
7327
|
-
|
|
7328
|
-
|
|
7329
|
-
|
|
7330
|
-
}
|
|
7331
|
-
}
|
|
7332
|
-
}
|
|
7333
|
-
for (const child of import_langium7.AstUtils.streamContents(node)) {
|
|
8658
|
+
import_langium10.AstUtils.streamReferences(node).forEach((ref) => {
|
|
8659
|
+
this.linkReference(ref, document, extraScopes);
|
|
8660
|
+
});
|
|
8661
|
+
for (const child of import_langium10.AstUtils.streamContents(node)) {
|
|
7334
8662
|
this.resolve(child, document, extraScopes);
|
|
7335
8663
|
}
|
|
7336
8664
|
}
|
|
@@ -7374,9 +8702,9 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
|
|
|
7374
8702
|
};
|
|
7375
8703
|
|
|
7376
8704
|
// src/zmodel-scope.ts
|
|
7377
|
-
var
|
|
7378
|
-
var
|
|
7379
|
-
var ZModelScopeComputation = class extends
|
|
8705
|
+
var import_langium11 = require("langium");
|
|
8706
|
+
var import_ts_pattern5 = require("ts-pattern");
|
|
8707
|
+
var ZModelScopeComputation = class extends import_langium11.DefaultScopeComputation {
|
|
7380
8708
|
static {
|
|
7381
8709
|
__name(this, "ZModelScopeComputation");
|
|
7382
8710
|
}
|
|
@@ -7386,9 +8714,9 @@ var ZModelScopeComputation = class extends import_langium8.DefaultScopeComputati
|
|
|
7386
8714
|
}
|
|
7387
8715
|
async computeExports(document, cancelToken) {
|
|
7388
8716
|
const result = await super.computeExports(document, cancelToken);
|
|
7389
|
-
for (const node of
|
|
8717
|
+
for (const node of import_langium11.AstUtils.streamAllContents(document.parseResult.value)) {
|
|
7390
8718
|
if (cancelToken) {
|
|
7391
|
-
await (0,
|
|
8719
|
+
await (0, import_langium11.interruptAndCheck)(cancelToken);
|
|
7392
8720
|
}
|
|
7393
8721
|
if (isEnumField(node)) {
|
|
7394
8722
|
const desc = this.services.workspace.AstNodeDescriptionProvider.createDescription(node, node.name, document);
|
|
@@ -7399,7 +8727,7 @@ var ZModelScopeComputation = class extends import_langium8.DefaultScopeComputati
|
|
|
7399
8727
|
}
|
|
7400
8728
|
processNode(node, document, scopes) {
|
|
7401
8729
|
super.processNode(node, document, scopes);
|
|
7402
|
-
if (isDataModel(node)) {
|
|
8730
|
+
if (isDataModel(node) || isTypeDef(node)) {
|
|
7403
8731
|
const bases = getRecursiveBases(node);
|
|
7404
8732
|
for (const base of bases) {
|
|
7405
8733
|
for (const field of base.fields) {
|
|
@@ -7409,7 +8737,7 @@ var ZModelScopeComputation = class extends import_langium8.DefaultScopeComputati
|
|
|
7409
8737
|
}
|
|
7410
8738
|
}
|
|
7411
8739
|
};
|
|
7412
|
-
var ZModelScopeProvider = class extends
|
|
8740
|
+
var ZModelScopeProvider = class extends import_langium11.DefaultScopeProvider {
|
|
7413
8741
|
static {
|
|
7414
8742
|
__name(this, "ZModelScopeProvider");
|
|
7415
8743
|
}
|
|
@@ -7418,19 +8746,19 @@ var ZModelScopeProvider = class extends import_langium8.DefaultScopeProvider {
|
|
|
7418
8746
|
super(services), this.services = services;
|
|
7419
8747
|
}
|
|
7420
8748
|
getGlobalScope(referenceType, context) {
|
|
7421
|
-
const model =
|
|
8749
|
+
const model = import_langium11.AstUtils.getContainerOfType(context.container, isModel);
|
|
7422
8750
|
if (!model) {
|
|
7423
|
-
return
|
|
8751
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7424
8752
|
}
|
|
7425
8753
|
const importedUris = model.imports.map(resolveImportUri).filter((url) => !!url);
|
|
7426
8754
|
const importedElements = this.indexManager.allElements(referenceType).filter((des) => (
|
|
7427
8755
|
// allow current document
|
|
7428
|
-
|
|
8756
|
+
import_langium11.UriUtils.equals(des.documentUri, model.$document?.uri) || // allow stdlib
|
|
7429
8757
|
des.documentUri.path.endsWith(STD_LIB_MODULE_NAME) || // allow plugin models
|
|
7430
8758
|
des.documentUri.path.endsWith(PLUGIN_MODULE_NAME) || // allow imported documents
|
|
7431
|
-
importedUris.some((importedUri) =>
|
|
8759
|
+
importedUris.some((importedUri) => import_langium11.UriUtils.equals(des.documentUri, importedUri))
|
|
7432
8760
|
));
|
|
7433
|
-
return new
|
|
8761
|
+
return new import_langium11.StreamScope(importedElements);
|
|
7434
8762
|
}
|
|
7435
8763
|
getScope(context) {
|
|
7436
8764
|
if (isMemberAccessExpr(context.container) && context.container.operand && context.property === "member") {
|
|
@@ -7448,68 +8776,65 @@ var ZModelScopeProvider = class extends import_langium8.DefaultScopeProvider {
|
|
|
7448
8776
|
const referenceType = this.reflection.getReferenceType(context);
|
|
7449
8777
|
const globalScope = this.getGlobalScope(referenceType, context);
|
|
7450
8778
|
const node = context.container;
|
|
7451
|
-
const allowTypeDefScope = (
|
|
7452
|
-
|
|
7453
|
-
!!import_langium8.AstUtils.getContainerOfType(node, isTypeDef)
|
|
7454
|
-
);
|
|
7455
|
-
return (0, import_ts_pattern3.match)(node.operand).when(isReferenceExpr, (operand) => {
|
|
8779
|
+
const allowTypeDefScope = isAuthOrAuthMemberAccess(node.operand) || !!import_langium11.AstUtils.getContainerOfType(node, isTypeDef);
|
|
8780
|
+
return (0, import_ts_pattern5.match)(node.operand).when(isReferenceExpr, (operand) => {
|
|
7456
8781
|
const ref = operand.target.ref;
|
|
7457
8782
|
if (isDataField(ref)) {
|
|
7458
8783
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7459
8784
|
}
|
|
7460
|
-
return
|
|
8785
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7461
8786
|
}).when(isMemberAccessExpr, (operand) => {
|
|
7462
8787
|
const ref = operand.member.ref;
|
|
7463
8788
|
if (isDataField(ref) && !ref.type.array) {
|
|
7464
8789
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7465
8790
|
}
|
|
7466
|
-
return
|
|
8791
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7467
8792
|
}).when(isThisExpr, () => {
|
|
7468
8793
|
return this.createScopeForContainingModel(node, globalScope);
|
|
7469
8794
|
}).when(isInvocationExpr, (operand) => {
|
|
7470
8795
|
if (isAuthInvocation(operand)) {
|
|
7471
8796
|
return this.createScopeForAuth(node, globalScope);
|
|
7472
8797
|
}
|
|
7473
|
-
if (
|
|
8798
|
+
if (isBeforeInvocation(operand)) {
|
|
7474
8799
|
return this.createScopeForContainingModel(node, globalScope);
|
|
7475
8800
|
}
|
|
7476
|
-
return
|
|
7477
|
-
}).otherwise(() =>
|
|
8801
|
+
return import_langium11.EMPTY_SCOPE;
|
|
8802
|
+
}).otherwise(() => import_langium11.EMPTY_SCOPE);
|
|
7478
8803
|
}
|
|
7479
8804
|
getCollectionPredicateScope(context, collectionPredicate) {
|
|
7480
8805
|
const referenceType = this.reflection.getReferenceType(context);
|
|
7481
8806
|
const globalScope = this.getGlobalScope(referenceType, context);
|
|
7482
8807
|
const collection = collectionPredicate.left;
|
|
7483
|
-
const allowTypeDefScope =
|
|
7484
|
-
return (0,
|
|
8808
|
+
const allowTypeDefScope = isAuthOrAuthMemberAccess(collection);
|
|
8809
|
+
return (0, import_ts_pattern5.match)(collection).when(isReferenceExpr, (expr) => {
|
|
7485
8810
|
const ref = expr.target.ref;
|
|
7486
8811
|
if (isDataField(ref)) {
|
|
7487
8812
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7488
8813
|
}
|
|
7489
|
-
return
|
|
8814
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7490
8815
|
}).when(isMemberAccessExpr, (expr) => {
|
|
7491
8816
|
const ref = expr.member.ref;
|
|
7492
8817
|
if (isDataField(ref)) {
|
|
7493
8818
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7494
8819
|
}
|
|
7495
|
-
return
|
|
8820
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7496
8821
|
}).when(isInvocationExpr, (expr) => {
|
|
7497
8822
|
const returnTypeDecl = expr.function.ref?.returnType.reference?.ref;
|
|
7498
8823
|
if (isDataModel(returnTypeDecl)) {
|
|
7499
8824
|
return this.createScopeForContainer(returnTypeDecl, globalScope, allowTypeDefScope);
|
|
7500
8825
|
} else {
|
|
7501
|
-
return
|
|
8826
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7502
8827
|
}
|
|
7503
8828
|
}).when(isAuthInvocation, (expr) => {
|
|
7504
8829
|
return this.createScopeForAuth(expr, globalScope);
|
|
7505
|
-
}).otherwise(() =>
|
|
8830
|
+
}).otherwise(() => import_langium11.EMPTY_SCOPE);
|
|
7506
8831
|
}
|
|
7507
8832
|
createScopeForContainingModel(node, globalScope) {
|
|
7508
|
-
const model =
|
|
8833
|
+
const model = import_langium11.AstUtils.getContainerOfType(node, isDataModel);
|
|
7509
8834
|
if (model) {
|
|
7510
8835
|
return this.createScopeForContainer(model, globalScope);
|
|
7511
8836
|
} else {
|
|
7512
|
-
return
|
|
8837
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7513
8838
|
}
|
|
7514
8839
|
}
|
|
7515
8840
|
createScopeForContainer(node, globalScope, includeTypeDefScope = false) {
|
|
@@ -7518,16 +8843,16 @@ var ZModelScopeProvider = class extends import_langium8.DefaultScopeProvider {
|
|
|
7518
8843
|
} else if (includeTypeDefScope && isTypeDef(node)) {
|
|
7519
8844
|
return this.createScopeForNodes(node.fields, globalScope);
|
|
7520
8845
|
} else {
|
|
7521
|
-
return
|
|
8846
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7522
8847
|
}
|
|
7523
8848
|
}
|
|
7524
8849
|
createScopeForAuth(node, globalScope) {
|
|
7525
|
-
const decls = getAllLoadedAndReachableDataModelsAndTypeDefs(this.services.shared.workspace.LangiumDocuments,
|
|
8850
|
+
const decls = getAllLoadedAndReachableDataModelsAndTypeDefs(this.services.shared.workspace.LangiumDocuments, import_langium11.AstUtils.getContainerOfType(node, isDataModel));
|
|
7526
8851
|
const authDecl = getAuthDecl(decls);
|
|
7527
8852
|
if (authDecl) {
|
|
7528
8853
|
return this.createScopeForContainer(authDecl, globalScope, true);
|
|
7529
8854
|
} else {
|
|
7530
|
-
return
|
|
8855
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7531
8856
|
}
|
|
7532
8857
|
}
|
|
7533
8858
|
};
|
|
@@ -7543,13 +8868,97 @@ function getCollectionPredicateContext(node) {
|
|
|
7543
8868
|
}
|
|
7544
8869
|
__name(getCollectionPredicateContext, "getCollectionPredicateContext");
|
|
7545
8870
|
|
|
8871
|
+
// src/zmodel-semantic.ts
|
|
8872
|
+
var import_lsp4 = require("langium/lsp");
|
|
8873
|
+
var import_vscode_languageserver3 = require("vscode-languageserver");
|
|
8874
|
+
var ZModelSemanticTokenProvider = class extends import_lsp4.AbstractSemanticTokenProvider {
|
|
8875
|
+
static {
|
|
8876
|
+
__name(this, "ZModelSemanticTokenProvider");
|
|
8877
|
+
}
|
|
8878
|
+
highlightElement(node, acceptor) {
|
|
8879
|
+
if (isDataModel(node)) {
|
|
8880
|
+
acceptor({
|
|
8881
|
+
node,
|
|
8882
|
+
property: "name",
|
|
8883
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.type
|
|
8884
|
+
});
|
|
8885
|
+
acceptor({
|
|
8886
|
+
node,
|
|
8887
|
+
property: "mixins",
|
|
8888
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.type
|
|
8889
|
+
});
|
|
8890
|
+
acceptor({
|
|
8891
|
+
node,
|
|
8892
|
+
property: "baseModel",
|
|
8893
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.type
|
|
8894
|
+
});
|
|
8895
|
+
} else if (isDataSource(node) || isGeneratorDecl(node) || isPlugin(node) || isEnum(node) || isTypeDef(node)) {
|
|
8896
|
+
acceptor({
|
|
8897
|
+
node,
|
|
8898
|
+
property: "name",
|
|
8899
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.type
|
|
8900
|
+
});
|
|
8901
|
+
} else if (isDataField(node) || isConfigField(node) || isAttributeArg(node) || isPluginField(node) || isEnumField(node)) {
|
|
8902
|
+
acceptor({
|
|
8903
|
+
node,
|
|
8904
|
+
property: "name",
|
|
8905
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.variable
|
|
8906
|
+
});
|
|
8907
|
+
} else if (isDataFieldType(node)) {
|
|
8908
|
+
if (node.type) {
|
|
8909
|
+
acceptor({
|
|
8910
|
+
node,
|
|
8911
|
+
property: "type",
|
|
8912
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.type
|
|
8913
|
+
});
|
|
8914
|
+
} else {
|
|
8915
|
+
acceptor({
|
|
8916
|
+
node,
|
|
8917
|
+
property: "reference",
|
|
8918
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.macro
|
|
8919
|
+
});
|
|
8920
|
+
}
|
|
8921
|
+
} else if (isDataModelAttribute(node) || isDataFieldAttribute(node) || isInternalAttribute(node)) {
|
|
8922
|
+
acceptor({
|
|
8923
|
+
node,
|
|
8924
|
+
property: "decl",
|
|
8925
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.function
|
|
8926
|
+
});
|
|
8927
|
+
} else if (isInvocationExpr(node)) {
|
|
8928
|
+
acceptor({
|
|
8929
|
+
node,
|
|
8930
|
+
property: "function",
|
|
8931
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.function
|
|
8932
|
+
});
|
|
8933
|
+
} else if (isFunctionDecl(node) || isAttribute(node)) {
|
|
8934
|
+
acceptor({
|
|
8935
|
+
node,
|
|
8936
|
+
property: "name",
|
|
8937
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.function
|
|
8938
|
+
});
|
|
8939
|
+
} else if (isReferenceExpr(node)) {
|
|
8940
|
+
acceptor({
|
|
8941
|
+
node,
|
|
8942
|
+
property: "target",
|
|
8943
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.variable
|
|
8944
|
+
});
|
|
8945
|
+
} else if (isMemberAccessExpr(node)) {
|
|
8946
|
+
acceptor({
|
|
8947
|
+
node,
|
|
8948
|
+
property: "member",
|
|
8949
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.property
|
|
8950
|
+
});
|
|
8951
|
+
}
|
|
8952
|
+
}
|
|
8953
|
+
};
|
|
8954
|
+
|
|
7546
8955
|
// src/zmodel-workspace-manager.ts
|
|
7547
|
-
var
|
|
7548
|
-
var
|
|
7549
|
-
var
|
|
7550
|
-
var
|
|
7551
|
-
var
|
|
7552
|
-
var ZModelWorkspaceManager = class extends
|
|
8956
|
+
var import_langium12 = require("langium");
|
|
8957
|
+
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
8958
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
8959
|
+
var import_node_url2 = require("url");
|
|
8960
|
+
var import_meta2 = {};
|
|
8961
|
+
var ZModelWorkspaceManager = class extends import_langium12.DefaultWorkspaceManager {
|
|
7553
8962
|
static {
|
|
7554
8963
|
__name(this, "ZModelWorkspaceManager");
|
|
7555
8964
|
}
|
|
@@ -7570,9 +8979,9 @@ var ZModelWorkspaceManager = class extends import_langium9.DefaultWorkspaceManag
|
|
|
7570
8979
|
folderPath
|
|
7571
8980
|
]
|
|
7572
8981
|
});
|
|
7573
|
-
const languagePackageDir =
|
|
7574
|
-
const candidateStdlibPath =
|
|
7575
|
-
if (
|
|
8982
|
+
const languagePackageDir = import_node_path2.default.dirname(languagePackagePath);
|
|
8983
|
+
const candidateStdlibPath = import_node_path2.default.join(languagePackageDir, "res", STD_LIB_MODULE_NAME);
|
|
8984
|
+
if (import_node_fs3.default.existsSync(candidateStdlibPath)) {
|
|
7576
8985
|
installedStdlibPath = candidateStdlibPath;
|
|
7577
8986
|
console.log(`Found installed zenstack package stdlib at: ${installedStdlibPath}`);
|
|
7578
8987
|
break;
|
|
@@ -7584,73 +8993,12 @@ var ZModelWorkspaceManager = class extends import_langium9.DefaultWorkspaceManag
|
|
|
7584
8993
|
if (installedStdlibPath) {
|
|
7585
8994
|
stdLibPath = installedStdlibPath;
|
|
7586
8995
|
} else {
|
|
7587
|
-
const _dirname = typeof __dirname !== "undefined" ? __dirname :
|
|
7588
|
-
stdLibPath =
|
|
8996
|
+
const _dirname = typeof __dirname !== "undefined" ? __dirname : import_node_path2.default.dirname((0, import_node_url2.fileURLToPath)(import_meta2.url));
|
|
8997
|
+
stdLibPath = import_node_path2.default.join(_dirname, "../res", STD_LIB_MODULE_NAME);
|
|
7589
8998
|
console.log(`Using bundled stdlib in extension:`, stdLibPath);
|
|
7590
8999
|
}
|
|
7591
|
-
const stdlib = await this.documentFactory.fromUri(
|
|
9000
|
+
const stdlib = await this.documentFactory.fromUri(import_langium12.URI.file(stdLibPath));
|
|
7592
9001
|
collector(stdlib);
|
|
7593
|
-
const documents = this.langiumDocuments.all;
|
|
7594
|
-
const pluginModels = /* @__PURE__ */ new Set();
|
|
7595
|
-
documents.forEach((doc) => {
|
|
7596
|
-
const parsed = doc.parseResult.value;
|
|
7597
|
-
parsed.declarations.forEach((decl) => {
|
|
7598
|
-
if (isPlugin(decl)) {
|
|
7599
|
-
const providerField = decl.fields.find((f) => f.name === "provider");
|
|
7600
|
-
if (providerField) {
|
|
7601
|
-
const provider = getLiteral(providerField.value);
|
|
7602
|
-
if (provider) {
|
|
7603
|
-
pluginModels.add(provider);
|
|
7604
|
-
}
|
|
7605
|
-
}
|
|
7606
|
-
}
|
|
7607
|
-
});
|
|
7608
|
-
});
|
|
7609
|
-
if (pluginModels.size > 0) {
|
|
7610
|
-
console.log(`Used plugin modules: ${Array.from(pluginModels)}`);
|
|
7611
|
-
const pendingPluginModules = new Set(pluginModels);
|
|
7612
|
-
await Promise.all(folders.map((wf) => [
|
|
7613
|
-
wf,
|
|
7614
|
-
this.getRootFolder(wf)
|
|
7615
|
-
]).map(async (entry) => this.loadPluginModels(...entry, pendingPluginModules, collector)));
|
|
7616
|
-
}
|
|
7617
|
-
}
|
|
7618
|
-
async loadPluginModels(workspaceFolder, folderPath, pendingPluginModels, collector) {
|
|
7619
|
-
const content = (await this.fileSystemProvider.readDirectory(folderPath)).sort((a, b) => {
|
|
7620
|
-
if (a.isDirectory && b.isDirectory) {
|
|
7621
|
-
const aName = import_langium9.UriUtils.basename(a.uri);
|
|
7622
|
-
if (aName === "node_modules") {
|
|
7623
|
-
return -1;
|
|
7624
|
-
} else {
|
|
7625
|
-
return 1;
|
|
7626
|
-
}
|
|
7627
|
-
} else {
|
|
7628
|
-
return 0;
|
|
7629
|
-
}
|
|
7630
|
-
});
|
|
7631
|
-
for (const entry of content) {
|
|
7632
|
-
if (entry.isDirectory) {
|
|
7633
|
-
const name = import_langium9.UriUtils.basename(entry.uri);
|
|
7634
|
-
if (name === "node_modules") {
|
|
7635
|
-
for (const plugin of Array.from(pendingPluginModels)) {
|
|
7636
|
-
const path4 = import_langium9.UriUtils.joinPath(entry.uri, plugin, PLUGIN_MODULE_NAME);
|
|
7637
|
-
try {
|
|
7638
|
-
await this.fileSystemProvider.readFile(path4);
|
|
7639
|
-
const document = await this.langiumDocuments.getOrCreateDocument(path4);
|
|
7640
|
-
collector(document);
|
|
7641
|
-
console.log(`Adding plugin document from ${path4.path}`);
|
|
7642
|
-
pendingPluginModels.delete(plugin);
|
|
7643
|
-
if (pendingPluginModels.size === 0) {
|
|
7644
|
-
return;
|
|
7645
|
-
}
|
|
7646
|
-
} catch {
|
|
7647
|
-
}
|
|
7648
|
-
}
|
|
7649
|
-
} else {
|
|
7650
|
-
await this.loadPluginModels(workspaceFolder, entry.uri, pendingPluginModels, collector);
|
|
7651
|
-
}
|
|
7652
|
-
}
|
|
7653
|
-
}
|
|
7654
9002
|
}
|
|
7655
9003
|
};
|
|
7656
9004
|
|
|
@@ -7663,16 +9011,27 @@ var ZModelLanguageModule = {
|
|
|
7663
9011
|
},
|
|
7664
9012
|
validation: {
|
|
7665
9013
|
ZModelValidator: /* @__PURE__ */ __name((services) => new ZModelValidator(services), "ZModelValidator")
|
|
9014
|
+
},
|
|
9015
|
+
lsp: {
|
|
9016
|
+
Formatter: /* @__PURE__ */ __name((services) => new ZModelFormatter(services), "Formatter"),
|
|
9017
|
+
DefinitionProvider: /* @__PURE__ */ __name((services) => new ZModelDefinitionProvider(services), "DefinitionProvider"),
|
|
9018
|
+
CompletionProvider: /* @__PURE__ */ __name((services) => new ZModelCompletionProvider(services), "CompletionProvider"),
|
|
9019
|
+
SemanticTokenProvider: /* @__PURE__ */ __name((services) => new ZModelSemanticTokenProvider(services), "SemanticTokenProvider")
|
|
9020
|
+
},
|
|
9021
|
+
documentation: {
|
|
9022
|
+
CommentProvider: /* @__PURE__ */ __name((services) => new ZModelCommentProvider(services), "CommentProvider"),
|
|
9023
|
+
DocumentationProvider: /* @__PURE__ */ __name((services) => new ZModelDocumentationProvider(services), "DocumentationProvider")
|
|
7666
9024
|
}
|
|
7667
9025
|
};
|
|
7668
9026
|
var ZModelSharedModule = {
|
|
7669
9027
|
workspace: {
|
|
9028
|
+
DocumentBuilder: /* @__PURE__ */ __name((services) => new ZModelDocumentBuilder(services), "DocumentBuilder"),
|
|
7670
9029
|
WorkspaceManager: /* @__PURE__ */ __name((services) => new ZModelWorkspaceManager(services), "WorkspaceManager")
|
|
7671
9030
|
}
|
|
7672
9031
|
};
|
|
7673
|
-
function createZModelLanguageServices(context) {
|
|
7674
|
-
const shared = (0,
|
|
7675
|
-
const ZModelLanguage = (0,
|
|
9032
|
+
function createZModelLanguageServices(context, logToConsole = false) {
|
|
9033
|
+
const shared = (0, import_langium13.inject)((0, import_lsp5.createDefaultSharedModule)(context), ZModelGeneratedSharedModule, ZModelSharedModule);
|
|
9034
|
+
const ZModelLanguage = (0, import_langium13.inject)((0, import_lsp5.createDefaultModule)({
|
|
7676
9035
|
shared
|
|
7677
9036
|
}), ZModelGeneratedModule, ZModelLanguageModule);
|
|
7678
9037
|
shared.ServiceRegistry.register(ZModelLanguage);
|
|
@@ -7680,31 +9039,48 @@ function createZModelLanguageServices(context) {
|
|
|
7680
9039
|
if (!context.connection) {
|
|
7681
9040
|
shared.workspace.ConfigurationProvider.initialized({});
|
|
7682
9041
|
}
|
|
9042
|
+
shared.workspace.DocumentBuilder.onBuildPhase(import_langium13.DocumentState.Parsed, async (documents) => {
|
|
9043
|
+
for (const doc of documents) {
|
|
9044
|
+
if (doc.parseResult.lexerErrors.length > 0 || doc.parseResult.parserErrors.length > 0) {
|
|
9045
|
+
continue;
|
|
9046
|
+
}
|
|
9047
|
+
if (doc.uri.scheme !== "file") {
|
|
9048
|
+
continue;
|
|
9049
|
+
}
|
|
9050
|
+
const schemaPath = (0, import_node_url3.fileURLToPath)(doc.uri.toString());
|
|
9051
|
+
const pluginSchemas = getPluginDocuments(doc.parseResult.value, schemaPath);
|
|
9052
|
+
for (const plugin of pluginSchemas) {
|
|
9053
|
+
const pluginDocUri = import_langium13.URI.file(import_node_path3.default.resolve(plugin));
|
|
9054
|
+
let pluginDoc = shared.workspace.LangiumDocuments.getDocument(pluginDocUri);
|
|
9055
|
+
if (!pluginDoc) {
|
|
9056
|
+
pluginDoc = await shared.workspace.LangiumDocuments.getOrCreateDocument(pluginDocUri);
|
|
9057
|
+
if (pluginDoc) {
|
|
9058
|
+
shared.workspace.IndexManager.updateContent(pluginDoc);
|
|
9059
|
+
if (logToConsole) {
|
|
9060
|
+
console.log(`Loaded plugin model: ${plugin}`);
|
|
9061
|
+
}
|
|
9062
|
+
}
|
|
9063
|
+
}
|
|
9064
|
+
}
|
|
9065
|
+
}
|
|
9066
|
+
});
|
|
7683
9067
|
return {
|
|
7684
9068
|
shared,
|
|
7685
9069
|
ZModelLanguage
|
|
7686
9070
|
};
|
|
7687
9071
|
}
|
|
7688
9072
|
__name(createZModelLanguageServices, "createZModelLanguageServices");
|
|
7689
|
-
|
|
7690
|
-
|
|
7691
|
-
var import_meta2 = {};
|
|
7692
|
-
function createZModelServices() {
|
|
7693
|
-
return createZModelLanguageServices(import_node.NodeFileSystem);
|
|
9073
|
+
function createZModelServices(logToConsole = false) {
|
|
9074
|
+
return createZModelLanguageServices(import_node.NodeFileSystem, logToConsole);
|
|
7694
9075
|
}
|
|
7695
9076
|
__name(createZModelServices, "createZModelServices");
|
|
7696
|
-
|
|
7697
|
-
|
|
7698
|
-
|
|
7699
|
-
|
|
7700
|
-
|
|
7701
|
-
super(message);
|
|
7702
|
-
}
|
|
7703
|
-
};
|
|
7704
|
-
async function loadDocument(fileName, pluginModelFiles = []) {
|
|
7705
|
-
const { ZModelLanguage: services } = createZModelServices();
|
|
9077
|
+
|
|
9078
|
+
// src/document.ts
|
|
9079
|
+
var import_meta3 = {};
|
|
9080
|
+
async function loadDocument(fileName, additionalModelFiles = []) {
|
|
9081
|
+
const { ZModelLanguage: services } = createZModelServices(false);
|
|
7706
9082
|
const extensions = services.LanguageMetaData.fileExtensions;
|
|
7707
|
-
if (!extensions.includes(
|
|
9083
|
+
if (!extensions.includes(import_node_path4.default.extname(fileName))) {
|
|
7708
9084
|
return {
|
|
7709
9085
|
success: false,
|
|
7710
9086
|
errors: [
|
|
@@ -7713,7 +9089,7 @@ async function loadDocument(fileName, pluginModelFiles = []) {
|
|
|
7713
9089
|
warnings: []
|
|
7714
9090
|
};
|
|
7715
9091
|
}
|
|
7716
|
-
if (!
|
|
9092
|
+
if (!import_node_fs4.default.existsSync(fileName)) {
|
|
7717
9093
|
return {
|
|
7718
9094
|
success: false,
|
|
7719
9095
|
errors: [
|
|
@@ -7722,23 +9098,27 @@ async function loadDocument(fileName, pluginModelFiles = []) {
|
|
|
7722
9098
|
warnings: []
|
|
7723
9099
|
};
|
|
7724
9100
|
}
|
|
7725
|
-
const _dirname = typeof __dirname !== "undefined" ? __dirname :
|
|
7726
|
-
const stdLib = await services.shared.workspace.LangiumDocuments.getOrCreateDocument(
|
|
7727
|
-
const pluginDocs = await Promise.all(pluginModelFiles.map((file) => services.shared.workspace.LangiumDocuments.getOrCreateDocument(import_langium11.URI.file(import_node_path2.default.resolve(file)))));
|
|
9101
|
+
const _dirname = typeof __dirname !== "undefined" ? __dirname : import_node_path4.default.dirname((0, import_node_url4.fileURLToPath)(import_meta3.url));
|
|
9102
|
+
const stdLib = await services.shared.workspace.LangiumDocuments.getOrCreateDocument(import_langium14.URI.file(import_node_path4.default.resolve(import_node_path4.default.join(_dirname, "../res", STD_LIB_MODULE_NAME))));
|
|
7728
9103
|
const langiumDocuments = services.shared.workspace.LangiumDocuments;
|
|
7729
|
-
const document = await langiumDocuments.getOrCreateDocument(
|
|
9104
|
+
const document = await langiumDocuments.getOrCreateDocument(import_langium14.URI.file(import_node_path4.default.resolve(fileName)));
|
|
7730
9105
|
const importedURIs = await loadImports(document, langiumDocuments);
|
|
7731
9106
|
const importedDocuments = [];
|
|
7732
9107
|
for (const uri of importedURIs) {
|
|
7733
9108
|
importedDocuments.push(await langiumDocuments.getOrCreateDocument(uri));
|
|
7734
9109
|
}
|
|
9110
|
+
const additionalDocs = await Promise.all(additionalModelFiles.map((file) => services.shared.workspace.LangiumDocuments.getOrCreateDocument(import_langium14.URI.file(import_node_path4.default.resolve(file)))));
|
|
7735
9111
|
await services.shared.workspace.DocumentBuilder.build([
|
|
7736
9112
|
stdLib,
|
|
7737
|
-
...
|
|
9113
|
+
...additionalDocs,
|
|
7738
9114
|
document,
|
|
7739
9115
|
...importedDocuments
|
|
7740
9116
|
], {
|
|
7741
|
-
validation:
|
|
9117
|
+
validation: {
|
|
9118
|
+
stopAfterLexingErrors: true,
|
|
9119
|
+
stopAfterParsingErrors: true,
|
|
9120
|
+
stopAfterLinkingErrors: true
|
|
9121
|
+
}
|
|
7742
9122
|
});
|
|
7743
9123
|
const diagnostics = langiumDocuments.all.flatMap((doc) => (doc.diagnostics ?? []).map((diag) => ({
|
|
7744
9124
|
doc,
|
|
@@ -7748,7 +9128,7 @@ async function loadDocument(fileName, pluginModelFiles = []) {
|
|
|
7748
9128
|
const warnings = [];
|
|
7749
9129
|
if (diagnostics.length > 0) {
|
|
7750
9130
|
for (const { doc, diag } of diagnostics) {
|
|
7751
|
-
const message = `${
|
|
9131
|
+
const message = `${import_node_path4.default.relative(process.cwd(), doc.uri.fsPath)}:${diag.range.start.line + 1}:${diag.range.start.character + 1} - ${diag.message}`;
|
|
7752
9132
|
if (diag.severity === 1) {
|
|
7753
9133
|
errors.push(message);
|
|
7754
9134
|
} else {
|
|
@@ -7797,7 +9177,7 @@ async function loadImports(document, documents, uris = /* @__PURE__ */ new Set()
|
|
|
7797
9177
|
}
|
|
7798
9178
|
}
|
|
7799
9179
|
}
|
|
7800
|
-
return Array.from(uris).filter((x) => uriString != x).map((e) =>
|
|
9180
|
+
return Array.from(uris).filter((x) => uriString != x).map((e) => import_langium14.URI.parse(e));
|
|
7801
9181
|
}
|
|
7802
9182
|
__name(loadImports, "loadImports");
|
|
7803
9183
|
function mergeImportsDeclarations(documents, model) {
|
|
@@ -7814,13 +9194,13 @@ function linkContentToContainer(node) {
|
|
|
7814
9194
|
if (!name.startsWith("$")) {
|
|
7815
9195
|
if (Array.isArray(value)) {
|
|
7816
9196
|
value.forEach((item, index) => {
|
|
7817
|
-
if ((0,
|
|
9197
|
+
if ((0, import_langium14.isAstNode)(item)) {
|
|
7818
9198
|
item.$container = node;
|
|
7819
9199
|
item.$containerProperty = name;
|
|
7820
9200
|
item.$containerIndex = index;
|
|
7821
9201
|
}
|
|
7822
9202
|
});
|
|
7823
|
-
} else if ((0,
|
|
9203
|
+
} else if ((0, import_langium14.isAstNode)(value)) {
|
|
7824
9204
|
value.$container = node;
|
|
7825
9205
|
value.$containerProperty = name;
|
|
7826
9206
|
}
|
|
@@ -7846,14 +9226,34 @@ function validationAfterImportMerge(model) {
|
|
|
7846
9226
|
return errors;
|
|
7847
9227
|
}
|
|
7848
9228
|
__name(validationAfterImportMerge, "validationAfterImportMerge");
|
|
9229
|
+
async function formatDocument(content) {
|
|
9230
|
+
const services = createZModelServices().ZModelLanguage;
|
|
9231
|
+
const langiumDocuments = services.shared.workspace.LangiumDocuments;
|
|
9232
|
+
const document = langiumDocuments.createDocument(import_langium14.URI.parse("memory://schema.zmodel"), content);
|
|
9233
|
+
const formatter = services.lsp.Formatter;
|
|
9234
|
+
const identifier = {
|
|
9235
|
+
uri: document.uri.toString()
|
|
9236
|
+
};
|
|
9237
|
+
const options = formatter.getFormatOptions() ?? {
|
|
9238
|
+
insertSpaces: true,
|
|
9239
|
+
tabSize: 4
|
|
9240
|
+
};
|
|
9241
|
+
const edits = await formatter.formatDocument(document, {
|
|
9242
|
+
options,
|
|
9243
|
+
textDocument: identifier
|
|
9244
|
+
});
|
|
9245
|
+
return import_langium14.TextDocument.applyEdits(document.textDocument, edits);
|
|
9246
|
+
}
|
|
9247
|
+
__name(formatDocument, "formatDocument");
|
|
7849
9248
|
// Annotate the CommonJS export names for ESM import in node:
|
|
7850
9249
|
0 && (module.exports = {
|
|
7851
|
-
|
|
9250
|
+
ZModelCodeGenerator,
|
|
7852
9251
|
ZModelLanguageMetaData,
|
|
7853
9252
|
ZModelLanguageModule,
|
|
7854
9253
|
ZModelSharedModule,
|
|
7855
9254
|
createZModelLanguageServices,
|
|
7856
9255
|
createZModelServices,
|
|
9256
|
+
formatDocument,
|
|
7857
9257
|
loadDocument
|
|
7858
9258
|
});
|
|
7859
9259
|
//# sourceMappingURL=index.cjs.map
|