@zenstackhq/language 3.0.0-beta.9 → 3.0.0
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 +1524 -235
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +89 -19
- package/dist/index.d.ts +89 -19
- package/dist/index.js +1470 -185
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +99 -8
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +7 -5
- package/dist/utils.d.ts +7 -5
- package/dist/utils.js +93 -5
- package/dist/utils.js.map +1 -1
- package/package.json +9 -11
- package/res/stdlib.zmodel +30 -97
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,14 +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
5197
|
var import_langium2 = require("langium");
|
|
5145
5198
|
var import_node_fs = __toESM(require("fs"), 1);
|
|
5146
|
-
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 = {};
|
|
5147
5203
|
function hasAttribute(decl, name) {
|
|
5148
5204
|
return !!getAttribute(decl, name);
|
|
5149
5205
|
}
|
|
@@ -5247,7 +5303,7 @@ function getRecursiveBases(decl, includeDelegate = true, seen = /* @__PURE__ */
|
|
|
5247
5303
|
] : []
|
|
5248
5304
|
];
|
|
5249
5305
|
bases.forEach((base) => {
|
|
5250
|
-
const baseDecl = decl.$container.declarations.find((d) => isTypeDef(d) || isDataModel(d) && d.name === base.$refText);
|
|
5306
|
+
const baseDecl = decl.$container.declarations.find((d) => (isTypeDef(d) || isDataModel(d)) && d.name === base.$refText);
|
|
5251
5307
|
if (baseDecl) {
|
|
5252
5308
|
if (!includeDelegate && isDelegateModel(baseDecl)) {
|
|
5253
5309
|
return;
|
|
@@ -5370,6 +5426,10 @@ function getArray(expr) {
|
|
|
5370
5426
|
return isArrayExpr(expr) || isConfigArrayExpr(expr) ? expr.items : void 0;
|
|
5371
5427
|
}
|
|
5372
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");
|
|
5373
5433
|
function getFunctionExpressionContext(funcDecl) {
|
|
5374
5434
|
const funcAllowedContext = [];
|
|
5375
5435
|
const funcAttr = funcDecl.attributes.find((attr) => attr.decl.$refText === "@@@expressionContext");
|
|
@@ -5437,9 +5497,9 @@ function resolveImportUri(imp) {
|
|
|
5437
5497
|
return void 0;
|
|
5438
5498
|
}
|
|
5439
5499
|
const doc = import_langium2.AstUtils.getDocument(imp);
|
|
5440
|
-
const dir =
|
|
5500
|
+
const dir = import_node_path.default.dirname(doc.uri.fsPath);
|
|
5441
5501
|
const importPath = imp.path.endsWith(".zmodel") ? imp.path : `${imp.path}.zmodel`;
|
|
5442
|
-
return import_langium2.URI.file(
|
|
5502
|
+
return import_langium2.URI.file(import_node_path.default.resolve(dir, importPath));
|
|
5443
5503
|
}
|
|
5444
5504
|
__name(resolveImportUri, "resolveImportUri");
|
|
5445
5505
|
function getDataModelAndTypeDefs(model, includeIgnored = false) {
|
|
@@ -5457,15 +5517,15 @@ function getAllDeclarationsIncludingImports(documents, model) {
|
|
|
5457
5517
|
}
|
|
5458
5518
|
__name(getAllDeclarationsIncludingImports, "getAllDeclarationsIncludingImports");
|
|
5459
5519
|
function getAuthDecl(decls) {
|
|
5460
|
-
let authModel = decls.find((
|
|
5520
|
+
let authModel = decls.find((d) => hasAttribute(d, "@@auth"));
|
|
5461
5521
|
if (!authModel) {
|
|
5462
|
-
authModel = decls.find((
|
|
5522
|
+
authModel = decls.find((d) => d.name === "User");
|
|
5463
5523
|
}
|
|
5464
5524
|
return authModel;
|
|
5465
5525
|
}
|
|
5466
5526
|
__name(getAuthDecl, "getAuthDecl");
|
|
5467
5527
|
function isBeforeInvocation(node) {
|
|
5468
|
-
return isInvocationExpr(node) && node.function.ref?.name === "before"
|
|
5528
|
+
return isInvocationExpr(node) && node.function.ref?.name === "before";
|
|
5469
5529
|
}
|
|
5470
5530
|
__name(isBeforeInvocation, "isBeforeInvocation");
|
|
5471
5531
|
function isCollectionPredicate(node) {
|
|
@@ -5548,13 +5608,23 @@ function getAllAttributes(decl, seen = /* @__PURE__ */ new Set()) {
|
|
|
5548
5608
|
}
|
|
5549
5609
|
if (isDataModel(decl) && decl.baseModel) {
|
|
5550
5610
|
if (decl.baseModel.ref) {
|
|
5551
|
-
|
|
5611
|
+
const attrs = getAllAttributes(decl.baseModel.ref, seen).filter((attr) => !isNonInheritableAttribute(attr));
|
|
5612
|
+
attributes.push(...attrs);
|
|
5552
5613
|
}
|
|
5553
5614
|
}
|
|
5554
5615
|
attributes.push(...decl.attributes);
|
|
5555
5616
|
return attributes;
|
|
5556
5617
|
}
|
|
5557
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");
|
|
5558
5628
|
function getDocument(node) {
|
|
5559
5629
|
const rootNode = findRootNode(node);
|
|
5560
5630
|
const result = rootNode.$document;
|
|
@@ -5564,6 +5634,71 @@ function getDocument(node) {
|
|
|
5564
5634
|
return result;
|
|
5565
5635
|
}
|
|
5566
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");
|
|
5567
5702
|
function findRootNode(node) {
|
|
5568
5703
|
while (node.$container) {
|
|
5569
5704
|
node = node.$container;
|
|
@@ -5573,6 +5708,9 @@ function findRootNode(node) {
|
|
|
5573
5708
|
__name(findRootNode, "findRootNode");
|
|
5574
5709
|
|
|
5575
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);
|
|
5576
5714
|
function _ts_decorate(decorators, target, key, desc) {
|
|
5577
5715
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5578
5716
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -5790,8 +5928,23 @@ var AttributeApplicationValidator = class {
|
|
|
5790
5928
|
});
|
|
5791
5929
|
}
|
|
5792
5930
|
}
|
|
5793
|
-
|
|
5794
|
-
const
|
|
5931
|
+
_checkId(attr, accept) {
|
|
5932
|
+
const dm = getContainingDataModel(attr);
|
|
5933
|
+
if (dm?.isView) {
|
|
5934
|
+
accept("error", `\`@id\` is not allowed for views`, {
|
|
5935
|
+
node: attr
|
|
5936
|
+
});
|
|
5937
|
+
}
|
|
5938
|
+
}
|
|
5939
|
+
_checkConstraint(attr, accept) {
|
|
5940
|
+
const dm = getContainingDataModel(attr);
|
|
5941
|
+
if (dm?.isView && (attr.decl.$refText === "@@id" || attr.decl.$refText === "@@index")) {
|
|
5942
|
+
accept("error", `\`${attr.decl.$refText}\` is not allowed for views`, {
|
|
5943
|
+
node: attr
|
|
5944
|
+
});
|
|
5945
|
+
}
|
|
5946
|
+
const fields = getAttributeArg(attr, "fields");
|
|
5947
|
+
const attrName = attr.decl.ref?.name;
|
|
5795
5948
|
if (!fields) {
|
|
5796
5949
|
accept("error", `expects an array of field references`, {
|
|
5797
5950
|
node: attr.args[0]
|
|
@@ -5800,7 +5953,7 @@ var AttributeApplicationValidator = class {
|
|
|
5800
5953
|
}
|
|
5801
5954
|
if (isArrayExpr(fields)) {
|
|
5802
5955
|
if (fields.items.length === 0) {
|
|
5803
|
-
accept("error",
|
|
5956
|
+
accept("error", `\`${attrName}\` expects at least one field reference`, {
|
|
5804
5957
|
node: fields
|
|
5805
5958
|
});
|
|
5806
5959
|
return;
|
|
@@ -5819,7 +5972,7 @@ var AttributeApplicationValidator = class {
|
|
|
5819
5972
|
return;
|
|
5820
5973
|
}
|
|
5821
5974
|
if (item.target.ref.$container !== attr.$container && isDelegateModel(item.target.ref.$container)) {
|
|
5822
|
-
accept("error", `Cannot use fields inherited from a polymorphic base model in
|
|
5975
|
+
accept("error", `Cannot use fields inherited from a polymorphic base model in \`${attrName}\``, {
|
|
5823
5976
|
node: item
|
|
5824
5977
|
});
|
|
5825
5978
|
}
|
|
@@ -5830,6 +5983,24 @@ var AttributeApplicationValidator = class {
|
|
|
5830
5983
|
});
|
|
5831
5984
|
}
|
|
5832
5985
|
}
|
|
5986
|
+
_checkSchema(attr, accept) {
|
|
5987
|
+
const schemaName = getStringLiteral(attr.args[0]?.value);
|
|
5988
|
+
(0, import_common_helpers.invariant)(schemaName, `@@schema expects a string literal`);
|
|
5989
|
+
const zmodel = import_langium3.AstUtils.getContainerOfType(attr, isModel);
|
|
5990
|
+
const datasource = zmodel.declarations.find(isDataSource);
|
|
5991
|
+
if (datasource) {
|
|
5992
|
+
let found = false;
|
|
5993
|
+
const schemas = datasource.fields.find((f) => f.name === "schemas");
|
|
5994
|
+
if (schemas && isConfigArrayExpr(schemas.value)) {
|
|
5995
|
+
found = schemas.value.items.some((item) => isLiteralExpr(item) && item.value === schemaName);
|
|
5996
|
+
}
|
|
5997
|
+
if (!found) {
|
|
5998
|
+
accept("error", `Schema "${schemaName}" is not defined in the datasource`, {
|
|
5999
|
+
node: attr
|
|
6000
|
+
});
|
|
6001
|
+
}
|
|
6002
|
+
}
|
|
6003
|
+
}
|
|
5833
6004
|
validatePolicyKinds(kind, candidates, attr, accept) {
|
|
5834
6005
|
const items = kind.split(",").map((x) => x.trim());
|
|
5835
6006
|
items.forEach((item) => {
|
|
@@ -5872,15 +6043,34 @@ _ts_decorate([
|
|
|
5872
6043
|
_ts_metadata("design:returntype", void 0)
|
|
5873
6044
|
], AttributeApplicationValidator.prototype, "_checkValidate", null);
|
|
5874
6045
|
_ts_decorate([
|
|
5875
|
-
check("
|
|
6046
|
+
check("@id"),
|
|
6047
|
+
_ts_metadata("design:type", Function),
|
|
6048
|
+
_ts_metadata("design:paramtypes", [
|
|
6049
|
+
typeof AttributeApplication === "undefined" ? Object : AttributeApplication,
|
|
6050
|
+
typeof ValidationAcceptor === "undefined" ? Object : ValidationAcceptor
|
|
6051
|
+
]),
|
|
6052
|
+
_ts_metadata("design:returntype", void 0)
|
|
6053
|
+
], AttributeApplicationValidator.prototype, "_checkId", null);
|
|
6054
|
+
_ts_decorate([
|
|
5876
6055
|
check("@@id"),
|
|
6056
|
+
check("@@index"),
|
|
6057
|
+
check("@@unique"),
|
|
6058
|
+
_ts_metadata("design:type", Function),
|
|
6059
|
+
_ts_metadata("design:paramtypes", [
|
|
6060
|
+
typeof AttributeApplication === "undefined" ? Object : AttributeApplication,
|
|
6061
|
+
typeof ValidationAcceptor === "undefined" ? Object : ValidationAcceptor
|
|
6062
|
+
]),
|
|
6063
|
+
_ts_metadata("design:returntype", void 0)
|
|
6064
|
+
], AttributeApplicationValidator.prototype, "_checkConstraint", null);
|
|
6065
|
+
_ts_decorate([
|
|
6066
|
+
check("@@schema"),
|
|
5877
6067
|
_ts_metadata("design:type", Function),
|
|
5878
6068
|
_ts_metadata("design:paramtypes", [
|
|
5879
6069
|
typeof AttributeApplication === "undefined" ? Object : AttributeApplication,
|
|
5880
6070
|
typeof ValidationAcceptor === "undefined" ? Object : ValidationAcceptor
|
|
5881
6071
|
]),
|
|
5882
6072
|
_ts_metadata("design:returntype", void 0)
|
|
5883
|
-
], AttributeApplicationValidator.prototype, "
|
|
6073
|
+
], AttributeApplicationValidator.prototype, "_checkSchema", null);
|
|
5884
6074
|
function assignableToAttributeParam(arg, param, attr) {
|
|
5885
6075
|
const argResolvedType = arg.$resolvedType;
|
|
5886
6076
|
if (!argResolvedType) {
|
|
@@ -6014,7 +6204,7 @@ var AttributeValidator = class {
|
|
|
6014
6204
|
};
|
|
6015
6205
|
|
|
6016
6206
|
// src/validators/datamodel-validator.ts
|
|
6017
|
-
var
|
|
6207
|
+
var import_common_helpers2 = require("@zenstackhq/common-helpers");
|
|
6018
6208
|
var import_langium4 = require("langium");
|
|
6019
6209
|
|
|
6020
6210
|
// src/validators/common.ts
|
|
@@ -6061,7 +6251,7 @@ var DataModelValidator = class {
|
|
|
6061
6251
|
const uniqueFields = allFields.filter((f) => f.attributes.find((attr) => attr.decl.ref?.name === "@unique"));
|
|
6062
6252
|
const modelLevelIds = getModelIdFields(dm);
|
|
6063
6253
|
const modelUniqueFields = getModelUniqueFields(dm);
|
|
6064
|
-
if (idFields.length === 0 && modelLevelIds.length === 0 && uniqueFields.length === 0 && modelUniqueFields.length === 0) {
|
|
6254
|
+
if (!dm.isView && idFields.length === 0 && modelLevelIds.length === 0 && uniqueFields.length === 0 && modelUniqueFields.length === 0) {
|
|
6065
6255
|
accept("error", "Model must have at least one unique criteria. Either mark a single field with `@id`, `@unique` or add a multi field criterion with `@@id([])` or `@@unique([])` to the model.", {
|
|
6066
6256
|
node: dm
|
|
6067
6257
|
});
|
|
@@ -6255,7 +6445,7 @@ var DataModelValidator = class {
|
|
|
6255
6445
|
if (!thisRelation.valid) {
|
|
6256
6446
|
return;
|
|
6257
6447
|
}
|
|
6258
|
-
if (this.isFieldInheritedFromDelegateModel(field)) {
|
|
6448
|
+
if (this.isFieldInheritedFromDelegateModel(field, contextModel)) {
|
|
6259
6449
|
return;
|
|
6260
6450
|
}
|
|
6261
6451
|
if (this.isSelfRelation(field)) {
|
|
@@ -6378,14 +6568,14 @@ var DataModelValidator = class {
|
|
|
6378
6568
|
}
|
|
6379
6569
|
}
|
|
6380
6570
|
// checks if the given field is inherited directly or indirectly from a delegate model
|
|
6381
|
-
isFieldInheritedFromDelegateModel(field) {
|
|
6382
|
-
return isDelegateModel(field.$container);
|
|
6571
|
+
isFieldInheritedFromDelegateModel(field, contextModel) {
|
|
6572
|
+
return field.$container !== contextModel && isDelegateModel(field.$container);
|
|
6383
6573
|
}
|
|
6384
6574
|
validateInherits(model, accept) {
|
|
6385
6575
|
if (!model.baseModel) {
|
|
6386
6576
|
return;
|
|
6387
6577
|
}
|
|
6388
|
-
(0,
|
|
6578
|
+
(0, import_common_helpers2.invariant)(model.baseModel.ref, "baseModel must be resolved");
|
|
6389
6579
|
if (!isDelegateModel(model.baseModel.ref)) {
|
|
6390
6580
|
accept("error", `Model ${model.baseModel.$refText} cannot be extended because it's not a delegate model`, {
|
|
6391
6581
|
node: model,
|
|
@@ -6407,7 +6597,7 @@ var DataModelValidator = class {
|
|
|
6407
6597
|
}
|
|
6408
6598
|
seen.push(current);
|
|
6409
6599
|
if (current.baseModel) {
|
|
6410
|
-
(0,
|
|
6600
|
+
(0, import_common_helpers2.invariant)(current.baseModel.ref, "baseModel must be resolved");
|
|
6411
6601
|
todo.push(current.baseModel.ref);
|
|
6412
6602
|
}
|
|
6413
6603
|
}
|
|
@@ -6438,7 +6628,6 @@ var DataSourceValidator = class {
|
|
|
6438
6628
|
validateDuplicatedDeclarations(ds, ds.fields, accept);
|
|
6439
6629
|
this.validateProvider(ds, accept);
|
|
6440
6630
|
this.validateUrl(ds, accept);
|
|
6441
|
-
this.validateRelationMode(ds, accept);
|
|
6442
6631
|
}
|
|
6443
6632
|
validateProvider(ds, accept) {
|
|
6444
6633
|
const provider = ds.fields.find((f) => f.name === "provider");
|
|
@@ -6448,16 +6637,61 @@ var DataSourceValidator = class {
|
|
|
6448
6637
|
});
|
|
6449
6638
|
return;
|
|
6450
6639
|
}
|
|
6451
|
-
const
|
|
6452
|
-
if (!
|
|
6640
|
+
const providerValue = getStringLiteral(provider.value);
|
|
6641
|
+
if (!providerValue) {
|
|
6453
6642
|
accept("error", '"provider" must be set to a string literal', {
|
|
6454
6643
|
node: provider.value
|
|
6455
6644
|
});
|
|
6456
|
-
} else if (!SUPPORTED_PROVIDERS.includes(
|
|
6457
|
-
accept("error", `Provider "${
|
|
6645
|
+
} else if (!SUPPORTED_PROVIDERS.includes(providerValue)) {
|
|
6646
|
+
accept("error", `Provider "${providerValue}" is not supported. Choose from ${SUPPORTED_PROVIDERS.map((p) => '"' + p + '"').join(" | ")}.`, {
|
|
6458
6647
|
node: provider.value
|
|
6459
6648
|
});
|
|
6460
6649
|
}
|
|
6650
|
+
const defaultSchemaField = ds.fields.find((f) => f.name === "defaultSchema");
|
|
6651
|
+
let defaultSchemaValue;
|
|
6652
|
+
if (defaultSchemaField) {
|
|
6653
|
+
if (providerValue !== "postgresql") {
|
|
6654
|
+
accept("error", '"defaultSchema" is only supported for "postgresql" provider', {
|
|
6655
|
+
node: defaultSchemaField
|
|
6656
|
+
});
|
|
6657
|
+
}
|
|
6658
|
+
defaultSchemaValue = getStringLiteral(defaultSchemaField.value);
|
|
6659
|
+
if (!defaultSchemaValue) {
|
|
6660
|
+
accept("error", '"defaultSchema" must be a string literal', {
|
|
6661
|
+
node: defaultSchemaField.value
|
|
6662
|
+
});
|
|
6663
|
+
}
|
|
6664
|
+
}
|
|
6665
|
+
const schemasField = ds.fields.find((f) => f.name === "schemas");
|
|
6666
|
+
if (schemasField) {
|
|
6667
|
+
if (providerValue !== "postgresql") {
|
|
6668
|
+
accept("error", '"schemas" is only supported for "postgresql" provider', {
|
|
6669
|
+
node: schemasField
|
|
6670
|
+
});
|
|
6671
|
+
}
|
|
6672
|
+
const schemasValue = schemasField.value;
|
|
6673
|
+
if (!isConfigArrayExpr(schemasValue) || !schemasValue.items.every((e) => isLiteralExpr(e) && typeof getStringLiteral(e) === "string")) {
|
|
6674
|
+
accept("error", '"schemas" must be an array of string literals', {
|
|
6675
|
+
node: schemasField
|
|
6676
|
+
});
|
|
6677
|
+
} else {
|
|
6678
|
+
const schemasArray = schemasValue.items.map((e) => getStringLiteral(e));
|
|
6679
|
+
if (defaultSchemaValue) {
|
|
6680
|
+
if (!schemasArray.includes(defaultSchemaValue)) {
|
|
6681
|
+
accept("error", `"${defaultSchemaValue}" must be included in the "schemas" array`, {
|
|
6682
|
+
node: schemasField
|
|
6683
|
+
});
|
|
6684
|
+
}
|
|
6685
|
+
} else {
|
|
6686
|
+
const hasImplicitPublicSchema = ds.$container.declarations.some((d) => (isDataModel(d) || isEnum(d)) && !d.attributes.some((a) => a.decl.$refText === "@@schema"));
|
|
6687
|
+
if (hasImplicitPublicSchema && !schemasArray.includes("public")) {
|
|
6688
|
+
accept("error", `"public" must be included in the "schemas" array`, {
|
|
6689
|
+
node: schemasField
|
|
6690
|
+
});
|
|
6691
|
+
}
|
|
6692
|
+
}
|
|
6693
|
+
}
|
|
6694
|
+
}
|
|
6461
6695
|
}
|
|
6462
6696
|
validateUrl(ds, accept) {
|
|
6463
6697
|
const urlField = ds.fields.find((f) => f.name === "url");
|
|
@@ -6471,20 +6705,6 @@ var DataSourceValidator = class {
|
|
|
6471
6705
|
});
|
|
6472
6706
|
}
|
|
6473
6707
|
}
|
|
6474
|
-
validateRelationMode(ds, accept) {
|
|
6475
|
-
const field = ds.fields.find((f) => f.name === "relationMode");
|
|
6476
|
-
if (field) {
|
|
6477
|
-
const val = getStringLiteral(field.value);
|
|
6478
|
-
if (!val || ![
|
|
6479
|
-
"foreignKeys",
|
|
6480
|
-
"prisma"
|
|
6481
|
-
].includes(val)) {
|
|
6482
|
-
accept("error", '"relationMode" must be set to "foreignKeys" or "prisma"', {
|
|
6483
|
-
node: field.value
|
|
6484
|
-
});
|
|
6485
|
-
}
|
|
6486
|
-
}
|
|
6487
|
-
}
|
|
6488
6708
|
};
|
|
6489
6709
|
|
|
6490
6710
|
// src/validators/enum-validator.ts
|
|
@@ -6543,6 +6763,9 @@ var ExpressionValidator = class {
|
|
|
6543
6763
|
case "BinaryExpr":
|
|
6544
6764
|
this.validateBinaryExpr(expr, accept);
|
|
6545
6765
|
break;
|
|
6766
|
+
case "UnaryExpr":
|
|
6767
|
+
this.validateUnaryExpr(expr, accept);
|
|
6768
|
+
break;
|
|
6546
6769
|
}
|
|
6547
6770
|
}
|
|
6548
6771
|
validateMemberAccessExpr(expr, accept) {
|
|
@@ -6684,6 +6907,13 @@ var ExpressionValidator = class {
|
|
|
6684
6907
|
break;
|
|
6685
6908
|
}
|
|
6686
6909
|
}
|
|
6910
|
+
validateUnaryExpr(expr, accept) {
|
|
6911
|
+
if (expr.operand.$resolvedType && expr.operand.$resolvedType.decl !== "Boolean") {
|
|
6912
|
+
accept("error", `operand of "${expr.operator}" must be of Boolean type`, {
|
|
6913
|
+
node: expr.operand
|
|
6914
|
+
});
|
|
6915
|
+
}
|
|
6916
|
+
}
|
|
6687
6917
|
validateCollectionPredicate(expr, accept) {
|
|
6688
6918
|
if (!expr.$resolvedType) {
|
|
6689
6919
|
accept("error", "collection predicate can only be used on an array of model type", {
|
|
@@ -6753,44 +6983,42 @@ var FunctionInvocationValidator = class {
|
|
|
6753
6983
|
});
|
|
6754
6984
|
return;
|
|
6755
6985
|
}
|
|
6756
|
-
if (!this.validateArgs(funcDecl, expr
|
|
6986
|
+
if (!this.validateArgs(funcDecl, expr, accept)) {
|
|
6757
6987
|
return;
|
|
6758
6988
|
}
|
|
6759
|
-
|
|
6760
|
-
|
|
6761
|
-
|
|
6762
|
-
|
|
6763
|
-
|
|
6764
|
-
|
|
6765
|
-
break;
|
|
6766
|
-
}
|
|
6767
|
-
curr = curr.$container;
|
|
6989
|
+
let curr = expr.$container;
|
|
6990
|
+
let containerAttribute;
|
|
6991
|
+
while (curr) {
|
|
6992
|
+
if (isDataModelAttribute(curr) || isDataFieldAttribute(curr)) {
|
|
6993
|
+
containerAttribute = curr;
|
|
6994
|
+
break;
|
|
6768
6995
|
}
|
|
6769
|
-
|
|
6770
|
-
|
|
6771
|
-
|
|
6772
|
-
|
|
6773
|
-
|
|
6996
|
+
curr = curr.$container;
|
|
6997
|
+
}
|
|
6998
|
+
const exprContext = this.getExpressionContext(containerAttribute);
|
|
6999
|
+
const funcAllowedContext = getFunctionExpressionContext(funcDecl);
|
|
7000
|
+
if (exprContext && !funcAllowedContext.includes(exprContext)) {
|
|
7001
|
+
accept("error", `function "${funcDecl.name}" is not allowed in the current context: ${exprContext}`, {
|
|
7002
|
+
node: expr
|
|
7003
|
+
});
|
|
7004
|
+
return;
|
|
7005
|
+
}
|
|
7006
|
+
const allCasing = [
|
|
7007
|
+
"original",
|
|
7008
|
+
"upper",
|
|
7009
|
+
"lower",
|
|
7010
|
+
"capitalize",
|
|
7011
|
+
"uncapitalize"
|
|
7012
|
+
];
|
|
7013
|
+
if ([
|
|
7014
|
+
"currentModel",
|
|
7015
|
+
"currentOperation"
|
|
7016
|
+
].includes(funcDecl.name)) {
|
|
7017
|
+
const arg = getLiteral(expr.args[0]?.value);
|
|
7018
|
+
if (arg && !allCasing.includes(arg)) {
|
|
7019
|
+
accept("error", `argument must be one of: ${allCasing.map((c) => '"' + c + '"').join(", ")}`, {
|
|
7020
|
+
node: expr.args[0]
|
|
6774
7021
|
});
|
|
6775
|
-
return;
|
|
6776
|
-
}
|
|
6777
|
-
const allCasing = [
|
|
6778
|
-
"original",
|
|
6779
|
-
"upper",
|
|
6780
|
-
"lower",
|
|
6781
|
-
"capitalize",
|
|
6782
|
-
"uncapitalize"
|
|
6783
|
-
];
|
|
6784
|
-
if ([
|
|
6785
|
-
"currentModel",
|
|
6786
|
-
"currentOperation"
|
|
6787
|
-
].includes(funcDecl.name)) {
|
|
6788
|
-
const arg = getLiteral(expr.args[0]?.value);
|
|
6789
|
-
if (arg && !allCasing.includes(arg)) {
|
|
6790
|
-
accept("error", `argument must be one of: ${allCasing.map((c) => '"' + c + '"').join(", ")}`, {
|
|
6791
|
-
node: expr.args[0]
|
|
6792
|
-
});
|
|
6793
|
-
}
|
|
6794
7022
|
}
|
|
6795
7023
|
}
|
|
6796
7024
|
const checker = invocationCheckers.get(expr.function.$refText);
|
|
@@ -6810,18 +7038,18 @@ var FunctionInvocationValidator = class {
|
|
|
6810
7038
|
isValidationAttribute(attr) {
|
|
6811
7039
|
return !!attr.decl.ref?.attributes.some((attr2) => attr2.decl.$refText === "@@@validation");
|
|
6812
7040
|
}
|
|
6813
|
-
validateArgs(funcDecl,
|
|
7041
|
+
validateArgs(funcDecl, expr, accept) {
|
|
6814
7042
|
let success = true;
|
|
6815
7043
|
for (let i = 0; i < funcDecl.params.length; i++) {
|
|
6816
7044
|
const param = funcDecl.params[i];
|
|
6817
7045
|
if (!param) {
|
|
6818
7046
|
continue;
|
|
6819
7047
|
}
|
|
6820
|
-
const arg = args[i];
|
|
7048
|
+
const arg = expr.args[i];
|
|
6821
7049
|
if (!arg) {
|
|
6822
7050
|
if (!param.optional) {
|
|
6823
7051
|
accept("error", `missing argument for parameter "${param.name}"`, {
|
|
6824
|
-
node:
|
|
7052
|
+
node: expr
|
|
6825
7053
|
});
|
|
6826
7054
|
success = false;
|
|
6827
7055
|
}
|
|
@@ -6870,6 +7098,13 @@ var FunctionInvocationValidator = class {
|
|
|
6870
7098
|
}
|
|
6871
7099
|
return true;
|
|
6872
7100
|
}
|
|
7101
|
+
_checkAuth(expr, accept) {
|
|
7102
|
+
if (!expr.$resolvedType) {
|
|
7103
|
+
accept("error", 'cannot resolve `auth()` - make sure you have a model or type with `@auth` attribute or named "User"', {
|
|
7104
|
+
node: expr
|
|
7105
|
+
});
|
|
7106
|
+
}
|
|
7107
|
+
}
|
|
6873
7108
|
_checkLength(expr, accept) {
|
|
6874
7109
|
const msg = "argument must be a string or list field";
|
|
6875
7110
|
const fieldArg = expr.args[0].value;
|
|
@@ -6979,6 +7214,15 @@ var FunctionInvocationValidator = class {
|
|
|
6979
7214
|
}
|
|
6980
7215
|
}
|
|
6981
7216
|
};
|
|
7217
|
+
_ts_decorate2([
|
|
7218
|
+
func("auth"),
|
|
7219
|
+
_ts_metadata2("design:type", Function),
|
|
7220
|
+
_ts_metadata2("design:paramtypes", [
|
|
7221
|
+
typeof InvocationExpr === "undefined" ? Object : InvocationExpr,
|
|
7222
|
+
typeof ValidationAcceptor === "undefined" ? Object : ValidationAcceptor
|
|
7223
|
+
]),
|
|
7224
|
+
_ts_metadata2("design:returntype", void 0)
|
|
7225
|
+
], FunctionInvocationValidator.prototype, "_checkAuth", null);
|
|
6982
7226
|
_ts_decorate2([
|
|
6983
7227
|
func("length"),
|
|
6984
7228
|
_ts_metadata2("design:type", Function),
|
|
@@ -7087,6 +7331,7 @@ function registerValidationChecks(services) {
|
|
|
7087
7331
|
const checks = {
|
|
7088
7332
|
Model: validator.checkModel,
|
|
7089
7333
|
DataSource: validator.checkDataSource,
|
|
7334
|
+
GeneratorDecl: validator.checkGenerator,
|
|
7090
7335
|
DataModel: validator.checkDataModel,
|
|
7091
7336
|
TypeDef: validator.checkTypeDef,
|
|
7092
7337
|
Enum: validator.checkEnum,
|
|
@@ -7112,6 +7357,11 @@ var ZModelValidator = class {
|
|
|
7112
7357
|
checkDataSource(node, accept) {
|
|
7113
7358
|
new DataSourceValidator().validate(node, accept);
|
|
7114
7359
|
}
|
|
7360
|
+
checkGenerator(node, accept) {
|
|
7361
|
+
accept("warning", '"generator" is not used by ZenStack and should be removed.', {
|
|
7362
|
+
node
|
|
7363
|
+
});
|
|
7364
|
+
}
|
|
7115
7365
|
checkDataModel(node, accept) {
|
|
7116
7366
|
new DataModelValidator().validate(node, accept);
|
|
7117
7367
|
}
|
|
@@ -7135,9 +7385,876 @@ var ZModelValidator = class {
|
|
|
7135
7385
|
}
|
|
7136
7386
|
};
|
|
7137
7387
|
|
|
7138
|
-
// src/zmodel-
|
|
7388
|
+
// src/zmodel-comment-provider.ts
|
|
7139
7389
|
var import_langium7 = require("langium");
|
|
7140
|
-
var
|
|
7390
|
+
var import_ts_pattern2 = require("ts-pattern");
|
|
7391
|
+
var ZModelCommentProvider = class extends import_langium7.DefaultCommentProvider {
|
|
7392
|
+
static {
|
|
7393
|
+
__name(this, "ZModelCommentProvider");
|
|
7394
|
+
}
|
|
7395
|
+
getComment(node) {
|
|
7396
|
+
let comment = super.getComment(node);
|
|
7397
|
+
if (!comment) {
|
|
7398
|
+
comment = (0, import_ts_pattern2.match)(node).when(isDataModel, (d) => `/**
|
|
7399
|
+
* Model *${d.name}*
|
|
7400
|
+
*/`).when(isTypeDef, (d) => `/**
|
|
7401
|
+
* Type *${d.name}*
|
|
7402
|
+
*/`).when(isEnum, (e) => `/**
|
|
7403
|
+
* Enum *${e.name}*
|
|
7404
|
+
*/`).when(isEnumField, (f) => `/**
|
|
7405
|
+
* Value of enum *${f.$container?.name}*
|
|
7406
|
+
*/`).when(isDataField, (f) => `/**
|
|
7407
|
+
* Field of *${f.$container?.name}*
|
|
7408
|
+
*/`).when(isFunctionDecl, (f) => `/**
|
|
7409
|
+
* Function *${f.name}*
|
|
7410
|
+
*/`).otherwise(() => "");
|
|
7411
|
+
}
|
|
7412
|
+
return comment;
|
|
7413
|
+
}
|
|
7414
|
+
};
|
|
7415
|
+
|
|
7416
|
+
// src/zmodel-completion-provider.ts
|
|
7417
|
+
var import_lsp = require("langium/lsp");
|
|
7418
|
+
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
7419
|
+
var import_ts_pattern3 = require("ts-pattern");
|
|
7420
|
+
var import_vscode_languageserver = require("vscode-languageserver");
|
|
7421
|
+
|
|
7422
|
+
// src/zmodel-code-generator.ts
|
|
7423
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
7424
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
7425
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
7426
|
+
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;
|
|
7427
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7428
|
+
}
|
|
7429
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
7430
|
+
function _ts_metadata3(k, v) {
|
|
7431
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
7432
|
+
}
|
|
7433
|
+
__name(_ts_metadata3, "_ts_metadata");
|
|
7434
|
+
var generationHandlers = /* @__PURE__ */ new Map();
|
|
7435
|
+
function gen(name) {
|
|
7436
|
+
return function(_target, _propertyKey, descriptor) {
|
|
7437
|
+
if (!generationHandlers.get(name)) {
|
|
7438
|
+
generationHandlers.set(name, descriptor);
|
|
7439
|
+
}
|
|
7440
|
+
return descriptor;
|
|
7441
|
+
};
|
|
7442
|
+
}
|
|
7443
|
+
__name(gen, "gen");
|
|
7444
|
+
var ZModelCodeGenerator = class {
|
|
7445
|
+
static {
|
|
7446
|
+
__name(this, "ZModelCodeGenerator");
|
|
7447
|
+
}
|
|
7448
|
+
options;
|
|
7449
|
+
constructor(options) {
|
|
7450
|
+
this.options = {
|
|
7451
|
+
binaryExprNumberOfSpaces: options?.binaryExprNumberOfSpaces ?? 1,
|
|
7452
|
+
unaryExprNumberOfSpaces: options?.unaryExprNumberOfSpaces ?? 0,
|
|
7453
|
+
indent: options?.indent ?? 4,
|
|
7454
|
+
quote: options?.quote ?? "single"
|
|
7455
|
+
};
|
|
7456
|
+
}
|
|
7457
|
+
/**
|
|
7458
|
+
* Generates ZModel source code from AST.
|
|
7459
|
+
*/
|
|
7460
|
+
generate(ast) {
|
|
7461
|
+
const handler = generationHandlers.get(ast.$type);
|
|
7462
|
+
if (!handler) {
|
|
7463
|
+
throw new Error(`No generation handler found for ${ast.$type}`);
|
|
7464
|
+
}
|
|
7465
|
+
return handler.value.call(this, ast);
|
|
7466
|
+
}
|
|
7467
|
+
_generateModel(ast) {
|
|
7468
|
+
return ast.declarations.map((d) => this.generate(d)).join("\n\n");
|
|
7469
|
+
}
|
|
7470
|
+
_generateDataSource(ast) {
|
|
7471
|
+
return `datasource ${ast.name} {
|
|
7472
|
+
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
7473
|
+
}`;
|
|
7474
|
+
}
|
|
7475
|
+
_generateEnum(ast) {
|
|
7476
|
+
return `enum ${ast.name} {
|
|
7477
|
+
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
7478
|
+
}`;
|
|
7479
|
+
}
|
|
7480
|
+
_generateEnumField(ast) {
|
|
7481
|
+
return `${ast.name}${ast.attributes.length > 0 ? " " + ast.attributes.map((x) => this.generate(x)).join(" ") : ""}`;
|
|
7482
|
+
}
|
|
7483
|
+
_generateGenerator(ast) {
|
|
7484
|
+
return `generator ${ast.name} {
|
|
7485
|
+
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
7486
|
+
}`;
|
|
7487
|
+
}
|
|
7488
|
+
_generateConfigField(ast) {
|
|
7489
|
+
return `${ast.name} = ${this.generate(ast.value)}`;
|
|
7490
|
+
}
|
|
7491
|
+
_generateConfigArrayExpr(ast) {
|
|
7492
|
+
return `[${ast.items.map((x) => this.generate(x)).join(", ")}]`;
|
|
7493
|
+
}
|
|
7494
|
+
_generateConfigInvocationExpr(ast) {
|
|
7495
|
+
if (ast.args.length === 0) {
|
|
7496
|
+
return ast.name;
|
|
7497
|
+
} else {
|
|
7498
|
+
return `${ast.name}(${ast.args.map((x) => (x.name ? x.name + ": " : "") + this.generate(x.value)).join(", ")})`;
|
|
7499
|
+
}
|
|
7500
|
+
}
|
|
7501
|
+
_generatePlugin(ast) {
|
|
7502
|
+
return `plugin ${ast.name} {
|
|
7503
|
+
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
7504
|
+
}`;
|
|
7505
|
+
}
|
|
7506
|
+
_generatePluginField(ast) {
|
|
7507
|
+
return `${ast.name} = ${this.generate(ast.value)}`;
|
|
7508
|
+
}
|
|
7509
|
+
_generateDataModel(ast) {
|
|
7510
|
+
return `${ast.isView ? "view" : "model"} ${ast.name}${ast.mixins.length > 0 ? " mixes " + ast.mixins.map((x) => x.$refText).join(", ") : ""} {
|
|
7511
|
+
${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") : ""}
|
|
7512
|
+
}`;
|
|
7513
|
+
}
|
|
7514
|
+
_generateDataField(ast) {
|
|
7515
|
+
return `${ast.name} ${this.fieldType(ast.type)}${ast.attributes.length > 0 ? " " + ast.attributes.map((x) => this.generate(x)).join(" ") : ""}`;
|
|
7516
|
+
}
|
|
7517
|
+
fieldType(type) {
|
|
7518
|
+
const baseType = type.type ? type.type : type.$type == "DataFieldType" && type.unsupported ? "Unsupported(" + this.generate(type.unsupported.value) + ")" : type.reference?.$refText;
|
|
7519
|
+
return `${baseType}${type.array ? "[]" : ""}${type.optional ? "?" : ""}`;
|
|
7520
|
+
}
|
|
7521
|
+
_generateDataModelAttribute(ast) {
|
|
7522
|
+
return this.attribute(ast);
|
|
7523
|
+
}
|
|
7524
|
+
_generateDataFieldAttribute(ast) {
|
|
7525
|
+
return this.attribute(ast);
|
|
7526
|
+
}
|
|
7527
|
+
attribute(ast) {
|
|
7528
|
+
const args = ast.args.length ? `(${ast.args.map((x) => this.generate(x)).join(", ")})` : "";
|
|
7529
|
+
return `${ast.decl.$refText}${args}`;
|
|
7530
|
+
}
|
|
7531
|
+
_generateAttributeArg(ast) {
|
|
7532
|
+
if (ast.name) {
|
|
7533
|
+
return `${ast.name}: ${this.generate(ast.value)}`;
|
|
7534
|
+
} else {
|
|
7535
|
+
return this.generate(ast.value);
|
|
7536
|
+
}
|
|
7537
|
+
}
|
|
7538
|
+
_generateObjectExpr(ast) {
|
|
7539
|
+
return `{ ${ast.fields.map((field) => this.objectField(field)).join(", ")} }`;
|
|
7540
|
+
}
|
|
7541
|
+
objectField(field) {
|
|
7542
|
+
return `${field.name}: ${this.generate(field.value)}`;
|
|
7543
|
+
}
|
|
7544
|
+
_generateArrayExpr(ast) {
|
|
7545
|
+
return `[${ast.items.map((item) => this.generate(item)).join(", ")}]`;
|
|
7546
|
+
}
|
|
7547
|
+
_generateLiteralExpr(ast) {
|
|
7548
|
+
return this.options.quote === "single" ? `'${ast.value}'` : `"${ast.value}"`;
|
|
7549
|
+
}
|
|
7550
|
+
_generateNumberLiteral(ast) {
|
|
7551
|
+
return ast.value.toString();
|
|
7552
|
+
}
|
|
7553
|
+
_generateBooleanLiteral(ast) {
|
|
7554
|
+
return ast.value.toString();
|
|
7555
|
+
}
|
|
7556
|
+
_generateUnaryExpr(ast) {
|
|
7557
|
+
return `${ast.operator}${this.unaryExprSpace}${this.generate(ast.operand)}`;
|
|
7558
|
+
}
|
|
7559
|
+
_generateBinaryExpr(ast) {
|
|
7560
|
+
const operator = ast.operator;
|
|
7561
|
+
const isCollectionPredicate2 = this.isCollectionPredicateOperator(operator);
|
|
7562
|
+
const rightExpr = this.generate(ast.right);
|
|
7563
|
+
const { left: isLeftParenthesis, right: isRightParenthesis } = this.isParenthesesNeededForBinaryExpr(ast);
|
|
7564
|
+
return `${isLeftParenthesis ? "(" : ""}${this.generate(ast.left)}${isLeftParenthesis ? ")" : ""}${isCollectionPredicate2 ? "" : this.binaryExprSpace}${operator}${isCollectionPredicate2 ? "" : this.binaryExprSpace}${isRightParenthesis ? "(" : ""}${isCollectionPredicate2 ? `[${rightExpr}]` : rightExpr}${isRightParenthesis ? ")" : ""}`;
|
|
7565
|
+
}
|
|
7566
|
+
_generateReferenceExpr(ast) {
|
|
7567
|
+
const args = ast.args.length ? `(${ast.args.map((x) => this.generate(x)).join(", ")})` : "";
|
|
7568
|
+
return `${ast.target.$refText}${args}`;
|
|
7569
|
+
}
|
|
7570
|
+
_generateReferenceArg(ast) {
|
|
7571
|
+
return `${ast.name}:${this.generate(ast.value)}`;
|
|
7572
|
+
}
|
|
7573
|
+
_generateMemberExpr(ast) {
|
|
7574
|
+
return `${this.generate(ast.operand)}.${ast.member.$refText}`;
|
|
7575
|
+
}
|
|
7576
|
+
_generateInvocationExpr(ast) {
|
|
7577
|
+
return `${ast.function.$refText}(${ast.args.map((x) => this.argument(x)).join(", ")})`;
|
|
7578
|
+
}
|
|
7579
|
+
_generateNullExpr() {
|
|
7580
|
+
return "null";
|
|
7581
|
+
}
|
|
7582
|
+
_generateThisExpr() {
|
|
7583
|
+
return "this";
|
|
7584
|
+
}
|
|
7585
|
+
_generateAttribute(ast) {
|
|
7586
|
+
return `attribute ${ast.name}(${ast.params.map((x) => this.generate(x)).join(", ")})`;
|
|
7587
|
+
}
|
|
7588
|
+
_generateAttributeParam(ast) {
|
|
7589
|
+
return `${ast.default ? "_ " : ""}${ast.name}: ${this.generate(ast.type)}`;
|
|
7590
|
+
}
|
|
7591
|
+
_generateAttributeParamType(ast) {
|
|
7592
|
+
return `${ast.type ?? ast.reference?.$refText}${ast.array ? "[]" : ""}${ast.optional ? "?" : ""}`;
|
|
7593
|
+
}
|
|
7594
|
+
_generateFunctionDecl(ast) {
|
|
7595
|
+
return `function ${ast.name}(${ast.params.map((x) => this.generate(x)).join(", ")}) ${ast.returnType ? ": " + this.generate(ast.returnType) : ""} {}`;
|
|
7596
|
+
}
|
|
7597
|
+
_generateFunctionParam(ast) {
|
|
7598
|
+
return `${ast.name}: ${this.generate(ast.type)}`;
|
|
7599
|
+
}
|
|
7600
|
+
_generateFunctionParamType(ast) {
|
|
7601
|
+
return `${ast.type ?? ast.reference?.$refText}${ast.array ? "[]" : ""}`;
|
|
7602
|
+
}
|
|
7603
|
+
_generateTypeDef(ast) {
|
|
7604
|
+
return `type ${ast.name} {
|
|
7605
|
+
${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") : ""}
|
|
7606
|
+
}`;
|
|
7607
|
+
}
|
|
7608
|
+
argument(ast) {
|
|
7609
|
+
return this.generate(ast.value);
|
|
7610
|
+
}
|
|
7611
|
+
get binaryExprSpace() {
|
|
7612
|
+
return " ".repeat(this.options.binaryExprNumberOfSpaces);
|
|
7613
|
+
}
|
|
7614
|
+
get unaryExprSpace() {
|
|
7615
|
+
return " ".repeat(this.options.unaryExprNumberOfSpaces);
|
|
7616
|
+
}
|
|
7617
|
+
get indent() {
|
|
7618
|
+
return " ".repeat(this.options.indent);
|
|
7619
|
+
}
|
|
7620
|
+
isParenthesesNeededForBinaryExpr(ast) {
|
|
7621
|
+
const result = {
|
|
7622
|
+
left: false,
|
|
7623
|
+
right: false
|
|
7624
|
+
};
|
|
7625
|
+
const operator = ast.operator;
|
|
7626
|
+
const isCollectionPredicate2 = this.isCollectionPredicateOperator(operator);
|
|
7627
|
+
const currentPriority = BinaryExprOperatorPriority[operator];
|
|
7628
|
+
if (ast.left.$type === BinaryExpr && BinaryExprOperatorPriority[ast.left["operator"]] < currentPriority) {
|
|
7629
|
+
result.left = true;
|
|
7630
|
+
}
|
|
7631
|
+
if (!isCollectionPredicate2 && ast.right.$type === BinaryExpr && BinaryExprOperatorPriority[ast.right["operator"]] <= currentPriority) {
|
|
7632
|
+
result.right = true;
|
|
7633
|
+
}
|
|
7634
|
+
return result;
|
|
7635
|
+
}
|
|
7636
|
+
isCollectionPredicateOperator(op) {
|
|
7637
|
+
return [
|
|
7638
|
+
"?",
|
|
7639
|
+
"!",
|
|
7640
|
+
"^"
|
|
7641
|
+
].includes(op);
|
|
7642
|
+
}
|
|
7643
|
+
};
|
|
7644
|
+
_ts_decorate3([
|
|
7645
|
+
gen(Model),
|
|
7646
|
+
_ts_metadata3("design:type", Function),
|
|
7647
|
+
_ts_metadata3("design:paramtypes", [
|
|
7648
|
+
typeof Model === "undefined" ? Object : Model
|
|
7649
|
+
]),
|
|
7650
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7651
|
+
], ZModelCodeGenerator.prototype, "_generateModel", null);
|
|
7652
|
+
_ts_decorate3([
|
|
7653
|
+
gen(DataSource),
|
|
7654
|
+
_ts_metadata3("design:type", Function),
|
|
7655
|
+
_ts_metadata3("design:paramtypes", [
|
|
7656
|
+
typeof DataSource === "undefined" ? Object : DataSource
|
|
7657
|
+
]),
|
|
7658
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7659
|
+
], ZModelCodeGenerator.prototype, "_generateDataSource", null);
|
|
7660
|
+
_ts_decorate3([
|
|
7661
|
+
gen(Enum),
|
|
7662
|
+
_ts_metadata3("design:type", Function),
|
|
7663
|
+
_ts_metadata3("design:paramtypes", [
|
|
7664
|
+
typeof Enum === "undefined" ? Object : Enum
|
|
7665
|
+
]),
|
|
7666
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7667
|
+
], ZModelCodeGenerator.prototype, "_generateEnum", null);
|
|
7668
|
+
_ts_decorate3([
|
|
7669
|
+
gen(EnumField),
|
|
7670
|
+
_ts_metadata3("design:type", Function),
|
|
7671
|
+
_ts_metadata3("design:paramtypes", [
|
|
7672
|
+
typeof EnumField === "undefined" ? Object : EnumField
|
|
7673
|
+
]),
|
|
7674
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7675
|
+
], ZModelCodeGenerator.prototype, "_generateEnumField", null);
|
|
7676
|
+
_ts_decorate3([
|
|
7677
|
+
gen(GeneratorDecl),
|
|
7678
|
+
_ts_metadata3("design:type", Function),
|
|
7679
|
+
_ts_metadata3("design:paramtypes", [
|
|
7680
|
+
typeof GeneratorDecl === "undefined" ? Object : GeneratorDecl
|
|
7681
|
+
]),
|
|
7682
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7683
|
+
], ZModelCodeGenerator.prototype, "_generateGenerator", null);
|
|
7684
|
+
_ts_decorate3([
|
|
7685
|
+
gen(ConfigField),
|
|
7686
|
+
_ts_metadata3("design:type", Function),
|
|
7687
|
+
_ts_metadata3("design:paramtypes", [
|
|
7688
|
+
typeof ConfigField === "undefined" ? Object : ConfigField
|
|
7689
|
+
]),
|
|
7690
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7691
|
+
], ZModelCodeGenerator.prototype, "_generateConfigField", null);
|
|
7692
|
+
_ts_decorate3([
|
|
7693
|
+
gen(ConfigArrayExpr),
|
|
7694
|
+
_ts_metadata3("design:type", Function),
|
|
7695
|
+
_ts_metadata3("design:paramtypes", [
|
|
7696
|
+
typeof ConfigArrayExpr === "undefined" ? Object : ConfigArrayExpr
|
|
7697
|
+
]),
|
|
7698
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7699
|
+
], ZModelCodeGenerator.prototype, "_generateConfigArrayExpr", null);
|
|
7700
|
+
_ts_decorate3([
|
|
7701
|
+
gen(ConfigInvocationExpr),
|
|
7702
|
+
_ts_metadata3("design:type", Function),
|
|
7703
|
+
_ts_metadata3("design:paramtypes", [
|
|
7704
|
+
typeof ConfigInvocationExpr === "undefined" ? Object : ConfigInvocationExpr
|
|
7705
|
+
]),
|
|
7706
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7707
|
+
], ZModelCodeGenerator.prototype, "_generateConfigInvocationExpr", null);
|
|
7708
|
+
_ts_decorate3([
|
|
7709
|
+
gen(Plugin),
|
|
7710
|
+
_ts_metadata3("design:type", Function),
|
|
7711
|
+
_ts_metadata3("design:paramtypes", [
|
|
7712
|
+
typeof Plugin === "undefined" ? Object : Plugin
|
|
7713
|
+
]),
|
|
7714
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7715
|
+
], ZModelCodeGenerator.prototype, "_generatePlugin", null);
|
|
7716
|
+
_ts_decorate3([
|
|
7717
|
+
gen(PluginField),
|
|
7718
|
+
_ts_metadata3("design:type", Function),
|
|
7719
|
+
_ts_metadata3("design:paramtypes", [
|
|
7720
|
+
typeof PluginField === "undefined" ? Object : PluginField
|
|
7721
|
+
]),
|
|
7722
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7723
|
+
], ZModelCodeGenerator.prototype, "_generatePluginField", null);
|
|
7724
|
+
_ts_decorate3([
|
|
7725
|
+
gen(DataModel),
|
|
7726
|
+
_ts_metadata3("design:type", Function),
|
|
7727
|
+
_ts_metadata3("design:paramtypes", [
|
|
7728
|
+
typeof DataModel === "undefined" ? Object : DataModel
|
|
7729
|
+
]),
|
|
7730
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7731
|
+
], ZModelCodeGenerator.prototype, "_generateDataModel", null);
|
|
7732
|
+
_ts_decorate3([
|
|
7733
|
+
gen(DataField),
|
|
7734
|
+
_ts_metadata3("design:type", Function),
|
|
7735
|
+
_ts_metadata3("design:paramtypes", [
|
|
7736
|
+
typeof DataField === "undefined" ? Object : DataField
|
|
7737
|
+
]),
|
|
7738
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7739
|
+
], ZModelCodeGenerator.prototype, "_generateDataField", null);
|
|
7740
|
+
_ts_decorate3([
|
|
7741
|
+
gen(DataModelAttribute),
|
|
7742
|
+
_ts_metadata3("design:type", Function),
|
|
7743
|
+
_ts_metadata3("design:paramtypes", [
|
|
7744
|
+
typeof DataModelAttribute === "undefined" ? Object : DataModelAttribute
|
|
7745
|
+
]),
|
|
7746
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7747
|
+
], ZModelCodeGenerator.prototype, "_generateDataModelAttribute", null);
|
|
7748
|
+
_ts_decorate3([
|
|
7749
|
+
gen(DataFieldAttribute),
|
|
7750
|
+
_ts_metadata3("design:type", Function),
|
|
7751
|
+
_ts_metadata3("design:paramtypes", [
|
|
7752
|
+
typeof DataFieldAttribute === "undefined" ? Object : DataFieldAttribute
|
|
7753
|
+
]),
|
|
7754
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7755
|
+
], ZModelCodeGenerator.prototype, "_generateDataFieldAttribute", null);
|
|
7756
|
+
_ts_decorate3([
|
|
7757
|
+
gen(AttributeArg),
|
|
7758
|
+
_ts_metadata3("design:type", Function),
|
|
7759
|
+
_ts_metadata3("design:paramtypes", [
|
|
7760
|
+
typeof AttributeArg === "undefined" ? Object : AttributeArg
|
|
7761
|
+
]),
|
|
7762
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7763
|
+
], ZModelCodeGenerator.prototype, "_generateAttributeArg", null);
|
|
7764
|
+
_ts_decorate3([
|
|
7765
|
+
gen(ObjectExpr),
|
|
7766
|
+
_ts_metadata3("design:type", Function),
|
|
7767
|
+
_ts_metadata3("design:paramtypes", [
|
|
7768
|
+
typeof ObjectExpr === "undefined" ? Object : ObjectExpr
|
|
7769
|
+
]),
|
|
7770
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7771
|
+
], ZModelCodeGenerator.prototype, "_generateObjectExpr", null);
|
|
7772
|
+
_ts_decorate3([
|
|
7773
|
+
gen(ArrayExpr),
|
|
7774
|
+
_ts_metadata3("design:type", Function),
|
|
7775
|
+
_ts_metadata3("design:paramtypes", [
|
|
7776
|
+
typeof ArrayExpr === "undefined" ? Object : ArrayExpr
|
|
7777
|
+
]),
|
|
7778
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7779
|
+
], ZModelCodeGenerator.prototype, "_generateArrayExpr", null);
|
|
7780
|
+
_ts_decorate3([
|
|
7781
|
+
gen(StringLiteral),
|
|
7782
|
+
_ts_metadata3("design:type", Function),
|
|
7783
|
+
_ts_metadata3("design:paramtypes", [
|
|
7784
|
+
typeof LiteralExpr === "undefined" ? Object : LiteralExpr
|
|
7785
|
+
]),
|
|
7786
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7787
|
+
], ZModelCodeGenerator.prototype, "_generateLiteralExpr", null);
|
|
7788
|
+
_ts_decorate3([
|
|
7789
|
+
gen(NumberLiteral),
|
|
7790
|
+
_ts_metadata3("design:type", Function),
|
|
7791
|
+
_ts_metadata3("design:paramtypes", [
|
|
7792
|
+
typeof NumberLiteral === "undefined" ? Object : NumberLiteral
|
|
7793
|
+
]),
|
|
7794
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7795
|
+
], ZModelCodeGenerator.prototype, "_generateNumberLiteral", null);
|
|
7796
|
+
_ts_decorate3([
|
|
7797
|
+
gen(BooleanLiteral),
|
|
7798
|
+
_ts_metadata3("design:type", Function),
|
|
7799
|
+
_ts_metadata3("design:paramtypes", [
|
|
7800
|
+
typeof BooleanLiteral === "undefined" ? Object : BooleanLiteral
|
|
7801
|
+
]),
|
|
7802
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7803
|
+
], ZModelCodeGenerator.prototype, "_generateBooleanLiteral", null);
|
|
7804
|
+
_ts_decorate3([
|
|
7805
|
+
gen(UnaryExpr),
|
|
7806
|
+
_ts_metadata3("design:type", Function),
|
|
7807
|
+
_ts_metadata3("design:paramtypes", [
|
|
7808
|
+
typeof UnaryExpr === "undefined" ? Object : UnaryExpr
|
|
7809
|
+
]),
|
|
7810
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7811
|
+
], ZModelCodeGenerator.prototype, "_generateUnaryExpr", null);
|
|
7812
|
+
_ts_decorate3([
|
|
7813
|
+
gen(BinaryExpr),
|
|
7814
|
+
_ts_metadata3("design:type", Function),
|
|
7815
|
+
_ts_metadata3("design:paramtypes", [
|
|
7816
|
+
typeof BinaryExpr === "undefined" ? Object : BinaryExpr
|
|
7817
|
+
]),
|
|
7818
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7819
|
+
], ZModelCodeGenerator.prototype, "_generateBinaryExpr", null);
|
|
7820
|
+
_ts_decorate3([
|
|
7821
|
+
gen(ReferenceExpr),
|
|
7822
|
+
_ts_metadata3("design:type", Function),
|
|
7823
|
+
_ts_metadata3("design:paramtypes", [
|
|
7824
|
+
typeof ReferenceExpr === "undefined" ? Object : ReferenceExpr
|
|
7825
|
+
]),
|
|
7826
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7827
|
+
], ZModelCodeGenerator.prototype, "_generateReferenceExpr", null);
|
|
7828
|
+
_ts_decorate3([
|
|
7829
|
+
gen(ReferenceArg),
|
|
7830
|
+
_ts_metadata3("design:type", Function),
|
|
7831
|
+
_ts_metadata3("design:paramtypes", [
|
|
7832
|
+
typeof ReferenceArg === "undefined" ? Object : ReferenceArg
|
|
7833
|
+
]),
|
|
7834
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7835
|
+
], ZModelCodeGenerator.prototype, "_generateReferenceArg", null);
|
|
7836
|
+
_ts_decorate3([
|
|
7837
|
+
gen(MemberAccessExpr),
|
|
7838
|
+
_ts_metadata3("design:type", Function),
|
|
7839
|
+
_ts_metadata3("design:paramtypes", [
|
|
7840
|
+
typeof MemberAccessExpr === "undefined" ? Object : MemberAccessExpr
|
|
7841
|
+
]),
|
|
7842
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7843
|
+
], ZModelCodeGenerator.prototype, "_generateMemberExpr", null);
|
|
7844
|
+
_ts_decorate3([
|
|
7845
|
+
gen(InvocationExpr),
|
|
7846
|
+
_ts_metadata3("design:type", Function),
|
|
7847
|
+
_ts_metadata3("design:paramtypes", [
|
|
7848
|
+
typeof InvocationExpr === "undefined" ? Object : InvocationExpr
|
|
7849
|
+
]),
|
|
7850
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7851
|
+
], ZModelCodeGenerator.prototype, "_generateInvocationExpr", null);
|
|
7852
|
+
_ts_decorate3([
|
|
7853
|
+
gen(NullExpr),
|
|
7854
|
+
_ts_metadata3("design:type", Function),
|
|
7855
|
+
_ts_metadata3("design:paramtypes", []),
|
|
7856
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7857
|
+
], ZModelCodeGenerator.prototype, "_generateNullExpr", null);
|
|
7858
|
+
_ts_decorate3([
|
|
7859
|
+
gen(ThisExpr),
|
|
7860
|
+
_ts_metadata3("design:type", Function),
|
|
7861
|
+
_ts_metadata3("design:paramtypes", []),
|
|
7862
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7863
|
+
], ZModelCodeGenerator.prototype, "_generateThisExpr", null);
|
|
7864
|
+
_ts_decorate3([
|
|
7865
|
+
gen(Attribute),
|
|
7866
|
+
_ts_metadata3("design:type", Function),
|
|
7867
|
+
_ts_metadata3("design:paramtypes", [
|
|
7868
|
+
typeof Attribute === "undefined" ? Object : Attribute
|
|
7869
|
+
]),
|
|
7870
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7871
|
+
], ZModelCodeGenerator.prototype, "_generateAttribute", null);
|
|
7872
|
+
_ts_decorate3([
|
|
7873
|
+
gen(AttributeParam),
|
|
7874
|
+
_ts_metadata3("design:type", Function),
|
|
7875
|
+
_ts_metadata3("design:paramtypes", [
|
|
7876
|
+
typeof AttributeParam === "undefined" ? Object : AttributeParam
|
|
7877
|
+
]),
|
|
7878
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7879
|
+
], ZModelCodeGenerator.prototype, "_generateAttributeParam", null);
|
|
7880
|
+
_ts_decorate3([
|
|
7881
|
+
gen(AttributeParamType),
|
|
7882
|
+
_ts_metadata3("design:type", Function),
|
|
7883
|
+
_ts_metadata3("design:paramtypes", [
|
|
7884
|
+
typeof AttributeParamType === "undefined" ? Object : AttributeParamType
|
|
7885
|
+
]),
|
|
7886
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7887
|
+
], ZModelCodeGenerator.prototype, "_generateAttributeParamType", null);
|
|
7888
|
+
_ts_decorate3([
|
|
7889
|
+
gen(FunctionDecl),
|
|
7890
|
+
_ts_metadata3("design:type", Function),
|
|
7891
|
+
_ts_metadata3("design:paramtypes", [
|
|
7892
|
+
typeof FunctionDecl === "undefined" ? Object : FunctionDecl
|
|
7893
|
+
]),
|
|
7894
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7895
|
+
], ZModelCodeGenerator.prototype, "_generateFunctionDecl", null);
|
|
7896
|
+
_ts_decorate3([
|
|
7897
|
+
gen(FunctionParam),
|
|
7898
|
+
_ts_metadata3("design:type", Function),
|
|
7899
|
+
_ts_metadata3("design:paramtypes", [
|
|
7900
|
+
typeof FunctionParam === "undefined" ? Object : FunctionParam
|
|
7901
|
+
]),
|
|
7902
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7903
|
+
], ZModelCodeGenerator.prototype, "_generateFunctionParam", null);
|
|
7904
|
+
_ts_decorate3([
|
|
7905
|
+
gen(FunctionParamType),
|
|
7906
|
+
_ts_metadata3("design:type", Function),
|
|
7907
|
+
_ts_metadata3("design:paramtypes", [
|
|
7908
|
+
typeof FunctionParamType === "undefined" ? Object : FunctionParamType
|
|
7909
|
+
]),
|
|
7910
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7911
|
+
], ZModelCodeGenerator.prototype, "_generateFunctionParamType", null);
|
|
7912
|
+
_ts_decorate3([
|
|
7913
|
+
gen(TypeDef),
|
|
7914
|
+
_ts_metadata3("design:type", Function),
|
|
7915
|
+
_ts_metadata3("design:paramtypes", [
|
|
7916
|
+
typeof TypeDef === "undefined" ? Object : TypeDef
|
|
7917
|
+
]),
|
|
7918
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7919
|
+
], ZModelCodeGenerator.prototype, "_generateTypeDef", null);
|
|
7920
|
+
|
|
7921
|
+
// src/zmodel-completion-provider.ts
|
|
7922
|
+
var ZModelCompletionProvider = class extends import_lsp.DefaultCompletionProvider {
|
|
7923
|
+
static {
|
|
7924
|
+
__name(this, "ZModelCompletionProvider");
|
|
7925
|
+
}
|
|
7926
|
+
services;
|
|
7927
|
+
constructor(services) {
|
|
7928
|
+
super(services), this.services = services;
|
|
7929
|
+
}
|
|
7930
|
+
completionOptions = {
|
|
7931
|
+
triggerCharacters: [
|
|
7932
|
+
"@",
|
|
7933
|
+
"(",
|
|
7934
|
+
",",
|
|
7935
|
+
"."
|
|
7936
|
+
]
|
|
7937
|
+
};
|
|
7938
|
+
async getCompletion(document, params) {
|
|
7939
|
+
try {
|
|
7940
|
+
return await super.getCompletion(document, params);
|
|
7941
|
+
} catch (e) {
|
|
7942
|
+
console.error("Completion error:", e.message);
|
|
7943
|
+
return void 0;
|
|
7944
|
+
}
|
|
7945
|
+
}
|
|
7946
|
+
completionFor(context, next, acceptor) {
|
|
7947
|
+
if (isDataModelAttribute(context.node) || isDataFieldAttribute(context.node)) {
|
|
7948
|
+
const completions = this.getCompletionFromHint(context.node);
|
|
7949
|
+
if (completions) {
|
|
7950
|
+
completions.forEach((c) => acceptor(context, c));
|
|
7951
|
+
return;
|
|
7952
|
+
}
|
|
7953
|
+
}
|
|
7954
|
+
return super.completionFor(context, next, acceptor);
|
|
7955
|
+
}
|
|
7956
|
+
getCompletionFromHint(contextNode) {
|
|
7957
|
+
const unfilledParams = this.getUnfilledAttributeParams(contextNode);
|
|
7958
|
+
const nextParam = unfilledParams[0];
|
|
7959
|
+
if (!nextParam) {
|
|
7960
|
+
return void 0;
|
|
7961
|
+
}
|
|
7962
|
+
const hintAttr = getAttribute(nextParam, "@@@completionHint");
|
|
7963
|
+
if (hintAttr) {
|
|
7964
|
+
const hint = hintAttr.args[0];
|
|
7965
|
+
if (hint?.value) {
|
|
7966
|
+
if (isArrayExpr(hint.value)) {
|
|
7967
|
+
return hint.value.items.map((item) => {
|
|
7968
|
+
return {
|
|
7969
|
+
label: `${item.value}`,
|
|
7970
|
+
kind: import_vscode_languageserver.CompletionItemKind.Value,
|
|
7971
|
+
detail: "Parameter",
|
|
7972
|
+
sortText: "0"
|
|
7973
|
+
};
|
|
7974
|
+
});
|
|
7975
|
+
}
|
|
7976
|
+
}
|
|
7977
|
+
}
|
|
7978
|
+
return void 0;
|
|
7979
|
+
}
|
|
7980
|
+
// TODO: this doesn't work when the file contains parse errors
|
|
7981
|
+
getUnfilledAttributeParams(contextNode) {
|
|
7982
|
+
try {
|
|
7983
|
+
const params = contextNode.decl.ref?.params;
|
|
7984
|
+
if (params) {
|
|
7985
|
+
const args = contextNode.args;
|
|
7986
|
+
let unfilledParams = [
|
|
7987
|
+
...params
|
|
7988
|
+
];
|
|
7989
|
+
args.forEach((arg) => {
|
|
7990
|
+
if (arg.name) {
|
|
7991
|
+
unfilledParams = unfilledParams.filter((p) => p.name !== arg.name);
|
|
7992
|
+
} else {
|
|
7993
|
+
unfilledParams.shift();
|
|
7994
|
+
}
|
|
7995
|
+
});
|
|
7996
|
+
return unfilledParams;
|
|
7997
|
+
}
|
|
7998
|
+
} catch {
|
|
7999
|
+
}
|
|
8000
|
+
return [];
|
|
8001
|
+
}
|
|
8002
|
+
completionForCrossReference(context, crossRef, acceptor) {
|
|
8003
|
+
if (crossRef.property === "member" && !isMemberAccessExpr(context.node)) {
|
|
8004
|
+
return;
|
|
8005
|
+
}
|
|
8006
|
+
const customAcceptor = /* @__PURE__ */ __name((context2, item) => {
|
|
8007
|
+
if (item.insertText?.startsWith("@@@") || item.label?.startsWith("@@@")) {
|
|
8008
|
+
return;
|
|
8009
|
+
}
|
|
8010
|
+
if ("nodeDescription" in item) {
|
|
8011
|
+
const node = this.getAstNode(item.nodeDescription);
|
|
8012
|
+
if (!node) {
|
|
8013
|
+
return;
|
|
8014
|
+
}
|
|
8015
|
+
if ((isEnum(node) || isEnumField(node)) && isFromStdlib(node)) {
|
|
8016
|
+
return;
|
|
8017
|
+
}
|
|
8018
|
+
if ((isDataModelAttribute(context2.node) || isDataFieldAttribute(context2.node)) && !this.filterAttributeApplicationCompletion(context2.node, node)) {
|
|
8019
|
+
return;
|
|
8020
|
+
}
|
|
8021
|
+
}
|
|
8022
|
+
acceptor(context2, item);
|
|
8023
|
+
}, "customAcceptor");
|
|
8024
|
+
return super.completionForCrossReference(context, crossRef, customAcceptor);
|
|
8025
|
+
}
|
|
8026
|
+
completionForKeyword(context, keyword, acceptor) {
|
|
8027
|
+
const customAcceptor = /* @__PURE__ */ __name((context2, item) => {
|
|
8028
|
+
if (!this.filterKeywordForContext(context2, keyword.value)) {
|
|
8029
|
+
return;
|
|
8030
|
+
}
|
|
8031
|
+
acceptor(context2, item);
|
|
8032
|
+
}, "customAcceptor");
|
|
8033
|
+
return super.completionForKeyword(context, keyword, customAcceptor);
|
|
8034
|
+
}
|
|
8035
|
+
filterKeywordForContext(context, keyword) {
|
|
8036
|
+
if (isInvocationExpr(context.node)) {
|
|
8037
|
+
return [
|
|
8038
|
+
"true",
|
|
8039
|
+
"false",
|
|
8040
|
+
"null",
|
|
8041
|
+
"this"
|
|
8042
|
+
].includes(keyword);
|
|
8043
|
+
} else if (isDataModelAttribute(context.node) || isDataFieldAttribute(context.node)) {
|
|
8044
|
+
const exprContext = this.getAttributeContextType(context.node);
|
|
8045
|
+
if (exprContext === "DefaultValue") {
|
|
8046
|
+
return [
|
|
8047
|
+
"true",
|
|
8048
|
+
"false",
|
|
8049
|
+
"null"
|
|
8050
|
+
].includes(keyword);
|
|
8051
|
+
} else {
|
|
8052
|
+
return [
|
|
8053
|
+
"true",
|
|
8054
|
+
"false",
|
|
8055
|
+
"null",
|
|
8056
|
+
"this"
|
|
8057
|
+
].includes(keyword);
|
|
8058
|
+
}
|
|
8059
|
+
} else {
|
|
8060
|
+
return true;
|
|
8061
|
+
}
|
|
8062
|
+
}
|
|
8063
|
+
filterAttributeApplicationCompletion(contextNode, node) {
|
|
8064
|
+
const attrContextType = this.getAttributeContextType(contextNode);
|
|
8065
|
+
if (isFunctionDecl(node) && attrContextType) {
|
|
8066
|
+
const funcExprContextAttr = getAttribute(node, "@@@expressionContext");
|
|
8067
|
+
if (funcExprContextAttr && funcExprContextAttr.args[0]) {
|
|
8068
|
+
const arg = funcExprContextAttr.args[0];
|
|
8069
|
+
if (isArrayExpr(arg.value)) {
|
|
8070
|
+
return arg.value.items.some((item) => isEnumFieldReference(item) && item.target.$refText === attrContextType);
|
|
8071
|
+
}
|
|
8072
|
+
}
|
|
8073
|
+
return false;
|
|
8074
|
+
}
|
|
8075
|
+
if (isDataField(node)) {
|
|
8076
|
+
return attrContextType !== "DefaultValue";
|
|
8077
|
+
}
|
|
8078
|
+
return true;
|
|
8079
|
+
}
|
|
8080
|
+
getAttributeContextType(node) {
|
|
8081
|
+
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);
|
|
8082
|
+
}
|
|
8083
|
+
createReferenceCompletionItem(nodeDescription) {
|
|
8084
|
+
const node = this.getAstNode(nodeDescription);
|
|
8085
|
+
const documentation = this.getNodeDocumentation(node);
|
|
8086
|
+
return (0, import_ts_pattern3.match)(node).when(isDataModel, () => ({
|
|
8087
|
+
nodeDescription,
|
|
8088
|
+
kind: import_vscode_languageserver.CompletionItemKind.Class,
|
|
8089
|
+
detail: "Model",
|
|
8090
|
+
sortText: "1",
|
|
8091
|
+
documentation
|
|
8092
|
+
})).when(isTypeDef, () => ({
|
|
8093
|
+
nodeDescription,
|
|
8094
|
+
kind: import_vscode_languageserver.CompletionItemKind.Class,
|
|
8095
|
+
detail: "Type",
|
|
8096
|
+
sortText: "1",
|
|
8097
|
+
documentation
|
|
8098
|
+
})).when(isDataField, () => ({
|
|
8099
|
+
nodeDescription,
|
|
8100
|
+
kind: import_vscode_languageserver.CompletionItemKind.Field,
|
|
8101
|
+
detail: "Field",
|
|
8102
|
+
sortText: "0",
|
|
8103
|
+
documentation
|
|
8104
|
+
})).when(isEnum, () => ({
|
|
8105
|
+
nodeDescription,
|
|
8106
|
+
kind: import_vscode_languageserver.CompletionItemKind.Class,
|
|
8107
|
+
detail: "Enum",
|
|
8108
|
+
sortText: "1",
|
|
8109
|
+
documentation
|
|
8110
|
+
})).when(isEnumField, (d) => {
|
|
8111
|
+
const container = d.$container;
|
|
8112
|
+
return {
|
|
8113
|
+
nodeDescription,
|
|
8114
|
+
kind: import_vscode_languageserver.CompletionItemKind.Enum,
|
|
8115
|
+
detail: `Value of enum "${container.name}"`,
|
|
8116
|
+
sortText: "1",
|
|
8117
|
+
documentation
|
|
8118
|
+
};
|
|
8119
|
+
}).when(isFunctionDecl, () => ({
|
|
8120
|
+
nodeDescription,
|
|
8121
|
+
insertText: this.getFunctionInsertText(nodeDescription),
|
|
8122
|
+
kind: import_vscode_languageserver.CompletionItemKind.Function,
|
|
8123
|
+
detail: "Function",
|
|
8124
|
+
sortText: "1",
|
|
8125
|
+
documentation
|
|
8126
|
+
})).when(isAttribute, () => ({
|
|
8127
|
+
nodeDescription,
|
|
8128
|
+
insertText: this.getAttributeInsertText(nodeDescription),
|
|
8129
|
+
kind: import_vscode_languageserver.CompletionItemKind.Property,
|
|
8130
|
+
detail: "Attribute",
|
|
8131
|
+
sortText: "1",
|
|
8132
|
+
documentation
|
|
8133
|
+
})).otherwise(() => ({
|
|
8134
|
+
nodeDescription,
|
|
8135
|
+
kind: import_vscode_languageserver.CompletionItemKind.Reference,
|
|
8136
|
+
detail: nodeDescription.type,
|
|
8137
|
+
sortText: "2",
|
|
8138
|
+
documentation
|
|
8139
|
+
}));
|
|
8140
|
+
}
|
|
8141
|
+
getFunctionInsertText(nodeDescription) {
|
|
8142
|
+
const node = this.getAstNode(nodeDescription);
|
|
8143
|
+
if (isFunctionDecl(node)) {
|
|
8144
|
+
if (node.params.some((p) => !p.optional)) {
|
|
8145
|
+
return nodeDescription.name;
|
|
8146
|
+
}
|
|
8147
|
+
}
|
|
8148
|
+
return `${nodeDescription.name}()`;
|
|
8149
|
+
}
|
|
8150
|
+
getAttributeInsertText(nodeDescription) {
|
|
8151
|
+
const node = this.getAstNode(nodeDescription);
|
|
8152
|
+
if (isAttribute(node)) {
|
|
8153
|
+
if (node.name === "@relation") {
|
|
8154
|
+
return `${nodeDescription.name}(fields: [], references: [])`;
|
|
8155
|
+
}
|
|
8156
|
+
}
|
|
8157
|
+
return nodeDescription.name;
|
|
8158
|
+
}
|
|
8159
|
+
getAstNode(nodeDescription) {
|
|
8160
|
+
let node = nodeDescription.node;
|
|
8161
|
+
if (!node) {
|
|
8162
|
+
const doc = this.getOrCreateDocumentSync(nodeDescription);
|
|
8163
|
+
if (!doc) {
|
|
8164
|
+
return void 0;
|
|
8165
|
+
}
|
|
8166
|
+
node = this.services.workspace.AstNodeLocator.getAstNode(doc.parseResult.value, nodeDescription.path);
|
|
8167
|
+
if (!node) {
|
|
8168
|
+
return void 0;
|
|
8169
|
+
}
|
|
8170
|
+
}
|
|
8171
|
+
return node;
|
|
8172
|
+
}
|
|
8173
|
+
getOrCreateDocumentSync(nodeDescription) {
|
|
8174
|
+
let doc = this.services.shared.workspace.LangiumDocuments.getDocument(nodeDescription.documentUri);
|
|
8175
|
+
if (!doc) {
|
|
8176
|
+
try {
|
|
8177
|
+
const content = import_node_fs2.default.readFileSync(nodeDescription.documentUri.fsPath, "utf-8");
|
|
8178
|
+
doc = this.services.shared.workspace.LangiumDocuments.createDocument(nodeDescription.documentUri, content);
|
|
8179
|
+
} catch {
|
|
8180
|
+
console.warn("Failed to read or create document:", nodeDescription.documentUri);
|
|
8181
|
+
return void 0;
|
|
8182
|
+
}
|
|
8183
|
+
}
|
|
8184
|
+
return doc;
|
|
8185
|
+
}
|
|
8186
|
+
getNodeDocumentation(node) {
|
|
8187
|
+
if (!node) {
|
|
8188
|
+
return void 0;
|
|
8189
|
+
}
|
|
8190
|
+
const md = this.commentsToMarkdown(node);
|
|
8191
|
+
return {
|
|
8192
|
+
kind: "markdown",
|
|
8193
|
+
value: md
|
|
8194
|
+
};
|
|
8195
|
+
}
|
|
8196
|
+
commentsToMarkdown(node) {
|
|
8197
|
+
const md = this.services.documentation.DocumentationProvider.getDocumentation(node) ?? "";
|
|
8198
|
+
const zModelGenerator = new ZModelCodeGenerator();
|
|
8199
|
+
const docs = [];
|
|
8200
|
+
try {
|
|
8201
|
+
(0, import_ts_pattern3.match)(node).when(isAttribute, (attr) => {
|
|
8202
|
+
docs.push("```prisma", zModelGenerator.generate(attr), "```");
|
|
8203
|
+
}).when(isFunctionDecl, (func2) => {
|
|
8204
|
+
docs.push("```ts", zModelGenerator.generate(func2), "```");
|
|
8205
|
+
}).when(isDataModel, (model) => {
|
|
8206
|
+
docs.push("```prisma", `model ${model.name} { ... }`, "```");
|
|
8207
|
+
}).when(isEnum, (enumDecl) => {
|
|
8208
|
+
docs.push("```prisma", zModelGenerator.generate(enumDecl), "```");
|
|
8209
|
+
}).when(isDataField, (field) => {
|
|
8210
|
+
docs.push(`${field.name}: ${field.type.type ?? field.type.reference?.$refText}`);
|
|
8211
|
+
}).otherwise((ast) => {
|
|
8212
|
+
const name = ast.name;
|
|
8213
|
+
if (name) {
|
|
8214
|
+
docs.push(name);
|
|
8215
|
+
}
|
|
8216
|
+
});
|
|
8217
|
+
} catch {
|
|
8218
|
+
}
|
|
8219
|
+
if (md) {
|
|
8220
|
+
docs.push("___", md);
|
|
8221
|
+
}
|
|
8222
|
+
return docs.join("\n");
|
|
8223
|
+
}
|
|
8224
|
+
};
|
|
8225
|
+
|
|
8226
|
+
// src/zmodel-definition.ts
|
|
8227
|
+
var import_lsp2 = require("langium/lsp");
|
|
8228
|
+
var import_vscode_languageserver2 = require("vscode-languageserver");
|
|
8229
|
+
var ZModelDefinitionProvider = class extends import_lsp2.DefaultDefinitionProvider {
|
|
8230
|
+
static {
|
|
8231
|
+
__name(this, "ZModelDefinitionProvider");
|
|
8232
|
+
}
|
|
8233
|
+
documents;
|
|
8234
|
+
constructor(services) {
|
|
8235
|
+
super(services);
|
|
8236
|
+
this.documents = services.shared.workspace.LangiumDocuments;
|
|
8237
|
+
}
|
|
8238
|
+
collectLocationLinks(sourceCstNode, _params) {
|
|
8239
|
+
if (isModelImport(sourceCstNode.astNode)) {
|
|
8240
|
+
const importedModel = resolveImport(this.documents, sourceCstNode.astNode);
|
|
8241
|
+
if (importedModel?.$document) {
|
|
8242
|
+
const targetObject = importedModel;
|
|
8243
|
+
const selectionRange = this.nameProvider.getNameNode(targetObject)?.range ?? import_vscode_languageserver2.Range.create(0, 0, 0, 0);
|
|
8244
|
+
const previewRange = targetObject.$cstNode?.range ?? import_vscode_languageserver2.Range.create(0, 0, 0, 0);
|
|
8245
|
+
return [
|
|
8246
|
+
import_vscode_languageserver2.LocationLink.create(importedModel.$document.uri.toString(), previewRange, selectionRange, sourceCstNode.range)
|
|
8247
|
+
];
|
|
8248
|
+
}
|
|
8249
|
+
return void 0;
|
|
8250
|
+
}
|
|
8251
|
+
return super.collectLocationLinks(sourceCstNode, _params);
|
|
8252
|
+
}
|
|
8253
|
+
};
|
|
8254
|
+
|
|
8255
|
+
// src/zmodel-document-builder.ts
|
|
8256
|
+
var import_langium8 = require("langium");
|
|
8257
|
+
var ZModelDocumentBuilder = class extends import_langium8.DefaultDocumentBuilder {
|
|
7141
8258
|
static {
|
|
7142
8259
|
__name(this, "ZModelDocumentBuilder");
|
|
7143
8260
|
}
|
|
@@ -7164,10 +8281,115 @@ var ZModelDocumentBuilder = class extends import_langium7.DefaultDocumentBuilder
|
|
|
7164
8281
|
}
|
|
7165
8282
|
};
|
|
7166
8283
|
|
|
8284
|
+
// src/zmodel-documentation-provider.ts
|
|
8285
|
+
var import_langium9 = require("langium");
|
|
8286
|
+
var ZModelDocumentationProvider = class extends import_langium9.JSDocDocumentationProvider {
|
|
8287
|
+
static {
|
|
8288
|
+
__name(this, "ZModelDocumentationProvider");
|
|
8289
|
+
}
|
|
8290
|
+
getDocumentation(node) {
|
|
8291
|
+
if ("comments" in node && Array.isArray(node.comments) && node.comments.length > 0) {
|
|
8292
|
+
return node.comments.map((c) => c.replace(/^[/]*\s*/, "")).join("\n");
|
|
8293
|
+
}
|
|
8294
|
+
return super.getDocumentation(node);
|
|
8295
|
+
}
|
|
8296
|
+
};
|
|
8297
|
+
|
|
8298
|
+
// src/zmodel-formatter.ts
|
|
8299
|
+
var import_lsp3 = require("langium/lsp");
|
|
8300
|
+
var ZModelFormatter = class extends import_lsp3.AbstractFormatter {
|
|
8301
|
+
static {
|
|
8302
|
+
__name(this, "ZModelFormatter");
|
|
8303
|
+
}
|
|
8304
|
+
formatOptions;
|
|
8305
|
+
configurationProvider;
|
|
8306
|
+
constructor(services) {
|
|
8307
|
+
super();
|
|
8308
|
+
this.configurationProvider = services.shared.workspace.ConfigurationProvider;
|
|
8309
|
+
}
|
|
8310
|
+
format(node) {
|
|
8311
|
+
const formatter = this.getNodeFormatter(node);
|
|
8312
|
+
if (isDataField(node)) {
|
|
8313
|
+
if (isDataModel(node.$container) || isTypeDef(node.$container)) {
|
|
8314
|
+
const dataModel = node.$container;
|
|
8315
|
+
const compareFn = /* @__PURE__ */ __name((a, b) => b - a, "compareFn");
|
|
8316
|
+
const maxNameLength = dataModel.fields.map((x) => x.name.length).sort(compareFn)[0] ?? 0;
|
|
8317
|
+
const maxTypeLength = dataModel.fields.map(this.getFieldTypeLength).sort(compareFn)[0] ?? 0;
|
|
8318
|
+
formatter.property("type").prepend(import_lsp3.Formatting.spaces(maxNameLength - node.name.length + 1));
|
|
8319
|
+
if (node.attributes.length > 0) {
|
|
8320
|
+
formatter.node(node.attributes[0]).prepend(import_lsp3.Formatting.spaces(maxTypeLength - this.getFieldTypeLength(node) + 1));
|
|
8321
|
+
formatter.nodes(...node.attributes.slice(1)).prepend(import_lsp3.Formatting.oneSpace());
|
|
8322
|
+
}
|
|
8323
|
+
} else {
|
|
8324
|
+
formatter.property("type").prepend(import_lsp3.Formatting.oneSpace());
|
|
8325
|
+
if (node.attributes.length > 0) {
|
|
8326
|
+
formatter.properties("attributes").prepend(import_lsp3.Formatting.oneSpace());
|
|
8327
|
+
}
|
|
8328
|
+
}
|
|
8329
|
+
} else if (isDataFieldAttribute(node)) {
|
|
8330
|
+
formatter.keyword("(").surround(import_lsp3.Formatting.noSpace());
|
|
8331
|
+
formatter.keyword(")").prepend(import_lsp3.Formatting.noSpace());
|
|
8332
|
+
formatter.keyword(",").append(import_lsp3.Formatting.oneSpace());
|
|
8333
|
+
if (node.args.length > 1) {
|
|
8334
|
+
formatter.nodes(...node.args.slice(1)).prepend(import_lsp3.Formatting.oneSpace());
|
|
8335
|
+
}
|
|
8336
|
+
} else if (isAttributeArg(node)) {
|
|
8337
|
+
formatter.keyword(":").prepend(import_lsp3.Formatting.noSpace());
|
|
8338
|
+
formatter.keyword(":").append(import_lsp3.Formatting.oneSpace());
|
|
8339
|
+
} else if (isAbstractDeclaration(node)) {
|
|
8340
|
+
const bracesOpen = formatter.keyword("{");
|
|
8341
|
+
const bracesClose = formatter.keyword("}");
|
|
8342
|
+
formatter.interior(bracesOpen, bracesClose).prepend(import_lsp3.Formatting.indent({
|
|
8343
|
+
allowMore: true
|
|
8344
|
+
}));
|
|
8345
|
+
bracesOpen.prepend(import_lsp3.Formatting.oneSpace());
|
|
8346
|
+
bracesClose.prepend(import_lsp3.Formatting.newLine());
|
|
8347
|
+
} else if (isModel(node)) {
|
|
8348
|
+
const model = node;
|
|
8349
|
+
const nodes = formatter.nodes(...model.declarations);
|
|
8350
|
+
nodes.prepend(import_lsp3.Formatting.noIndent());
|
|
8351
|
+
}
|
|
8352
|
+
}
|
|
8353
|
+
formatDocument(document, params) {
|
|
8354
|
+
this.formatOptions = params.options;
|
|
8355
|
+
this.configurationProvider.getConfiguration(ZModelLanguageMetaData.languageId, "format").then((config) => {
|
|
8356
|
+
if (config) {
|
|
8357
|
+
}
|
|
8358
|
+
});
|
|
8359
|
+
return super.formatDocument(document, params);
|
|
8360
|
+
}
|
|
8361
|
+
getFormatOptions() {
|
|
8362
|
+
return this.formatOptions;
|
|
8363
|
+
}
|
|
8364
|
+
getIndent() {
|
|
8365
|
+
return 1;
|
|
8366
|
+
}
|
|
8367
|
+
getFieldTypeLength(field) {
|
|
8368
|
+
let length;
|
|
8369
|
+
if (field.type.type) {
|
|
8370
|
+
length = field.type.type.length;
|
|
8371
|
+
} else if (field.type.reference) {
|
|
8372
|
+
length = field.type.reference.$refText.length;
|
|
8373
|
+
} else if (isDataField(field) && field.type.unsupported) {
|
|
8374
|
+
const name = `Unsupported("${field.type.unsupported.value.value}")`;
|
|
8375
|
+
length = name.length;
|
|
8376
|
+
} else {
|
|
8377
|
+
length = 1;
|
|
8378
|
+
}
|
|
8379
|
+
if (field.type.optional) {
|
|
8380
|
+
length += 1;
|
|
8381
|
+
}
|
|
8382
|
+
if (field.type.array) {
|
|
8383
|
+
length += 2;
|
|
8384
|
+
}
|
|
8385
|
+
return length;
|
|
8386
|
+
}
|
|
8387
|
+
};
|
|
8388
|
+
|
|
7167
8389
|
// src/zmodel-linker.ts
|
|
7168
|
-
var
|
|
7169
|
-
var
|
|
7170
|
-
var ZModelLinker = class extends
|
|
8390
|
+
var import_langium10 = require("langium");
|
|
8391
|
+
var import_ts_pattern4 = require("ts-pattern");
|
|
8392
|
+
var ZModelLinker = class extends import_langium10.DefaultLinker {
|
|
7171
8393
|
static {
|
|
7172
8394
|
__name(this, "ZModelLinker");
|
|
7173
8395
|
}
|
|
@@ -7177,15 +8399,15 @@ var ZModelLinker = class extends import_langium8.DefaultLinker {
|
|
|
7177
8399
|
this.descriptions = services.workspace.AstNodeDescriptionProvider;
|
|
7178
8400
|
}
|
|
7179
8401
|
//#region Reference linking
|
|
7180
|
-
async link(document, cancelToken =
|
|
8402
|
+
async link(document, cancelToken = import_langium10.Cancellation.CancellationToken.None) {
|
|
7181
8403
|
if (document.parseResult.lexerErrors?.length > 0 || document.parseResult.parserErrors?.length > 0) {
|
|
7182
8404
|
return;
|
|
7183
8405
|
}
|
|
7184
|
-
for (const node of
|
|
7185
|
-
await (0,
|
|
8406
|
+
for (const node of import_langium10.AstUtils.streamContents(document.parseResult.value)) {
|
|
8407
|
+
await (0, import_langium10.interruptAndCheck)(cancelToken);
|
|
7186
8408
|
this.resolve(node, document);
|
|
7187
8409
|
}
|
|
7188
|
-
document.state =
|
|
8410
|
+
document.state = import_langium10.DocumentState.Linked;
|
|
7189
8411
|
}
|
|
7190
8412
|
linkReference(refInfo, document, extraScopes) {
|
|
7191
8413
|
const defaultRef = refInfo.reference;
|
|
@@ -7337,7 +8559,7 @@ var ZModelLinker = class extends import_langium8.DefaultLinker {
|
|
|
7337
8559
|
if (node.function.ref) {
|
|
7338
8560
|
const funcDecl = node.function.ref;
|
|
7339
8561
|
if (isAuthInvocation(node)) {
|
|
7340
|
-
const allDecls = getAllLoadedAndReachableDataModelsAndTypeDefs(this.langiumDocuments(),
|
|
8562
|
+
const allDecls = getAllLoadedAndReachableDataModelsAndTypeDefs(this.langiumDocuments(), import_langium10.AstUtils.getContainerOfType(node, isDataModel));
|
|
7341
8563
|
const authDecl = getAuthDecl(allDecls);
|
|
7342
8564
|
if (authDecl) {
|
|
7343
8565
|
node.$resolvedType = {
|
|
@@ -7355,7 +8577,7 @@ var ZModelLinker = class extends import_langium8.DefaultLinker {
|
|
|
7355
8577
|
}
|
|
7356
8578
|
}
|
|
7357
8579
|
resolveLiteral(node) {
|
|
7358
|
-
const type = (0,
|
|
8580
|
+
const type = (0, import_ts_pattern4.match)(node).when(isStringLiteral, () => "String").when(isBooleanLiteral, () => "Boolean").when(isNumberLiteral, () => "Int").exhaustive();
|
|
7359
8581
|
if (type) {
|
|
7360
8582
|
this.resolveToBuiltinTypeOrDecl(node, type);
|
|
7361
8583
|
}
|
|
@@ -7475,10 +8697,10 @@ var ZModelLinker = class extends import_langium8.DefaultLinker {
|
|
|
7475
8697
|
this.resolveDefault(node, document, scopes);
|
|
7476
8698
|
}
|
|
7477
8699
|
resolveDefault(node, document, extraScopes) {
|
|
7478
|
-
|
|
8700
|
+
import_langium10.AstUtils.streamReferences(node).forEach((ref) => {
|
|
7479
8701
|
this.linkReference(ref, document, extraScopes);
|
|
7480
8702
|
});
|
|
7481
|
-
for (const child of
|
|
8703
|
+
for (const child of import_langium10.AstUtils.streamContents(node)) {
|
|
7482
8704
|
this.resolve(child, document, extraScopes);
|
|
7483
8705
|
}
|
|
7484
8706
|
}
|
|
@@ -7522,9 +8744,9 @@ var ZModelLinker = class extends import_langium8.DefaultLinker {
|
|
|
7522
8744
|
};
|
|
7523
8745
|
|
|
7524
8746
|
// src/zmodel-scope.ts
|
|
7525
|
-
var
|
|
7526
|
-
var
|
|
7527
|
-
var ZModelScopeComputation = class extends
|
|
8747
|
+
var import_langium11 = require("langium");
|
|
8748
|
+
var import_ts_pattern5 = require("ts-pattern");
|
|
8749
|
+
var ZModelScopeComputation = class extends import_langium11.DefaultScopeComputation {
|
|
7528
8750
|
static {
|
|
7529
8751
|
__name(this, "ZModelScopeComputation");
|
|
7530
8752
|
}
|
|
@@ -7534,9 +8756,9 @@ var ZModelScopeComputation = class extends import_langium9.DefaultScopeComputati
|
|
|
7534
8756
|
}
|
|
7535
8757
|
async computeExports(document, cancelToken) {
|
|
7536
8758
|
const result = await super.computeExports(document, cancelToken);
|
|
7537
|
-
for (const node of
|
|
8759
|
+
for (const node of import_langium11.AstUtils.streamAllContents(document.parseResult.value)) {
|
|
7538
8760
|
if (cancelToken) {
|
|
7539
|
-
await (0,
|
|
8761
|
+
await (0, import_langium11.interruptAndCheck)(cancelToken);
|
|
7540
8762
|
}
|
|
7541
8763
|
if (isEnumField(node)) {
|
|
7542
8764
|
const desc = this.services.workspace.AstNodeDescriptionProvider.createDescription(node, node.name, document);
|
|
@@ -7557,7 +8779,7 @@ var ZModelScopeComputation = class extends import_langium9.DefaultScopeComputati
|
|
|
7557
8779
|
}
|
|
7558
8780
|
}
|
|
7559
8781
|
};
|
|
7560
|
-
var ZModelScopeProvider = class extends
|
|
8782
|
+
var ZModelScopeProvider = class extends import_langium11.DefaultScopeProvider {
|
|
7561
8783
|
static {
|
|
7562
8784
|
__name(this, "ZModelScopeProvider");
|
|
7563
8785
|
}
|
|
@@ -7566,19 +8788,19 @@ var ZModelScopeProvider = class extends import_langium9.DefaultScopeProvider {
|
|
|
7566
8788
|
super(services), this.services = services;
|
|
7567
8789
|
}
|
|
7568
8790
|
getGlobalScope(referenceType, context) {
|
|
7569
|
-
const model =
|
|
8791
|
+
const model = import_langium11.AstUtils.getContainerOfType(context.container, isModel);
|
|
7570
8792
|
if (!model) {
|
|
7571
|
-
return
|
|
8793
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7572
8794
|
}
|
|
7573
8795
|
const importedUris = model.imports.map(resolveImportUri).filter((url) => !!url);
|
|
7574
8796
|
const importedElements = this.indexManager.allElements(referenceType).filter((des) => (
|
|
7575
8797
|
// allow current document
|
|
7576
|
-
|
|
8798
|
+
import_langium11.UriUtils.equals(des.documentUri, model.$document?.uri) || // allow stdlib
|
|
7577
8799
|
des.documentUri.path.endsWith(STD_LIB_MODULE_NAME) || // allow plugin models
|
|
7578
8800
|
des.documentUri.path.endsWith(PLUGIN_MODULE_NAME) || // allow imported documents
|
|
7579
|
-
importedUris.some((importedUri) =>
|
|
8801
|
+
importedUris.some((importedUri) => import_langium11.UriUtils.equals(des.documentUri, importedUri))
|
|
7580
8802
|
));
|
|
7581
|
-
return new
|
|
8803
|
+
return new import_langium11.StreamScope(importedElements);
|
|
7582
8804
|
}
|
|
7583
8805
|
getScope(context) {
|
|
7584
8806
|
if (isMemberAccessExpr(context.container) && context.container.operand && context.property === "member") {
|
|
@@ -7596,22 +8818,19 @@ var ZModelScopeProvider = class extends import_langium9.DefaultScopeProvider {
|
|
|
7596
8818
|
const referenceType = this.reflection.getReferenceType(context);
|
|
7597
8819
|
const globalScope = this.getGlobalScope(referenceType, context);
|
|
7598
8820
|
const node = context.container;
|
|
7599
|
-
const allowTypeDefScope = (
|
|
7600
|
-
|
|
7601
|
-
!!import_langium9.AstUtils.getContainerOfType(node, isTypeDef)
|
|
7602
|
-
);
|
|
7603
|
-
return (0, import_ts_pattern3.match)(node.operand).when(isReferenceExpr, (operand) => {
|
|
8821
|
+
const allowTypeDefScope = isAuthOrAuthMemberAccess(node.operand) || !!import_langium11.AstUtils.getContainerOfType(node, isTypeDef);
|
|
8822
|
+
return (0, import_ts_pattern5.match)(node.operand).when(isReferenceExpr, (operand) => {
|
|
7604
8823
|
const ref = operand.target.ref;
|
|
7605
8824
|
if (isDataField(ref)) {
|
|
7606
8825
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7607
8826
|
}
|
|
7608
|
-
return
|
|
8827
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7609
8828
|
}).when(isMemberAccessExpr, (operand) => {
|
|
7610
8829
|
const ref = operand.member.ref;
|
|
7611
8830
|
if (isDataField(ref) && !ref.type.array) {
|
|
7612
8831
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7613
8832
|
}
|
|
7614
|
-
return
|
|
8833
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7615
8834
|
}).when(isThisExpr, () => {
|
|
7616
8835
|
return this.createScopeForContainingModel(node, globalScope);
|
|
7617
8836
|
}).when(isInvocationExpr, (operand) => {
|
|
@@ -7621,43 +8840,43 @@ var ZModelScopeProvider = class extends import_langium9.DefaultScopeProvider {
|
|
|
7621
8840
|
if (isBeforeInvocation(operand)) {
|
|
7622
8841
|
return this.createScopeForContainingModel(node, globalScope);
|
|
7623
8842
|
}
|
|
7624
|
-
return
|
|
7625
|
-
}).otherwise(() =>
|
|
8843
|
+
return import_langium11.EMPTY_SCOPE;
|
|
8844
|
+
}).otherwise(() => import_langium11.EMPTY_SCOPE);
|
|
7626
8845
|
}
|
|
7627
8846
|
getCollectionPredicateScope(context, collectionPredicate) {
|
|
7628
8847
|
const referenceType = this.reflection.getReferenceType(context);
|
|
7629
8848
|
const globalScope = this.getGlobalScope(referenceType, context);
|
|
7630
8849
|
const collection = collectionPredicate.left;
|
|
7631
|
-
const allowTypeDefScope =
|
|
7632
|
-
return (0,
|
|
8850
|
+
const allowTypeDefScope = isAuthOrAuthMemberAccess(collection);
|
|
8851
|
+
return (0, import_ts_pattern5.match)(collection).when(isReferenceExpr, (expr) => {
|
|
7633
8852
|
const ref = expr.target.ref;
|
|
7634
8853
|
if (isDataField(ref)) {
|
|
7635
8854
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7636
8855
|
}
|
|
7637
|
-
return
|
|
8856
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7638
8857
|
}).when(isMemberAccessExpr, (expr) => {
|
|
7639
8858
|
const ref = expr.member.ref;
|
|
7640
8859
|
if (isDataField(ref)) {
|
|
7641
8860
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7642
8861
|
}
|
|
7643
|
-
return
|
|
8862
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7644
8863
|
}).when(isInvocationExpr, (expr) => {
|
|
7645
8864
|
const returnTypeDecl = expr.function.ref?.returnType.reference?.ref;
|
|
7646
8865
|
if (isDataModel(returnTypeDecl)) {
|
|
7647
8866
|
return this.createScopeForContainer(returnTypeDecl, globalScope, allowTypeDefScope);
|
|
7648
8867
|
} else {
|
|
7649
|
-
return
|
|
8868
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7650
8869
|
}
|
|
7651
8870
|
}).when(isAuthInvocation, (expr) => {
|
|
7652
8871
|
return this.createScopeForAuth(expr, globalScope);
|
|
7653
|
-
}).otherwise(() =>
|
|
8872
|
+
}).otherwise(() => import_langium11.EMPTY_SCOPE);
|
|
7654
8873
|
}
|
|
7655
8874
|
createScopeForContainingModel(node, globalScope) {
|
|
7656
|
-
const model =
|
|
8875
|
+
const model = import_langium11.AstUtils.getContainerOfType(node, isDataModel);
|
|
7657
8876
|
if (model) {
|
|
7658
8877
|
return this.createScopeForContainer(model, globalScope);
|
|
7659
8878
|
} else {
|
|
7660
|
-
return
|
|
8879
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7661
8880
|
}
|
|
7662
8881
|
}
|
|
7663
8882
|
createScopeForContainer(node, globalScope, includeTypeDefScope = false) {
|
|
@@ -7666,16 +8885,16 @@ var ZModelScopeProvider = class extends import_langium9.DefaultScopeProvider {
|
|
|
7666
8885
|
} else if (includeTypeDefScope && isTypeDef(node)) {
|
|
7667
8886
|
return this.createScopeForNodes(node.fields, globalScope);
|
|
7668
8887
|
} else {
|
|
7669
|
-
return
|
|
8888
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7670
8889
|
}
|
|
7671
8890
|
}
|
|
7672
8891
|
createScopeForAuth(node, globalScope) {
|
|
7673
|
-
const decls = getAllLoadedAndReachableDataModelsAndTypeDefs(this.services.shared.workspace.LangiumDocuments,
|
|
8892
|
+
const decls = getAllLoadedAndReachableDataModelsAndTypeDefs(this.services.shared.workspace.LangiumDocuments, import_langium11.AstUtils.getContainerOfType(node, isDataModel));
|
|
7674
8893
|
const authDecl = getAuthDecl(decls);
|
|
7675
8894
|
if (authDecl) {
|
|
7676
8895
|
return this.createScopeForContainer(authDecl, globalScope, true);
|
|
7677
8896
|
} else {
|
|
7678
|
-
return
|
|
8897
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7679
8898
|
}
|
|
7680
8899
|
}
|
|
7681
8900
|
};
|
|
@@ -7691,13 +8910,97 @@ function getCollectionPredicateContext(node) {
|
|
|
7691
8910
|
}
|
|
7692
8911
|
__name(getCollectionPredicateContext, "getCollectionPredicateContext");
|
|
7693
8912
|
|
|
8913
|
+
// src/zmodel-semantic.ts
|
|
8914
|
+
var import_lsp4 = require("langium/lsp");
|
|
8915
|
+
var import_vscode_languageserver3 = require("vscode-languageserver");
|
|
8916
|
+
var ZModelSemanticTokenProvider = class extends import_lsp4.AbstractSemanticTokenProvider {
|
|
8917
|
+
static {
|
|
8918
|
+
__name(this, "ZModelSemanticTokenProvider");
|
|
8919
|
+
}
|
|
8920
|
+
highlightElement(node, acceptor) {
|
|
8921
|
+
if (isDataModel(node)) {
|
|
8922
|
+
acceptor({
|
|
8923
|
+
node,
|
|
8924
|
+
property: "name",
|
|
8925
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.type
|
|
8926
|
+
});
|
|
8927
|
+
acceptor({
|
|
8928
|
+
node,
|
|
8929
|
+
property: "mixins",
|
|
8930
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.type
|
|
8931
|
+
});
|
|
8932
|
+
acceptor({
|
|
8933
|
+
node,
|
|
8934
|
+
property: "baseModel",
|
|
8935
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.type
|
|
8936
|
+
});
|
|
8937
|
+
} else if (isDataSource(node) || isGeneratorDecl(node) || isPlugin(node) || isEnum(node) || isTypeDef(node)) {
|
|
8938
|
+
acceptor({
|
|
8939
|
+
node,
|
|
8940
|
+
property: "name",
|
|
8941
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.type
|
|
8942
|
+
});
|
|
8943
|
+
} else if (isDataField(node) || isConfigField(node) || isAttributeArg(node) || isPluginField(node) || isEnumField(node)) {
|
|
8944
|
+
acceptor({
|
|
8945
|
+
node,
|
|
8946
|
+
property: "name",
|
|
8947
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.variable
|
|
8948
|
+
});
|
|
8949
|
+
} else if (isDataFieldType(node)) {
|
|
8950
|
+
if (node.type) {
|
|
8951
|
+
acceptor({
|
|
8952
|
+
node,
|
|
8953
|
+
property: "type",
|
|
8954
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.type
|
|
8955
|
+
});
|
|
8956
|
+
} else {
|
|
8957
|
+
acceptor({
|
|
8958
|
+
node,
|
|
8959
|
+
property: "reference",
|
|
8960
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.macro
|
|
8961
|
+
});
|
|
8962
|
+
}
|
|
8963
|
+
} else if (isDataModelAttribute(node) || isDataFieldAttribute(node) || isInternalAttribute(node)) {
|
|
8964
|
+
acceptor({
|
|
8965
|
+
node,
|
|
8966
|
+
property: "decl",
|
|
8967
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.function
|
|
8968
|
+
});
|
|
8969
|
+
} else if (isInvocationExpr(node)) {
|
|
8970
|
+
acceptor({
|
|
8971
|
+
node,
|
|
8972
|
+
property: "function",
|
|
8973
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.function
|
|
8974
|
+
});
|
|
8975
|
+
} else if (isFunctionDecl(node) || isAttribute(node)) {
|
|
8976
|
+
acceptor({
|
|
8977
|
+
node,
|
|
8978
|
+
property: "name",
|
|
8979
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.function
|
|
8980
|
+
});
|
|
8981
|
+
} else if (isReferenceExpr(node)) {
|
|
8982
|
+
acceptor({
|
|
8983
|
+
node,
|
|
8984
|
+
property: "target",
|
|
8985
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.variable
|
|
8986
|
+
});
|
|
8987
|
+
} else if (isMemberAccessExpr(node)) {
|
|
8988
|
+
acceptor({
|
|
8989
|
+
node,
|
|
8990
|
+
property: "member",
|
|
8991
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.property
|
|
8992
|
+
});
|
|
8993
|
+
}
|
|
8994
|
+
}
|
|
8995
|
+
};
|
|
8996
|
+
|
|
7694
8997
|
// src/zmodel-workspace-manager.ts
|
|
7695
|
-
var
|
|
7696
|
-
var
|
|
7697
|
-
var
|
|
7698
|
-
var
|
|
7699
|
-
var
|
|
7700
|
-
var ZModelWorkspaceManager = class extends
|
|
8998
|
+
var import_langium12 = require("langium");
|
|
8999
|
+
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
9000
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
9001
|
+
var import_node_url2 = require("url");
|
|
9002
|
+
var import_meta2 = {};
|
|
9003
|
+
var ZModelWorkspaceManager = class extends import_langium12.DefaultWorkspaceManager {
|
|
7701
9004
|
static {
|
|
7702
9005
|
__name(this, "ZModelWorkspaceManager");
|
|
7703
9006
|
}
|
|
@@ -7718,9 +9021,9 @@ var ZModelWorkspaceManager = class extends import_langium10.DefaultWorkspaceMana
|
|
|
7718
9021
|
folderPath
|
|
7719
9022
|
]
|
|
7720
9023
|
});
|
|
7721
|
-
const languagePackageDir =
|
|
7722
|
-
const candidateStdlibPath =
|
|
7723
|
-
if (
|
|
9024
|
+
const languagePackageDir = import_node_path2.default.dirname(languagePackagePath);
|
|
9025
|
+
const candidateStdlibPath = import_node_path2.default.join(languagePackageDir, "res", STD_LIB_MODULE_NAME);
|
|
9026
|
+
if (import_node_fs3.default.existsSync(candidateStdlibPath)) {
|
|
7724
9027
|
installedStdlibPath = candidateStdlibPath;
|
|
7725
9028
|
console.log(`Found installed zenstack package stdlib at: ${installedStdlibPath}`);
|
|
7726
9029
|
break;
|
|
@@ -7732,73 +9035,12 @@ var ZModelWorkspaceManager = class extends import_langium10.DefaultWorkspaceMana
|
|
|
7732
9035
|
if (installedStdlibPath) {
|
|
7733
9036
|
stdLibPath = installedStdlibPath;
|
|
7734
9037
|
} else {
|
|
7735
|
-
const _dirname = typeof __dirname !== "undefined" ? __dirname :
|
|
7736
|
-
stdLibPath =
|
|
9038
|
+
const _dirname = typeof __dirname !== "undefined" ? __dirname : import_node_path2.default.dirname((0, import_node_url2.fileURLToPath)(import_meta2.url));
|
|
9039
|
+
stdLibPath = import_node_path2.default.join(_dirname, "../res", STD_LIB_MODULE_NAME);
|
|
7737
9040
|
console.log(`Using bundled stdlib in extension:`, stdLibPath);
|
|
7738
9041
|
}
|
|
7739
|
-
const stdlib = await this.documentFactory.fromUri(
|
|
9042
|
+
const stdlib = await this.documentFactory.fromUri(import_langium12.URI.file(stdLibPath));
|
|
7740
9043
|
collector(stdlib);
|
|
7741
|
-
const documents = this.langiumDocuments.all;
|
|
7742
|
-
const pluginModels = /* @__PURE__ */ new Set();
|
|
7743
|
-
documents.forEach((doc) => {
|
|
7744
|
-
const parsed = doc.parseResult.value;
|
|
7745
|
-
parsed.declarations.forEach((decl) => {
|
|
7746
|
-
if (isPlugin(decl)) {
|
|
7747
|
-
const providerField = decl.fields.find((f) => f.name === "provider");
|
|
7748
|
-
if (providerField) {
|
|
7749
|
-
const provider = getLiteral(providerField.value);
|
|
7750
|
-
if (provider) {
|
|
7751
|
-
pluginModels.add(provider);
|
|
7752
|
-
}
|
|
7753
|
-
}
|
|
7754
|
-
}
|
|
7755
|
-
});
|
|
7756
|
-
});
|
|
7757
|
-
if (pluginModels.size > 0) {
|
|
7758
|
-
console.log(`Used plugin modules: ${Array.from(pluginModels)}`);
|
|
7759
|
-
const pendingPluginModules = new Set(pluginModels);
|
|
7760
|
-
await Promise.all(folders.map((wf) => [
|
|
7761
|
-
wf,
|
|
7762
|
-
this.getRootFolder(wf)
|
|
7763
|
-
]).map(async (entry) => this.loadPluginModels(...entry, pendingPluginModules, collector)));
|
|
7764
|
-
}
|
|
7765
|
-
}
|
|
7766
|
-
async loadPluginModels(workspaceFolder, folderPath, pendingPluginModels, collector) {
|
|
7767
|
-
const content = (await this.fileSystemProvider.readDirectory(folderPath)).sort((a, b) => {
|
|
7768
|
-
if (a.isDirectory && b.isDirectory) {
|
|
7769
|
-
const aName = import_langium10.UriUtils.basename(a.uri);
|
|
7770
|
-
if (aName === "node_modules") {
|
|
7771
|
-
return -1;
|
|
7772
|
-
} else {
|
|
7773
|
-
return 1;
|
|
7774
|
-
}
|
|
7775
|
-
} else {
|
|
7776
|
-
return 0;
|
|
7777
|
-
}
|
|
7778
|
-
});
|
|
7779
|
-
for (const entry of content) {
|
|
7780
|
-
if (entry.isDirectory) {
|
|
7781
|
-
const name = import_langium10.UriUtils.basename(entry.uri);
|
|
7782
|
-
if (name === "node_modules") {
|
|
7783
|
-
for (const plugin of Array.from(pendingPluginModels)) {
|
|
7784
|
-
const path4 = import_langium10.UriUtils.joinPath(entry.uri, plugin, PLUGIN_MODULE_NAME);
|
|
7785
|
-
try {
|
|
7786
|
-
await this.fileSystemProvider.readFile(path4);
|
|
7787
|
-
const document = await this.langiumDocuments.getOrCreateDocument(path4);
|
|
7788
|
-
collector(document);
|
|
7789
|
-
console.log(`Adding plugin document from ${path4.path}`);
|
|
7790
|
-
pendingPluginModels.delete(plugin);
|
|
7791
|
-
if (pendingPluginModels.size === 0) {
|
|
7792
|
-
return;
|
|
7793
|
-
}
|
|
7794
|
-
} catch {
|
|
7795
|
-
}
|
|
7796
|
-
}
|
|
7797
|
-
} else {
|
|
7798
|
-
await this.loadPluginModels(workspaceFolder, entry.uri, pendingPluginModels, collector);
|
|
7799
|
-
}
|
|
7800
|
-
}
|
|
7801
|
-
}
|
|
7802
9044
|
}
|
|
7803
9045
|
};
|
|
7804
9046
|
|
|
@@ -7811,6 +9053,16 @@ var ZModelLanguageModule = {
|
|
|
7811
9053
|
},
|
|
7812
9054
|
validation: {
|
|
7813
9055
|
ZModelValidator: /* @__PURE__ */ __name((services) => new ZModelValidator(services), "ZModelValidator")
|
|
9056
|
+
},
|
|
9057
|
+
lsp: {
|
|
9058
|
+
Formatter: /* @__PURE__ */ __name((services) => new ZModelFormatter(services), "Formatter"),
|
|
9059
|
+
DefinitionProvider: /* @__PURE__ */ __name((services) => new ZModelDefinitionProvider(services), "DefinitionProvider"),
|
|
9060
|
+
CompletionProvider: /* @__PURE__ */ __name((services) => new ZModelCompletionProvider(services), "CompletionProvider"),
|
|
9061
|
+
SemanticTokenProvider: /* @__PURE__ */ __name((services) => new ZModelSemanticTokenProvider(services), "SemanticTokenProvider")
|
|
9062
|
+
},
|
|
9063
|
+
documentation: {
|
|
9064
|
+
CommentProvider: /* @__PURE__ */ __name((services) => new ZModelCommentProvider(services), "CommentProvider"),
|
|
9065
|
+
DocumentationProvider: /* @__PURE__ */ __name((services) => new ZModelDocumentationProvider(services), "DocumentationProvider")
|
|
7814
9066
|
}
|
|
7815
9067
|
};
|
|
7816
9068
|
var ZModelSharedModule = {
|
|
@@ -7819,9 +9071,9 @@ var ZModelSharedModule = {
|
|
|
7819
9071
|
WorkspaceManager: /* @__PURE__ */ __name((services) => new ZModelWorkspaceManager(services), "WorkspaceManager")
|
|
7820
9072
|
}
|
|
7821
9073
|
};
|
|
7822
|
-
function createZModelLanguageServices(context) {
|
|
7823
|
-
const shared = (0,
|
|
7824
|
-
const ZModelLanguage = (0,
|
|
9074
|
+
function createZModelLanguageServices(context, logToConsole = false) {
|
|
9075
|
+
const shared = (0, import_langium13.inject)((0, import_lsp5.createDefaultSharedModule)(context), ZModelGeneratedSharedModule, ZModelSharedModule);
|
|
9076
|
+
const ZModelLanguage = (0, import_langium13.inject)((0, import_lsp5.createDefaultModule)({
|
|
7825
9077
|
shared
|
|
7826
9078
|
}), ZModelGeneratedModule, ZModelLanguageModule);
|
|
7827
9079
|
shared.ServiceRegistry.register(ZModelLanguage);
|
|
@@ -7829,31 +9081,48 @@ function createZModelLanguageServices(context) {
|
|
|
7829
9081
|
if (!context.connection) {
|
|
7830
9082
|
shared.workspace.ConfigurationProvider.initialized({});
|
|
7831
9083
|
}
|
|
9084
|
+
shared.workspace.DocumentBuilder.onBuildPhase(import_langium13.DocumentState.Parsed, async (documents) => {
|
|
9085
|
+
for (const doc of documents) {
|
|
9086
|
+
if (doc.parseResult.lexerErrors.length > 0 || doc.parseResult.parserErrors.length > 0) {
|
|
9087
|
+
continue;
|
|
9088
|
+
}
|
|
9089
|
+
if (doc.uri.scheme !== "file") {
|
|
9090
|
+
continue;
|
|
9091
|
+
}
|
|
9092
|
+
const schemaPath = (0, import_node_url3.fileURLToPath)(doc.uri.toString());
|
|
9093
|
+
const pluginSchemas = getPluginDocuments(doc.parseResult.value, schemaPath);
|
|
9094
|
+
for (const plugin of pluginSchemas) {
|
|
9095
|
+
const pluginDocUri = import_langium13.URI.file(import_node_path3.default.resolve(plugin));
|
|
9096
|
+
let pluginDoc = shared.workspace.LangiumDocuments.getDocument(pluginDocUri);
|
|
9097
|
+
if (!pluginDoc) {
|
|
9098
|
+
pluginDoc = await shared.workspace.LangiumDocuments.getOrCreateDocument(pluginDocUri);
|
|
9099
|
+
if (pluginDoc) {
|
|
9100
|
+
shared.workspace.IndexManager.updateContent(pluginDoc);
|
|
9101
|
+
if (logToConsole) {
|
|
9102
|
+
console.log(`Loaded plugin model: ${plugin}`);
|
|
9103
|
+
}
|
|
9104
|
+
}
|
|
9105
|
+
}
|
|
9106
|
+
}
|
|
9107
|
+
}
|
|
9108
|
+
});
|
|
7832
9109
|
return {
|
|
7833
9110
|
shared,
|
|
7834
9111
|
ZModelLanguage
|
|
7835
9112
|
};
|
|
7836
9113
|
}
|
|
7837
9114
|
__name(createZModelLanguageServices, "createZModelLanguageServices");
|
|
7838
|
-
|
|
7839
|
-
|
|
7840
|
-
var import_meta2 = {};
|
|
7841
|
-
function createZModelServices() {
|
|
7842
|
-
return createZModelLanguageServices(import_node.NodeFileSystem);
|
|
9115
|
+
function createZModelServices(logToConsole = false) {
|
|
9116
|
+
return createZModelLanguageServices(import_node.NodeFileSystem, logToConsole);
|
|
7843
9117
|
}
|
|
7844
9118
|
__name(createZModelServices, "createZModelServices");
|
|
7845
|
-
|
|
7846
|
-
|
|
7847
|
-
|
|
7848
|
-
}
|
|
7849
|
-
constructor(message) {
|
|
7850
|
-
super(message);
|
|
7851
|
-
}
|
|
7852
|
-
};
|
|
9119
|
+
|
|
9120
|
+
// src/document.ts
|
|
9121
|
+
var import_meta3 = {};
|
|
7853
9122
|
async function loadDocument(fileName, additionalModelFiles = []) {
|
|
7854
|
-
const { ZModelLanguage: services } = createZModelServices();
|
|
9123
|
+
const { ZModelLanguage: services } = createZModelServices(false);
|
|
7855
9124
|
const extensions = services.LanguageMetaData.fileExtensions;
|
|
7856
|
-
if (!extensions.includes(
|
|
9125
|
+
if (!extensions.includes(import_node_path4.default.extname(fileName))) {
|
|
7857
9126
|
return {
|
|
7858
9127
|
success: false,
|
|
7859
9128
|
errors: [
|
|
@@ -7862,7 +9131,7 @@ async function loadDocument(fileName, additionalModelFiles = []) {
|
|
|
7862
9131
|
warnings: []
|
|
7863
9132
|
};
|
|
7864
9133
|
}
|
|
7865
|
-
if (!
|
|
9134
|
+
if (!import_node_fs4.default.existsSync(fileName)) {
|
|
7866
9135
|
return {
|
|
7867
9136
|
success: false,
|
|
7868
9137
|
errors: [
|
|
@@ -7871,19 +9140,19 @@ async function loadDocument(fileName, additionalModelFiles = []) {
|
|
|
7871
9140
|
warnings: []
|
|
7872
9141
|
};
|
|
7873
9142
|
}
|
|
7874
|
-
const _dirname = typeof __dirname !== "undefined" ? __dirname :
|
|
7875
|
-
const stdLib = await services.shared.workspace.LangiumDocuments.getOrCreateDocument(
|
|
7876
|
-
const pluginDocs = await Promise.all(additionalModelFiles.map((file) => services.shared.workspace.LangiumDocuments.getOrCreateDocument(import_langium12.URI.file(import_node_path2.default.resolve(file)))));
|
|
9143
|
+
const _dirname = typeof __dirname !== "undefined" ? __dirname : import_node_path4.default.dirname((0, import_node_url4.fileURLToPath)(import_meta3.url));
|
|
9144
|
+
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))));
|
|
7877
9145
|
const langiumDocuments = services.shared.workspace.LangiumDocuments;
|
|
7878
|
-
const document = await langiumDocuments.getOrCreateDocument(
|
|
9146
|
+
const document = await langiumDocuments.getOrCreateDocument(import_langium14.URI.file(import_node_path4.default.resolve(fileName)));
|
|
7879
9147
|
const importedURIs = await loadImports(document, langiumDocuments);
|
|
7880
9148
|
const importedDocuments = [];
|
|
7881
9149
|
for (const uri of importedURIs) {
|
|
7882
9150
|
importedDocuments.push(await langiumDocuments.getOrCreateDocument(uri));
|
|
7883
9151
|
}
|
|
9152
|
+
const additionalDocs = await Promise.all(additionalModelFiles.map((file) => services.shared.workspace.LangiumDocuments.getOrCreateDocument(import_langium14.URI.file(import_node_path4.default.resolve(file)))));
|
|
7884
9153
|
await services.shared.workspace.DocumentBuilder.build([
|
|
7885
9154
|
stdLib,
|
|
7886
|
-
...
|
|
9155
|
+
...additionalDocs,
|
|
7887
9156
|
document,
|
|
7888
9157
|
...importedDocuments
|
|
7889
9158
|
], {
|
|
@@ -7901,7 +9170,7 @@ async function loadDocument(fileName, additionalModelFiles = []) {
|
|
|
7901
9170
|
const warnings = [];
|
|
7902
9171
|
if (diagnostics.length > 0) {
|
|
7903
9172
|
for (const { doc, diag } of diagnostics) {
|
|
7904
|
-
const message = `${
|
|
9173
|
+
const message = `${import_node_path4.default.relative(process.cwd(), doc.uri.fsPath)}:${diag.range.start.line + 1}:${diag.range.start.character + 1} - ${diag.message}`;
|
|
7905
9174
|
if (diag.severity === 1) {
|
|
7906
9175
|
errors.push(message);
|
|
7907
9176
|
} else {
|
|
@@ -7950,7 +9219,7 @@ async function loadImports(document, documents, uris = /* @__PURE__ */ new Set()
|
|
|
7950
9219
|
}
|
|
7951
9220
|
}
|
|
7952
9221
|
}
|
|
7953
|
-
return Array.from(uris).filter((x) => uriString != x).map((e) =>
|
|
9222
|
+
return Array.from(uris).filter((x) => uriString != x).map((e) => import_langium14.URI.parse(e));
|
|
7954
9223
|
}
|
|
7955
9224
|
__name(loadImports, "loadImports");
|
|
7956
9225
|
function mergeImportsDeclarations(documents, model) {
|
|
@@ -7967,13 +9236,13 @@ function linkContentToContainer(node) {
|
|
|
7967
9236
|
if (!name.startsWith("$")) {
|
|
7968
9237
|
if (Array.isArray(value)) {
|
|
7969
9238
|
value.forEach((item, index) => {
|
|
7970
|
-
if ((0,
|
|
9239
|
+
if ((0, import_langium14.isAstNode)(item)) {
|
|
7971
9240
|
item.$container = node;
|
|
7972
9241
|
item.$containerProperty = name;
|
|
7973
9242
|
item.$containerIndex = index;
|
|
7974
9243
|
}
|
|
7975
9244
|
});
|
|
7976
|
-
} else if ((0,
|
|
9245
|
+
} else if ((0, import_langium14.isAstNode)(value)) {
|
|
7977
9246
|
value.$container = node;
|
|
7978
9247
|
value.$containerProperty = name;
|
|
7979
9248
|
}
|
|
@@ -7999,14 +9268,34 @@ function validationAfterImportMerge(model) {
|
|
|
7999
9268
|
return errors;
|
|
8000
9269
|
}
|
|
8001
9270
|
__name(validationAfterImportMerge, "validationAfterImportMerge");
|
|
9271
|
+
async function formatDocument(content) {
|
|
9272
|
+
const services = createZModelServices().ZModelLanguage;
|
|
9273
|
+
const langiumDocuments = services.shared.workspace.LangiumDocuments;
|
|
9274
|
+
const document = langiumDocuments.createDocument(import_langium14.URI.parse("memory://schema.zmodel"), content);
|
|
9275
|
+
const formatter = services.lsp.Formatter;
|
|
9276
|
+
const identifier = {
|
|
9277
|
+
uri: document.uri.toString()
|
|
9278
|
+
};
|
|
9279
|
+
const options = formatter.getFormatOptions() ?? {
|
|
9280
|
+
insertSpaces: true,
|
|
9281
|
+
tabSize: 4
|
|
9282
|
+
};
|
|
9283
|
+
const edits = await formatter.formatDocument(document, {
|
|
9284
|
+
options,
|
|
9285
|
+
textDocument: identifier
|
|
9286
|
+
});
|
|
9287
|
+
return import_langium14.TextDocument.applyEdits(document.textDocument, edits);
|
|
9288
|
+
}
|
|
9289
|
+
__name(formatDocument, "formatDocument");
|
|
8002
9290
|
// Annotate the CommonJS export names for ESM import in node:
|
|
8003
9291
|
0 && (module.exports = {
|
|
8004
|
-
|
|
9292
|
+
ZModelCodeGenerator,
|
|
8005
9293
|
ZModelLanguageMetaData,
|
|
8006
9294
|
ZModelLanguageModule,
|
|
8007
9295
|
ZModelSharedModule,
|
|
8008
9296
|
createZModelLanguageServices,
|
|
8009
9297
|
createZModelServices,
|
|
9298
|
+
formatDocument,
|
|
8010
9299
|
loadDocument
|
|
8011
9300
|
});
|
|
8012
9301
|
//# sourceMappingURL=index.cjs.map
|