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