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