@zenstackhq/language 3.0.0-beta.2 → 3.0.0-beta.20
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 +1577 -280
- 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 +1528 -234
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +106 -28
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +5 -5
- package/dist/utils.d.ts +5 -5
- package/dist/utils.js +100 -23
- package/dist/utils.js.map +1 -1
- package/package.json +11 -7
- package/res/stdlib.zmodel +43 -71
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;
|
|
@@ -5386,7 +5442,7 @@ function getFunctionExpressionContext(funcDecl) {
|
|
|
5386
5442
|
}
|
|
5387
5443
|
__name(getFunctionExpressionContext, "getFunctionExpressionContext");
|
|
5388
5444
|
function isCheckInvocation(node) {
|
|
5389
|
-
return isInvocationExpr(node) && node.function.ref?.name === "check"
|
|
5445
|
+
return isInvocationExpr(node) && node.function.ref?.name === "check";
|
|
5390
5446
|
}
|
|
5391
5447
|
__name(isCheckInvocation, "isCheckInvocation");
|
|
5392
5448
|
function resolveTransitiveImports(documents, model) {
|
|
@@ -5436,9 +5492,9 @@ function resolveImportUri(imp) {
|
|
|
5436
5492
|
return void 0;
|
|
5437
5493
|
}
|
|
5438
5494
|
const doc = import_langium2.AstUtils.getDocument(imp);
|
|
5439
|
-
const dir =
|
|
5495
|
+
const dir = import_node_path.default.dirname(doc.uri.fsPath);
|
|
5440
5496
|
const importPath = imp.path.endsWith(".zmodel") ? imp.path : `${imp.path}.zmodel`;
|
|
5441
|
-
return import_langium2.URI.file(
|
|
5497
|
+
return import_langium2.URI.file(import_node_path.default.resolve(dir, importPath));
|
|
5442
5498
|
}
|
|
5443
5499
|
__name(resolveImportUri, "resolveImportUri");
|
|
5444
5500
|
function getDataModelAndTypeDefs(model, includeIgnored = false) {
|
|
@@ -5456,17 +5512,17 @@ function getAllDeclarationsIncludingImports(documents, model) {
|
|
|
5456
5512
|
}
|
|
5457
5513
|
__name(getAllDeclarationsIncludingImports, "getAllDeclarationsIncludingImports");
|
|
5458
5514
|
function getAuthDecl(decls) {
|
|
5459
|
-
let authModel = decls.find((
|
|
5515
|
+
let authModel = decls.find((d) => hasAttribute(d, "@@auth"));
|
|
5460
5516
|
if (!authModel) {
|
|
5461
|
-
authModel = decls.find((
|
|
5517
|
+
authModel = decls.find((d) => d.name === "User");
|
|
5462
5518
|
}
|
|
5463
5519
|
return authModel;
|
|
5464
5520
|
}
|
|
5465
5521
|
__name(getAuthDecl, "getAuthDecl");
|
|
5466
|
-
function
|
|
5467
|
-
return isInvocationExpr(node) && node.function.ref?.name === "
|
|
5522
|
+
function isBeforeInvocation(node) {
|
|
5523
|
+
return isInvocationExpr(node) && node.function.ref?.name === "before";
|
|
5468
5524
|
}
|
|
5469
|
-
__name(
|
|
5525
|
+
__name(isBeforeInvocation, "isBeforeInvocation");
|
|
5470
5526
|
function isCollectionPredicate(node) {
|
|
5471
5527
|
return isBinaryExpr(node) && [
|
|
5472
5528
|
"?",
|
|
@@ -5521,12 +5577,14 @@ function getAllFields(decl, includeIgnored = false, seen = /* @__PURE__ */ new S
|
|
|
5521
5577
|
seen.add(decl);
|
|
5522
5578
|
const fields = [];
|
|
5523
5579
|
for (const mixin of decl.mixins) {
|
|
5524
|
-
|
|
5525
|
-
|
|
5580
|
+
if (mixin.ref) {
|
|
5581
|
+
fields.push(...getAllFields(mixin.ref, includeIgnored, seen));
|
|
5582
|
+
}
|
|
5526
5583
|
}
|
|
5527
5584
|
if (isDataModel(decl) && decl.baseModel) {
|
|
5528
|
-
|
|
5529
|
-
|
|
5585
|
+
if (decl.baseModel.ref) {
|
|
5586
|
+
fields.push(...getAllFields(decl.baseModel.ref, includeIgnored, seen));
|
|
5587
|
+
}
|
|
5530
5588
|
}
|
|
5531
5589
|
fields.push(...decl.fields.filter((f) => includeIgnored || !hasAttribute(f, "@ignore")));
|
|
5532
5590
|
return fields;
|
|
@@ -5539,12 +5597,14 @@ function getAllAttributes(decl, seen = /* @__PURE__ */ new Set()) {
|
|
|
5539
5597
|
seen.add(decl);
|
|
5540
5598
|
const attributes = [];
|
|
5541
5599
|
for (const mixin of decl.mixins) {
|
|
5542
|
-
|
|
5543
|
-
|
|
5600
|
+
if (mixin.ref) {
|
|
5601
|
+
attributes.push(...getAllAttributes(mixin.ref, seen));
|
|
5602
|
+
}
|
|
5544
5603
|
}
|
|
5545
5604
|
if (isDataModel(decl) && decl.baseModel) {
|
|
5546
|
-
|
|
5547
|
-
|
|
5605
|
+
if (decl.baseModel.ref) {
|
|
5606
|
+
attributes.push(...getAllAttributes(decl.baseModel.ref, seen));
|
|
5607
|
+
}
|
|
5548
5608
|
}
|
|
5549
5609
|
attributes.push(...decl.attributes);
|
|
5550
5610
|
return attributes;
|
|
@@ -5559,6 +5619,71 @@ function getDocument(node) {
|
|
|
5559
5619
|
return result;
|
|
5560
5620
|
}
|
|
5561
5621
|
__name(getDocument, "getDocument");
|
|
5622
|
+
function getPluginDocuments(model, schemaPath) {
|
|
5623
|
+
const result = [];
|
|
5624
|
+
for (const decl of model.declarations.filter(isPlugin)) {
|
|
5625
|
+
const providerField = decl.fields.find((f) => f.name === "provider");
|
|
5626
|
+
if (!providerField) {
|
|
5627
|
+
continue;
|
|
5628
|
+
}
|
|
5629
|
+
const provider = getLiteral(providerField.value);
|
|
5630
|
+
if (!provider) {
|
|
5631
|
+
continue;
|
|
5632
|
+
}
|
|
5633
|
+
let pluginModelFile;
|
|
5634
|
+
let providerPath = import_node_path.default.resolve(import_node_path.default.dirname(schemaPath), provider);
|
|
5635
|
+
if (import_node_fs.default.existsSync(providerPath)) {
|
|
5636
|
+
if (import_node_fs.default.statSync(providerPath).isDirectory()) {
|
|
5637
|
+
providerPath = import_node_path.default.join(providerPath, "index.js");
|
|
5638
|
+
}
|
|
5639
|
+
pluginModelFile = import_node_path.default.resolve(import_node_path.default.dirname(providerPath), PLUGIN_MODULE_NAME);
|
|
5640
|
+
if (!import_node_fs.default.existsSync(pluginModelFile)) {
|
|
5641
|
+
pluginModelFile = findUp([
|
|
5642
|
+
PLUGIN_MODULE_NAME
|
|
5643
|
+
], import_node_path.default.dirname(providerPath));
|
|
5644
|
+
}
|
|
5645
|
+
}
|
|
5646
|
+
if (!pluginModelFile) {
|
|
5647
|
+
if (typeof import_meta.resolve === "function") {
|
|
5648
|
+
try {
|
|
5649
|
+
const resolvedUrl = import_meta.resolve(`${provider}/${PLUGIN_MODULE_NAME}`);
|
|
5650
|
+
pluginModelFile = (0, import_node_url.fileURLToPath)(resolvedUrl);
|
|
5651
|
+
} catch {
|
|
5652
|
+
}
|
|
5653
|
+
}
|
|
5654
|
+
}
|
|
5655
|
+
if (!pluginModelFile) {
|
|
5656
|
+
try {
|
|
5657
|
+
const require2 = (0, import_node_module.createRequire)((0, import_node_url.pathToFileURL)(schemaPath));
|
|
5658
|
+
pluginModelFile = require2.resolve(`${provider}/${PLUGIN_MODULE_NAME}`);
|
|
5659
|
+
} catch {
|
|
5660
|
+
}
|
|
5661
|
+
}
|
|
5662
|
+
if (pluginModelFile && import_node_fs.default.existsSync(pluginModelFile)) {
|
|
5663
|
+
result.push(pluginModelFile);
|
|
5664
|
+
}
|
|
5665
|
+
}
|
|
5666
|
+
return result;
|
|
5667
|
+
}
|
|
5668
|
+
__name(getPluginDocuments, "getPluginDocuments");
|
|
5669
|
+
function findUp(names, cwd = process.cwd(), multiple = false, result = []) {
|
|
5670
|
+
if (!names.some((name) => !!name)) {
|
|
5671
|
+
return void 0;
|
|
5672
|
+
}
|
|
5673
|
+
const target = names.find((name) => import_node_fs.default.existsSync(import_node_path.default.join(cwd, name)));
|
|
5674
|
+
if (multiple === false && target) {
|
|
5675
|
+
return import_node_path.default.join(cwd, target);
|
|
5676
|
+
}
|
|
5677
|
+
if (target) {
|
|
5678
|
+
result.push(import_node_path.default.join(cwd, target));
|
|
5679
|
+
}
|
|
5680
|
+
const up = import_node_path.default.resolve(cwd, "..");
|
|
5681
|
+
if (up === cwd) {
|
|
5682
|
+
return multiple && result.length > 0 ? result : void 0;
|
|
5683
|
+
}
|
|
5684
|
+
return findUp(names, up, multiple, result);
|
|
5685
|
+
}
|
|
5686
|
+
__name(findUp, "findUp");
|
|
5562
5687
|
function findRootNode(node) {
|
|
5563
5688
|
while (node.$container) {
|
|
5564
5689
|
node = node.$container;
|
|
@@ -5568,6 +5693,8 @@ function findRootNode(node) {
|
|
|
5568
5693
|
__name(findRootNode, "findRootNode");
|
|
5569
5694
|
|
|
5570
5695
|
// src/validators/attribute-application-validator.ts
|
|
5696
|
+
var import_langium3 = require("langium");
|
|
5697
|
+
var import_pluralize = __toESM(require("pluralize"), 1);
|
|
5571
5698
|
function _ts_decorate(decorators, target, key, desc) {
|
|
5572
5699
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5573
5700
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -5681,6 +5808,7 @@ var AttributeApplicationValidator = class {
|
|
|
5681
5808
|
});
|
|
5682
5809
|
}
|
|
5683
5810
|
}
|
|
5811
|
+
// TODO: design a way to let plugin register validation
|
|
5684
5812
|
_checkModelLevelPolicy(attr, accept) {
|
|
5685
5813
|
const kind = getStringLiteral(attr.args[0]?.value);
|
|
5686
5814
|
if (!kind) {
|
|
@@ -5693,11 +5821,61 @@ var AttributeApplicationValidator = class {
|
|
|
5693
5821
|
"create",
|
|
5694
5822
|
"read",
|
|
5695
5823
|
"update",
|
|
5824
|
+
"post-update",
|
|
5696
5825
|
"delete",
|
|
5697
5826
|
"all"
|
|
5698
5827
|
], attr, accept);
|
|
5699
|
-
|
|
5828
|
+
if ((kind === "create" || kind === "all") && attr.args[1]?.value) {
|
|
5829
|
+
this.rejectNonOwnedRelationInExpression(attr.args[1].value, accept);
|
|
5830
|
+
}
|
|
5831
|
+
if (kind !== "post-update" && attr.args[1]?.value) {
|
|
5832
|
+
const beforeCall = import_langium3.AstUtils.streamAst(attr.args[1]?.value).find(isBeforeInvocation);
|
|
5833
|
+
if (beforeCall) {
|
|
5834
|
+
accept("error", `"before()" is only allowed in "post-update" policy rules`, {
|
|
5835
|
+
node: beforeCall
|
|
5836
|
+
});
|
|
5837
|
+
}
|
|
5838
|
+
}
|
|
5700
5839
|
}
|
|
5840
|
+
rejectNonOwnedRelationInExpression(expr, accept) {
|
|
5841
|
+
const contextModel = import_langium3.AstUtils.getContainerOfType(expr, isDataModel);
|
|
5842
|
+
if (!contextModel) {
|
|
5843
|
+
return;
|
|
5844
|
+
}
|
|
5845
|
+
if (import_langium3.AstUtils.streamAst(expr).some((node) => {
|
|
5846
|
+
if (!isDataFieldReference(node)) {
|
|
5847
|
+
return false;
|
|
5848
|
+
}
|
|
5849
|
+
if (node.target.ref?.$container !== contextModel) {
|
|
5850
|
+
return false;
|
|
5851
|
+
}
|
|
5852
|
+
const field = node.target.ref;
|
|
5853
|
+
if (!isRelationshipField(field)) {
|
|
5854
|
+
return false;
|
|
5855
|
+
}
|
|
5856
|
+
if (isAuthOrAuthMemberAccess(node)) {
|
|
5857
|
+
return false;
|
|
5858
|
+
}
|
|
5859
|
+
const startNode = isCollectionPredicate(node.$container) && node.$container.left === node ? node.$container : node;
|
|
5860
|
+
const collectionPredicate = import_langium3.AstUtils.getContainerOfType(startNode.$container, isCollectionPredicate);
|
|
5861
|
+
if (collectionPredicate && isAuthOrAuthMemberAccess(collectionPredicate.left)) {
|
|
5862
|
+
return false;
|
|
5863
|
+
}
|
|
5864
|
+
const relationAttr = field.attributes.find((attr) => attr.decl.ref?.name === "@relation");
|
|
5865
|
+
if (!relationAttr) {
|
|
5866
|
+
return true;
|
|
5867
|
+
}
|
|
5868
|
+
if (!relationAttr.args.some((arg) => arg.name === "fields")) {
|
|
5869
|
+
return true;
|
|
5870
|
+
}
|
|
5871
|
+
return false;
|
|
5872
|
+
})) {
|
|
5873
|
+
accept("error", `non-owned relation fields are not allowed in "create" rules`, {
|
|
5874
|
+
node: expr
|
|
5875
|
+
});
|
|
5876
|
+
}
|
|
5877
|
+
}
|
|
5878
|
+
// TODO: design a way to let plugin register validation
|
|
5701
5879
|
_checkFieldLevelPolicy(attr, accept) {
|
|
5702
5880
|
const kind = getStringLiteral(attr.args[0]?.value);
|
|
5703
5881
|
if (!kind) {
|
|
@@ -5712,8 +5890,8 @@ var AttributeApplicationValidator = class {
|
|
|
5712
5890
|
"all"
|
|
5713
5891
|
], attr, accept);
|
|
5714
5892
|
const expr = attr.args[1]?.value;
|
|
5715
|
-
if (expr && import_langium3.AstUtils.streamAst(expr).some((node) =>
|
|
5716
|
-
accept("error", `"
|
|
5893
|
+
if (expr && import_langium3.AstUtils.streamAst(expr).some((node) => isBeforeInvocation(node))) {
|
|
5894
|
+
accept("error", `"before()" is not allowed in field-level policy rules`, {
|
|
5717
5895
|
node: expr
|
|
5718
5896
|
});
|
|
5719
5897
|
}
|
|
@@ -5725,7 +5903,6 @@ var AttributeApplicationValidator = class {
|
|
|
5725
5903
|
});
|
|
5726
5904
|
}
|
|
5727
5905
|
}
|
|
5728
|
-
this.rejectEncryptedFields(attr, accept);
|
|
5729
5906
|
}
|
|
5730
5907
|
_checkValidate(attr, accept) {
|
|
5731
5908
|
const condition = attr.args[0]?.value;
|
|
@@ -5735,8 +5912,9 @@ var AttributeApplicationValidator = class {
|
|
|
5735
5912
|
});
|
|
5736
5913
|
}
|
|
5737
5914
|
}
|
|
5738
|
-
|
|
5915
|
+
_checkConstraint(attr, accept) {
|
|
5739
5916
|
const fields = attr.args[0]?.value;
|
|
5917
|
+
const attrName = attr.decl.ref?.name;
|
|
5740
5918
|
if (!fields) {
|
|
5741
5919
|
accept("error", `expects an array of field references`, {
|
|
5742
5920
|
node: attr.args[0]
|
|
@@ -5745,7 +5923,7 @@ var AttributeApplicationValidator = class {
|
|
|
5745
5923
|
}
|
|
5746
5924
|
if (isArrayExpr(fields)) {
|
|
5747
5925
|
if (fields.items.length === 0) {
|
|
5748
|
-
accept("error",
|
|
5926
|
+
accept("error", `\`${attrName}\` expects at least one field reference`, {
|
|
5749
5927
|
node: fields
|
|
5750
5928
|
});
|
|
5751
5929
|
return;
|
|
@@ -5764,7 +5942,7 @@ var AttributeApplicationValidator = class {
|
|
|
5764
5942
|
return;
|
|
5765
5943
|
}
|
|
5766
5944
|
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
|
|
5945
|
+
accept("error", `Cannot use fields inherited from a polymorphic base model in \`${attrName}\``, {
|
|
5768
5946
|
node: item
|
|
5769
5947
|
});
|
|
5770
5948
|
}
|
|
@@ -5775,15 +5953,6 @@ var AttributeApplicationValidator = class {
|
|
|
5775
5953
|
});
|
|
5776
5954
|
}
|
|
5777
5955
|
}
|
|
5778
|
-
rejectEncryptedFields(attr, accept) {
|
|
5779
|
-
import_langium3.AstUtils.streamAllContents(attr).forEach((node) => {
|
|
5780
|
-
if (isDataFieldReference(node) && hasAttribute(node.target.ref, "@encrypted")) {
|
|
5781
|
-
accept("error", `Encrypted fields cannot be used in policy rules`, {
|
|
5782
|
-
node
|
|
5783
|
-
});
|
|
5784
|
-
}
|
|
5785
|
-
});
|
|
5786
|
-
}
|
|
5787
5956
|
validatePolicyKinds(kind, candidates, attr, accept) {
|
|
5788
5957
|
const items = kind.split(",").map((x) => x.trim());
|
|
5789
5958
|
items.forEach((item) => {
|
|
@@ -5826,15 +5995,16 @@ _ts_decorate([
|
|
|
5826
5995
|
_ts_metadata("design:returntype", void 0)
|
|
5827
5996
|
], AttributeApplicationValidator.prototype, "_checkValidate", null);
|
|
5828
5997
|
_ts_decorate([
|
|
5829
|
-
check("@@unique"),
|
|
5830
5998
|
check("@@id"),
|
|
5999
|
+
check("@@index"),
|
|
6000
|
+
check("@@unique"),
|
|
5831
6001
|
_ts_metadata("design:type", Function),
|
|
5832
6002
|
_ts_metadata("design:paramtypes", [
|
|
5833
6003
|
typeof AttributeApplication === "undefined" ? Object : AttributeApplication,
|
|
5834
6004
|
typeof ValidationAcceptor === "undefined" ? Object : ValidationAcceptor
|
|
5835
6005
|
]),
|
|
5836
6006
|
_ts_metadata("design:returntype", void 0)
|
|
5837
|
-
], AttributeApplicationValidator.prototype, "
|
|
6007
|
+
], AttributeApplicationValidator.prototype, "_checkConstraint", null);
|
|
5838
6008
|
function assignableToAttributeParam(arg, param, attr) {
|
|
5839
6009
|
const argResolvedType = arg.$resolvedType;
|
|
5840
6010
|
if (!argResolvedType) {
|
|
@@ -5844,6 +6014,10 @@ function assignableToAttributeParam(arg, param, attr) {
|
|
|
5844
6014
|
let dstIsArray = param.type.array;
|
|
5845
6015
|
if (dstType === "ContextType") {
|
|
5846
6016
|
if (isDataField(attr.$container)) {
|
|
6017
|
+
const dstIsTypedJson = hasAttribute(attr.$container, "@json");
|
|
6018
|
+
if (dstIsTypedJson && attr.decl.ref?.name === "@default") {
|
|
6019
|
+
return argResolvedType.decl === "String";
|
|
6020
|
+
}
|
|
5847
6021
|
dstIsArray = attr.$container.type.array;
|
|
5848
6022
|
}
|
|
5849
6023
|
}
|
|
@@ -5935,6 +6109,9 @@ function isValidAttributeTarget(attrDecl, targetDecl) {
|
|
|
5935
6109
|
case "TypeDefField":
|
|
5936
6110
|
allowed = allowed || isTypeDef(targetDecl.type.reference?.ref);
|
|
5937
6111
|
break;
|
|
6112
|
+
case "ListField":
|
|
6113
|
+
allowed = allowed || !isDataModel(targetDecl.type.reference?.ref) && targetDecl.type.array;
|
|
6114
|
+
break;
|
|
5938
6115
|
default:
|
|
5939
6116
|
break;
|
|
5940
6117
|
}
|
|
@@ -5961,7 +6138,7 @@ var AttributeValidator = class {
|
|
|
5961
6138
|
};
|
|
5962
6139
|
|
|
5963
6140
|
// src/validators/datamodel-validator.ts
|
|
5964
|
-
var
|
|
6141
|
+
var import_common_helpers = require("@zenstackhq/common-helpers");
|
|
5965
6142
|
var import_langium4 = require("langium");
|
|
5966
6143
|
|
|
5967
6144
|
// src/validators/common.ts
|
|
@@ -6332,7 +6509,7 @@ var DataModelValidator = class {
|
|
|
6332
6509
|
if (!model.baseModel) {
|
|
6333
6510
|
return;
|
|
6334
6511
|
}
|
|
6335
|
-
(0,
|
|
6512
|
+
(0, import_common_helpers.invariant)(model.baseModel.ref, "baseModel must be resolved");
|
|
6336
6513
|
if (!isDelegateModel(model.baseModel.ref)) {
|
|
6337
6514
|
accept("error", `Model ${model.baseModel.$refText} cannot be extended because it's not a delegate model`, {
|
|
6338
6515
|
node: model,
|
|
@@ -6354,7 +6531,7 @@ var DataModelValidator = class {
|
|
|
6354
6531
|
}
|
|
6355
6532
|
seen.push(current);
|
|
6356
6533
|
if (current.baseModel) {
|
|
6357
|
-
(0,
|
|
6534
|
+
(0, import_common_helpers.invariant)(current.baseModel.ref, "baseModel must be resolved");
|
|
6358
6535
|
todo.push(current.baseModel.ref);
|
|
6359
6536
|
}
|
|
6360
6537
|
}
|
|
@@ -6484,11 +6661,21 @@ var ExpressionValidator = class {
|
|
|
6484
6661
|
}
|
|
6485
6662
|
}
|
|
6486
6663
|
switch (expr.$type) {
|
|
6664
|
+
case "MemberAccessExpr":
|
|
6665
|
+
this.validateMemberAccessExpr(expr, accept);
|
|
6666
|
+
break;
|
|
6487
6667
|
case "BinaryExpr":
|
|
6488
6668
|
this.validateBinaryExpr(expr, accept);
|
|
6489
6669
|
break;
|
|
6490
6670
|
}
|
|
6491
6671
|
}
|
|
6672
|
+
validateMemberAccessExpr(expr, accept) {
|
|
6673
|
+
if (isBeforeInvocation(expr.operand) && isDataModel(expr.$resolvedType?.decl)) {
|
|
6674
|
+
accept("error", "relation fields cannot be accessed from `before()`", {
|
|
6675
|
+
node: expr
|
|
6676
|
+
});
|
|
6677
|
+
}
|
|
6678
|
+
}
|
|
6492
6679
|
validateBinaryExpr(expr, accept) {
|
|
6493
6680
|
switch (expr.operator) {
|
|
6494
6681
|
case "in": {
|
|
@@ -6541,23 +6728,25 @@ var ExpressionValidator = class {
|
|
|
6541
6728
|
"Any"
|
|
6542
6729
|
];
|
|
6543
6730
|
}
|
|
6544
|
-
|
|
6731
|
+
const leftResolvedDecl = expr.left.$resolvedType?.decl;
|
|
6732
|
+
const rightResolvedDecl = expr.right.$resolvedType?.decl;
|
|
6733
|
+
if (leftResolvedDecl && (typeof leftResolvedDecl !== "string" || !supportedShapes.includes(leftResolvedDecl))) {
|
|
6545
6734
|
accept("error", `invalid operand type for "${expr.operator}" operator`, {
|
|
6546
6735
|
node: expr.left
|
|
6547
6736
|
});
|
|
6548
6737
|
return;
|
|
6549
6738
|
}
|
|
6550
|
-
if (typeof
|
|
6739
|
+
if (rightResolvedDecl && (typeof rightResolvedDecl !== "string" || !supportedShapes.includes(rightResolvedDecl))) {
|
|
6551
6740
|
accept("error", `invalid operand type for "${expr.operator}" operator`, {
|
|
6552
6741
|
node: expr.right
|
|
6553
6742
|
});
|
|
6554
6743
|
return;
|
|
6555
6744
|
}
|
|
6556
|
-
if (
|
|
6745
|
+
if (leftResolvedDecl === "DateTime" && rightResolvedDecl && rightResolvedDecl !== "DateTime") {
|
|
6557
6746
|
accept("error", "incompatible operand types", {
|
|
6558
6747
|
node: expr
|
|
6559
6748
|
});
|
|
6560
|
-
} else if (
|
|
6749
|
+
} else if (rightResolvedDecl === "DateTime" && leftResolvedDecl && leftResolvedDecl !== "DateTime") {
|
|
6561
6750
|
accept("error", "incompatible operand types", {
|
|
6562
6751
|
node: expr
|
|
6563
6752
|
});
|
|
@@ -6597,11 +6786,11 @@ var ExpressionValidator = class {
|
|
|
6597
6786
|
});
|
|
6598
6787
|
}
|
|
6599
6788
|
if (isDataFieldReference(expr.left) && (isThisExpr(expr.right) || isDataFieldReference(expr.right))) {
|
|
6600
|
-
accept("error", "comparison between
|
|
6789
|
+
accept("error", "comparison between models is not supported", {
|
|
6601
6790
|
node: expr
|
|
6602
6791
|
});
|
|
6603
6792
|
} else if (isDataFieldReference(expr.right) && (isThisExpr(expr.left) || isDataFieldReference(expr.left))) {
|
|
6604
|
-
accept("error", "comparison between
|
|
6793
|
+
accept("error", "comparison between models is not supported", {
|
|
6605
6794
|
node: expr
|
|
6606
6795
|
});
|
|
6607
6796
|
}
|
|
@@ -6691,41 +6880,39 @@ var FunctionInvocationValidator = class {
|
|
|
6691
6880
|
if (!this.validateArgs(funcDecl, expr.args, accept)) {
|
|
6692
6881
|
return;
|
|
6693
6882
|
}
|
|
6694
|
-
|
|
6695
|
-
|
|
6696
|
-
|
|
6697
|
-
|
|
6698
|
-
|
|
6699
|
-
|
|
6700
|
-
break;
|
|
6701
|
-
}
|
|
6702
|
-
curr = curr.$container;
|
|
6883
|
+
let curr = expr.$container;
|
|
6884
|
+
let containerAttribute;
|
|
6885
|
+
while (curr) {
|
|
6886
|
+
if (isDataModelAttribute(curr) || isDataFieldAttribute(curr)) {
|
|
6887
|
+
containerAttribute = curr;
|
|
6888
|
+
break;
|
|
6703
6889
|
}
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6890
|
+
curr = curr.$container;
|
|
6891
|
+
}
|
|
6892
|
+
const exprContext = this.getExpressionContext(containerAttribute);
|
|
6893
|
+
const funcAllowedContext = getFunctionExpressionContext(funcDecl);
|
|
6894
|
+
if (exprContext && !funcAllowedContext.includes(exprContext)) {
|
|
6895
|
+
accept("error", `function "${funcDecl.name}" is not allowed in the current context: ${exprContext}`, {
|
|
6896
|
+
node: expr
|
|
6897
|
+
});
|
|
6898
|
+
return;
|
|
6899
|
+
}
|
|
6900
|
+
const allCasing = [
|
|
6901
|
+
"original",
|
|
6902
|
+
"upper",
|
|
6903
|
+
"lower",
|
|
6904
|
+
"capitalize",
|
|
6905
|
+
"uncapitalize"
|
|
6906
|
+
];
|
|
6907
|
+
if ([
|
|
6908
|
+
"currentModel",
|
|
6909
|
+
"currentOperation"
|
|
6910
|
+
].includes(funcDecl.name)) {
|
|
6911
|
+
const arg = getLiteral(expr.args[0]?.value);
|
|
6912
|
+
if (arg && !allCasing.includes(arg)) {
|
|
6913
|
+
accept("error", `argument must be one of: ${allCasing.map((c) => '"' + c + '"').join(", ")}`, {
|
|
6914
|
+
node: expr.args[0]
|
|
6709
6915
|
});
|
|
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
6916
|
}
|
|
6730
6917
|
}
|
|
6731
6918
|
const checker = invocationCheckers.get(expr.function.$refText);
|
|
@@ -6733,6 +6920,18 @@ var FunctionInvocationValidator = class {
|
|
|
6733
6920
|
checker.value.call(this, expr, accept);
|
|
6734
6921
|
}
|
|
6735
6922
|
}
|
|
6923
|
+
getExpressionContext(containerAttribute) {
|
|
6924
|
+
if (!containerAttribute) {
|
|
6925
|
+
return void 0;
|
|
6926
|
+
}
|
|
6927
|
+
if (this.isValidationAttribute(containerAttribute)) {
|
|
6928
|
+
return ExpressionContext.ValidationRule;
|
|
6929
|
+
}
|
|
6930
|
+
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);
|
|
6931
|
+
}
|
|
6932
|
+
isValidationAttribute(attr) {
|
|
6933
|
+
return !!attr.decl.ref?.attributes.some((attr2) => attr2.decl.$refText === "@@@validation");
|
|
6934
|
+
}
|
|
6736
6935
|
validateArgs(funcDecl, args, accept) {
|
|
6737
6936
|
let success = true;
|
|
6738
6937
|
for (let i = 0; i < funcDecl.params.length; i++) {
|
|
@@ -6793,6 +6992,44 @@ var FunctionInvocationValidator = class {
|
|
|
6793
6992
|
}
|
|
6794
6993
|
return true;
|
|
6795
6994
|
}
|
|
6995
|
+
_checkLength(expr, accept) {
|
|
6996
|
+
const msg = "argument must be a string or list field";
|
|
6997
|
+
const fieldArg = expr.args[0].value;
|
|
6998
|
+
if (!isDataFieldReference(fieldArg)) {
|
|
6999
|
+
accept("error", msg, {
|
|
7000
|
+
node: expr.args[0]
|
|
7001
|
+
});
|
|
7002
|
+
return;
|
|
7003
|
+
}
|
|
7004
|
+
if (isDataModel(fieldArg.$resolvedType?.decl)) {
|
|
7005
|
+
accept("error", msg, {
|
|
7006
|
+
node: expr.args[0]
|
|
7007
|
+
});
|
|
7008
|
+
return;
|
|
7009
|
+
}
|
|
7010
|
+
if (!fieldArg.$resolvedType?.array && fieldArg.$resolvedType?.decl !== "String") {
|
|
7011
|
+
accept("error", msg, {
|
|
7012
|
+
node: expr.args[0]
|
|
7013
|
+
});
|
|
7014
|
+
}
|
|
7015
|
+
}
|
|
7016
|
+
_checkRegex(expr, accept) {
|
|
7017
|
+
const regex = expr.args[1]?.value;
|
|
7018
|
+
if (!isStringLiteral(regex)) {
|
|
7019
|
+
accept("error", "second argument must be a string literal", {
|
|
7020
|
+
node: expr.args[1]
|
|
7021
|
+
});
|
|
7022
|
+
return;
|
|
7023
|
+
}
|
|
7024
|
+
try {
|
|
7025
|
+
new RegExp(regex.value);
|
|
7026
|
+
} catch (e) {
|
|
7027
|
+
accept("error", "invalid regular expression: " + e.message, {
|
|
7028
|
+
node: expr.args[1]
|
|
7029
|
+
});
|
|
7030
|
+
}
|
|
7031
|
+
}
|
|
7032
|
+
// TODO: move this to policy plugin
|
|
6796
7033
|
_checkCheck(expr, accept) {
|
|
6797
7034
|
let valid = true;
|
|
6798
7035
|
const fieldArg = expr.args[0].value;
|
|
@@ -6864,6 +7101,24 @@ var FunctionInvocationValidator = class {
|
|
|
6864
7101
|
}
|
|
6865
7102
|
}
|
|
6866
7103
|
};
|
|
7104
|
+
_ts_decorate2([
|
|
7105
|
+
func("length"),
|
|
7106
|
+
_ts_metadata2("design:type", Function),
|
|
7107
|
+
_ts_metadata2("design:paramtypes", [
|
|
7108
|
+
typeof InvocationExpr === "undefined" ? Object : InvocationExpr,
|
|
7109
|
+
typeof ValidationAcceptor === "undefined" ? Object : ValidationAcceptor
|
|
7110
|
+
]),
|
|
7111
|
+
_ts_metadata2("design:returntype", void 0)
|
|
7112
|
+
], FunctionInvocationValidator.prototype, "_checkLength", null);
|
|
7113
|
+
_ts_decorate2([
|
|
7114
|
+
func("regex"),
|
|
7115
|
+
_ts_metadata2("design:type", Function),
|
|
7116
|
+
_ts_metadata2("design:paramtypes", [
|
|
7117
|
+
typeof InvocationExpr === "undefined" ? Object : InvocationExpr,
|
|
7118
|
+
typeof ValidationAcceptor === "undefined" ? Object : ValidationAcceptor
|
|
7119
|
+
]),
|
|
7120
|
+
_ts_metadata2("design:returntype", void 0)
|
|
7121
|
+
], FunctionInvocationValidator.prototype, "_checkRegex", null);
|
|
6867
7122
|
_ts_decorate2([
|
|
6868
7123
|
func("check"),
|
|
6869
7124
|
_ts_metadata2("design:type", Function),
|
|
@@ -6973,51 +7228,1040 @@ var ZModelValidator = class {
|
|
|
6973
7228
|
constructor(services) {
|
|
6974
7229
|
this.services = services;
|
|
6975
7230
|
}
|
|
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
7231
|
checkModel(node, accept) {
|
|
6989
|
-
|
|
7232
|
+
new SchemaValidator(this.services.shared.workspace.LangiumDocuments).validate(node, accept);
|
|
6990
7233
|
}
|
|
6991
7234
|
checkDataSource(node, accept) {
|
|
6992
|
-
|
|
7235
|
+
new DataSourceValidator().validate(node, accept);
|
|
6993
7236
|
}
|
|
6994
7237
|
checkDataModel(node, accept) {
|
|
6995
|
-
|
|
7238
|
+
new DataModelValidator().validate(node, accept);
|
|
6996
7239
|
}
|
|
6997
7240
|
checkTypeDef(node, accept) {
|
|
6998
|
-
|
|
7241
|
+
new TypeDefValidator().validate(node, accept);
|
|
6999
7242
|
}
|
|
7000
7243
|
checkEnum(node, accept) {
|
|
7001
|
-
|
|
7244
|
+
new EnumValidator().validate(node, accept);
|
|
7002
7245
|
}
|
|
7003
7246
|
checkAttribute(node, accept) {
|
|
7004
|
-
|
|
7247
|
+
new AttributeValidator().validate(node, accept);
|
|
7005
7248
|
}
|
|
7006
7249
|
checkExpression(node, accept) {
|
|
7007
|
-
|
|
7250
|
+
new ExpressionValidator().validate(node, accept);
|
|
7008
7251
|
}
|
|
7009
7252
|
checkFunctionInvocation(node, accept) {
|
|
7010
|
-
|
|
7253
|
+
new FunctionInvocationValidator().validate(node, accept);
|
|
7011
7254
|
}
|
|
7012
7255
|
checkFunctionDecl(node, accept) {
|
|
7013
|
-
|
|
7256
|
+
new FunctionDeclValidator().validate(node, accept);
|
|
7014
7257
|
}
|
|
7015
7258
|
};
|
|
7016
7259
|
|
|
7017
|
-
// src/zmodel-
|
|
7260
|
+
// src/zmodel-comment-provider.ts
|
|
7018
7261
|
var import_langium7 = require("langium");
|
|
7019
7262
|
var import_ts_pattern2 = require("ts-pattern");
|
|
7020
|
-
var
|
|
7263
|
+
var ZModelCommentProvider = class extends import_langium7.DefaultCommentProvider {
|
|
7264
|
+
static {
|
|
7265
|
+
__name(this, "ZModelCommentProvider");
|
|
7266
|
+
}
|
|
7267
|
+
getComment(node) {
|
|
7268
|
+
let comment = super.getComment(node);
|
|
7269
|
+
if (!comment) {
|
|
7270
|
+
comment = (0, import_ts_pattern2.match)(node).when(isDataModel, (d) => `/**
|
|
7271
|
+
* Model *${d.name}*
|
|
7272
|
+
*/`).when(isTypeDef, (d) => `/**
|
|
7273
|
+
* Type *${d.name}*
|
|
7274
|
+
*/`).when(isEnum, (e) => `/**
|
|
7275
|
+
* Enum *${e.name}*
|
|
7276
|
+
*/`).when(isEnumField, (f) => `/**
|
|
7277
|
+
* Value of enum *${f.$container?.name}*
|
|
7278
|
+
*/`).when(isDataField, (f) => `/**
|
|
7279
|
+
* Field of *${f.$container?.name}*
|
|
7280
|
+
*/`).when(isFunctionDecl, (f) => `/**
|
|
7281
|
+
* Function *${f.name}*
|
|
7282
|
+
*/`).otherwise(() => "");
|
|
7283
|
+
}
|
|
7284
|
+
return comment;
|
|
7285
|
+
}
|
|
7286
|
+
};
|
|
7287
|
+
|
|
7288
|
+
// src/zmodel-completion-provider.ts
|
|
7289
|
+
var import_lsp = require("langium/lsp");
|
|
7290
|
+
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
7291
|
+
var import_ts_pattern3 = require("ts-pattern");
|
|
7292
|
+
var import_vscode_languageserver = require("vscode-languageserver");
|
|
7293
|
+
|
|
7294
|
+
// src/zmodel-code-generator.ts
|
|
7295
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
7296
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
7297
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
7298
|
+
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;
|
|
7299
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7300
|
+
}
|
|
7301
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
7302
|
+
function _ts_metadata3(k, v) {
|
|
7303
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
7304
|
+
}
|
|
7305
|
+
__name(_ts_metadata3, "_ts_metadata");
|
|
7306
|
+
var generationHandlers = /* @__PURE__ */ new Map();
|
|
7307
|
+
function gen(name) {
|
|
7308
|
+
return function(_target, _propertyKey, descriptor) {
|
|
7309
|
+
if (!generationHandlers.get(name)) {
|
|
7310
|
+
generationHandlers.set(name, descriptor);
|
|
7311
|
+
}
|
|
7312
|
+
return descriptor;
|
|
7313
|
+
};
|
|
7314
|
+
}
|
|
7315
|
+
__name(gen, "gen");
|
|
7316
|
+
var ZModelCodeGenerator = class {
|
|
7317
|
+
static {
|
|
7318
|
+
__name(this, "ZModelCodeGenerator");
|
|
7319
|
+
}
|
|
7320
|
+
options;
|
|
7321
|
+
constructor(options) {
|
|
7322
|
+
this.options = {
|
|
7323
|
+
binaryExprNumberOfSpaces: options?.binaryExprNumberOfSpaces ?? 1,
|
|
7324
|
+
unaryExprNumberOfSpaces: options?.unaryExprNumberOfSpaces ?? 0,
|
|
7325
|
+
indent: options?.indent ?? 4,
|
|
7326
|
+
quote: options?.quote ?? "single"
|
|
7327
|
+
};
|
|
7328
|
+
}
|
|
7329
|
+
/**
|
|
7330
|
+
* Generates ZModel source code from AST.
|
|
7331
|
+
*/
|
|
7332
|
+
generate(ast) {
|
|
7333
|
+
const handler = generationHandlers.get(ast.$type);
|
|
7334
|
+
if (!handler) {
|
|
7335
|
+
throw new Error(`No generation handler found for ${ast.$type}`);
|
|
7336
|
+
}
|
|
7337
|
+
return handler.value.call(this, ast);
|
|
7338
|
+
}
|
|
7339
|
+
_generateModel(ast) {
|
|
7340
|
+
return ast.declarations.map((d) => this.generate(d)).join("\n\n");
|
|
7341
|
+
}
|
|
7342
|
+
_generateDataSource(ast) {
|
|
7343
|
+
return `datasource ${ast.name} {
|
|
7344
|
+
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
7345
|
+
}`;
|
|
7346
|
+
}
|
|
7347
|
+
_generateEnum(ast) {
|
|
7348
|
+
return `enum ${ast.name} {
|
|
7349
|
+
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
7350
|
+
}`;
|
|
7351
|
+
}
|
|
7352
|
+
_generateEnumField(ast) {
|
|
7353
|
+
return `${ast.name}${ast.attributes.length > 0 ? " " + ast.attributes.map((x) => this.generate(x)).join(" ") : ""}`;
|
|
7354
|
+
}
|
|
7355
|
+
_generateGenerator(ast) {
|
|
7356
|
+
return `generator ${ast.name} {
|
|
7357
|
+
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
7358
|
+
}`;
|
|
7359
|
+
}
|
|
7360
|
+
_generateConfigField(ast) {
|
|
7361
|
+
return `${ast.name} = ${this.generate(ast.value)}`;
|
|
7362
|
+
}
|
|
7363
|
+
_generateConfigArrayExpr(ast) {
|
|
7364
|
+
return `[${ast.items.map((x) => this.generate(x)).join(", ")}]`;
|
|
7365
|
+
}
|
|
7366
|
+
_generateConfigInvocationExpr(ast) {
|
|
7367
|
+
if (ast.args.length === 0) {
|
|
7368
|
+
return ast.name;
|
|
7369
|
+
} else {
|
|
7370
|
+
return `${ast.name}(${ast.args.map((x) => (x.name ? x.name + ": " : "") + this.generate(x.value)).join(", ")})`;
|
|
7371
|
+
}
|
|
7372
|
+
}
|
|
7373
|
+
_generatePlugin(ast) {
|
|
7374
|
+
return `plugin ${ast.name} {
|
|
7375
|
+
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
7376
|
+
}`;
|
|
7377
|
+
}
|
|
7378
|
+
_generatePluginField(ast) {
|
|
7379
|
+
return `${ast.name} = ${this.generate(ast.value)}`;
|
|
7380
|
+
}
|
|
7381
|
+
_generateDataModel(ast) {
|
|
7382
|
+
return `${ast.isView ? "view" : "model"} ${ast.name}${ast.mixins.length > 0 ? " mixes " + ast.mixins.map((x) => x.ref?.name).join(", ") : ""} {
|
|
7383
|
+
${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") : ""}
|
|
7384
|
+
}`;
|
|
7385
|
+
}
|
|
7386
|
+
_generateDataField(ast) {
|
|
7387
|
+
return `${ast.name} ${this.fieldType(ast.type)}${ast.attributes.length > 0 ? " " + ast.attributes.map((x) => this.generate(x)).join(" ") : ""}`;
|
|
7388
|
+
}
|
|
7389
|
+
fieldType(type) {
|
|
7390
|
+
const baseType = type.type ? type.type : type.$type == "DataFieldType" && type.unsupported ? "Unsupported(" + this.generate(type.unsupported.value) + ")" : type.reference?.$refText;
|
|
7391
|
+
return `${baseType}${type.array ? "[]" : ""}${type.optional ? "?" : ""}`;
|
|
7392
|
+
}
|
|
7393
|
+
_generateDataModelAttribute(ast) {
|
|
7394
|
+
return this.attribute(ast);
|
|
7395
|
+
}
|
|
7396
|
+
_generateDataFieldAttribute(ast) {
|
|
7397
|
+
return this.attribute(ast);
|
|
7398
|
+
}
|
|
7399
|
+
attribute(ast) {
|
|
7400
|
+
const args = ast.args.length ? `(${ast.args.map((x) => this.generate(x)).join(", ")})` : "";
|
|
7401
|
+
return `${resolved(ast.decl).name}${args}`;
|
|
7402
|
+
}
|
|
7403
|
+
_generateAttributeArg(ast) {
|
|
7404
|
+
if (ast.name) {
|
|
7405
|
+
return `${ast.name}: ${this.generate(ast.value)}`;
|
|
7406
|
+
} else {
|
|
7407
|
+
return this.generate(ast.value);
|
|
7408
|
+
}
|
|
7409
|
+
}
|
|
7410
|
+
_generateObjectExpr(ast) {
|
|
7411
|
+
return `{ ${ast.fields.map((field) => this.objectField(field)).join(", ")} }`;
|
|
7412
|
+
}
|
|
7413
|
+
objectField(field) {
|
|
7414
|
+
return `${field.name}: ${this.generate(field.value)}`;
|
|
7415
|
+
}
|
|
7416
|
+
_generateArrayExpr(ast) {
|
|
7417
|
+
return `[${ast.items.map((item) => this.generate(item)).join(", ")}]`;
|
|
7418
|
+
}
|
|
7419
|
+
_generateLiteralExpr(ast) {
|
|
7420
|
+
return this.options.quote === "single" ? `'${ast.value}'` : `"${ast.value}"`;
|
|
7421
|
+
}
|
|
7422
|
+
_generateNumberLiteral(ast) {
|
|
7423
|
+
return ast.value.toString();
|
|
7424
|
+
}
|
|
7425
|
+
_generateBooleanLiteral(ast) {
|
|
7426
|
+
return ast.value.toString();
|
|
7427
|
+
}
|
|
7428
|
+
_generateUnaryExpr(ast) {
|
|
7429
|
+
return `${ast.operator}${this.unaryExprSpace}${this.generate(ast.operand)}`;
|
|
7430
|
+
}
|
|
7431
|
+
_generateBinaryExpr(ast) {
|
|
7432
|
+
const operator = ast.operator;
|
|
7433
|
+
const isCollectionPredicate2 = this.isCollectionPredicateOperator(operator);
|
|
7434
|
+
const rightExpr = this.generate(ast.right);
|
|
7435
|
+
const { left: isLeftParenthesis, right: isRightParenthesis } = this.isParenthesesNeededForBinaryExpr(ast);
|
|
7436
|
+
return `${isLeftParenthesis ? "(" : ""}${this.generate(ast.left)}${isLeftParenthesis ? ")" : ""}${isCollectionPredicate2 ? "" : this.binaryExprSpace}${operator}${isCollectionPredicate2 ? "" : this.binaryExprSpace}${isRightParenthesis ? "(" : ""}${isCollectionPredicate2 ? `[${rightExpr}]` : rightExpr}${isRightParenthesis ? ")" : ""}`;
|
|
7437
|
+
}
|
|
7438
|
+
_generateReferenceExpr(ast) {
|
|
7439
|
+
const args = ast.args.length ? `(${ast.args.map((x) => this.generate(x)).join(", ")})` : "";
|
|
7440
|
+
return `${ast.target.ref?.name}${args}`;
|
|
7441
|
+
}
|
|
7442
|
+
_generateReferenceArg(ast) {
|
|
7443
|
+
return `${ast.name}:${this.generate(ast.value)}`;
|
|
7444
|
+
}
|
|
7445
|
+
_generateMemberExpr(ast) {
|
|
7446
|
+
return `${this.generate(ast.operand)}.${ast.member.ref?.name}`;
|
|
7447
|
+
}
|
|
7448
|
+
_generateInvocationExpr(ast) {
|
|
7449
|
+
return `${ast.function.ref?.name}(${ast.args.map((x) => this.argument(x)).join(", ")})`;
|
|
7450
|
+
}
|
|
7451
|
+
_generateNullExpr() {
|
|
7452
|
+
return "null";
|
|
7453
|
+
}
|
|
7454
|
+
_generateThisExpr() {
|
|
7455
|
+
return "this";
|
|
7456
|
+
}
|
|
7457
|
+
_generateAttribute(ast) {
|
|
7458
|
+
return `attribute ${ast.name}(${ast.params.map((x) => this.generate(x)).join(", ")})`;
|
|
7459
|
+
}
|
|
7460
|
+
_generateAttributeParam(ast) {
|
|
7461
|
+
return `${ast.default ? "_ " : ""}${ast.name}: ${this.generate(ast.type)}`;
|
|
7462
|
+
}
|
|
7463
|
+
_generateAttributeParamType(ast) {
|
|
7464
|
+
return `${ast.type ?? ast.reference?.$refText}${ast.array ? "[]" : ""}${ast.optional ? "?" : ""}`;
|
|
7465
|
+
}
|
|
7466
|
+
_generateFunctionDecl(ast) {
|
|
7467
|
+
return `function ${ast.name}(${ast.params.map((x) => this.generate(x)).join(", ")}) ${ast.returnType ? ": " + this.generate(ast.returnType) : ""} {}`;
|
|
7468
|
+
}
|
|
7469
|
+
_generateFunctionParam(ast) {
|
|
7470
|
+
return `${ast.name}: ${this.generate(ast.type)}`;
|
|
7471
|
+
}
|
|
7472
|
+
_generateFunctionParamType(ast) {
|
|
7473
|
+
return `${ast.type ?? ast.reference?.$refText}${ast.array ? "[]" : ""}`;
|
|
7474
|
+
}
|
|
7475
|
+
_generateTypeDef(ast) {
|
|
7476
|
+
return `type ${ast.name} {
|
|
7477
|
+
${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") : ""}
|
|
7478
|
+
}`;
|
|
7479
|
+
}
|
|
7480
|
+
argument(ast) {
|
|
7481
|
+
return this.generate(ast.value);
|
|
7482
|
+
}
|
|
7483
|
+
get binaryExprSpace() {
|
|
7484
|
+
return " ".repeat(this.options.binaryExprNumberOfSpaces);
|
|
7485
|
+
}
|
|
7486
|
+
get unaryExprSpace() {
|
|
7487
|
+
return " ".repeat(this.options.unaryExprNumberOfSpaces);
|
|
7488
|
+
}
|
|
7489
|
+
get indent() {
|
|
7490
|
+
return " ".repeat(this.options.indent);
|
|
7491
|
+
}
|
|
7492
|
+
isParenthesesNeededForBinaryExpr(ast) {
|
|
7493
|
+
const result = {
|
|
7494
|
+
left: false,
|
|
7495
|
+
right: false
|
|
7496
|
+
};
|
|
7497
|
+
const operator = ast.operator;
|
|
7498
|
+
const isCollectionPredicate2 = this.isCollectionPredicateOperator(operator);
|
|
7499
|
+
const currentPriority = BinaryExprOperatorPriority[operator];
|
|
7500
|
+
if (ast.left.$type === BinaryExpr && BinaryExprOperatorPriority[ast.left["operator"]] < currentPriority) {
|
|
7501
|
+
result.left = true;
|
|
7502
|
+
}
|
|
7503
|
+
if (!isCollectionPredicate2 && ast.right.$type === BinaryExpr && BinaryExprOperatorPriority[ast.right["operator"]] <= currentPriority) {
|
|
7504
|
+
result.right = true;
|
|
7505
|
+
}
|
|
7506
|
+
return result;
|
|
7507
|
+
}
|
|
7508
|
+
isCollectionPredicateOperator(op) {
|
|
7509
|
+
return [
|
|
7510
|
+
"?",
|
|
7511
|
+
"!",
|
|
7512
|
+
"^"
|
|
7513
|
+
].includes(op);
|
|
7514
|
+
}
|
|
7515
|
+
};
|
|
7516
|
+
_ts_decorate3([
|
|
7517
|
+
gen(Model),
|
|
7518
|
+
_ts_metadata3("design:type", Function),
|
|
7519
|
+
_ts_metadata3("design:paramtypes", [
|
|
7520
|
+
typeof Model === "undefined" ? Object : Model
|
|
7521
|
+
]),
|
|
7522
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7523
|
+
], ZModelCodeGenerator.prototype, "_generateModel", null);
|
|
7524
|
+
_ts_decorate3([
|
|
7525
|
+
gen(DataSource),
|
|
7526
|
+
_ts_metadata3("design:type", Function),
|
|
7527
|
+
_ts_metadata3("design:paramtypes", [
|
|
7528
|
+
typeof DataSource === "undefined" ? Object : DataSource
|
|
7529
|
+
]),
|
|
7530
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7531
|
+
], ZModelCodeGenerator.prototype, "_generateDataSource", null);
|
|
7532
|
+
_ts_decorate3([
|
|
7533
|
+
gen(Enum),
|
|
7534
|
+
_ts_metadata3("design:type", Function),
|
|
7535
|
+
_ts_metadata3("design:paramtypes", [
|
|
7536
|
+
typeof Enum === "undefined" ? Object : Enum
|
|
7537
|
+
]),
|
|
7538
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7539
|
+
], ZModelCodeGenerator.prototype, "_generateEnum", null);
|
|
7540
|
+
_ts_decorate3([
|
|
7541
|
+
gen(EnumField),
|
|
7542
|
+
_ts_metadata3("design:type", Function),
|
|
7543
|
+
_ts_metadata3("design:paramtypes", [
|
|
7544
|
+
typeof EnumField === "undefined" ? Object : EnumField
|
|
7545
|
+
]),
|
|
7546
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7547
|
+
], ZModelCodeGenerator.prototype, "_generateEnumField", null);
|
|
7548
|
+
_ts_decorate3([
|
|
7549
|
+
gen(GeneratorDecl),
|
|
7550
|
+
_ts_metadata3("design:type", Function),
|
|
7551
|
+
_ts_metadata3("design:paramtypes", [
|
|
7552
|
+
typeof GeneratorDecl === "undefined" ? Object : GeneratorDecl
|
|
7553
|
+
]),
|
|
7554
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7555
|
+
], ZModelCodeGenerator.prototype, "_generateGenerator", null);
|
|
7556
|
+
_ts_decorate3([
|
|
7557
|
+
gen(ConfigField),
|
|
7558
|
+
_ts_metadata3("design:type", Function),
|
|
7559
|
+
_ts_metadata3("design:paramtypes", [
|
|
7560
|
+
typeof ConfigField === "undefined" ? Object : ConfigField
|
|
7561
|
+
]),
|
|
7562
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7563
|
+
], ZModelCodeGenerator.prototype, "_generateConfigField", null);
|
|
7564
|
+
_ts_decorate3([
|
|
7565
|
+
gen(ConfigArrayExpr),
|
|
7566
|
+
_ts_metadata3("design:type", Function),
|
|
7567
|
+
_ts_metadata3("design:paramtypes", [
|
|
7568
|
+
typeof ConfigArrayExpr === "undefined" ? Object : ConfigArrayExpr
|
|
7569
|
+
]),
|
|
7570
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7571
|
+
], ZModelCodeGenerator.prototype, "_generateConfigArrayExpr", null);
|
|
7572
|
+
_ts_decorate3([
|
|
7573
|
+
gen(ConfigInvocationExpr),
|
|
7574
|
+
_ts_metadata3("design:type", Function),
|
|
7575
|
+
_ts_metadata3("design:paramtypes", [
|
|
7576
|
+
typeof ConfigInvocationExpr === "undefined" ? Object : ConfigInvocationExpr
|
|
7577
|
+
]),
|
|
7578
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7579
|
+
], ZModelCodeGenerator.prototype, "_generateConfigInvocationExpr", null);
|
|
7580
|
+
_ts_decorate3([
|
|
7581
|
+
gen(Plugin),
|
|
7582
|
+
_ts_metadata3("design:type", Function),
|
|
7583
|
+
_ts_metadata3("design:paramtypes", [
|
|
7584
|
+
typeof Plugin === "undefined" ? Object : Plugin
|
|
7585
|
+
]),
|
|
7586
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7587
|
+
], ZModelCodeGenerator.prototype, "_generatePlugin", null);
|
|
7588
|
+
_ts_decorate3([
|
|
7589
|
+
gen(PluginField),
|
|
7590
|
+
_ts_metadata3("design:type", Function),
|
|
7591
|
+
_ts_metadata3("design:paramtypes", [
|
|
7592
|
+
typeof PluginField === "undefined" ? Object : PluginField
|
|
7593
|
+
]),
|
|
7594
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7595
|
+
], ZModelCodeGenerator.prototype, "_generatePluginField", null);
|
|
7596
|
+
_ts_decorate3([
|
|
7597
|
+
gen(DataModel),
|
|
7598
|
+
_ts_metadata3("design:type", Function),
|
|
7599
|
+
_ts_metadata3("design:paramtypes", [
|
|
7600
|
+
typeof DataModel === "undefined" ? Object : DataModel
|
|
7601
|
+
]),
|
|
7602
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7603
|
+
], ZModelCodeGenerator.prototype, "_generateDataModel", null);
|
|
7604
|
+
_ts_decorate3([
|
|
7605
|
+
gen(DataField),
|
|
7606
|
+
_ts_metadata3("design:type", Function),
|
|
7607
|
+
_ts_metadata3("design:paramtypes", [
|
|
7608
|
+
typeof DataField === "undefined" ? Object : DataField
|
|
7609
|
+
]),
|
|
7610
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7611
|
+
], ZModelCodeGenerator.prototype, "_generateDataField", null);
|
|
7612
|
+
_ts_decorate3([
|
|
7613
|
+
gen(DataModelAttribute),
|
|
7614
|
+
_ts_metadata3("design:type", Function),
|
|
7615
|
+
_ts_metadata3("design:paramtypes", [
|
|
7616
|
+
typeof DataModelAttribute === "undefined" ? Object : DataModelAttribute
|
|
7617
|
+
]),
|
|
7618
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7619
|
+
], ZModelCodeGenerator.prototype, "_generateDataModelAttribute", null);
|
|
7620
|
+
_ts_decorate3([
|
|
7621
|
+
gen(DataFieldAttribute),
|
|
7622
|
+
_ts_metadata3("design:type", Function),
|
|
7623
|
+
_ts_metadata3("design:paramtypes", [
|
|
7624
|
+
typeof DataFieldAttribute === "undefined" ? Object : DataFieldAttribute
|
|
7625
|
+
]),
|
|
7626
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7627
|
+
], ZModelCodeGenerator.prototype, "_generateDataFieldAttribute", null);
|
|
7628
|
+
_ts_decorate3([
|
|
7629
|
+
gen(AttributeArg),
|
|
7630
|
+
_ts_metadata3("design:type", Function),
|
|
7631
|
+
_ts_metadata3("design:paramtypes", [
|
|
7632
|
+
typeof AttributeArg === "undefined" ? Object : AttributeArg
|
|
7633
|
+
]),
|
|
7634
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7635
|
+
], ZModelCodeGenerator.prototype, "_generateAttributeArg", null);
|
|
7636
|
+
_ts_decorate3([
|
|
7637
|
+
gen(ObjectExpr),
|
|
7638
|
+
_ts_metadata3("design:type", Function),
|
|
7639
|
+
_ts_metadata3("design:paramtypes", [
|
|
7640
|
+
typeof ObjectExpr === "undefined" ? Object : ObjectExpr
|
|
7641
|
+
]),
|
|
7642
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7643
|
+
], ZModelCodeGenerator.prototype, "_generateObjectExpr", null);
|
|
7644
|
+
_ts_decorate3([
|
|
7645
|
+
gen(ArrayExpr),
|
|
7646
|
+
_ts_metadata3("design:type", Function),
|
|
7647
|
+
_ts_metadata3("design:paramtypes", [
|
|
7648
|
+
typeof ArrayExpr === "undefined" ? Object : ArrayExpr
|
|
7649
|
+
]),
|
|
7650
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7651
|
+
], ZModelCodeGenerator.prototype, "_generateArrayExpr", null);
|
|
7652
|
+
_ts_decorate3([
|
|
7653
|
+
gen(StringLiteral),
|
|
7654
|
+
_ts_metadata3("design:type", Function),
|
|
7655
|
+
_ts_metadata3("design:paramtypes", [
|
|
7656
|
+
typeof LiteralExpr === "undefined" ? Object : LiteralExpr
|
|
7657
|
+
]),
|
|
7658
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7659
|
+
], ZModelCodeGenerator.prototype, "_generateLiteralExpr", null);
|
|
7660
|
+
_ts_decorate3([
|
|
7661
|
+
gen(NumberLiteral),
|
|
7662
|
+
_ts_metadata3("design:type", Function),
|
|
7663
|
+
_ts_metadata3("design:paramtypes", [
|
|
7664
|
+
typeof NumberLiteral === "undefined" ? Object : NumberLiteral
|
|
7665
|
+
]),
|
|
7666
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7667
|
+
], ZModelCodeGenerator.prototype, "_generateNumberLiteral", null);
|
|
7668
|
+
_ts_decorate3([
|
|
7669
|
+
gen(BooleanLiteral),
|
|
7670
|
+
_ts_metadata3("design:type", Function),
|
|
7671
|
+
_ts_metadata3("design:paramtypes", [
|
|
7672
|
+
typeof BooleanLiteral === "undefined" ? Object : BooleanLiteral
|
|
7673
|
+
]),
|
|
7674
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7675
|
+
], ZModelCodeGenerator.prototype, "_generateBooleanLiteral", null);
|
|
7676
|
+
_ts_decorate3([
|
|
7677
|
+
gen(UnaryExpr),
|
|
7678
|
+
_ts_metadata3("design:type", Function),
|
|
7679
|
+
_ts_metadata3("design:paramtypes", [
|
|
7680
|
+
typeof UnaryExpr === "undefined" ? Object : UnaryExpr
|
|
7681
|
+
]),
|
|
7682
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7683
|
+
], ZModelCodeGenerator.prototype, "_generateUnaryExpr", null);
|
|
7684
|
+
_ts_decorate3([
|
|
7685
|
+
gen(BinaryExpr),
|
|
7686
|
+
_ts_metadata3("design:type", Function),
|
|
7687
|
+
_ts_metadata3("design:paramtypes", [
|
|
7688
|
+
typeof BinaryExpr === "undefined" ? Object : BinaryExpr
|
|
7689
|
+
]),
|
|
7690
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7691
|
+
], ZModelCodeGenerator.prototype, "_generateBinaryExpr", null);
|
|
7692
|
+
_ts_decorate3([
|
|
7693
|
+
gen(ReferenceExpr),
|
|
7694
|
+
_ts_metadata3("design:type", Function),
|
|
7695
|
+
_ts_metadata3("design:paramtypes", [
|
|
7696
|
+
typeof ReferenceExpr === "undefined" ? Object : ReferenceExpr
|
|
7697
|
+
]),
|
|
7698
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7699
|
+
], ZModelCodeGenerator.prototype, "_generateReferenceExpr", null);
|
|
7700
|
+
_ts_decorate3([
|
|
7701
|
+
gen(ReferenceArg),
|
|
7702
|
+
_ts_metadata3("design:type", Function),
|
|
7703
|
+
_ts_metadata3("design:paramtypes", [
|
|
7704
|
+
typeof ReferenceArg === "undefined" ? Object : ReferenceArg
|
|
7705
|
+
]),
|
|
7706
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7707
|
+
], ZModelCodeGenerator.prototype, "_generateReferenceArg", null);
|
|
7708
|
+
_ts_decorate3([
|
|
7709
|
+
gen(MemberAccessExpr),
|
|
7710
|
+
_ts_metadata3("design:type", Function),
|
|
7711
|
+
_ts_metadata3("design:paramtypes", [
|
|
7712
|
+
typeof MemberAccessExpr === "undefined" ? Object : MemberAccessExpr
|
|
7713
|
+
]),
|
|
7714
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7715
|
+
], ZModelCodeGenerator.prototype, "_generateMemberExpr", null);
|
|
7716
|
+
_ts_decorate3([
|
|
7717
|
+
gen(InvocationExpr),
|
|
7718
|
+
_ts_metadata3("design:type", Function),
|
|
7719
|
+
_ts_metadata3("design:paramtypes", [
|
|
7720
|
+
typeof InvocationExpr === "undefined" ? Object : InvocationExpr
|
|
7721
|
+
]),
|
|
7722
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7723
|
+
], ZModelCodeGenerator.prototype, "_generateInvocationExpr", null);
|
|
7724
|
+
_ts_decorate3([
|
|
7725
|
+
gen(NullExpr),
|
|
7726
|
+
_ts_metadata3("design:type", Function),
|
|
7727
|
+
_ts_metadata3("design:paramtypes", []),
|
|
7728
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7729
|
+
], ZModelCodeGenerator.prototype, "_generateNullExpr", null);
|
|
7730
|
+
_ts_decorate3([
|
|
7731
|
+
gen(ThisExpr),
|
|
7732
|
+
_ts_metadata3("design:type", Function),
|
|
7733
|
+
_ts_metadata3("design:paramtypes", []),
|
|
7734
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7735
|
+
], ZModelCodeGenerator.prototype, "_generateThisExpr", null);
|
|
7736
|
+
_ts_decorate3([
|
|
7737
|
+
gen(Attribute),
|
|
7738
|
+
_ts_metadata3("design:type", Function),
|
|
7739
|
+
_ts_metadata3("design:paramtypes", [
|
|
7740
|
+
typeof Attribute === "undefined" ? Object : Attribute
|
|
7741
|
+
]),
|
|
7742
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7743
|
+
], ZModelCodeGenerator.prototype, "_generateAttribute", null);
|
|
7744
|
+
_ts_decorate3([
|
|
7745
|
+
gen(AttributeParam),
|
|
7746
|
+
_ts_metadata3("design:type", Function),
|
|
7747
|
+
_ts_metadata3("design:paramtypes", [
|
|
7748
|
+
typeof AttributeParam === "undefined" ? Object : AttributeParam
|
|
7749
|
+
]),
|
|
7750
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7751
|
+
], ZModelCodeGenerator.prototype, "_generateAttributeParam", null);
|
|
7752
|
+
_ts_decorate3([
|
|
7753
|
+
gen(AttributeParamType),
|
|
7754
|
+
_ts_metadata3("design:type", Function),
|
|
7755
|
+
_ts_metadata3("design:paramtypes", [
|
|
7756
|
+
typeof AttributeParamType === "undefined" ? Object : AttributeParamType
|
|
7757
|
+
]),
|
|
7758
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7759
|
+
], ZModelCodeGenerator.prototype, "_generateAttributeParamType", null);
|
|
7760
|
+
_ts_decorate3([
|
|
7761
|
+
gen(FunctionDecl),
|
|
7762
|
+
_ts_metadata3("design:type", Function),
|
|
7763
|
+
_ts_metadata3("design:paramtypes", [
|
|
7764
|
+
typeof FunctionDecl === "undefined" ? Object : FunctionDecl
|
|
7765
|
+
]),
|
|
7766
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7767
|
+
], ZModelCodeGenerator.prototype, "_generateFunctionDecl", null);
|
|
7768
|
+
_ts_decorate3([
|
|
7769
|
+
gen(FunctionParam),
|
|
7770
|
+
_ts_metadata3("design:type", Function),
|
|
7771
|
+
_ts_metadata3("design:paramtypes", [
|
|
7772
|
+
typeof FunctionParam === "undefined" ? Object : FunctionParam
|
|
7773
|
+
]),
|
|
7774
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7775
|
+
], ZModelCodeGenerator.prototype, "_generateFunctionParam", null);
|
|
7776
|
+
_ts_decorate3([
|
|
7777
|
+
gen(FunctionParamType),
|
|
7778
|
+
_ts_metadata3("design:type", Function),
|
|
7779
|
+
_ts_metadata3("design:paramtypes", [
|
|
7780
|
+
typeof FunctionParamType === "undefined" ? Object : FunctionParamType
|
|
7781
|
+
]),
|
|
7782
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7783
|
+
], ZModelCodeGenerator.prototype, "_generateFunctionParamType", null);
|
|
7784
|
+
_ts_decorate3([
|
|
7785
|
+
gen(TypeDef),
|
|
7786
|
+
_ts_metadata3("design:type", Function),
|
|
7787
|
+
_ts_metadata3("design:paramtypes", [
|
|
7788
|
+
typeof TypeDef === "undefined" ? Object : TypeDef
|
|
7789
|
+
]),
|
|
7790
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7791
|
+
], ZModelCodeGenerator.prototype, "_generateTypeDef", null);
|
|
7792
|
+
|
|
7793
|
+
// src/zmodel-completion-provider.ts
|
|
7794
|
+
var ZModelCompletionProvider = class extends import_lsp.DefaultCompletionProvider {
|
|
7795
|
+
static {
|
|
7796
|
+
__name(this, "ZModelCompletionProvider");
|
|
7797
|
+
}
|
|
7798
|
+
services;
|
|
7799
|
+
constructor(services) {
|
|
7800
|
+
super(services), this.services = services;
|
|
7801
|
+
}
|
|
7802
|
+
completionOptions = {
|
|
7803
|
+
triggerCharacters: [
|
|
7804
|
+
"@",
|
|
7805
|
+
"(",
|
|
7806
|
+
",",
|
|
7807
|
+
"."
|
|
7808
|
+
]
|
|
7809
|
+
};
|
|
7810
|
+
async getCompletion(document, params) {
|
|
7811
|
+
try {
|
|
7812
|
+
return await super.getCompletion(document, params);
|
|
7813
|
+
} catch (e) {
|
|
7814
|
+
console.error("Completion error:", e.message);
|
|
7815
|
+
return void 0;
|
|
7816
|
+
}
|
|
7817
|
+
}
|
|
7818
|
+
completionFor(context, next, acceptor) {
|
|
7819
|
+
if (isDataModelAttribute(context.node) || isDataFieldAttribute(context.node)) {
|
|
7820
|
+
const completions = this.getCompletionFromHint(context.node);
|
|
7821
|
+
if (completions) {
|
|
7822
|
+
completions.forEach((c) => acceptor(context, c));
|
|
7823
|
+
return;
|
|
7824
|
+
}
|
|
7825
|
+
}
|
|
7826
|
+
return super.completionFor(context, next, acceptor);
|
|
7827
|
+
}
|
|
7828
|
+
getCompletionFromHint(contextNode) {
|
|
7829
|
+
const unfilledParams = this.getUnfilledAttributeParams(contextNode);
|
|
7830
|
+
const nextParam = unfilledParams[0];
|
|
7831
|
+
if (!nextParam) {
|
|
7832
|
+
return void 0;
|
|
7833
|
+
}
|
|
7834
|
+
const hintAttr = getAttribute(nextParam, "@@@completionHint");
|
|
7835
|
+
if (hintAttr) {
|
|
7836
|
+
const hint = hintAttr.args[0];
|
|
7837
|
+
if (hint?.value) {
|
|
7838
|
+
if (isArrayExpr(hint.value)) {
|
|
7839
|
+
return hint.value.items.map((item) => {
|
|
7840
|
+
return {
|
|
7841
|
+
label: `${item.value}`,
|
|
7842
|
+
kind: import_vscode_languageserver.CompletionItemKind.Value,
|
|
7843
|
+
detail: "Parameter",
|
|
7844
|
+
sortText: "0"
|
|
7845
|
+
};
|
|
7846
|
+
});
|
|
7847
|
+
}
|
|
7848
|
+
}
|
|
7849
|
+
}
|
|
7850
|
+
return void 0;
|
|
7851
|
+
}
|
|
7852
|
+
// TODO: this doesn't work when the file contains parse errors
|
|
7853
|
+
getUnfilledAttributeParams(contextNode) {
|
|
7854
|
+
try {
|
|
7855
|
+
const params = contextNode.decl.ref?.params;
|
|
7856
|
+
if (params) {
|
|
7857
|
+
const args = contextNode.args;
|
|
7858
|
+
let unfilledParams = [
|
|
7859
|
+
...params
|
|
7860
|
+
];
|
|
7861
|
+
args.forEach((arg) => {
|
|
7862
|
+
if (arg.name) {
|
|
7863
|
+
unfilledParams = unfilledParams.filter((p) => p.name !== arg.name);
|
|
7864
|
+
} else {
|
|
7865
|
+
unfilledParams.shift();
|
|
7866
|
+
}
|
|
7867
|
+
});
|
|
7868
|
+
return unfilledParams;
|
|
7869
|
+
}
|
|
7870
|
+
} catch {
|
|
7871
|
+
}
|
|
7872
|
+
return [];
|
|
7873
|
+
}
|
|
7874
|
+
completionForCrossReference(context, crossRef, acceptor) {
|
|
7875
|
+
if (crossRef.property === "member" && !isMemberAccessExpr(context.node)) {
|
|
7876
|
+
return;
|
|
7877
|
+
}
|
|
7878
|
+
const customAcceptor = /* @__PURE__ */ __name((context2, item) => {
|
|
7879
|
+
if (item.insertText?.startsWith("@@@") || item.label?.startsWith("@@@")) {
|
|
7880
|
+
return;
|
|
7881
|
+
}
|
|
7882
|
+
if ("nodeDescription" in item) {
|
|
7883
|
+
const node = this.getAstNode(item.nodeDescription);
|
|
7884
|
+
if (!node) {
|
|
7885
|
+
return;
|
|
7886
|
+
}
|
|
7887
|
+
if ((isEnum(node) || isEnumField(node)) && isFromStdlib(node)) {
|
|
7888
|
+
return;
|
|
7889
|
+
}
|
|
7890
|
+
if ((isDataModelAttribute(context2.node) || isDataFieldAttribute(context2.node)) && !this.filterAttributeApplicationCompletion(context2.node, node)) {
|
|
7891
|
+
return;
|
|
7892
|
+
}
|
|
7893
|
+
}
|
|
7894
|
+
acceptor(context2, item);
|
|
7895
|
+
}, "customAcceptor");
|
|
7896
|
+
return super.completionForCrossReference(context, crossRef, customAcceptor);
|
|
7897
|
+
}
|
|
7898
|
+
completionForKeyword(context, keyword, acceptor) {
|
|
7899
|
+
const customAcceptor = /* @__PURE__ */ __name((context2, item) => {
|
|
7900
|
+
if (!this.filterKeywordForContext(context2, keyword.value)) {
|
|
7901
|
+
return;
|
|
7902
|
+
}
|
|
7903
|
+
acceptor(context2, item);
|
|
7904
|
+
}, "customAcceptor");
|
|
7905
|
+
return super.completionForKeyword(context, keyword, customAcceptor);
|
|
7906
|
+
}
|
|
7907
|
+
filterKeywordForContext(context, keyword) {
|
|
7908
|
+
if (isInvocationExpr(context.node)) {
|
|
7909
|
+
return [
|
|
7910
|
+
"true",
|
|
7911
|
+
"false",
|
|
7912
|
+
"null",
|
|
7913
|
+
"this"
|
|
7914
|
+
].includes(keyword);
|
|
7915
|
+
} else if (isDataModelAttribute(context.node) || isDataFieldAttribute(context.node)) {
|
|
7916
|
+
const exprContext = this.getAttributeContextType(context.node);
|
|
7917
|
+
if (exprContext === "DefaultValue") {
|
|
7918
|
+
return [
|
|
7919
|
+
"true",
|
|
7920
|
+
"false",
|
|
7921
|
+
"null"
|
|
7922
|
+
].includes(keyword);
|
|
7923
|
+
} else {
|
|
7924
|
+
return [
|
|
7925
|
+
"true",
|
|
7926
|
+
"false",
|
|
7927
|
+
"null",
|
|
7928
|
+
"this"
|
|
7929
|
+
].includes(keyword);
|
|
7930
|
+
}
|
|
7931
|
+
} else {
|
|
7932
|
+
return true;
|
|
7933
|
+
}
|
|
7934
|
+
}
|
|
7935
|
+
filterAttributeApplicationCompletion(contextNode, node) {
|
|
7936
|
+
const attrContextType = this.getAttributeContextType(contextNode);
|
|
7937
|
+
if (isFunctionDecl(node) && attrContextType) {
|
|
7938
|
+
const funcExprContextAttr = getAttribute(node, "@@@expressionContext");
|
|
7939
|
+
if (funcExprContextAttr && funcExprContextAttr.args[0]) {
|
|
7940
|
+
const arg = funcExprContextAttr.args[0];
|
|
7941
|
+
if (isArrayExpr(arg.value)) {
|
|
7942
|
+
return arg.value.items.some((item) => isEnumFieldReference(item) && item.target.$refText === attrContextType);
|
|
7943
|
+
}
|
|
7944
|
+
}
|
|
7945
|
+
return false;
|
|
7946
|
+
}
|
|
7947
|
+
if (isDataField(node)) {
|
|
7948
|
+
return attrContextType !== "DefaultValue";
|
|
7949
|
+
}
|
|
7950
|
+
return true;
|
|
7951
|
+
}
|
|
7952
|
+
getAttributeContextType(node) {
|
|
7953
|
+
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);
|
|
7954
|
+
}
|
|
7955
|
+
createReferenceCompletionItem(nodeDescription) {
|
|
7956
|
+
const node = this.getAstNode(nodeDescription);
|
|
7957
|
+
const documentation = this.getNodeDocumentation(node);
|
|
7958
|
+
return (0, import_ts_pattern3.match)(node).when(isDataModel, () => ({
|
|
7959
|
+
nodeDescription,
|
|
7960
|
+
kind: import_vscode_languageserver.CompletionItemKind.Class,
|
|
7961
|
+
detail: "Model",
|
|
7962
|
+
sortText: "1",
|
|
7963
|
+
documentation
|
|
7964
|
+
})).when(isTypeDef, () => ({
|
|
7965
|
+
nodeDescription,
|
|
7966
|
+
kind: import_vscode_languageserver.CompletionItemKind.Class,
|
|
7967
|
+
detail: "Type",
|
|
7968
|
+
sortText: "1",
|
|
7969
|
+
documentation
|
|
7970
|
+
})).when(isDataField, () => ({
|
|
7971
|
+
nodeDescription,
|
|
7972
|
+
kind: import_vscode_languageserver.CompletionItemKind.Field,
|
|
7973
|
+
detail: "Field",
|
|
7974
|
+
sortText: "0",
|
|
7975
|
+
documentation
|
|
7976
|
+
})).when(isEnum, () => ({
|
|
7977
|
+
nodeDescription,
|
|
7978
|
+
kind: import_vscode_languageserver.CompletionItemKind.Class,
|
|
7979
|
+
detail: "Enum",
|
|
7980
|
+
sortText: "1",
|
|
7981
|
+
documentation
|
|
7982
|
+
})).when(isEnumField, (d) => {
|
|
7983
|
+
const container = d.$container;
|
|
7984
|
+
return {
|
|
7985
|
+
nodeDescription,
|
|
7986
|
+
kind: import_vscode_languageserver.CompletionItemKind.Enum,
|
|
7987
|
+
detail: `Value of enum "${container.name}"`,
|
|
7988
|
+
sortText: "1",
|
|
7989
|
+
documentation
|
|
7990
|
+
};
|
|
7991
|
+
}).when(isFunctionDecl, () => ({
|
|
7992
|
+
nodeDescription,
|
|
7993
|
+
insertText: this.getFunctionInsertText(nodeDescription),
|
|
7994
|
+
kind: import_vscode_languageserver.CompletionItemKind.Function,
|
|
7995
|
+
detail: "Function",
|
|
7996
|
+
sortText: "1",
|
|
7997
|
+
documentation
|
|
7998
|
+
})).when(isAttribute, () => ({
|
|
7999
|
+
nodeDescription,
|
|
8000
|
+
insertText: this.getAttributeInsertText(nodeDescription),
|
|
8001
|
+
kind: import_vscode_languageserver.CompletionItemKind.Property,
|
|
8002
|
+
detail: "Attribute",
|
|
8003
|
+
sortText: "1",
|
|
8004
|
+
documentation
|
|
8005
|
+
})).otherwise(() => ({
|
|
8006
|
+
nodeDescription,
|
|
8007
|
+
kind: import_vscode_languageserver.CompletionItemKind.Reference,
|
|
8008
|
+
detail: nodeDescription.type,
|
|
8009
|
+
sortText: "2",
|
|
8010
|
+
documentation
|
|
8011
|
+
}));
|
|
8012
|
+
}
|
|
8013
|
+
getFunctionInsertText(nodeDescription) {
|
|
8014
|
+
const node = this.getAstNode(nodeDescription);
|
|
8015
|
+
if (isFunctionDecl(node)) {
|
|
8016
|
+
if (node.params.some((p) => !p.optional)) {
|
|
8017
|
+
return nodeDescription.name;
|
|
8018
|
+
}
|
|
8019
|
+
}
|
|
8020
|
+
return `${nodeDescription.name}()`;
|
|
8021
|
+
}
|
|
8022
|
+
getAttributeInsertText(nodeDescription) {
|
|
8023
|
+
const node = this.getAstNode(nodeDescription);
|
|
8024
|
+
if (isAttribute(node)) {
|
|
8025
|
+
if (node.name === "@relation") {
|
|
8026
|
+
return `${nodeDescription.name}(fields: [], references: [])`;
|
|
8027
|
+
}
|
|
8028
|
+
}
|
|
8029
|
+
return nodeDescription.name;
|
|
8030
|
+
}
|
|
8031
|
+
getAstNode(nodeDescription) {
|
|
8032
|
+
let node = nodeDescription.node;
|
|
8033
|
+
if (!node) {
|
|
8034
|
+
const doc = this.getOrCreateDocumentSync(nodeDescription);
|
|
8035
|
+
if (!doc) {
|
|
8036
|
+
return void 0;
|
|
8037
|
+
}
|
|
8038
|
+
node = this.services.workspace.AstNodeLocator.getAstNode(doc.parseResult.value, nodeDescription.path);
|
|
8039
|
+
if (!node) {
|
|
8040
|
+
return void 0;
|
|
8041
|
+
}
|
|
8042
|
+
}
|
|
8043
|
+
return node;
|
|
8044
|
+
}
|
|
8045
|
+
getOrCreateDocumentSync(nodeDescription) {
|
|
8046
|
+
let doc = this.services.shared.workspace.LangiumDocuments.getDocument(nodeDescription.documentUri);
|
|
8047
|
+
if (!doc) {
|
|
8048
|
+
try {
|
|
8049
|
+
const content = import_node_fs2.default.readFileSync(nodeDescription.documentUri.fsPath, "utf-8");
|
|
8050
|
+
doc = this.services.shared.workspace.LangiumDocuments.createDocument(nodeDescription.documentUri, content);
|
|
8051
|
+
} catch {
|
|
8052
|
+
console.warn("Failed to read or create document:", nodeDescription.documentUri);
|
|
8053
|
+
return void 0;
|
|
8054
|
+
}
|
|
8055
|
+
}
|
|
8056
|
+
return doc;
|
|
8057
|
+
}
|
|
8058
|
+
getNodeDocumentation(node) {
|
|
8059
|
+
if (!node) {
|
|
8060
|
+
return void 0;
|
|
8061
|
+
}
|
|
8062
|
+
const md = this.commentsToMarkdown(node);
|
|
8063
|
+
return {
|
|
8064
|
+
kind: "markdown",
|
|
8065
|
+
value: md
|
|
8066
|
+
};
|
|
8067
|
+
}
|
|
8068
|
+
commentsToMarkdown(node) {
|
|
8069
|
+
const md = this.services.documentation.DocumentationProvider.getDocumentation(node) ?? "";
|
|
8070
|
+
const zModelGenerator = new ZModelCodeGenerator();
|
|
8071
|
+
const docs = [];
|
|
8072
|
+
try {
|
|
8073
|
+
(0, import_ts_pattern3.match)(node).when(isAttribute, (attr) => {
|
|
8074
|
+
docs.push("```prisma", zModelGenerator.generate(attr), "```");
|
|
8075
|
+
}).when(isFunctionDecl, (func2) => {
|
|
8076
|
+
docs.push("```ts", zModelGenerator.generate(func2), "```");
|
|
8077
|
+
}).when(isDataModel, (model) => {
|
|
8078
|
+
docs.push("```prisma", `model ${model.name} { ... }`, "```");
|
|
8079
|
+
}).when(isEnum, (enumDecl) => {
|
|
8080
|
+
docs.push("```prisma", zModelGenerator.generate(enumDecl), "```");
|
|
8081
|
+
}).when(isDataField, (field) => {
|
|
8082
|
+
docs.push(`${field.name}: ${field.type.type ?? field.type.reference?.$refText}`);
|
|
8083
|
+
}).otherwise((ast) => {
|
|
8084
|
+
const name = ast.name;
|
|
8085
|
+
if (name) {
|
|
8086
|
+
docs.push(name);
|
|
8087
|
+
}
|
|
8088
|
+
});
|
|
8089
|
+
} catch {
|
|
8090
|
+
}
|
|
8091
|
+
if (md) {
|
|
8092
|
+
docs.push("___", md);
|
|
8093
|
+
}
|
|
8094
|
+
return docs.join("\n");
|
|
8095
|
+
}
|
|
8096
|
+
};
|
|
8097
|
+
|
|
8098
|
+
// src/zmodel-definition.ts
|
|
8099
|
+
var import_lsp2 = require("langium/lsp");
|
|
8100
|
+
var import_vscode_languageserver2 = require("vscode-languageserver");
|
|
8101
|
+
var ZModelDefinitionProvider = class extends import_lsp2.DefaultDefinitionProvider {
|
|
8102
|
+
static {
|
|
8103
|
+
__name(this, "ZModelDefinitionProvider");
|
|
8104
|
+
}
|
|
8105
|
+
documents;
|
|
8106
|
+
constructor(services) {
|
|
8107
|
+
super(services);
|
|
8108
|
+
this.documents = services.shared.workspace.LangiumDocuments;
|
|
8109
|
+
}
|
|
8110
|
+
collectLocationLinks(sourceCstNode, _params) {
|
|
8111
|
+
if (isModelImport(sourceCstNode.astNode)) {
|
|
8112
|
+
const importedModel = resolveImport(this.documents, sourceCstNode.astNode);
|
|
8113
|
+
if (importedModel?.$document) {
|
|
8114
|
+
const targetObject = importedModel;
|
|
8115
|
+
const selectionRange = this.nameProvider.getNameNode(targetObject)?.range ?? import_vscode_languageserver2.Range.create(0, 0, 0, 0);
|
|
8116
|
+
const previewRange = targetObject.$cstNode?.range ?? import_vscode_languageserver2.Range.create(0, 0, 0, 0);
|
|
8117
|
+
return [
|
|
8118
|
+
import_vscode_languageserver2.LocationLink.create(importedModel.$document.uri.toString(), previewRange, selectionRange, sourceCstNode.range)
|
|
8119
|
+
];
|
|
8120
|
+
}
|
|
8121
|
+
return void 0;
|
|
8122
|
+
}
|
|
8123
|
+
return super.collectLocationLinks(sourceCstNode, _params);
|
|
8124
|
+
}
|
|
8125
|
+
};
|
|
8126
|
+
|
|
8127
|
+
// src/zmodel-document-builder.ts
|
|
8128
|
+
var import_langium8 = require("langium");
|
|
8129
|
+
var ZModelDocumentBuilder = class extends import_langium8.DefaultDocumentBuilder {
|
|
8130
|
+
static {
|
|
8131
|
+
__name(this, "ZModelDocumentBuilder");
|
|
8132
|
+
}
|
|
8133
|
+
constructor(services) {
|
|
8134
|
+
super(services);
|
|
8135
|
+
let validationOptions = this.updateBuildOptions.validation;
|
|
8136
|
+
const stopFlags = {
|
|
8137
|
+
stopAfterLinkingErrors: true,
|
|
8138
|
+
stopAfterLexingErrors: true,
|
|
8139
|
+
stopAfterParsingErrors: true
|
|
8140
|
+
};
|
|
8141
|
+
if (validationOptions === true) {
|
|
8142
|
+
validationOptions = stopFlags;
|
|
8143
|
+
} else if (typeof validationOptions === "object") {
|
|
8144
|
+
validationOptions = {
|
|
8145
|
+
...validationOptions,
|
|
8146
|
+
...stopFlags
|
|
8147
|
+
};
|
|
8148
|
+
}
|
|
8149
|
+
this.updateBuildOptions = {
|
|
8150
|
+
...this.updateBuildOptions,
|
|
8151
|
+
validation: validationOptions
|
|
8152
|
+
};
|
|
8153
|
+
}
|
|
8154
|
+
};
|
|
8155
|
+
|
|
8156
|
+
// src/zmodel-documentation-provider.ts
|
|
8157
|
+
var import_langium9 = require("langium");
|
|
8158
|
+
var ZModelDocumentationProvider = class extends import_langium9.JSDocDocumentationProvider {
|
|
8159
|
+
static {
|
|
8160
|
+
__name(this, "ZModelDocumentationProvider");
|
|
8161
|
+
}
|
|
8162
|
+
getDocumentation(node) {
|
|
8163
|
+
if ("comments" in node && Array.isArray(node.comments) && node.comments.length > 0) {
|
|
8164
|
+
return node.comments.map((c) => c.replace(/^[/]*\s*/, "")).join("\n");
|
|
8165
|
+
}
|
|
8166
|
+
return super.getDocumentation(node);
|
|
8167
|
+
}
|
|
8168
|
+
};
|
|
8169
|
+
|
|
8170
|
+
// src/zmodel-formatter.ts
|
|
8171
|
+
var import_lsp3 = require("langium/lsp");
|
|
8172
|
+
var ZModelFormatter = class extends import_lsp3.AbstractFormatter {
|
|
8173
|
+
static {
|
|
8174
|
+
__name(this, "ZModelFormatter");
|
|
8175
|
+
}
|
|
8176
|
+
formatOptions;
|
|
8177
|
+
configurationProvider;
|
|
8178
|
+
constructor(services) {
|
|
8179
|
+
super();
|
|
8180
|
+
this.configurationProvider = services.shared.workspace.ConfigurationProvider;
|
|
8181
|
+
}
|
|
8182
|
+
format(node) {
|
|
8183
|
+
const formatter = this.getNodeFormatter(node);
|
|
8184
|
+
if (isDataField(node)) {
|
|
8185
|
+
if (isDataModel(node.$container) || isTypeDef(node.$container)) {
|
|
8186
|
+
const dataModel = node.$container;
|
|
8187
|
+
const compareFn = /* @__PURE__ */ __name((a, b) => b - a, "compareFn");
|
|
8188
|
+
const maxNameLength = dataModel.fields.map((x) => x.name.length).sort(compareFn)[0] ?? 0;
|
|
8189
|
+
const maxTypeLength = dataModel.fields.map(this.getFieldTypeLength).sort(compareFn)[0] ?? 0;
|
|
8190
|
+
formatter.property("type").prepend(import_lsp3.Formatting.spaces(maxNameLength - node.name.length + 1));
|
|
8191
|
+
if (node.attributes.length > 0) {
|
|
8192
|
+
formatter.node(node.attributes[0]).prepend(import_lsp3.Formatting.spaces(maxTypeLength - this.getFieldTypeLength(node) + 1));
|
|
8193
|
+
formatter.nodes(...node.attributes.slice(1)).prepend(import_lsp3.Formatting.oneSpace());
|
|
8194
|
+
}
|
|
8195
|
+
} else {
|
|
8196
|
+
formatter.property("type").prepend(import_lsp3.Formatting.oneSpace());
|
|
8197
|
+
if (node.attributes.length > 0) {
|
|
8198
|
+
formatter.properties("attributes").prepend(import_lsp3.Formatting.oneSpace());
|
|
8199
|
+
}
|
|
8200
|
+
}
|
|
8201
|
+
} else if (isDataFieldAttribute(node)) {
|
|
8202
|
+
formatter.keyword("(").surround(import_lsp3.Formatting.noSpace());
|
|
8203
|
+
formatter.keyword(")").prepend(import_lsp3.Formatting.noSpace());
|
|
8204
|
+
formatter.keyword(",").append(import_lsp3.Formatting.oneSpace());
|
|
8205
|
+
if (node.args.length > 1) {
|
|
8206
|
+
formatter.nodes(...node.args.slice(1)).prepend(import_lsp3.Formatting.oneSpace());
|
|
8207
|
+
}
|
|
8208
|
+
} else if (isAttributeArg(node)) {
|
|
8209
|
+
formatter.keyword(":").prepend(import_lsp3.Formatting.noSpace());
|
|
8210
|
+
formatter.keyword(":").append(import_lsp3.Formatting.oneSpace());
|
|
8211
|
+
} else if (isAbstractDeclaration(node)) {
|
|
8212
|
+
const bracesOpen = formatter.keyword("{");
|
|
8213
|
+
const bracesClose = formatter.keyword("}");
|
|
8214
|
+
formatter.interior(bracesOpen, bracesClose).prepend(import_lsp3.Formatting.indent({
|
|
8215
|
+
allowMore: true
|
|
8216
|
+
}));
|
|
8217
|
+
bracesOpen.prepend(import_lsp3.Formatting.oneSpace());
|
|
8218
|
+
bracesClose.prepend(import_lsp3.Formatting.newLine());
|
|
8219
|
+
} else if (isModel(node)) {
|
|
8220
|
+
const model = node;
|
|
8221
|
+
const nodes = formatter.nodes(...model.declarations);
|
|
8222
|
+
nodes.prepend(import_lsp3.Formatting.noIndent());
|
|
8223
|
+
}
|
|
8224
|
+
}
|
|
8225
|
+
formatDocument(document, params) {
|
|
8226
|
+
this.formatOptions = params.options;
|
|
8227
|
+
this.configurationProvider.getConfiguration(ZModelLanguageMetaData.languageId, "format").then((config) => {
|
|
8228
|
+
if (config) {
|
|
8229
|
+
}
|
|
8230
|
+
});
|
|
8231
|
+
return super.formatDocument(document, params);
|
|
8232
|
+
}
|
|
8233
|
+
getFormatOptions() {
|
|
8234
|
+
return this.formatOptions;
|
|
8235
|
+
}
|
|
8236
|
+
getIndent() {
|
|
8237
|
+
return 1;
|
|
8238
|
+
}
|
|
8239
|
+
getFieldTypeLength(field) {
|
|
8240
|
+
let length;
|
|
8241
|
+
if (field.type.type) {
|
|
8242
|
+
length = field.type.type.length;
|
|
8243
|
+
} else if (field.type.reference) {
|
|
8244
|
+
length = field.type.reference.$refText.length;
|
|
8245
|
+
} else if (isDataField(field) && field.type.unsupported) {
|
|
8246
|
+
const name = `Unsupported("${field.type.unsupported.value.value}")`;
|
|
8247
|
+
length = name.length;
|
|
8248
|
+
} else {
|
|
8249
|
+
length = 1;
|
|
8250
|
+
}
|
|
8251
|
+
if (field.type.optional) {
|
|
8252
|
+
length += 1;
|
|
8253
|
+
}
|
|
8254
|
+
if (field.type.array) {
|
|
8255
|
+
length += 2;
|
|
8256
|
+
}
|
|
8257
|
+
return length;
|
|
8258
|
+
}
|
|
8259
|
+
};
|
|
8260
|
+
|
|
8261
|
+
// src/zmodel-linker.ts
|
|
8262
|
+
var import_langium10 = require("langium");
|
|
8263
|
+
var import_ts_pattern4 = require("ts-pattern");
|
|
8264
|
+
var ZModelLinker = class extends import_langium10.DefaultLinker {
|
|
7021
8265
|
static {
|
|
7022
8266
|
__name(this, "ZModelLinker");
|
|
7023
8267
|
}
|
|
@@ -7027,31 +8271,29 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
|
|
|
7027
8271
|
this.descriptions = services.workspace.AstNodeDescriptionProvider;
|
|
7028
8272
|
}
|
|
7029
8273
|
//#region Reference linking
|
|
7030
|
-
async link(document, cancelToken =
|
|
8274
|
+
async link(document, cancelToken = import_langium10.Cancellation.CancellationToken.None) {
|
|
7031
8275
|
if (document.parseResult.lexerErrors?.length > 0 || document.parseResult.parserErrors?.length > 0) {
|
|
7032
8276
|
return;
|
|
7033
8277
|
}
|
|
7034
|
-
for (const node of
|
|
7035
|
-
await (0,
|
|
8278
|
+
for (const node of import_langium10.AstUtils.streamContents(document.parseResult.value)) {
|
|
8279
|
+
await (0, import_langium10.interruptAndCheck)(cancelToken);
|
|
7036
8280
|
this.resolve(node, document);
|
|
7037
8281
|
}
|
|
7038
|
-
document.state =
|
|
8282
|
+
document.state = import_langium10.DocumentState.Linked;
|
|
7039
8283
|
}
|
|
7040
|
-
linkReference(
|
|
7041
|
-
|
|
8284
|
+
linkReference(refInfo, document, extraScopes) {
|
|
8285
|
+
const defaultRef = refInfo.reference;
|
|
8286
|
+
if (defaultRef._ref) {
|
|
8287
|
+
return;
|
|
8288
|
+
}
|
|
8289
|
+
if (this.resolveFromScopeProviders(refInfo.reference, document, extraScopes)) {
|
|
7042
8290
|
return;
|
|
7043
8291
|
}
|
|
7044
|
-
|
|
7045
|
-
this.doLink({
|
|
7046
|
-
reference,
|
|
7047
|
-
container,
|
|
7048
|
-
property
|
|
7049
|
-
}, document);
|
|
8292
|
+
this.doLink(refInfo, document);
|
|
7050
8293
|
}
|
|
7051
8294
|
//#endregion
|
|
7052
8295
|
//#region Expression type resolving
|
|
7053
|
-
resolveFromScopeProviders(
|
|
7054
|
-
const reference = node[property];
|
|
8296
|
+
resolveFromScopeProviders(reference, document, providers) {
|
|
7055
8297
|
for (const provider of providers) {
|
|
7056
8298
|
const target = provider(reference.$refText);
|
|
7057
8299
|
if (target) {
|
|
@@ -7180,12 +8422,16 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
|
|
|
7180
8422
|
}
|
|
7181
8423
|
}
|
|
7182
8424
|
resolveInvocation(node, document, extraScopes) {
|
|
7183
|
-
this.linkReference(
|
|
8425
|
+
this.linkReference({
|
|
8426
|
+
reference: node.function,
|
|
8427
|
+
container: node,
|
|
8428
|
+
property: "function"
|
|
8429
|
+
}, document, extraScopes);
|
|
7184
8430
|
node.args.forEach((arg) => this.resolve(arg, document, extraScopes));
|
|
7185
8431
|
if (node.function.ref) {
|
|
7186
8432
|
const funcDecl = node.function.ref;
|
|
7187
8433
|
if (isAuthInvocation(node)) {
|
|
7188
|
-
const allDecls = getAllLoadedAndReachableDataModelsAndTypeDefs(this.langiumDocuments(),
|
|
8434
|
+
const allDecls = getAllLoadedAndReachableDataModelsAndTypeDefs(this.langiumDocuments(), import_langium10.AstUtils.getContainerOfType(node, isDataModel));
|
|
7189
8435
|
const authDecl = getAuthDecl(allDecls);
|
|
7190
8436
|
if (authDecl) {
|
|
7191
8437
|
node.$resolvedType = {
|
|
@@ -7193,7 +8439,7 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
|
|
|
7193
8439
|
nullable: true
|
|
7194
8440
|
};
|
|
7195
8441
|
}
|
|
7196
|
-
} else if (
|
|
8442
|
+
} else if (isBeforeInvocation(node)) {
|
|
7197
8443
|
node.$resolvedType = {
|
|
7198
8444
|
decl: getContainingDataModel(node)
|
|
7199
8445
|
};
|
|
@@ -7203,7 +8449,7 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
|
|
|
7203
8449
|
}
|
|
7204
8450
|
}
|
|
7205
8451
|
resolveLiteral(node) {
|
|
7206
|
-
const type = (0,
|
|
8452
|
+
const type = (0, import_ts_pattern4.match)(node).when(isStringLiteral, () => "String").when(isBooleanLiteral, () => "Boolean").when(isNumberLiteral, () => "Int").exhaustive();
|
|
7207
8453
|
if (type) {
|
|
7208
8454
|
this.resolveToBuiltinTypeOrDecl(node, type);
|
|
7209
8455
|
}
|
|
@@ -7257,7 +8503,7 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
|
|
|
7257
8503
|
if (isArrayExpr(node.value)) {
|
|
7258
8504
|
node.value.items.forEach((item) => {
|
|
7259
8505
|
if (isReferenceExpr(item)) {
|
|
7260
|
-
const resolved2 = this.resolveFromScopeProviders(item
|
|
8506
|
+
const resolved2 = this.resolveFromScopeProviders(item.target, document, [
|
|
7261
8507
|
scopeProvider
|
|
7262
8508
|
]);
|
|
7263
8509
|
if (resolved2) {
|
|
@@ -7271,7 +8517,7 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
|
|
|
7271
8517
|
this.resolveToBuiltinTypeOrDecl(node.value, node.value.items[0].$resolvedType.decl, true);
|
|
7272
8518
|
}
|
|
7273
8519
|
} else if (isReferenceExpr(node.value)) {
|
|
7274
|
-
const resolved2 = this.resolveFromScopeProviders(node.value
|
|
8520
|
+
const resolved2 = this.resolveFromScopeProviders(node.value.target, document, [
|
|
7275
8521
|
scopeProvider
|
|
7276
8522
|
]);
|
|
7277
8523
|
if (resolved2) {
|
|
@@ -7323,14 +8569,10 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
|
|
|
7323
8569
|
this.resolveDefault(node, document, scopes);
|
|
7324
8570
|
}
|
|
7325
8571
|
resolveDefault(node, document, extraScopes) {
|
|
7326
|
-
|
|
7327
|
-
|
|
7328
|
-
|
|
7329
|
-
|
|
7330
|
-
}
|
|
7331
|
-
}
|
|
7332
|
-
}
|
|
7333
|
-
for (const child of import_langium7.AstUtils.streamContents(node)) {
|
|
8572
|
+
import_langium10.AstUtils.streamReferences(node).forEach((ref) => {
|
|
8573
|
+
this.linkReference(ref, document, extraScopes);
|
|
8574
|
+
});
|
|
8575
|
+
for (const child of import_langium10.AstUtils.streamContents(node)) {
|
|
7334
8576
|
this.resolve(child, document, extraScopes);
|
|
7335
8577
|
}
|
|
7336
8578
|
}
|
|
@@ -7374,9 +8616,9 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
|
|
|
7374
8616
|
};
|
|
7375
8617
|
|
|
7376
8618
|
// src/zmodel-scope.ts
|
|
7377
|
-
var
|
|
7378
|
-
var
|
|
7379
|
-
var ZModelScopeComputation = class extends
|
|
8619
|
+
var import_langium11 = require("langium");
|
|
8620
|
+
var import_ts_pattern5 = require("ts-pattern");
|
|
8621
|
+
var ZModelScopeComputation = class extends import_langium11.DefaultScopeComputation {
|
|
7380
8622
|
static {
|
|
7381
8623
|
__name(this, "ZModelScopeComputation");
|
|
7382
8624
|
}
|
|
@@ -7386,9 +8628,9 @@ var ZModelScopeComputation = class extends import_langium8.DefaultScopeComputati
|
|
|
7386
8628
|
}
|
|
7387
8629
|
async computeExports(document, cancelToken) {
|
|
7388
8630
|
const result = await super.computeExports(document, cancelToken);
|
|
7389
|
-
for (const node of
|
|
8631
|
+
for (const node of import_langium11.AstUtils.streamAllContents(document.parseResult.value)) {
|
|
7390
8632
|
if (cancelToken) {
|
|
7391
|
-
await (0,
|
|
8633
|
+
await (0, import_langium11.interruptAndCheck)(cancelToken);
|
|
7392
8634
|
}
|
|
7393
8635
|
if (isEnumField(node)) {
|
|
7394
8636
|
const desc = this.services.workspace.AstNodeDescriptionProvider.createDescription(node, node.name, document);
|
|
@@ -7399,7 +8641,7 @@ var ZModelScopeComputation = class extends import_langium8.DefaultScopeComputati
|
|
|
7399
8641
|
}
|
|
7400
8642
|
processNode(node, document, scopes) {
|
|
7401
8643
|
super.processNode(node, document, scopes);
|
|
7402
|
-
if (isDataModel(node)) {
|
|
8644
|
+
if (isDataModel(node) || isTypeDef(node)) {
|
|
7403
8645
|
const bases = getRecursiveBases(node);
|
|
7404
8646
|
for (const base of bases) {
|
|
7405
8647
|
for (const field of base.fields) {
|
|
@@ -7409,7 +8651,7 @@ var ZModelScopeComputation = class extends import_langium8.DefaultScopeComputati
|
|
|
7409
8651
|
}
|
|
7410
8652
|
}
|
|
7411
8653
|
};
|
|
7412
|
-
var ZModelScopeProvider = class extends
|
|
8654
|
+
var ZModelScopeProvider = class extends import_langium11.DefaultScopeProvider {
|
|
7413
8655
|
static {
|
|
7414
8656
|
__name(this, "ZModelScopeProvider");
|
|
7415
8657
|
}
|
|
@@ -7418,19 +8660,19 @@ var ZModelScopeProvider = class extends import_langium8.DefaultScopeProvider {
|
|
|
7418
8660
|
super(services), this.services = services;
|
|
7419
8661
|
}
|
|
7420
8662
|
getGlobalScope(referenceType, context) {
|
|
7421
|
-
const model =
|
|
8663
|
+
const model = import_langium11.AstUtils.getContainerOfType(context.container, isModel);
|
|
7422
8664
|
if (!model) {
|
|
7423
|
-
return
|
|
8665
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7424
8666
|
}
|
|
7425
8667
|
const importedUris = model.imports.map(resolveImportUri).filter((url) => !!url);
|
|
7426
8668
|
const importedElements = this.indexManager.allElements(referenceType).filter((des) => (
|
|
7427
8669
|
// allow current document
|
|
7428
|
-
|
|
8670
|
+
import_langium11.UriUtils.equals(des.documentUri, model.$document?.uri) || // allow stdlib
|
|
7429
8671
|
des.documentUri.path.endsWith(STD_LIB_MODULE_NAME) || // allow plugin models
|
|
7430
8672
|
des.documentUri.path.endsWith(PLUGIN_MODULE_NAME) || // allow imported documents
|
|
7431
|
-
importedUris.some((importedUri) =>
|
|
8673
|
+
importedUris.some((importedUri) => import_langium11.UriUtils.equals(des.documentUri, importedUri))
|
|
7432
8674
|
));
|
|
7433
|
-
return new
|
|
8675
|
+
return new import_langium11.StreamScope(importedElements);
|
|
7434
8676
|
}
|
|
7435
8677
|
getScope(context) {
|
|
7436
8678
|
if (isMemberAccessExpr(context.container) && context.container.operand && context.property === "member") {
|
|
@@ -7450,66 +8692,66 @@ var ZModelScopeProvider = class extends import_langium8.DefaultScopeProvider {
|
|
|
7450
8692
|
const node = context.container;
|
|
7451
8693
|
const allowTypeDefScope = (
|
|
7452
8694
|
// isAuthOrAuthMemberAccess(node.operand) ||
|
|
7453
|
-
!!
|
|
8695
|
+
!!import_langium11.AstUtils.getContainerOfType(node, isTypeDef)
|
|
7454
8696
|
);
|
|
7455
|
-
return (0,
|
|
8697
|
+
return (0, import_ts_pattern5.match)(node.operand).when(isReferenceExpr, (operand) => {
|
|
7456
8698
|
const ref = operand.target.ref;
|
|
7457
8699
|
if (isDataField(ref)) {
|
|
7458
8700
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7459
8701
|
}
|
|
7460
|
-
return
|
|
8702
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7461
8703
|
}).when(isMemberAccessExpr, (operand) => {
|
|
7462
8704
|
const ref = operand.member.ref;
|
|
7463
8705
|
if (isDataField(ref) && !ref.type.array) {
|
|
7464
8706
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7465
8707
|
}
|
|
7466
|
-
return
|
|
8708
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7467
8709
|
}).when(isThisExpr, () => {
|
|
7468
8710
|
return this.createScopeForContainingModel(node, globalScope);
|
|
7469
8711
|
}).when(isInvocationExpr, (operand) => {
|
|
7470
8712
|
if (isAuthInvocation(operand)) {
|
|
7471
8713
|
return this.createScopeForAuth(node, globalScope);
|
|
7472
8714
|
}
|
|
7473
|
-
if (
|
|
8715
|
+
if (isBeforeInvocation(operand)) {
|
|
7474
8716
|
return this.createScopeForContainingModel(node, globalScope);
|
|
7475
8717
|
}
|
|
7476
|
-
return
|
|
7477
|
-
}).otherwise(() =>
|
|
8718
|
+
return import_langium11.EMPTY_SCOPE;
|
|
8719
|
+
}).otherwise(() => import_langium11.EMPTY_SCOPE);
|
|
7478
8720
|
}
|
|
7479
8721
|
getCollectionPredicateScope(context, collectionPredicate) {
|
|
7480
8722
|
const referenceType = this.reflection.getReferenceType(context);
|
|
7481
8723
|
const globalScope = this.getGlobalScope(referenceType, context);
|
|
7482
8724
|
const collection = collectionPredicate.left;
|
|
7483
8725
|
const allowTypeDefScope = false;
|
|
7484
|
-
return (0,
|
|
8726
|
+
return (0, import_ts_pattern5.match)(collection).when(isReferenceExpr, (expr) => {
|
|
7485
8727
|
const ref = expr.target.ref;
|
|
7486
8728
|
if (isDataField(ref)) {
|
|
7487
8729
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7488
8730
|
}
|
|
7489
|
-
return
|
|
8731
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7490
8732
|
}).when(isMemberAccessExpr, (expr) => {
|
|
7491
8733
|
const ref = expr.member.ref;
|
|
7492
8734
|
if (isDataField(ref)) {
|
|
7493
8735
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7494
8736
|
}
|
|
7495
|
-
return
|
|
8737
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7496
8738
|
}).when(isInvocationExpr, (expr) => {
|
|
7497
8739
|
const returnTypeDecl = expr.function.ref?.returnType.reference?.ref;
|
|
7498
8740
|
if (isDataModel(returnTypeDecl)) {
|
|
7499
8741
|
return this.createScopeForContainer(returnTypeDecl, globalScope, allowTypeDefScope);
|
|
7500
8742
|
} else {
|
|
7501
|
-
return
|
|
8743
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7502
8744
|
}
|
|
7503
8745
|
}).when(isAuthInvocation, (expr) => {
|
|
7504
8746
|
return this.createScopeForAuth(expr, globalScope);
|
|
7505
|
-
}).otherwise(() =>
|
|
8747
|
+
}).otherwise(() => import_langium11.EMPTY_SCOPE);
|
|
7506
8748
|
}
|
|
7507
8749
|
createScopeForContainingModel(node, globalScope) {
|
|
7508
|
-
const model =
|
|
8750
|
+
const model = import_langium11.AstUtils.getContainerOfType(node, isDataModel);
|
|
7509
8751
|
if (model) {
|
|
7510
8752
|
return this.createScopeForContainer(model, globalScope);
|
|
7511
8753
|
} else {
|
|
7512
|
-
return
|
|
8754
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7513
8755
|
}
|
|
7514
8756
|
}
|
|
7515
8757
|
createScopeForContainer(node, globalScope, includeTypeDefScope = false) {
|
|
@@ -7518,16 +8760,16 @@ var ZModelScopeProvider = class extends import_langium8.DefaultScopeProvider {
|
|
|
7518
8760
|
} else if (includeTypeDefScope && isTypeDef(node)) {
|
|
7519
8761
|
return this.createScopeForNodes(node.fields, globalScope);
|
|
7520
8762
|
} else {
|
|
7521
|
-
return
|
|
8763
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7522
8764
|
}
|
|
7523
8765
|
}
|
|
7524
8766
|
createScopeForAuth(node, globalScope) {
|
|
7525
|
-
const decls = getAllLoadedAndReachableDataModelsAndTypeDefs(this.services.shared.workspace.LangiumDocuments,
|
|
8767
|
+
const decls = getAllLoadedAndReachableDataModelsAndTypeDefs(this.services.shared.workspace.LangiumDocuments, import_langium11.AstUtils.getContainerOfType(node, isDataModel));
|
|
7526
8768
|
const authDecl = getAuthDecl(decls);
|
|
7527
8769
|
if (authDecl) {
|
|
7528
8770
|
return this.createScopeForContainer(authDecl, globalScope, true);
|
|
7529
8771
|
} else {
|
|
7530
|
-
return
|
|
8772
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7531
8773
|
}
|
|
7532
8774
|
}
|
|
7533
8775
|
};
|
|
@@ -7543,13 +8785,97 @@ function getCollectionPredicateContext(node) {
|
|
|
7543
8785
|
}
|
|
7544
8786
|
__name(getCollectionPredicateContext, "getCollectionPredicateContext");
|
|
7545
8787
|
|
|
8788
|
+
// src/zmodel-semantic.ts
|
|
8789
|
+
var import_lsp4 = require("langium/lsp");
|
|
8790
|
+
var import_vscode_languageserver3 = require("vscode-languageserver");
|
|
8791
|
+
var ZModelSemanticTokenProvider = class extends import_lsp4.AbstractSemanticTokenProvider {
|
|
8792
|
+
static {
|
|
8793
|
+
__name(this, "ZModelSemanticTokenProvider");
|
|
8794
|
+
}
|
|
8795
|
+
highlightElement(node, acceptor) {
|
|
8796
|
+
if (isDataModel(node)) {
|
|
8797
|
+
acceptor({
|
|
8798
|
+
node,
|
|
8799
|
+
property: "name",
|
|
8800
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.type
|
|
8801
|
+
});
|
|
8802
|
+
acceptor({
|
|
8803
|
+
node,
|
|
8804
|
+
property: "mixins",
|
|
8805
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.type
|
|
8806
|
+
});
|
|
8807
|
+
acceptor({
|
|
8808
|
+
node,
|
|
8809
|
+
property: "baseModel",
|
|
8810
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.type
|
|
8811
|
+
});
|
|
8812
|
+
} else if (isDataSource(node) || isGeneratorDecl(node) || isPlugin(node) || isEnum(node) || isTypeDef(node)) {
|
|
8813
|
+
acceptor({
|
|
8814
|
+
node,
|
|
8815
|
+
property: "name",
|
|
8816
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.type
|
|
8817
|
+
});
|
|
8818
|
+
} else if (isDataField(node) || isConfigField(node) || isAttributeArg(node) || isPluginField(node) || isEnumField(node)) {
|
|
8819
|
+
acceptor({
|
|
8820
|
+
node,
|
|
8821
|
+
property: "name",
|
|
8822
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.variable
|
|
8823
|
+
});
|
|
8824
|
+
} else if (isDataFieldType(node)) {
|
|
8825
|
+
if (node.type) {
|
|
8826
|
+
acceptor({
|
|
8827
|
+
node,
|
|
8828
|
+
property: "type",
|
|
8829
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.type
|
|
8830
|
+
});
|
|
8831
|
+
} else {
|
|
8832
|
+
acceptor({
|
|
8833
|
+
node,
|
|
8834
|
+
property: "reference",
|
|
8835
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.macro
|
|
8836
|
+
});
|
|
8837
|
+
}
|
|
8838
|
+
} else if (isDataModelAttribute(node) || isDataFieldAttribute(node) || isInternalAttribute(node)) {
|
|
8839
|
+
acceptor({
|
|
8840
|
+
node,
|
|
8841
|
+
property: "decl",
|
|
8842
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.function
|
|
8843
|
+
});
|
|
8844
|
+
} else if (isInvocationExpr(node)) {
|
|
8845
|
+
acceptor({
|
|
8846
|
+
node,
|
|
8847
|
+
property: "function",
|
|
8848
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.function
|
|
8849
|
+
});
|
|
8850
|
+
} else if (isFunctionDecl(node) || isAttribute(node)) {
|
|
8851
|
+
acceptor({
|
|
8852
|
+
node,
|
|
8853
|
+
property: "name",
|
|
8854
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.function
|
|
8855
|
+
});
|
|
8856
|
+
} else if (isReferenceExpr(node)) {
|
|
8857
|
+
acceptor({
|
|
8858
|
+
node,
|
|
8859
|
+
property: "target",
|
|
8860
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.variable
|
|
8861
|
+
});
|
|
8862
|
+
} else if (isMemberAccessExpr(node)) {
|
|
8863
|
+
acceptor({
|
|
8864
|
+
node,
|
|
8865
|
+
property: "member",
|
|
8866
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.property
|
|
8867
|
+
});
|
|
8868
|
+
}
|
|
8869
|
+
}
|
|
8870
|
+
};
|
|
8871
|
+
|
|
7546
8872
|
// src/zmodel-workspace-manager.ts
|
|
7547
|
-
var
|
|
7548
|
-
var
|
|
7549
|
-
var
|
|
7550
|
-
var
|
|
7551
|
-
var
|
|
7552
|
-
var ZModelWorkspaceManager = class extends
|
|
8873
|
+
var import_langium12 = require("langium");
|
|
8874
|
+
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
8875
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
8876
|
+
var import_node_url2 = require("url");
|
|
8877
|
+
var import_meta2 = {};
|
|
8878
|
+
var ZModelWorkspaceManager = class extends import_langium12.DefaultWorkspaceManager {
|
|
7553
8879
|
static {
|
|
7554
8880
|
__name(this, "ZModelWorkspaceManager");
|
|
7555
8881
|
}
|
|
@@ -7570,9 +8896,9 @@ var ZModelWorkspaceManager = class extends import_langium9.DefaultWorkspaceManag
|
|
|
7570
8896
|
folderPath
|
|
7571
8897
|
]
|
|
7572
8898
|
});
|
|
7573
|
-
const languagePackageDir =
|
|
7574
|
-
const candidateStdlibPath =
|
|
7575
|
-
if (
|
|
8899
|
+
const languagePackageDir = import_node_path2.default.dirname(languagePackagePath);
|
|
8900
|
+
const candidateStdlibPath = import_node_path2.default.join(languagePackageDir, "res", STD_LIB_MODULE_NAME);
|
|
8901
|
+
if (import_node_fs3.default.existsSync(candidateStdlibPath)) {
|
|
7576
8902
|
installedStdlibPath = candidateStdlibPath;
|
|
7577
8903
|
console.log(`Found installed zenstack package stdlib at: ${installedStdlibPath}`);
|
|
7578
8904
|
break;
|
|
@@ -7584,73 +8910,12 @@ var ZModelWorkspaceManager = class extends import_langium9.DefaultWorkspaceManag
|
|
|
7584
8910
|
if (installedStdlibPath) {
|
|
7585
8911
|
stdLibPath = installedStdlibPath;
|
|
7586
8912
|
} else {
|
|
7587
|
-
const _dirname = typeof __dirname !== "undefined" ? __dirname :
|
|
7588
|
-
stdLibPath =
|
|
8913
|
+
const _dirname = typeof __dirname !== "undefined" ? __dirname : import_node_path2.default.dirname((0, import_node_url2.fileURLToPath)(import_meta2.url));
|
|
8914
|
+
stdLibPath = import_node_path2.default.join(_dirname, "../res", STD_LIB_MODULE_NAME);
|
|
7589
8915
|
console.log(`Using bundled stdlib in extension:`, stdLibPath);
|
|
7590
8916
|
}
|
|
7591
|
-
const stdlib = await this.documentFactory.fromUri(
|
|
8917
|
+
const stdlib = await this.documentFactory.fromUri(import_langium12.URI.file(stdLibPath));
|
|
7592
8918
|
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
8919
|
}
|
|
7655
8920
|
};
|
|
7656
8921
|
|
|
@@ -7663,16 +8928,27 @@ var ZModelLanguageModule = {
|
|
|
7663
8928
|
},
|
|
7664
8929
|
validation: {
|
|
7665
8930
|
ZModelValidator: /* @__PURE__ */ __name((services) => new ZModelValidator(services), "ZModelValidator")
|
|
8931
|
+
},
|
|
8932
|
+
lsp: {
|
|
8933
|
+
Formatter: /* @__PURE__ */ __name((services) => new ZModelFormatter(services), "Formatter"),
|
|
8934
|
+
DefinitionProvider: /* @__PURE__ */ __name((services) => new ZModelDefinitionProvider(services), "DefinitionProvider"),
|
|
8935
|
+
CompletionProvider: /* @__PURE__ */ __name((services) => new ZModelCompletionProvider(services), "CompletionProvider"),
|
|
8936
|
+
SemanticTokenProvider: /* @__PURE__ */ __name((services) => new ZModelSemanticTokenProvider(services), "SemanticTokenProvider")
|
|
8937
|
+
},
|
|
8938
|
+
documentation: {
|
|
8939
|
+
CommentProvider: /* @__PURE__ */ __name((services) => new ZModelCommentProvider(services), "CommentProvider"),
|
|
8940
|
+
DocumentationProvider: /* @__PURE__ */ __name((services) => new ZModelDocumentationProvider(services), "DocumentationProvider")
|
|
7666
8941
|
}
|
|
7667
8942
|
};
|
|
7668
8943
|
var ZModelSharedModule = {
|
|
7669
8944
|
workspace: {
|
|
8945
|
+
DocumentBuilder: /* @__PURE__ */ __name((services) => new ZModelDocumentBuilder(services), "DocumentBuilder"),
|
|
7670
8946
|
WorkspaceManager: /* @__PURE__ */ __name((services) => new ZModelWorkspaceManager(services), "WorkspaceManager")
|
|
7671
8947
|
}
|
|
7672
8948
|
};
|
|
7673
|
-
function createZModelLanguageServices(context) {
|
|
7674
|
-
const shared = (0,
|
|
7675
|
-
const ZModelLanguage = (0,
|
|
8949
|
+
function createZModelLanguageServices(context, logToConsole = false) {
|
|
8950
|
+
const shared = (0, import_langium13.inject)((0, import_lsp5.createDefaultSharedModule)(context), ZModelGeneratedSharedModule, ZModelSharedModule);
|
|
8951
|
+
const ZModelLanguage = (0, import_langium13.inject)((0, import_lsp5.createDefaultModule)({
|
|
7676
8952
|
shared
|
|
7677
8953
|
}), ZModelGeneratedModule, ZModelLanguageModule);
|
|
7678
8954
|
shared.ServiceRegistry.register(ZModelLanguage);
|
|
@@ -7680,31 +8956,48 @@ function createZModelLanguageServices(context) {
|
|
|
7680
8956
|
if (!context.connection) {
|
|
7681
8957
|
shared.workspace.ConfigurationProvider.initialized({});
|
|
7682
8958
|
}
|
|
8959
|
+
shared.workspace.DocumentBuilder.onBuildPhase(import_langium13.DocumentState.Parsed, async (documents) => {
|
|
8960
|
+
for (const doc of documents) {
|
|
8961
|
+
if (doc.parseResult.lexerErrors.length > 0 || doc.parseResult.parserErrors.length > 0) {
|
|
8962
|
+
continue;
|
|
8963
|
+
}
|
|
8964
|
+
if (doc.uri.scheme !== "file") {
|
|
8965
|
+
continue;
|
|
8966
|
+
}
|
|
8967
|
+
const schemaPath = (0, import_node_url3.fileURLToPath)(doc.uri.toString());
|
|
8968
|
+
const pluginSchemas = getPluginDocuments(doc.parseResult.value, schemaPath);
|
|
8969
|
+
for (const plugin of pluginSchemas) {
|
|
8970
|
+
const pluginDocUri = import_langium13.URI.file(import_node_path3.default.resolve(plugin));
|
|
8971
|
+
let pluginDoc = shared.workspace.LangiumDocuments.getDocument(pluginDocUri);
|
|
8972
|
+
if (!pluginDoc) {
|
|
8973
|
+
pluginDoc = await shared.workspace.LangiumDocuments.getOrCreateDocument(pluginDocUri);
|
|
8974
|
+
if (pluginDoc) {
|
|
8975
|
+
shared.workspace.IndexManager.updateContent(pluginDoc);
|
|
8976
|
+
if (logToConsole) {
|
|
8977
|
+
console.log(`Loaded plugin model: ${plugin}`);
|
|
8978
|
+
}
|
|
8979
|
+
}
|
|
8980
|
+
}
|
|
8981
|
+
}
|
|
8982
|
+
}
|
|
8983
|
+
});
|
|
7683
8984
|
return {
|
|
7684
8985
|
shared,
|
|
7685
8986
|
ZModelLanguage
|
|
7686
8987
|
};
|
|
7687
8988
|
}
|
|
7688
8989
|
__name(createZModelLanguageServices, "createZModelLanguageServices");
|
|
7689
|
-
|
|
7690
|
-
|
|
7691
|
-
var import_meta2 = {};
|
|
7692
|
-
function createZModelServices() {
|
|
7693
|
-
return createZModelLanguageServices(import_node.NodeFileSystem);
|
|
8990
|
+
function createZModelServices(logToConsole = false) {
|
|
8991
|
+
return createZModelLanguageServices(import_node.NodeFileSystem, logToConsole);
|
|
7694
8992
|
}
|
|
7695
8993
|
__name(createZModelServices, "createZModelServices");
|
|
7696
|
-
|
|
7697
|
-
|
|
7698
|
-
|
|
7699
|
-
|
|
7700
|
-
|
|
7701
|
-
super(message);
|
|
7702
|
-
}
|
|
7703
|
-
};
|
|
7704
|
-
async function loadDocument(fileName, pluginModelFiles = []) {
|
|
7705
|
-
const { ZModelLanguage: services } = createZModelServices();
|
|
8994
|
+
|
|
8995
|
+
// src/document.ts
|
|
8996
|
+
var import_meta3 = {};
|
|
8997
|
+
async function loadDocument(fileName, additionalModelFiles = []) {
|
|
8998
|
+
const { ZModelLanguage: services } = createZModelServices(false);
|
|
7706
8999
|
const extensions = services.LanguageMetaData.fileExtensions;
|
|
7707
|
-
if (!extensions.includes(
|
|
9000
|
+
if (!extensions.includes(import_node_path4.default.extname(fileName))) {
|
|
7708
9001
|
return {
|
|
7709
9002
|
success: false,
|
|
7710
9003
|
errors: [
|
|
@@ -7713,7 +9006,7 @@ async function loadDocument(fileName, pluginModelFiles = []) {
|
|
|
7713
9006
|
warnings: []
|
|
7714
9007
|
};
|
|
7715
9008
|
}
|
|
7716
|
-
if (!
|
|
9009
|
+
if (!import_node_fs4.default.existsSync(fileName)) {
|
|
7717
9010
|
return {
|
|
7718
9011
|
success: false,
|
|
7719
9012
|
errors: [
|
|
@@ -7722,23 +9015,27 @@ async function loadDocument(fileName, pluginModelFiles = []) {
|
|
|
7722
9015
|
warnings: []
|
|
7723
9016
|
};
|
|
7724
9017
|
}
|
|
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)))));
|
|
9018
|
+
const _dirname = typeof __dirname !== "undefined" ? __dirname : import_node_path4.default.dirname((0, import_node_url4.fileURLToPath)(import_meta3.url));
|
|
9019
|
+
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
9020
|
const langiumDocuments = services.shared.workspace.LangiumDocuments;
|
|
7729
|
-
const document = await langiumDocuments.getOrCreateDocument(
|
|
9021
|
+
const document = await langiumDocuments.getOrCreateDocument(import_langium14.URI.file(import_node_path4.default.resolve(fileName)));
|
|
7730
9022
|
const importedURIs = await loadImports(document, langiumDocuments);
|
|
7731
9023
|
const importedDocuments = [];
|
|
7732
9024
|
for (const uri of importedURIs) {
|
|
7733
9025
|
importedDocuments.push(await langiumDocuments.getOrCreateDocument(uri));
|
|
7734
9026
|
}
|
|
9027
|
+
const additionalDocs = await Promise.all(additionalModelFiles.map((file) => services.shared.workspace.LangiumDocuments.getOrCreateDocument(import_langium14.URI.file(import_node_path4.default.resolve(file)))));
|
|
7735
9028
|
await services.shared.workspace.DocumentBuilder.build([
|
|
7736
9029
|
stdLib,
|
|
7737
|
-
...
|
|
9030
|
+
...additionalDocs,
|
|
7738
9031
|
document,
|
|
7739
9032
|
...importedDocuments
|
|
7740
9033
|
], {
|
|
7741
|
-
validation:
|
|
9034
|
+
validation: {
|
|
9035
|
+
stopAfterLexingErrors: true,
|
|
9036
|
+
stopAfterParsingErrors: true,
|
|
9037
|
+
stopAfterLinkingErrors: true
|
|
9038
|
+
}
|
|
7742
9039
|
});
|
|
7743
9040
|
const diagnostics = langiumDocuments.all.flatMap((doc) => (doc.diagnostics ?? []).map((diag) => ({
|
|
7744
9041
|
doc,
|
|
@@ -7748,7 +9045,7 @@ async function loadDocument(fileName, pluginModelFiles = []) {
|
|
|
7748
9045
|
const warnings = [];
|
|
7749
9046
|
if (diagnostics.length > 0) {
|
|
7750
9047
|
for (const { doc, diag } of diagnostics) {
|
|
7751
|
-
const message = `${
|
|
9048
|
+
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
9049
|
if (diag.severity === 1) {
|
|
7753
9050
|
errors.push(message);
|
|
7754
9051
|
} else {
|
|
@@ -7797,7 +9094,7 @@ async function loadImports(document, documents, uris = /* @__PURE__ */ new Set()
|
|
|
7797
9094
|
}
|
|
7798
9095
|
}
|
|
7799
9096
|
}
|
|
7800
|
-
return Array.from(uris).filter((x) => uriString != x).map((e) =>
|
|
9097
|
+
return Array.from(uris).filter((x) => uriString != x).map((e) => import_langium14.URI.parse(e));
|
|
7801
9098
|
}
|
|
7802
9099
|
__name(loadImports, "loadImports");
|
|
7803
9100
|
function mergeImportsDeclarations(documents, model) {
|
|
@@ -7814,13 +9111,13 @@ function linkContentToContainer(node) {
|
|
|
7814
9111
|
if (!name.startsWith("$")) {
|
|
7815
9112
|
if (Array.isArray(value)) {
|
|
7816
9113
|
value.forEach((item, index) => {
|
|
7817
|
-
if ((0,
|
|
9114
|
+
if ((0, import_langium14.isAstNode)(item)) {
|
|
7818
9115
|
item.$container = node;
|
|
7819
9116
|
item.$containerProperty = name;
|
|
7820
9117
|
item.$containerIndex = index;
|
|
7821
9118
|
}
|
|
7822
9119
|
});
|
|
7823
|
-
} else if ((0,
|
|
9120
|
+
} else if ((0, import_langium14.isAstNode)(value)) {
|
|
7824
9121
|
value.$container = node;
|
|
7825
9122
|
value.$containerProperty = name;
|
|
7826
9123
|
}
|
|
@@ -7848,7 +9145,7 @@ function validationAfterImportMerge(model) {
|
|
|
7848
9145
|
__name(validationAfterImportMerge, "validationAfterImportMerge");
|
|
7849
9146
|
// Annotate the CommonJS export names for ESM import in node:
|
|
7850
9147
|
0 && (module.exports = {
|
|
7851
|
-
|
|
9148
|
+
ZModelCodeGenerator,
|
|
7852
9149
|
ZModelLanguageMetaData,
|
|
7853
9150
|
ZModelLanguageModule,
|
|
7854
9151
|
ZModelSharedModule,
|