@zenstackhq/language 3.0.0-beta.9 → 3.1.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 +1597 -234
- 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 +1543 -184
- 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 +34 -101
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"),
|
|
5877
6058
|
_ts_metadata("design:type", Function),
|
|
5878
6059
|
_ts_metadata("design:paramtypes", [
|
|
5879
6060
|
typeof AttributeApplication === "undefined" ? Object : AttributeApplication,
|
|
5880
6061
|
typeof ValidationAcceptor === "undefined" ? Object : ValidationAcceptor
|
|
5881
6062
|
]),
|
|
5882
6063
|
_ts_metadata("design:returntype", void 0)
|
|
5883
|
-
], AttributeApplicationValidator.prototype, "
|
|
6064
|
+
], AttributeApplicationValidator.prototype, "_checkConstraint", null);
|
|
6065
|
+
_ts_decorate([
|
|
6066
|
+
check("@@schema"),
|
|
6067
|
+
_ts_metadata("design:type", Function),
|
|
6068
|
+
_ts_metadata("design:paramtypes", [
|
|
6069
|
+
typeof AttributeApplication === "undefined" ? Object : AttributeApplication,
|
|
6070
|
+
typeof ValidationAcceptor === "undefined" ? Object : ValidationAcceptor
|
|
6071
|
+
]),
|
|
6072
|
+
_ts_metadata("design:returntype", void 0)
|
|
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,56 @@ 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
7022
|
}
|
|
6777
|
-
|
|
6778
|
-
|
|
6779
|
-
|
|
6780
|
-
|
|
6781
|
-
|
|
6782
|
-
|
|
6783
|
-
|
|
6784
|
-
|
|
6785
|
-
|
|
6786
|
-
|
|
6787
|
-
|
|
6788
|
-
|
|
6789
|
-
|
|
6790
|
-
accept("error", `argument must be one of: ${allCasing.map((c) => '"' + c + '"').join(", ")}`, {
|
|
6791
|
-
node: expr.args[0]
|
|
6792
|
-
});
|
|
6793
|
-
}
|
|
7023
|
+
}
|
|
7024
|
+
if ([
|
|
7025
|
+
"uuid",
|
|
7026
|
+
"ulid",
|
|
7027
|
+
"cuid",
|
|
7028
|
+
"nanoid"
|
|
7029
|
+
].includes(funcDecl.name)) {
|
|
7030
|
+
const formatParamIdx = funcDecl.params.findIndex((param) => param.name === "format");
|
|
7031
|
+
const formatArg = getLiteral(expr.args[formatParamIdx]?.value);
|
|
7032
|
+
if (formatArg !== void 0 && !/(?<!\\)%s/g.test(formatArg)) {
|
|
7033
|
+
accept("error", 'argument must include "%s"', {
|
|
7034
|
+
node: expr.args[formatParamIdx]
|
|
7035
|
+
});
|
|
6794
7036
|
}
|
|
6795
7037
|
}
|
|
6796
7038
|
const checker = invocationCheckers.get(expr.function.$refText);
|
|
@@ -6810,18 +7052,18 @@ var FunctionInvocationValidator = class {
|
|
|
6810
7052
|
isValidationAttribute(attr) {
|
|
6811
7053
|
return !!attr.decl.ref?.attributes.some((attr2) => attr2.decl.$refText === "@@@validation");
|
|
6812
7054
|
}
|
|
6813
|
-
validateArgs(funcDecl,
|
|
7055
|
+
validateArgs(funcDecl, expr, accept) {
|
|
6814
7056
|
let success = true;
|
|
6815
7057
|
for (let i = 0; i < funcDecl.params.length; i++) {
|
|
6816
7058
|
const param = funcDecl.params[i];
|
|
6817
7059
|
if (!param) {
|
|
6818
7060
|
continue;
|
|
6819
7061
|
}
|
|
6820
|
-
const arg = args[i];
|
|
7062
|
+
const arg = expr.args[i];
|
|
6821
7063
|
if (!arg) {
|
|
6822
7064
|
if (!param.optional) {
|
|
6823
7065
|
accept("error", `missing argument for parameter "${param.name}"`, {
|
|
6824
|
-
node:
|
|
7066
|
+
node: expr
|
|
6825
7067
|
});
|
|
6826
7068
|
success = false;
|
|
6827
7069
|
}
|
|
@@ -6870,6 +7112,46 @@ var FunctionInvocationValidator = class {
|
|
|
6870
7112
|
}
|
|
6871
7113
|
return true;
|
|
6872
7114
|
}
|
|
7115
|
+
_checkUuid(expr, accept) {
|
|
7116
|
+
const versionArg = expr.args[0]?.value;
|
|
7117
|
+
if (versionArg) {
|
|
7118
|
+
const version = getLiteral(versionArg);
|
|
7119
|
+
if (version !== void 0 && version !== 4 && version !== 7) {
|
|
7120
|
+
accept("error", "first argument must be 4 or 7", {
|
|
7121
|
+
node: expr.args[0]
|
|
7122
|
+
});
|
|
7123
|
+
}
|
|
7124
|
+
}
|
|
7125
|
+
}
|
|
7126
|
+
_checkCuid(expr, accept) {
|
|
7127
|
+
const versionArg = expr.args[0]?.value;
|
|
7128
|
+
if (versionArg) {
|
|
7129
|
+
const version = getLiteral(versionArg);
|
|
7130
|
+
if (version !== void 0 && version !== 1 && version !== 2) {
|
|
7131
|
+
accept("error", "first argument must be 1 or 2", {
|
|
7132
|
+
node: expr.args[0]
|
|
7133
|
+
});
|
|
7134
|
+
}
|
|
7135
|
+
}
|
|
7136
|
+
}
|
|
7137
|
+
_checkNanoid(expr, accept) {
|
|
7138
|
+
const lengthArg = expr.args[0]?.value;
|
|
7139
|
+
if (lengthArg) {
|
|
7140
|
+
const length = getLiteral(lengthArg);
|
|
7141
|
+
if (length !== void 0 && length <= 0) {
|
|
7142
|
+
accept("error", "first argument must be a positive number", {
|
|
7143
|
+
node: expr.args[0]
|
|
7144
|
+
});
|
|
7145
|
+
}
|
|
7146
|
+
}
|
|
7147
|
+
}
|
|
7148
|
+
_checkAuth(expr, accept) {
|
|
7149
|
+
if (!expr.$resolvedType) {
|
|
7150
|
+
accept("error", 'cannot resolve `auth()` - make sure you have a model or type with `@auth` attribute or named "User"', {
|
|
7151
|
+
node: expr
|
|
7152
|
+
});
|
|
7153
|
+
}
|
|
7154
|
+
}
|
|
6873
7155
|
_checkLength(expr, accept) {
|
|
6874
7156
|
const msg = "argument must be a string or list field";
|
|
6875
7157
|
const fieldArg = expr.args[0].value;
|
|
@@ -6979,6 +7261,42 @@ var FunctionInvocationValidator = class {
|
|
|
6979
7261
|
}
|
|
6980
7262
|
}
|
|
6981
7263
|
};
|
|
7264
|
+
_ts_decorate2([
|
|
7265
|
+
func("uuid"),
|
|
7266
|
+
_ts_metadata2("design:type", Function),
|
|
7267
|
+
_ts_metadata2("design:paramtypes", [
|
|
7268
|
+
typeof InvocationExpr === "undefined" ? Object : InvocationExpr,
|
|
7269
|
+
typeof ValidationAcceptor === "undefined" ? Object : ValidationAcceptor
|
|
7270
|
+
]),
|
|
7271
|
+
_ts_metadata2("design:returntype", void 0)
|
|
7272
|
+
], FunctionInvocationValidator.prototype, "_checkUuid", null);
|
|
7273
|
+
_ts_decorate2([
|
|
7274
|
+
func("cuid"),
|
|
7275
|
+
_ts_metadata2("design:type", Function),
|
|
7276
|
+
_ts_metadata2("design:paramtypes", [
|
|
7277
|
+
typeof InvocationExpr === "undefined" ? Object : InvocationExpr,
|
|
7278
|
+
typeof ValidationAcceptor === "undefined" ? Object : ValidationAcceptor
|
|
7279
|
+
]),
|
|
7280
|
+
_ts_metadata2("design:returntype", void 0)
|
|
7281
|
+
], FunctionInvocationValidator.prototype, "_checkCuid", null);
|
|
7282
|
+
_ts_decorate2([
|
|
7283
|
+
func("nanoid"),
|
|
7284
|
+
_ts_metadata2("design:type", Function),
|
|
7285
|
+
_ts_metadata2("design:paramtypes", [
|
|
7286
|
+
typeof InvocationExpr === "undefined" ? Object : InvocationExpr,
|
|
7287
|
+
typeof ValidationAcceptor === "undefined" ? Object : ValidationAcceptor
|
|
7288
|
+
]),
|
|
7289
|
+
_ts_metadata2("design:returntype", void 0)
|
|
7290
|
+
], FunctionInvocationValidator.prototype, "_checkNanoid", null);
|
|
7291
|
+
_ts_decorate2([
|
|
7292
|
+
func("auth"),
|
|
7293
|
+
_ts_metadata2("design:type", Function),
|
|
7294
|
+
_ts_metadata2("design:paramtypes", [
|
|
7295
|
+
typeof InvocationExpr === "undefined" ? Object : InvocationExpr,
|
|
7296
|
+
typeof ValidationAcceptor === "undefined" ? Object : ValidationAcceptor
|
|
7297
|
+
]),
|
|
7298
|
+
_ts_metadata2("design:returntype", void 0)
|
|
7299
|
+
], FunctionInvocationValidator.prototype, "_checkAuth", null);
|
|
6982
7300
|
_ts_decorate2([
|
|
6983
7301
|
func("length"),
|
|
6984
7302
|
_ts_metadata2("design:type", Function),
|
|
@@ -7087,6 +7405,7 @@ function registerValidationChecks(services) {
|
|
|
7087
7405
|
const checks = {
|
|
7088
7406
|
Model: validator.checkModel,
|
|
7089
7407
|
DataSource: validator.checkDataSource,
|
|
7408
|
+
GeneratorDecl: validator.checkGenerator,
|
|
7090
7409
|
DataModel: validator.checkDataModel,
|
|
7091
7410
|
TypeDef: validator.checkTypeDef,
|
|
7092
7411
|
Enum: validator.checkEnum,
|
|
@@ -7112,6 +7431,11 @@ var ZModelValidator = class {
|
|
|
7112
7431
|
checkDataSource(node, accept) {
|
|
7113
7432
|
new DataSourceValidator().validate(node, accept);
|
|
7114
7433
|
}
|
|
7434
|
+
checkGenerator(node, accept) {
|
|
7435
|
+
accept("warning", '"generator" is not used by ZenStack and should be removed.', {
|
|
7436
|
+
node
|
|
7437
|
+
});
|
|
7438
|
+
}
|
|
7115
7439
|
checkDataModel(node, accept) {
|
|
7116
7440
|
new DataModelValidator().validate(node, accept);
|
|
7117
7441
|
}
|
|
@@ -7135,9 +7459,876 @@ var ZModelValidator = class {
|
|
|
7135
7459
|
}
|
|
7136
7460
|
};
|
|
7137
7461
|
|
|
7138
|
-
// src/zmodel-
|
|
7462
|
+
// src/zmodel-comment-provider.ts
|
|
7139
7463
|
var import_langium7 = require("langium");
|
|
7140
|
-
var
|
|
7464
|
+
var import_ts_pattern2 = require("ts-pattern");
|
|
7465
|
+
var ZModelCommentProvider = class extends import_langium7.DefaultCommentProvider {
|
|
7466
|
+
static {
|
|
7467
|
+
__name(this, "ZModelCommentProvider");
|
|
7468
|
+
}
|
|
7469
|
+
getComment(node) {
|
|
7470
|
+
let comment = super.getComment(node);
|
|
7471
|
+
if (!comment) {
|
|
7472
|
+
comment = (0, import_ts_pattern2.match)(node).when(isDataModel, (d) => `/**
|
|
7473
|
+
* Model *${d.name}*
|
|
7474
|
+
*/`).when(isTypeDef, (d) => `/**
|
|
7475
|
+
* Type *${d.name}*
|
|
7476
|
+
*/`).when(isEnum, (e) => `/**
|
|
7477
|
+
* Enum *${e.name}*
|
|
7478
|
+
*/`).when(isEnumField, (f) => `/**
|
|
7479
|
+
* Value of enum *${f.$container?.name}*
|
|
7480
|
+
*/`).when(isDataField, (f) => `/**
|
|
7481
|
+
* Field of *${f.$container?.name}*
|
|
7482
|
+
*/`).when(isFunctionDecl, (f) => `/**
|
|
7483
|
+
* Function *${f.name}*
|
|
7484
|
+
*/`).otherwise(() => "");
|
|
7485
|
+
}
|
|
7486
|
+
return comment;
|
|
7487
|
+
}
|
|
7488
|
+
};
|
|
7489
|
+
|
|
7490
|
+
// src/zmodel-completion-provider.ts
|
|
7491
|
+
var import_lsp = require("langium/lsp");
|
|
7492
|
+
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
7493
|
+
var import_ts_pattern3 = require("ts-pattern");
|
|
7494
|
+
var import_vscode_languageserver = require("vscode-languageserver");
|
|
7495
|
+
|
|
7496
|
+
// src/zmodel-code-generator.ts
|
|
7497
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
7498
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
7499
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
7500
|
+
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;
|
|
7501
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7502
|
+
}
|
|
7503
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
7504
|
+
function _ts_metadata3(k, v) {
|
|
7505
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
7506
|
+
}
|
|
7507
|
+
__name(_ts_metadata3, "_ts_metadata");
|
|
7508
|
+
var generationHandlers = /* @__PURE__ */ new Map();
|
|
7509
|
+
function gen(name) {
|
|
7510
|
+
return function(_target, _propertyKey, descriptor) {
|
|
7511
|
+
if (!generationHandlers.get(name)) {
|
|
7512
|
+
generationHandlers.set(name, descriptor);
|
|
7513
|
+
}
|
|
7514
|
+
return descriptor;
|
|
7515
|
+
};
|
|
7516
|
+
}
|
|
7517
|
+
__name(gen, "gen");
|
|
7518
|
+
var ZModelCodeGenerator = class {
|
|
7519
|
+
static {
|
|
7520
|
+
__name(this, "ZModelCodeGenerator");
|
|
7521
|
+
}
|
|
7522
|
+
options;
|
|
7523
|
+
constructor(options) {
|
|
7524
|
+
this.options = {
|
|
7525
|
+
binaryExprNumberOfSpaces: options?.binaryExprNumberOfSpaces ?? 1,
|
|
7526
|
+
unaryExprNumberOfSpaces: options?.unaryExprNumberOfSpaces ?? 0,
|
|
7527
|
+
indent: options?.indent ?? 4,
|
|
7528
|
+
quote: options?.quote ?? "single"
|
|
7529
|
+
};
|
|
7530
|
+
}
|
|
7531
|
+
/**
|
|
7532
|
+
* Generates ZModel source code from AST.
|
|
7533
|
+
*/
|
|
7534
|
+
generate(ast) {
|
|
7535
|
+
const handler = generationHandlers.get(ast.$type);
|
|
7536
|
+
if (!handler) {
|
|
7537
|
+
throw new Error(`No generation handler found for ${ast.$type}`);
|
|
7538
|
+
}
|
|
7539
|
+
return handler.value.call(this, ast);
|
|
7540
|
+
}
|
|
7541
|
+
_generateModel(ast) {
|
|
7542
|
+
return ast.declarations.map((d) => this.generate(d)).join("\n\n");
|
|
7543
|
+
}
|
|
7544
|
+
_generateDataSource(ast) {
|
|
7545
|
+
return `datasource ${ast.name} {
|
|
7546
|
+
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
7547
|
+
}`;
|
|
7548
|
+
}
|
|
7549
|
+
_generateEnum(ast) {
|
|
7550
|
+
return `enum ${ast.name} {
|
|
7551
|
+
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
7552
|
+
}`;
|
|
7553
|
+
}
|
|
7554
|
+
_generateEnumField(ast) {
|
|
7555
|
+
return `${ast.name}${ast.attributes.length > 0 ? " " + ast.attributes.map((x) => this.generate(x)).join(" ") : ""}`;
|
|
7556
|
+
}
|
|
7557
|
+
_generateGenerator(ast) {
|
|
7558
|
+
return `generator ${ast.name} {
|
|
7559
|
+
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
7560
|
+
}`;
|
|
7561
|
+
}
|
|
7562
|
+
_generateConfigField(ast) {
|
|
7563
|
+
return `${ast.name} = ${this.generate(ast.value)}`;
|
|
7564
|
+
}
|
|
7565
|
+
_generateConfigArrayExpr(ast) {
|
|
7566
|
+
return `[${ast.items.map((x) => this.generate(x)).join(", ")}]`;
|
|
7567
|
+
}
|
|
7568
|
+
_generateConfigInvocationExpr(ast) {
|
|
7569
|
+
if (ast.args.length === 0) {
|
|
7570
|
+
return ast.name;
|
|
7571
|
+
} else {
|
|
7572
|
+
return `${ast.name}(${ast.args.map((x) => (x.name ? x.name + ": " : "") + this.generate(x.value)).join(", ")})`;
|
|
7573
|
+
}
|
|
7574
|
+
}
|
|
7575
|
+
_generatePlugin(ast) {
|
|
7576
|
+
return `plugin ${ast.name} {
|
|
7577
|
+
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
7578
|
+
}`;
|
|
7579
|
+
}
|
|
7580
|
+
_generatePluginField(ast) {
|
|
7581
|
+
return `${ast.name} = ${this.generate(ast.value)}`;
|
|
7582
|
+
}
|
|
7583
|
+
_generateDataModel(ast) {
|
|
7584
|
+
return `${ast.isView ? "view" : "model"} ${ast.name}${ast.mixins.length > 0 ? " mixes " + ast.mixins.map((x) => x.$refText).join(", ") : ""} {
|
|
7585
|
+
${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") : ""}
|
|
7586
|
+
}`;
|
|
7587
|
+
}
|
|
7588
|
+
_generateDataField(ast) {
|
|
7589
|
+
return `${ast.name} ${this.fieldType(ast.type)}${ast.attributes.length > 0 ? " " + ast.attributes.map((x) => this.generate(x)).join(" ") : ""}`;
|
|
7590
|
+
}
|
|
7591
|
+
fieldType(type) {
|
|
7592
|
+
const baseType = type.type ? type.type : type.$type == "DataFieldType" && type.unsupported ? "Unsupported(" + this.generate(type.unsupported.value) + ")" : type.reference?.$refText;
|
|
7593
|
+
return `${baseType}${type.array ? "[]" : ""}${type.optional ? "?" : ""}`;
|
|
7594
|
+
}
|
|
7595
|
+
_generateDataModelAttribute(ast) {
|
|
7596
|
+
return this.attribute(ast);
|
|
7597
|
+
}
|
|
7598
|
+
_generateDataFieldAttribute(ast) {
|
|
7599
|
+
return this.attribute(ast);
|
|
7600
|
+
}
|
|
7601
|
+
attribute(ast) {
|
|
7602
|
+
const args = ast.args.length ? `(${ast.args.map((x) => this.generate(x)).join(", ")})` : "";
|
|
7603
|
+
return `${ast.decl.$refText}${args}`;
|
|
7604
|
+
}
|
|
7605
|
+
_generateAttributeArg(ast) {
|
|
7606
|
+
if (ast.name) {
|
|
7607
|
+
return `${ast.name}: ${this.generate(ast.value)}`;
|
|
7608
|
+
} else {
|
|
7609
|
+
return this.generate(ast.value);
|
|
7610
|
+
}
|
|
7611
|
+
}
|
|
7612
|
+
_generateObjectExpr(ast) {
|
|
7613
|
+
return `{ ${ast.fields.map((field) => this.objectField(field)).join(", ")} }`;
|
|
7614
|
+
}
|
|
7615
|
+
objectField(field) {
|
|
7616
|
+
return `${field.name}: ${this.generate(field.value)}`;
|
|
7617
|
+
}
|
|
7618
|
+
_generateArrayExpr(ast) {
|
|
7619
|
+
return `[${ast.items.map((item) => this.generate(item)).join(", ")}]`;
|
|
7620
|
+
}
|
|
7621
|
+
_generateLiteralExpr(ast) {
|
|
7622
|
+
return this.options.quote === "single" ? `'${ast.value}'` : `"${ast.value}"`;
|
|
7623
|
+
}
|
|
7624
|
+
_generateNumberLiteral(ast) {
|
|
7625
|
+
return ast.value.toString();
|
|
7626
|
+
}
|
|
7627
|
+
_generateBooleanLiteral(ast) {
|
|
7628
|
+
return ast.value.toString();
|
|
7629
|
+
}
|
|
7630
|
+
_generateUnaryExpr(ast) {
|
|
7631
|
+
return `${ast.operator}${this.unaryExprSpace}${this.generate(ast.operand)}`;
|
|
7632
|
+
}
|
|
7633
|
+
_generateBinaryExpr(ast) {
|
|
7634
|
+
const operator = ast.operator;
|
|
7635
|
+
const isCollectionPredicate2 = this.isCollectionPredicateOperator(operator);
|
|
7636
|
+
const rightExpr = this.generate(ast.right);
|
|
7637
|
+
const { left: isLeftParenthesis, right: isRightParenthesis } = this.isParenthesesNeededForBinaryExpr(ast);
|
|
7638
|
+
return `${isLeftParenthesis ? "(" : ""}${this.generate(ast.left)}${isLeftParenthesis ? ")" : ""}${isCollectionPredicate2 ? "" : this.binaryExprSpace}${operator}${isCollectionPredicate2 ? "" : this.binaryExprSpace}${isRightParenthesis ? "(" : ""}${isCollectionPredicate2 ? `[${rightExpr}]` : rightExpr}${isRightParenthesis ? ")" : ""}`;
|
|
7639
|
+
}
|
|
7640
|
+
_generateReferenceExpr(ast) {
|
|
7641
|
+
const args = ast.args.length ? `(${ast.args.map((x) => this.generate(x)).join(", ")})` : "";
|
|
7642
|
+
return `${ast.target.$refText}${args}`;
|
|
7643
|
+
}
|
|
7644
|
+
_generateReferenceArg(ast) {
|
|
7645
|
+
return `${ast.name}:${this.generate(ast.value)}`;
|
|
7646
|
+
}
|
|
7647
|
+
_generateMemberExpr(ast) {
|
|
7648
|
+
return `${this.generate(ast.operand)}.${ast.member.$refText}`;
|
|
7649
|
+
}
|
|
7650
|
+
_generateInvocationExpr(ast) {
|
|
7651
|
+
return `${ast.function.$refText}(${ast.args.map((x) => this.argument(x)).join(", ")})`;
|
|
7652
|
+
}
|
|
7653
|
+
_generateNullExpr() {
|
|
7654
|
+
return "null";
|
|
7655
|
+
}
|
|
7656
|
+
_generateThisExpr() {
|
|
7657
|
+
return "this";
|
|
7658
|
+
}
|
|
7659
|
+
_generateAttribute(ast) {
|
|
7660
|
+
return `attribute ${ast.name}(${ast.params.map((x) => this.generate(x)).join(", ")})`;
|
|
7661
|
+
}
|
|
7662
|
+
_generateAttributeParam(ast) {
|
|
7663
|
+
return `${ast.default ? "_ " : ""}${ast.name}: ${this.generate(ast.type)}`;
|
|
7664
|
+
}
|
|
7665
|
+
_generateAttributeParamType(ast) {
|
|
7666
|
+
return `${ast.type ?? ast.reference?.$refText}${ast.array ? "[]" : ""}${ast.optional ? "?" : ""}`;
|
|
7667
|
+
}
|
|
7668
|
+
_generateFunctionDecl(ast) {
|
|
7669
|
+
return `function ${ast.name}(${ast.params.map((x) => this.generate(x)).join(", ")}) ${ast.returnType ? ": " + this.generate(ast.returnType) : ""} {}`;
|
|
7670
|
+
}
|
|
7671
|
+
_generateFunctionParam(ast) {
|
|
7672
|
+
return `${ast.name}: ${this.generate(ast.type)}`;
|
|
7673
|
+
}
|
|
7674
|
+
_generateFunctionParamType(ast) {
|
|
7675
|
+
return `${ast.type ?? ast.reference?.$refText}${ast.array ? "[]" : ""}`;
|
|
7676
|
+
}
|
|
7677
|
+
_generateTypeDef(ast) {
|
|
7678
|
+
return `type ${ast.name} {
|
|
7679
|
+
${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") : ""}
|
|
7680
|
+
}`;
|
|
7681
|
+
}
|
|
7682
|
+
argument(ast) {
|
|
7683
|
+
return this.generate(ast.value);
|
|
7684
|
+
}
|
|
7685
|
+
get binaryExprSpace() {
|
|
7686
|
+
return " ".repeat(this.options.binaryExprNumberOfSpaces);
|
|
7687
|
+
}
|
|
7688
|
+
get unaryExprSpace() {
|
|
7689
|
+
return " ".repeat(this.options.unaryExprNumberOfSpaces);
|
|
7690
|
+
}
|
|
7691
|
+
get indent() {
|
|
7692
|
+
return " ".repeat(this.options.indent);
|
|
7693
|
+
}
|
|
7694
|
+
isParenthesesNeededForBinaryExpr(ast) {
|
|
7695
|
+
const result = {
|
|
7696
|
+
left: false,
|
|
7697
|
+
right: false
|
|
7698
|
+
};
|
|
7699
|
+
const operator = ast.operator;
|
|
7700
|
+
const isCollectionPredicate2 = this.isCollectionPredicateOperator(operator);
|
|
7701
|
+
const currentPriority = BinaryExprOperatorPriority[operator];
|
|
7702
|
+
if (ast.left.$type === BinaryExpr && BinaryExprOperatorPriority[ast.left["operator"]] < currentPriority) {
|
|
7703
|
+
result.left = true;
|
|
7704
|
+
}
|
|
7705
|
+
if (!isCollectionPredicate2 && ast.right.$type === BinaryExpr && BinaryExprOperatorPriority[ast.right["operator"]] <= currentPriority) {
|
|
7706
|
+
result.right = true;
|
|
7707
|
+
}
|
|
7708
|
+
return result;
|
|
7709
|
+
}
|
|
7710
|
+
isCollectionPredicateOperator(op) {
|
|
7711
|
+
return [
|
|
7712
|
+
"?",
|
|
7713
|
+
"!",
|
|
7714
|
+
"^"
|
|
7715
|
+
].includes(op);
|
|
7716
|
+
}
|
|
7717
|
+
};
|
|
7718
|
+
_ts_decorate3([
|
|
7719
|
+
gen(Model),
|
|
7720
|
+
_ts_metadata3("design:type", Function),
|
|
7721
|
+
_ts_metadata3("design:paramtypes", [
|
|
7722
|
+
typeof Model === "undefined" ? Object : Model
|
|
7723
|
+
]),
|
|
7724
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7725
|
+
], ZModelCodeGenerator.prototype, "_generateModel", null);
|
|
7726
|
+
_ts_decorate3([
|
|
7727
|
+
gen(DataSource),
|
|
7728
|
+
_ts_metadata3("design:type", Function),
|
|
7729
|
+
_ts_metadata3("design:paramtypes", [
|
|
7730
|
+
typeof DataSource === "undefined" ? Object : DataSource
|
|
7731
|
+
]),
|
|
7732
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7733
|
+
], ZModelCodeGenerator.prototype, "_generateDataSource", null);
|
|
7734
|
+
_ts_decorate3([
|
|
7735
|
+
gen(Enum),
|
|
7736
|
+
_ts_metadata3("design:type", Function),
|
|
7737
|
+
_ts_metadata3("design:paramtypes", [
|
|
7738
|
+
typeof Enum === "undefined" ? Object : Enum
|
|
7739
|
+
]),
|
|
7740
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7741
|
+
], ZModelCodeGenerator.prototype, "_generateEnum", null);
|
|
7742
|
+
_ts_decorate3([
|
|
7743
|
+
gen(EnumField),
|
|
7744
|
+
_ts_metadata3("design:type", Function),
|
|
7745
|
+
_ts_metadata3("design:paramtypes", [
|
|
7746
|
+
typeof EnumField === "undefined" ? Object : EnumField
|
|
7747
|
+
]),
|
|
7748
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7749
|
+
], ZModelCodeGenerator.prototype, "_generateEnumField", null);
|
|
7750
|
+
_ts_decorate3([
|
|
7751
|
+
gen(GeneratorDecl),
|
|
7752
|
+
_ts_metadata3("design:type", Function),
|
|
7753
|
+
_ts_metadata3("design:paramtypes", [
|
|
7754
|
+
typeof GeneratorDecl === "undefined" ? Object : GeneratorDecl
|
|
7755
|
+
]),
|
|
7756
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7757
|
+
], ZModelCodeGenerator.prototype, "_generateGenerator", null);
|
|
7758
|
+
_ts_decorate3([
|
|
7759
|
+
gen(ConfigField),
|
|
7760
|
+
_ts_metadata3("design:type", Function),
|
|
7761
|
+
_ts_metadata3("design:paramtypes", [
|
|
7762
|
+
typeof ConfigField === "undefined" ? Object : ConfigField
|
|
7763
|
+
]),
|
|
7764
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7765
|
+
], ZModelCodeGenerator.prototype, "_generateConfigField", null);
|
|
7766
|
+
_ts_decorate3([
|
|
7767
|
+
gen(ConfigArrayExpr),
|
|
7768
|
+
_ts_metadata3("design:type", Function),
|
|
7769
|
+
_ts_metadata3("design:paramtypes", [
|
|
7770
|
+
typeof ConfigArrayExpr === "undefined" ? Object : ConfigArrayExpr
|
|
7771
|
+
]),
|
|
7772
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7773
|
+
], ZModelCodeGenerator.prototype, "_generateConfigArrayExpr", null);
|
|
7774
|
+
_ts_decorate3([
|
|
7775
|
+
gen(ConfigInvocationExpr),
|
|
7776
|
+
_ts_metadata3("design:type", Function),
|
|
7777
|
+
_ts_metadata3("design:paramtypes", [
|
|
7778
|
+
typeof ConfigInvocationExpr === "undefined" ? Object : ConfigInvocationExpr
|
|
7779
|
+
]),
|
|
7780
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7781
|
+
], ZModelCodeGenerator.prototype, "_generateConfigInvocationExpr", null);
|
|
7782
|
+
_ts_decorate3([
|
|
7783
|
+
gen(Plugin),
|
|
7784
|
+
_ts_metadata3("design:type", Function),
|
|
7785
|
+
_ts_metadata3("design:paramtypes", [
|
|
7786
|
+
typeof Plugin === "undefined" ? Object : Plugin
|
|
7787
|
+
]),
|
|
7788
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7789
|
+
], ZModelCodeGenerator.prototype, "_generatePlugin", null);
|
|
7790
|
+
_ts_decorate3([
|
|
7791
|
+
gen(PluginField),
|
|
7792
|
+
_ts_metadata3("design:type", Function),
|
|
7793
|
+
_ts_metadata3("design:paramtypes", [
|
|
7794
|
+
typeof PluginField === "undefined" ? Object : PluginField
|
|
7795
|
+
]),
|
|
7796
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7797
|
+
], ZModelCodeGenerator.prototype, "_generatePluginField", null);
|
|
7798
|
+
_ts_decorate3([
|
|
7799
|
+
gen(DataModel),
|
|
7800
|
+
_ts_metadata3("design:type", Function),
|
|
7801
|
+
_ts_metadata3("design:paramtypes", [
|
|
7802
|
+
typeof DataModel === "undefined" ? Object : DataModel
|
|
7803
|
+
]),
|
|
7804
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7805
|
+
], ZModelCodeGenerator.prototype, "_generateDataModel", null);
|
|
7806
|
+
_ts_decorate3([
|
|
7807
|
+
gen(DataField),
|
|
7808
|
+
_ts_metadata3("design:type", Function),
|
|
7809
|
+
_ts_metadata3("design:paramtypes", [
|
|
7810
|
+
typeof DataField === "undefined" ? Object : DataField
|
|
7811
|
+
]),
|
|
7812
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7813
|
+
], ZModelCodeGenerator.prototype, "_generateDataField", null);
|
|
7814
|
+
_ts_decorate3([
|
|
7815
|
+
gen(DataModelAttribute),
|
|
7816
|
+
_ts_metadata3("design:type", Function),
|
|
7817
|
+
_ts_metadata3("design:paramtypes", [
|
|
7818
|
+
typeof DataModelAttribute === "undefined" ? Object : DataModelAttribute
|
|
7819
|
+
]),
|
|
7820
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7821
|
+
], ZModelCodeGenerator.prototype, "_generateDataModelAttribute", null);
|
|
7822
|
+
_ts_decorate3([
|
|
7823
|
+
gen(DataFieldAttribute),
|
|
7824
|
+
_ts_metadata3("design:type", Function),
|
|
7825
|
+
_ts_metadata3("design:paramtypes", [
|
|
7826
|
+
typeof DataFieldAttribute === "undefined" ? Object : DataFieldAttribute
|
|
7827
|
+
]),
|
|
7828
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7829
|
+
], ZModelCodeGenerator.prototype, "_generateDataFieldAttribute", null);
|
|
7830
|
+
_ts_decorate3([
|
|
7831
|
+
gen(AttributeArg),
|
|
7832
|
+
_ts_metadata3("design:type", Function),
|
|
7833
|
+
_ts_metadata3("design:paramtypes", [
|
|
7834
|
+
typeof AttributeArg === "undefined" ? Object : AttributeArg
|
|
7835
|
+
]),
|
|
7836
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7837
|
+
], ZModelCodeGenerator.prototype, "_generateAttributeArg", null);
|
|
7838
|
+
_ts_decorate3([
|
|
7839
|
+
gen(ObjectExpr),
|
|
7840
|
+
_ts_metadata3("design:type", Function),
|
|
7841
|
+
_ts_metadata3("design:paramtypes", [
|
|
7842
|
+
typeof ObjectExpr === "undefined" ? Object : ObjectExpr
|
|
7843
|
+
]),
|
|
7844
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7845
|
+
], ZModelCodeGenerator.prototype, "_generateObjectExpr", null);
|
|
7846
|
+
_ts_decorate3([
|
|
7847
|
+
gen(ArrayExpr),
|
|
7848
|
+
_ts_metadata3("design:type", Function),
|
|
7849
|
+
_ts_metadata3("design:paramtypes", [
|
|
7850
|
+
typeof ArrayExpr === "undefined" ? Object : ArrayExpr
|
|
7851
|
+
]),
|
|
7852
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7853
|
+
], ZModelCodeGenerator.prototype, "_generateArrayExpr", null);
|
|
7854
|
+
_ts_decorate3([
|
|
7855
|
+
gen(StringLiteral),
|
|
7856
|
+
_ts_metadata3("design:type", Function),
|
|
7857
|
+
_ts_metadata3("design:paramtypes", [
|
|
7858
|
+
typeof LiteralExpr === "undefined" ? Object : LiteralExpr
|
|
7859
|
+
]),
|
|
7860
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7861
|
+
], ZModelCodeGenerator.prototype, "_generateLiteralExpr", null);
|
|
7862
|
+
_ts_decorate3([
|
|
7863
|
+
gen(NumberLiteral),
|
|
7864
|
+
_ts_metadata3("design:type", Function),
|
|
7865
|
+
_ts_metadata3("design:paramtypes", [
|
|
7866
|
+
typeof NumberLiteral === "undefined" ? Object : NumberLiteral
|
|
7867
|
+
]),
|
|
7868
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7869
|
+
], ZModelCodeGenerator.prototype, "_generateNumberLiteral", null);
|
|
7870
|
+
_ts_decorate3([
|
|
7871
|
+
gen(BooleanLiteral),
|
|
7872
|
+
_ts_metadata3("design:type", Function),
|
|
7873
|
+
_ts_metadata3("design:paramtypes", [
|
|
7874
|
+
typeof BooleanLiteral === "undefined" ? Object : BooleanLiteral
|
|
7875
|
+
]),
|
|
7876
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7877
|
+
], ZModelCodeGenerator.prototype, "_generateBooleanLiteral", null);
|
|
7878
|
+
_ts_decorate3([
|
|
7879
|
+
gen(UnaryExpr),
|
|
7880
|
+
_ts_metadata3("design:type", Function),
|
|
7881
|
+
_ts_metadata3("design:paramtypes", [
|
|
7882
|
+
typeof UnaryExpr === "undefined" ? Object : UnaryExpr
|
|
7883
|
+
]),
|
|
7884
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7885
|
+
], ZModelCodeGenerator.prototype, "_generateUnaryExpr", null);
|
|
7886
|
+
_ts_decorate3([
|
|
7887
|
+
gen(BinaryExpr),
|
|
7888
|
+
_ts_metadata3("design:type", Function),
|
|
7889
|
+
_ts_metadata3("design:paramtypes", [
|
|
7890
|
+
typeof BinaryExpr === "undefined" ? Object : BinaryExpr
|
|
7891
|
+
]),
|
|
7892
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7893
|
+
], ZModelCodeGenerator.prototype, "_generateBinaryExpr", null);
|
|
7894
|
+
_ts_decorate3([
|
|
7895
|
+
gen(ReferenceExpr),
|
|
7896
|
+
_ts_metadata3("design:type", Function),
|
|
7897
|
+
_ts_metadata3("design:paramtypes", [
|
|
7898
|
+
typeof ReferenceExpr === "undefined" ? Object : ReferenceExpr
|
|
7899
|
+
]),
|
|
7900
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7901
|
+
], ZModelCodeGenerator.prototype, "_generateReferenceExpr", null);
|
|
7902
|
+
_ts_decorate3([
|
|
7903
|
+
gen(ReferenceArg),
|
|
7904
|
+
_ts_metadata3("design:type", Function),
|
|
7905
|
+
_ts_metadata3("design:paramtypes", [
|
|
7906
|
+
typeof ReferenceArg === "undefined" ? Object : ReferenceArg
|
|
7907
|
+
]),
|
|
7908
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7909
|
+
], ZModelCodeGenerator.prototype, "_generateReferenceArg", null);
|
|
7910
|
+
_ts_decorate3([
|
|
7911
|
+
gen(MemberAccessExpr),
|
|
7912
|
+
_ts_metadata3("design:type", Function),
|
|
7913
|
+
_ts_metadata3("design:paramtypes", [
|
|
7914
|
+
typeof MemberAccessExpr === "undefined" ? Object : MemberAccessExpr
|
|
7915
|
+
]),
|
|
7916
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7917
|
+
], ZModelCodeGenerator.prototype, "_generateMemberExpr", null);
|
|
7918
|
+
_ts_decorate3([
|
|
7919
|
+
gen(InvocationExpr),
|
|
7920
|
+
_ts_metadata3("design:type", Function),
|
|
7921
|
+
_ts_metadata3("design:paramtypes", [
|
|
7922
|
+
typeof InvocationExpr === "undefined" ? Object : InvocationExpr
|
|
7923
|
+
]),
|
|
7924
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7925
|
+
], ZModelCodeGenerator.prototype, "_generateInvocationExpr", null);
|
|
7926
|
+
_ts_decorate3([
|
|
7927
|
+
gen(NullExpr),
|
|
7928
|
+
_ts_metadata3("design:type", Function),
|
|
7929
|
+
_ts_metadata3("design:paramtypes", []),
|
|
7930
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7931
|
+
], ZModelCodeGenerator.prototype, "_generateNullExpr", null);
|
|
7932
|
+
_ts_decorate3([
|
|
7933
|
+
gen(ThisExpr),
|
|
7934
|
+
_ts_metadata3("design:type", Function),
|
|
7935
|
+
_ts_metadata3("design:paramtypes", []),
|
|
7936
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7937
|
+
], ZModelCodeGenerator.prototype, "_generateThisExpr", null);
|
|
7938
|
+
_ts_decorate3([
|
|
7939
|
+
gen(Attribute),
|
|
7940
|
+
_ts_metadata3("design:type", Function),
|
|
7941
|
+
_ts_metadata3("design:paramtypes", [
|
|
7942
|
+
typeof Attribute === "undefined" ? Object : Attribute
|
|
7943
|
+
]),
|
|
7944
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7945
|
+
], ZModelCodeGenerator.prototype, "_generateAttribute", null);
|
|
7946
|
+
_ts_decorate3([
|
|
7947
|
+
gen(AttributeParam),
|
|
7948
|
+
_ts_metadata3("design:type", Function),
|
|
7949
|
+
_ts_metadata3("design:paramtypes", [
|
|
7950
|
+
typeof AttributeParam === "undefined" ? Object : AttributeParam
|
|
7951
|
+
]),
|
|
7952
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7953
|
+
], ZModelCodeGenerator.prototype, "_generateAttributeParam", null);
|
|
7954
|
+
_ts_decorate3([
|
|
7955
|
+
gen(AttributeParamType),
|
|
7956
|
+
_ts_metadata3("design:type", Function),
|
|
7957
|
+
_ts_metadata3("design:paramtypes", [
|
|
7958
|
+
typeof AttributeParamType === "undefined" ? Object : AttributeParamType
|
|
7959
|
+
]),
|
|
7960
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7961
|
+
], ZModelCodeGenerator.prototype, "_generateAttributeParamType", null);
|
|
7962
|
+
_ts_decorate3([
|
|
7963
|
+
gen(FunctionDecl),
|
|
7964
|
+
_ts_metadata3("design:type", Function),
|
|
7965
|
+
_ts_metadata3("design:paramtypes", [
|
|
7966
|
+
typeof FunctionDecl === "undefined" ? Object : FunctionDecl
|
|
7967
|
+
]),
|
|
7968
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7969
|
+
], ZModelCodeGenerator.prototype, "_generateFunctionDecl", null);
|
|
7970
|
+
_ts_decorate3([
|
|
7971
|
+
gen(FunctionParam),
|
|
7972
|
+
_ts_metadata3("design:type", Function),
|
|
7973
|
+
_ts_metadata3("design:paramtypes", [
|
|
7974
|
+
typeof FunctionParam === "undefined" ? Object : FunctionParam
|
|
7975
|
+
]),
|
|
7976
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7977
|
+
], ZModelCodeGenerator.prototype, "_generateFunctionParam", null);
|
|
7978
|
+
_ts_decorate3([
|
|
7979
|
+
gen(FunctionParamType),
|
|
7980
|
+
_ts_metadata3("design:type", Function),
|
|
7981
|
+
_ts_metadata3("design:paramtypes", [
|
|
7982
|
+
typeof FunctionParamType === "undefined" ? Object : FunctionParamType
|
|
7983
|
+
]),
|
|
7984
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7985
|
+
], ZModelCodeGenerator.prototype, "_generateFunctionParamType", null);
|
|
7986
|
+
_ts_decorate3([
|
|
7987
|
+
gen(TypeDef),
|
|
7988
|
+
_ts_metadata3("design:type", Function),
|
|
7989
|
+
_ts_metadata3("design:paramtypes", [
|
|
7990
|
+
typeof TypeDef === "undefined" ? Object : TypeDef
|
|
7991
|
+
]),
|
|
7992
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7993
|
+
], ZModelCodeGenerator.prototype, "_generateTypeDef", null);
|
|
7994
|
+
|
|
7995
|
+
// src/zmodel-completion-provider.ts
|
|
7996
|
+
var ZModelCompletionProvider = class extends import_lsp.DefaultCompletionProvider {
|
|
7997
|
+
static {
|
|
7998
|
+
__name(this, "ZModelCompletionProvider");
|
|
7999
|
+
}
|
|
8000
|
+
services;
|
|
8001
|
+
constructor(services) {
|
|
8002
|
+
super(services), this.services = services;
|
|
8003
|
+
}
|
|
8004
|
+
completionOptions = {
|
|
8005
|
+
triggerCharacters: [
|
|
8006
|
+
"@",
|
|
8007
|
+
"(",
|
|
8008
|
+
",",
|
|
8009
|
+
"."
|
|
8010
|
+
]
|
|
8011
|
+
};
|
|
8012
|
+
async getCompletion(document, params) {
|
|
8013
|
+
try {
|
|
8014
|
+
return await super.getCompletion(document, params);
|
|
8015
|
+
} catch (e) {
|
|
8016
|
+
console.error("Completion error:", e.message);
|
|
8017
|
+
return void 0;
|
|
8018
|
+
}
|
|
8019
|
+
}
|
|
8020
|
+
completionFor(context, next, acceptor) {
|
|
8021
|
+
if (isDataModelAttribute(context.node) || isDataFieldAttribute(context.node)) {
|
|
8022
|
+
const completions = this.getCompletionFromHint(context.node);
|
|
8023
|
+
if (completions) {
|
|
8024
|
+
completions.forEach((c) => acceptor(context, c));
|
|
8025
|
+
return;
|
|
8026
|
+
}
|
|
8027
|
+
}
|
|
8028
|
+
return super.completionFor(context, next, acceptor);
|
|
8029
|
+
}
|
|
8030
|
+
getCompletionFromHint(contextNode) {
|
|
8031
|
+
const unfilledParams = this.getUnfilledAttributeParams(contextNode);
|
|
8032
|
+
const nextParam = unfilledParams[0];
|
|
8033
|
+
if (!nextParam) {
|
|
8034
|
+
return void 0;
|
|
8035
|
+
}
|
|
8036
|
+
const hintAttr = getAttribute(nextParam, "@@@completionHint");
|
|
8037
|
+
if (hintAttr) {
|
|
8038
|
+
const hint = hintAttr.args[0];
|
|
8039
|
+
if (hint?.value) {
|
|
8040
|
+
if (isArrayExpr(hint.value)) {
|
|
8041
|
+
return hint.value.items.map((item) => {
|
|
8042
|
+
return {
|
|
8043
|
+
label: `${item.value}`,
|
|
8044
|
+
kind: import_vscode_languageserver.CompletionItemKind.Value,
|
|
8045
|
+
detail: "Parameter",
|
|
8046
|
+
sortText: "0"
|
|
8047
|
+
};
|
|
8048
|
+
});
|
|
8049
|
+
}
|
|
8050
|
+
}
|
|
8051
|
+
}
|
|
8052
|
+
return void 0;
|
|
8053
|
+
}
|
|
8054
|
+
// TODO: this doesn't work when the file contains parse errors
|
|
8055
|
+
getUnfilledAttributeParams(contextNode) {
|
|
8056
|
+
try {
|
|
8057
|
+
const params = contextNode.decl.ref?.params;
|
|
8058
|
+
if (params) {
|
|
8059
|
+
const args = contextNode.args;
|
|
8060
|
+
let unfilledParams = [
|
|
8061
|
+
...params
|
|
8062
|
+
];
|
|
8063
|
+
args.forEach((arg) => {
|
|
8064
|
+
if (arg.name) {
|
|
8065
|
+
unfilledParams = unfilledParams.filter((p) => p.name !== arg.name);
|
|
8066
|
+
} else {
|
|
8067
|
+
unfilledParams.shift();
|
|
8068
|
+
}
|
|
8069
|
+
});
|
|
8070
|
+
return unfilledParams;
|
|
8071
|
+
}
|
|
8072
|
+
} catch {
|
|
8073
|
+
}
|
|
8074
|
+
return [];
|
|
8075
|
+
}
|
|
8076
|
+
completionForCrossReference(context, crossRef, acceptor) {
|
|
8077
|
+
if (crossRef.property === "member" && !isMemberAccessExpr(context.node)) {
|
|
8078
|
+
return;
|
|
8079
|
+
}
|
|
8080
|
+
const customAcceptor = /* @__PURE__ */ __name((context2, item) => {
|
|
8081
|
+
if (item.insertText?.startsWith("@@@") || item.label?.startsWith("@@@")) {
|
|
8082
|
+
return;
|
|
8083
|
+
}
|
|
8084
|
+
if ("nodeDescription" in item) {
|
|
8085
|
+
const node = this.getAstNode(item.nodeDescription);
|
|
8086
|
+
if (!node) {
|
|
8087
|
+
return;
|
|
8088
|
+
}
|
|
8089
|
+
if ((isEnum(node) || isEnumField(node)) && isFromStdlib(node)) {
|
|
8090
|
+
return;
|
|
8091
|
+
}
|
|
8092
|
+
if ((isDataModelAttribute(context2.node) || isDataFieldAttribute(context2.node)) && !this.filterAttributeApplicationCompletion(context2.node, node)) {
|
|
8093
|
+
return;
|
|
8094
|
+
}
|
|
8095
|
+
}
|
|
8096
|
+
acceptor(context2, item);
|
|
8097
|
+
}, "customAcceptor");
|
|
8098
|
+
return super.completionForCrossReference(context, crossRef, customAcceptor);
|
|
8099
|
+
}
|
|
8100
|
+
completionForKeyword(context, keyword, acceptor) {
|
|
8101
|
+
const customAcceptor = /* @__PURE__ */ __name((context2, item) => {
|
|
8102
|
+
if (!this.filterKeywordForContext(context2, keyword.value)) {
|
|
8103
|
+
return;
|
|
8104
|
+
}
|
|
8105
|
+
acceptor(context2, item);
|
|
8106
|
+
}, "customAcceptor");
|
|
8107
|
+
return super.completionForKeyword(context, keyword, customAcceptor);
|
|
8108
|
+
}
|
|
8109
|
+
filterKeywordForContext(context, keyword) {
|
|
8110
|
+
if (isInvocationExpr(context.node)) {
|
|
8111
|
+
return [
|
|
8112
|
+
"true",
|
|
8113
|
+
"false",
|
|
8114
|
+
"null",
|
|
8115
|
+
"this"
|
|
8116
|
+
].includes(keyword);
|
|
8117
|
+
} else if (isDataModelAttribute(context.node) || isDataFieldAttribute(context.node)) {
|
|
8118
|
+
const exprContext = this.getAttributeContextType(context.node);
|
|
8119
|
+
if (exprContext === "DefaultValue") {
|
|
8120
|
+
return [
|
|
8121
|
+
"true",
|
|
8122
|
+
"false",
|
|
8123
|
+
"null"
|
|
8124
|
+
].includes(keyword);
|
|
8125
|
+
} else {
|
|
8126
|
+
return [
|
|
8127
|
+
"true",
|
|
8128
|
+
"false",
|
|
8129
|
+
"null",
|
|
8130
|
+
"this"
|
|
8131
|
+
].includes(keyword);
|
|
8132
|
+
}
|
|
8133
|
+
} else {
|
|
8134
|
+
return true;
|
|
8135
|
+
}
|
|
8136
|
+
}
|
|
8137
|
+
filterAttributeApplicationCompletion(contextNode, node) {
|
|
8138
|
+
const attrContextType = this.getAttributeContextType(contextNode);
|
|
8139
|
+
if (isFunctionDecl(node) && attrContextType) {
|
|
8140
|
+
const funcExprContextAttr = getAttribute(node, "@@@expressionContext");
|
|
8141
|
+
if (funcExprContextAttr && funcExprContextAttr.args[0]) {
|
|
8142
|
+
const arg = funcExprContextAttr.args[0];
|
|
8143
|
+
if (isArrayExpr(arg.value)) {
|
|
8144
|
+
return arg.value.items.some((item) => isEnumFieldReference(item) && item.target.$refText === attrContextType);
|
|
8145
|
+
}
|
|
8146
|
+
}
|
|
8147
|
+
return false;
|
|
8148
|
+
}
|
|
8149
|
+
if (isDataField(node)) {
|
|
8150
|
+
return attrContextType !== "DefaultValue";
|
|
8151
|
+
}
|
|
8152
|
+
return true;
|
|
8153
|
+
}
|
|
8154
|
+
getAttributeContextType(node) {
|
|
8155
|
+
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);
|
|
8156
|
+
}
|
|
8157
|
+
createReferenceCompletionItem(nodeDescription) {
|
|
8158
|
+
const node = this.getAstNode(nodeDescription);
|
|
8159
|
+
const documentation = this.getNodeDocumentation(node);
|
|
8160
|
+
return (0, import_ts_pattern3.match)(node).when(isDataModel, () => ({
|
|
8161
|
+
nodeDescription,
|
|
8162
|
+
kind: import_vscode_languageserver.CompletionItemKind.Class,
|
|
8163
|
+
detail: "Model",
|
|
8164
|
+
sortText: "1",
|
|
8165
|
+
documentation
|
|
8166
|
+
})).when(isTypeDef, () => ({
|
|
8167
|
+
nodeDescription,
|
|
8168
|
+
kind: import_vscode_languageserver.CompletionItemKind.Class,
|
|
8169
|
+
detail: "Type",
|
|
8170
|
+
sortText: "1",
|
|
8171
|
+
documentation
|
|
8172
|
+
})).when(isDataField, () => ({
|
|
8173
|
+
nodeDescription,
|
|
8174
|
+
kind: import_vscode_languageserver.CompletionItemKind.Field,
|
|
8175
|
+
detail: "Field",
|
|
8176
|
+
sortText: "0",
|
|
8177
|
+
documentation
|
|
8178
|
+
})).when(isEnum, () => ({
|
|
8179
|
+
nodeDescription,
|
|
8180
|
+
kind: import_vscode_languageserver.CompletionItemKind.Class,
|
|
8181
|
+
detail: "Enum",
|
|
8182
|
+
sortText: "1",
|
|
8183
|
+
documentation
|
|
8184
|
+
})).when(isEnumField, (d) => {
|
|
8185
|
+
const container = d.$container;
|
|
8186
|
+
return {
|
|
8187
|
+
nodeDescription,
|
|
8188
|
+
kind: import_vscode_languageserver.CompletionItemKind.Enum,
|
|
8189
|
+
detail: `Value of enum "${container.name}"`,
|
|
8190
|
+
sortText: "1",
|
|
8191
|
+
documentation
|
|
8192
|
+
};
|
|
8193
|
+
}).when(isFunctionDecl, () => ({
|
|
8194
|
+
nodeDescription,
|
|
8195
|
+
insertText: this.getFunctionInsertText(nodeDescription),
|
|
8196
|
+
kind: import_vscode_languageserver.CompletionItemKind.Function,
|
|
8197
|
+
detail: "Function",
|
|
8198
|
+
sortText: "1",
|
|
8199
|
+
documentation
|
|
8200
|
+
})).when(isAttribute, () => ({
|
|
8201
|
+
nodeDescription,
|
|
8202
|
+
insertText: this.getAttributeInsertText(nodeDescription),
|
|
8203
|
+
kind: import_vscode_languageserver.CompletionItemKind.Property,
|
|
8204
|
+
detail: "Attribute",
|
|
8205
|
+
sortText: "1",
|
|
8206
|
+
documentation
|
|
8207
|
+
})).otherwise(() => ({
|
|
8208
|
+
nodeDescription,
|
|
8209
|
+
kind: import_vscode_languageserver.CompletionItemKind.Reference,
|
|
8210
|
+
detail: nodeDescription.type,
|
|
8211
|
+
sortText: "2",
|
|
8212
|
+
documentation
|
|
8213
|
+
}));
|
|
8214
|
+
}
|
|
8215
|
+
getFunctionInsertText(nodeDescription) {
|
|
8216
|
+
const node = this.getAstNode(nodeDescription);
|
|
8217
|
+
if (isFunctionDecl(node)) {
|
|
8218
|
+
if (node.params.some((p) => !p.optional)) {
|
|
8219
|
+
return nodeDescription.name;
|
|
8220
|
+
}
|
|
8221
|
+
}
|
|
8222
|
+
return `${nodeDescription.name}()`;
|
|
8223
|
+
}
|
|
8224
|
+
getAttributeInsertText(nodeDescription) {
|
|
8225
|
+
const node = this.getAstNode(nodeDescription);
|
|
8226
|
+
if (isAttribute(node)) {
|
|
8227
|
+
if (node.name === "@relation") {
|
|
8228
|
+
return `${nodeDescription.name}(fields: [], references: [])`;
|
|
8229
|
+
}
|
|
8230
|
+
}
|
|
8231
|
+
return nodeDescription.name;
|
|
8232
|
+
}
|
|
8233
|
+
getAstNode(nodeDescription) {
|
|
8234
|
+
let node = nodeDescription.node;
|
|
8235
|
+
if (!node) {
|
|
8236
|
+
const doc = this.getOrCreateDocumentSync(nodeDescription);
|
|
8237
|
+
if (!doc) {
|
|
8238
|
+
return void 0;
|
|
8239
|
+
}
|
|
8240
|
+
node = this.services.workspace.AstNodeLocator.getAstNode(doc.parseResult.value, nodeDescription.path);
|
|
8241
|
+
if (!node) {
|
|
8242
|
+
return void 0;
|
|
8243
|
+
}
|
|
8244
|
+
}
|
|
8245
|
+
return node;
|
|
8246
|
+
}
|
|
8247
|
+
getOrCreateDocumentSync(nodeDescription) {
|
|
8248
|
+
let doc = this.services.shared.workspace.LangiumDocuments.getDocument(nodeDescription.documentUri);
|
|
8249
|
+
if (!doc) {
|
|
8250
|
+
try {
|
|
8251
|
+
const content = import_node_fs2.default.readFileSync(nodeDescription.documentUri.fsPath, "utf-8");
|
|
8252
|
+
doc = this.services.shared.workspace.LangiumDocuments.createDocument(nodeDescription.documentUri, content);
|
|
8253
|
+
} catch {
|
|
8254
|
+
console.warn("Failed to read or create document:", nodeDescription.documentUri);
|
|
8255
|
+
return void 0;
|
|
8256
|
+
}
|
|
8257
|
+
}
|
|
8258
|
+
return doc;
|
|
8259
|
+
}
|
|
8260
|
+
getNodeDocumentation(node) {
|
|
8261
|
+
if (!node) {
|
|
8262
|
+
return void 0;
|
|
8263
|
+
}
|
|
8264
|
+
const md = this.commentsToMarkdown(node);
|
|
8265
|
+
return {
|
|
8266
|
+
kind: "markdown",
|
|
8267
|
+
value: md
|
|
8268
|
+
};
|
|
8269
|
+
}
|
|
8270
|
+
commentsToMarkdown(node) {
|
|
8271
|
+
const md = this.services.documentation.DocumentationProvider.getDocumentation(node) ?? "";
|
|
8272
|
+
const zModelGenerator = new ZModelCodeGenerator();
|
|
8273
|
+
const docs = [];
|
|
8274
|
+
try {
|
|
8275
|
+
(0, import_ts_pattern3.match)(node).when(isAttribute, (attr) => {
|
|
8276
|
+
docs.push("```prisma", zModelGenerator.generate(attr), "```");
|
|
8277
|
+
}).when(isFunctionDecl, (func2) => {
|
|
8278
|
+
docs.push("```ts", zModelGenerator.generate(func2), "```");
|
|
8279
|
+
}).when(isDataModel, (model) => {
|
|
8280
|
+
docs.push("```prisma", `model ${model.name} { ... }`, "```");
|
|
8281
|
+
}).when(isEnum, (enumDecl) => {
|
|
8282
|
+
docs.push("```prisma", zModelGenerator.generate(enumDecl), "```");
|
|
8283
|
+
}).when(isDataField, (field) => {
|
|
8284
|
+
docs.push(`${field.name}: ${field.type.type ?? field.type.reference?.$refText}`);
|
|
8285
|
+
}).otherwise((ast) => {
|
|
8286
|
+
const name = ast.name;
|
|
8287
|
+
if (name) {
|
|
8288
|
+
docs.push(name);
|
|
8289
|
+
}
|
|
8290
|
+
});
|
|
8291
|
+
} catch {
|
|
8292
|
+
}
|
|
8293
|
+
if (md) {
|
|
8294
|
+
docs.push("___", md);
|
|
8295
|
+
}
|
|
8296
|
+
return docs.join("\n");
|
|
8297
|
+
}
|
|
8298
|
+
};
|
|
8299
|
+
|
|
8300
|
+
// src/zmodel-definition.ts
|
|
8301
|
+
var import_lsp2 = require("langium/lsp");
|
|
8302
|
+
var import_vscode_languageserver2 = require("vscode-languageserver");
|
|
8303
|
+
var ZModelDefinitionProvider = class extends import_lsp2.DefaultDefinitionProvider {
|
|
8304
|
+
static {
|
|
8305
|
+
__name(this, "ZModelDefinitionProvider");
|
|
8306
|
+
}
|
|
8307
|
+
documents;
|
|
8308
|
+
constructor(services) {
|
|
8309
|
+
super(services);
|
|
8310
|
+
this.documents = services.shared.workspace.LangiumDocuments;
|
|
8311
|
+
}
|
|
8312
|
+
collectLocationLinks(sourceCstNode, _params) {
|
|
8313
|
+
if (isModelImport(sourceCstNode.astNode)) {
|
|
8314
|
+
const importedModel = resolveImport(this.documents, sourceCstNode.astNode);
|
|
8315
|
+
if (importedModel?.$document) {
|
|
8316
|
+
const targetObject = importedModel;
|
|
8317
|
+
const selectionRange = this.nameProvider.getNameNode(targetObject)?.range ?? import_vscode_languageserver2.Range.create(0, 0, 0, 0);
|
|
8318
|
+
const previewRange = targetObject.$cstNode?.range ?? import_vscode_languageserver2.Range.create(0, 0, 0, 0);
|
|
8319
|
+
return [
|
|
8320
|
+
import_vscode_languageserver2.LocationLink.create(importedModel.$document.uri.toString(), previewRange, selectionRange, sourceCstNode.range)
|
|
8321
|
+
];
|
|
8322
|
+
}
|
|
8323
|
+
return void 0;
|
|
8324
|
+
}
|
|
8325
|
+
return super.collectLocationLinks(sourceCstNode, _params);
|
|
8326
|
+
}
|
|
8327
|
+
};
|
|
8328
|
+
|
|
8329
|
+
// src/zmodel-document-builder.ts
|
|
8330
|
+
var import_langium8 = require("langium");
|
|
8331
|
+
var ZModelDocumentBuilder = class extends import_langium8.DefaultDocumentBuilder {
|
|
7141
8332
|
static {
|
|
7142
8333
|
__name(this, "ZModelDocumentBuilder");
|
|
7143
8334
|
}
|
|
@@ -7164,10 +8355,115 @@ var ZModelDocumentBuilder = class extends import_langium7.DefaultDocumentBuilder
|
|
|
7164
8355
|
}
|
|
7165
8356
|
};
|
|
7166
8357
|
|
|
8358
|
+
// src/zmodel-documentation-provider.ts
|
|
8359
|
+
var import_langium9 = require("langium");
|
|
8360
|
+
var ZModelDocumentationProvider = class extends import_langium9.JSDocDocumentationProvider {
|
|
8361
|
+
static {
|
|
8362
|
+
__name(this, "ZModelDocumentationProvider");
|
|
8363
|
+
}
|
|
8364
|
+
getDocumentation(node) {
|
|
8365
|
+
if ("comments" in node && Array.isArray(node.comments) && node.comments.length > 0) {
|
|
8366
|
+
return node.comments.map((c) => c.replace(/^[/]*\s*/, "")).join("\n");
|
|
8367
|
+
}
|
|
8368
|
+
return super.getDocumentation(node);
|
|
8369
|
+
}
|
|
8370
|
+
};
|
|
8371
|
+
|
|
8372
|
+
// src/zmodel-formatter.ts
|
|
8373
|
+
var import_lsp3 = require("langium/lsp");
|
|
8374
|
+
var ZModelFormatter = class extends import_lsp3.AbstractFormatter {
|
|
8375
|
+
static {
|
|
8376
|
+
__name(this, "ZModelFormatter");
|
|
8377
|
+
}
|
|
8378
|
+
formatOptions;
|
|
8379
|
+
configurationProvider;
|
|
8380
|
+
constructor(services) {
|
|
8381
|
+
super();
|
|
8382
|
+
this.configurationProvider = services.shared.workspace.ConfigurationProvider;
|
|
8383
|
+
}
|
|
8384
|
+
format(node) {
|
|
8385
|
+
const formatter = this.getNodeFormatter(node);
|
|
8386
|
+
if (isDataField(node)) {
|
|
8387
|
+
if (isDataModel(node.$container) || isTypeDef(node.$container)) {
|
|
8388
|
+
const dataModel = node.$container;
|
|
8389
|
+
const compareFn = /* @__PURE__ */ __name((a, b) => b - a, "compareFn");
|
|
8390
|
+
const maxNameLength = dataModel.fields.map((x) => x.name.length).sort(compareFn)[0] ?? 0;
|
|
8391
|
+
const maxTypeLength = dataModel.fields.map(this.getFieldTypeLength).sort(compareFn)[0] ?? 0;
|
|
8392
|
+
formatter.property("type").prepend(import_lsp3.Formatting.spaces(maxNameLength - node.name.length + 1));
|
|
8393
|
+
if (node.attributes.length > 0) {
|
|
8394
|
+
formatter.node(node.attributes[0]).prepend(import_lsp3.Formatting.spaces(maxTypeLength - this.getFieldTypeLength(node) + 1));
|
|
8395
|
+
formatter.nodes(...node.attributes.slice(1)).prepend(import_lsp3.Formatting.oneSpace());
|
|
8396
|
+
}
|
|
8397
|
+
} else {
|
|
8398
|
+
formatter.property("type").prepend(import_lsp3.Formatting.oneSpace());
|
|
8399
|
+
if (node.attributes.length > 0) {
|
|
8400
|
+
formatter.properties("attributes").prepend(import_lsp3.Formatting.oneSpace());
|
|
8401
|
+
}
|
|
8402
|
+
}
|
|
8403
|
+
} else if (isDataFieldAttribute(node)) {
|
|
8404
|
+
formatter.keyword("(").surround(import_lsp3.Formatting.noSpace());
|
|
8405
|
+
formatter.keyword(")").prepend(import_lsp3.Formatting.noSpace());
|
|
8406
|
+
formatter.keyword(",").append(import_lsp3.Formatting.oneSpace());
|
|
8407
|
+
if (node.args.length > 1) {
|
|
8408
|
+
formatter.nodes(...node.args.slice(1)).prepend(import_lsp3.Formatting.oneSpace());
|
|
8409
|
+
}
|
|
8410
|
+
} else if (isAttributeArg(node)) {
|
|
8411
|
+
formatter.keyword(":").prepend(import_lsp3.Formatting.noSpace());
|
|
8412
|
+
formatter.keyword(":").append(import_lsp3.Formatting.oneSpace());
|
|
8413
|
+
} else if (isAbstractDeclaration(node)) {
|
|
8414
|
+
const bracesOpen = formatter.keyword("{");
|
|
8415
|
+
const bracesClose = formatter.keyword("}");
|
|
8416
|
+
formatter.interior(bracesOpen, bracesClose).prepend(import_lsp3.Formatting.indent({
|
|
8417
|
+
allowMore: true
|
|
8418
|
+
}));
|
|
8419
|
+
bracesOpen.prepend(import_lsp3.Formatting.oneSpace());
|
|
8420
|
+
bracesClose.prepend(import_lsp3.Formatting.newLine());
|
|
8421
|
+
} else if (isModel(node)) {
|
|
8422
|
+
const model = node;
|
|
8423
|
+
const nodes = formatter.nodes(...model.declarations);
|
|
8424
|
+
nodes.prepend(import_lsp3.Formatting.noIndent());
|
|
8425
|
+
}
|
|
8426
|
+
}
|
|
8427
|
+
formatDocument(document, params) {
|
|
8428
|
+
this.formatOptions = params.options;
|
|
8429
|
+
this.configurationProvider.getConfiguration(ZModelLanguageMetaData.languageId, "format").then((config) => {
|
|
8430
|
+
if (config) {
|
|
8431
|
+
}
|
|
8432
|
+
});
|
|
8433
|
+
return super.formatDocument(document, params);
|
|
8434
|
+
}
|
|
8435
|
+
getFormatOptions() {
|
|
8436
|
+
return this.formatOptions;
|
|
8437
|
+
}
|
|
8438
|
+
getIndent() {
|
|
8439
|
+
return 1;
|
|
8440
|
+
}
|
|
8441
|
+
getFieldTypeLength(field) {
|
|
8442
|
+
let length;
|
|
8443
|
+
if (field.type.type) {
|
|
8444
|
+
length = field.type.type.length;
|
|
8445
|
+
} else if (field.type.reference) {
|
|
8446
|
+
length = field.type.reference.$refText.length;
|
|
8447
|
+
} else if (isDataField(field) && field.type.unsupported) {
|
|
8448
|
+
const name = `Unsupported("${field.type.unsupported.value.value}")`;
|
|
8449
|
+
length = name.length;
|
|
8450
|
+
} else {
|
|
8451
|
+
length = 1;
|
|
8452
|
+
}
|
|
8453
|
+
if (field.type.optional) {
|
|
8454
|
+
length += 1;
|
|
8455
|
+
}
|
|
8456
|
+
if (field.type.array) {
|
|
8457
|
+
length += 2;
|
|
8458
|
+
}
|
|
8459
|
+
return length;
|
|
8460
|
+
}
|
|
8461
|
+
};
|
|
8462
|
+
|
|
7167
8463
|
// src/zmodel-linker.ts
|
|
7168
|
-
var
|
|
7169
|
-
var
|
|
7170
|
-
var ZModelLinker = class extends
|
|
8464
|
+
var import_langium10 = require("langium");
|
|
8465
|
+
var import_ts_pattern4 = require("ts-pattern");
|
|
8466
|
+
var ZModelLinker = class extends import_langium10.DefaultLinker {
|
|
7171
8467
|
static {
|
|
7172
8468
|
__name(this, "ZModelLinker");
|
|
7173
8469
|
}
|
|
@@ -7177,15 +8473,15 @@ var ZModelLinker = class extends import_langium8.DefaultLinker {
|
|
|
7177
8473
|
this.descriptions = services.workspace.AstNodeDescriptionProvider;
|
|
7178
8474
|
}
|
|
7179
8475
|
//#region Reference linking
|
|
7180
|
-
async link(document, cancelToken =
|
|
8476
|
+
async link(document, cancelToken = import_langium10.Cancellation.CancellationToken.None) {
|
|
7181
8477
|
if (document.parseResult.lexerErrors?.length > 0 || document.parseResult.parserErrors?.length > 0) {
|
|
7182
8478
|
return;
|
|
7183
8479
|
}
|
|
7184
|
-
for (const node of
|
|
7185
|
-
await (0,
|
|
8480
|
+
for (const node of import_langium10.AstUtils.streamContents(document.parseResult.value)) {
|
|
8481
|
+
await (0, import_langium10.interruptAndCheck)(cancelToken);
|
|
7186
8482
|
this.resolve(node, document);
|
|
7187
8483
|
}
|
|
7188
|
-
document.state =
|
|
8484
|
+
document.state = import_langium10.DocumentState.Linked;
|
|
7189
8485
|
}
|
|
7190
8486
|
linkReference(refInfo, document, extraScopes) {
|
|
7191
8487
|
const defaultRef = refInfo.reference;
|
|
@@ -7337,7 +8633,7 @@ var ZModelLinker = class extends import_langium8.DefaultLinker {
|
|
|
7337
8633
|
if (node.function.ref) {
|
|
7338
8634
|
const funcDecl = node.function.ref;
|
|
7339
8635
|
if (isAuthInvocation(node)) {
|
|
7340
|
-
const allDecls = getAllLoadedAndReachableDataModelsAndTypeDefs(this.langiumDocuments(),
|
|
8636
|
+
const allDecls = getAllLoadedAndReachableDataModelsAndTypeDefs(this.langiumDocuments(), import_langium10.AstUtils.getContainerOfType(node, isDataModel));
|
|
7341
8637
|
const authDecl = getAuthDecl(allDecls);
|
|
7342
8638
|
if (authDecl) {
|
|
7343
8639
|
node.$resolvedType = {
|
|
@@ -7355,7 +8651,7 @@ var ZModelLinker = class extends import_langium8.DefaultLinker {
|
|
|
7355
8651
|
}
|
|
7356
8652
|
}
|
|
7357
8653
|
resolveLiteral(node) {
|
|
7358
|
-
const type = (0,
|
|
8654
|
+
const type = (0, import_ts_pattern4.match)(node).when(isStringLiteral, () => "String").when(isBooleanLiteral, () => "Boolean").when(isNumberLiteral, () => "Int").exhaustive();
|
|
7359
8655
|
if (type) {
|
|
7360
8656
|
this.resolveToBuiltinTypeOrDecl(node, type);
|
|
7361
8657
|
}
|
|
@@ -7475,10 +8771,10 @@ var ZModelLinker = class extends import_langium8.DefaultLinker {
|
|
|
7475
8771
|
this.resolveDefault(node, document, scopes);
|
|
7476
8772
|
}
|
|
7477
8773
|
resolveDefault(node, document, extraScopes) {
|
|
7478
|
-
|
|
8774
|
+
import_langium10.AstUtils.streamReferences(node).forEach((ref) => {
|
|
7479
8775
|
this.linkReference(ref, document, extraScopes);
|
|
7480
8776
|
});
|
|
7481
|
-
for (const child of
|
|
8777
|
+
for (const child of import_langium10.AstUtils.streamContents(node)) {
|
|
7482
8778
|
this.resolve(child, document, extraScopes);
|
|
7483
8779
|
}
|
|
7484
8780
|
}
|
|
@@ -7522,9 +8818,9 @@ var ZModelLinker = class extends import_langium8.DefaultLinker {
|
|
|
7522
8818
|
};
|
|
7523
8819
|
|
|
7524
8820
|
// src/zmodel-scope.ts
|
|
7525
|
-
var
|
|
7526
|
-
var
|
|
7527
|
-
var ZModelScopeComputation = class extends
|
|
8821
|
+
var import_langium11 = require("langium");
|
|
8822
|
+
var import_ts_pattern5 = require("ts-pattern");
|
|
8823
|
+
var ZModelScopeComputation = class extends import_langium11.DefaultScopeComputation {
|
|
7528
8824
|
static {
|
|
7529
8825
|
__name(this, "ZModelScopeComputation");
|
|
7530
8826
|
}
|
|
@@ -7534,9 +8830,9 @@ var ZModelScopeComputation = class extends import_langium9.DefaultScopeComputati
|
|
|
7534
8830
|
}
|
|
7535
8831
|
async computeExports(document, cancelToken) {
|
|
7536
8832
|
const result = await super.computeExports(document, cancelToken);
|
|
7537
|
-
for (const node of
|
|
8833
|
+
for (const node of import_langium11.AstUtils.streamAllContents(document.parseResult.value)) {
|
|
7538
8834
|
if (cancelToken) {
|
|
7539
|
-
await (0,
|
|
8835
|
+
await (0, import_langium11.interruptAndCheck)(cancelToken);
|
|
7540
8836
|
}
|
|
7541
8837
|
if (isEnumField(node)) {
|
|
7542
8838
|
const desc = this.services.workspace.AstNodeDescriptionProvider.createDescription(node, node.name, document);
|
|
@@ -7557,7 +8853,7 @@ var ZModelScopeComputation = class extends import_langium9.DefaultScopeComputati
|
|
|
7557
8853
|
}
|
|
7558
8854
|
}
|
|
7559
8855
|
};
|
|
7560
|
-
var ZModelScopeProvider = class extends
|
|
8856
|
+
var ZModelScopeProvider = class extends import_langium11.DefaultScopeProvider {
|
|
7561
8857
|
static {
|
|
7562
8858
|
__name(this, "ZModelScopeProvider");
|
|
7563
8859
|
}
|
|
@@ -7566,19 +8862,19 @@ var ZModelScopeProvider = class extends import_langium9.DefaultScopeProvider {
|
|
|
7566
8862
|
super(services), this.services = services;
|
|
7567
8863
|
}
|
|
7568
8864
|
getGlobalScope(referenceType, context) {
|
|
7569
|
-
const model =
|
|
8865
|
+
const model = import_langium11.AstUtils.getContainerOfType(context.container, isModel);
|
|
7570
8866
|
if (!model) {
|
|
7571
|
-
return
|
|
8867
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7572
8868
|
}
|
|
7573
8869
|
const importedUris = model.imports.map(resolveImportUri).filter((url) => !!url);
|
|
7574
8870
|
const importedElements = this.indexManager.allElements(referenceType).filter((des) => (
|
|
7575
8871
|
// allow current document
|
|
7576
|
-
|
|
8872
|
+
import_langium11.UriUtils.equals(des.documentUri, model.$document?.uri) || // allow stdlib
|
|
7577
8873
|
des.documentUri.path.endsWith(STD_LIB_MODULE_NAME) || // allow plugin models
|
|
7578
8874
|
des.documentUri.path.endsWith(PLUGIN_MODULE_NAME) || // allow imported documents
|
|
7579
|
-
importedUris.some((importedUri) =>
|
|
8875
|
+
importedUris.some((importedUri) => import_langium11.UriUtils.equals(des.documentUri, importedUri))
|
|
7580
8876
|
));
|
|
7581
|
-
return new
|
|
8877
|
+
return new import_langium11.StreamScope(importedElements);
|
|
7582
8878
|
}
|
|
7583
8879
|
getScope(context) {
|
|
7584
8880
|
if (isMemberAccessExpr(context.container) && context.container.operand && context.property === "member") {
|
|
@@ -7596,22 +8892,19 @@ var ZModelScopeProvider = class extends import_langium9.DefaultScopeProvider {
|
|
|
7596
8892
|
const referenceType = this.reflection.getReferenceType(context);
|
|
7597
8893
|
const globalScope = this.getGlobalScope(referenceType, context);
|
|
7598
8894
|
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) => {
|
|
8895
|
+
const allowTypeDefScope = isAuthOrAuthMemberAccess(node.operand) || !!import_langium11.AstUtils.getContainerOfType(node, isTypeDef);
|
|
8896
|
+
return (0, import_ts_pattern5.match)(node.operand).when(isReferenceExpr, (operand) => {
|
|
7604
8897
|
const ref = operand.target.ref;
|
|
7605
8898
|
if (isDataField(ref)) {
|
|
7606
8899
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7607
8900
|
}
|
|
7608
|
-
return
|
|
8901
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7609
8902
|
}).when(isMemberAccessExpr, (operand) => {
|
|
7610
8903
|
const ref = operand.member.ref;
|
|
7611
8904
|
if (isDataField(ref) && !ref.type.array) {
|
|
7612
8905
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7613
8906
|
}
|
|
7614
|
-
return
|
|
8907
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7615
8908
|
}).when(isThisExpr, () => {
|
|
7616
8909
|
return this.createScopeForContainingModel(node, globalScope);
|
|
7617
8910
|
}).when(isInvocationExpr, (operand) => {
|
|
@@ -7621,43 +8914,43 @@ var ZModelScopeProvider = class extends import_langium9.DefaultScopeProvider {
|
|
|
7621
8914
|
if (isBeforeInvocation(operand)) {
|
|
7622
8915
|
return this.createScopeForContainingModel(node, globalScope);
|
|
7623
8916
|
}
|
|
7624
|
-
return
|
|
7625
|
-
}).otherwise(() =>
|
|
8917
|
+
return import_langium11.EMPTY_SCOPE;
|
|
8918
|
+
}).otherwise(() => import_langium11.EMPTY_SCOPE);
|
|
7626
8919
|
}
|
|
7627
8920
|
getCollectionPredicateScope(context, collectionPredicate) {
|
|
7628
8921
|
const referenceType = this.reflection.getReferenceType(context);
|
|
7629
8922
|
const globalScope = this.getGlobalScope(referenceType, context);
|
|
7630
8923
|
const collection = collectionPredicate.left;
|
|
7631
|
-
const allowTypeDefScope =
|
|
7632
|
-
return (0,
|
|
8924
|
+
const allowTypeDefScope = isAuthOrAuthMemberAccess(collection);
|
|
8925
|
+
return (0, import_ts_pattern5.match)(collection).when(isReferenceExpr, (expr) => {
|
|
7633
8926
|
const ref = expr.target.ref;
|
|
7634
8927
|
if (isDataField(ref)) {
|
|
7635
8928
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7636
8929
|
}
|
|
7637
|
-
return
|
|
8930
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7638
8931
|
}).when(isMemberAccessExpr, (expr) => {
|
|
7639
8932
|
const ref = expr.member.ref;
|
|
7640
8933
|
if (isDataField(ref)) {
|
|
7641
8934
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7642
8935
|
}
|
|
7643
|
-
return
|
|
8936
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7644
8937
|
}).when(isInvocationExpr, (expr) => {
|
|
7645
8938
|
const returnTypeDecl = expr.function.ref?.returnType.reference?.ref;
|
|
7646
8939
|
if (isDataModel(returnTypeDecl)) {
|
|
7647
8940
|
return this.createScopeForContainer(returnTypeDecl, globalScope, allowTypeDefScope);
|
|
7648
8941
|
} else {
|
|
7649
|
-
return
|
|
8942
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7650
8943
|
}
|
|
7651
8944
|
}).when(isAuthInvocation, (expr) => {
|
|
7652
8945
|
return this.createScopeForAuth(expr, globalScope);
|
|
7653
|
-
}).otherwise(() =>
|
|
8946
|
+
}).otherwise(() => import_langium11.EMPTY_SCOPE);
|
|
7654
8947
|
}
|
|
7655
8948
|
createScopeForContainingModel(node, globalScope) {
|
|
7656
|
-
const model =
|
|
8949
|
+
const model = import_langium11.AstUtils.getContainerOfType(node, isDataModel);
|
|
7657
8950
|
if (model) {
|
|
7658
8951
|
return this.createScopeForContainer(model, globalScope);
|
|
7659
8952
|
} else {
|
|
7660
|
-
return
|
|
8953
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7661
8954
|
}
|
|
7662
8955
|
}
|
|
7663
8956
|
createScopeForContainer(node, globalScope, includeTypeDefScope = false) {
|
|
@@ -7666,16 +8959,16 @@ var ZModelScopeProvider = class extends import_langium9.DefaultScopeProvider {
|
|
|
7666
8959
|
} else if (includeTypeDefScope && isTypeDef(node)) {
|
|
7667
8960
|
return this.createScopeForNodes(node.fields, globalScope);
|
|
7668
8961
|
} else {
|
|
7669
|
-
return
|
|
8962
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7670
8963
|
}
|
|
7671
8964
|
}
|
|
7672
8965
|
createScopeForAuth(node, globalScope) {
|
|
7673
|
-
const decls = getAllLoadedAndReachableDataModelsAndTypeDefs(this.services.shared.workspace.LangiumDocuments,
|
|
8966
|
+
const decls = getAllLoadedAndReachableDataModelsAndTypeDefs(this.services.shared.workspace.LangiumDocuments, import_langium11.AstUtils.getContainerOfType(node, isDataModel));
|
|
7674
8967
|
const authDecl = getAuthDecl(decls);
|
|
7675
8968
|
if (authDecl) {
|
|
7676
8969
|
return this.createScopeForContainer(authDecl, globalScope, true);
|
|
7677
8970
|
} else {
|
|
7678
|
-
return
|
|
8971
|
+
return import_langium11.EMPTY_SCOPE;
|
|
7679
8972
|
}
|
|
7680
8973
|
}
|
|
7681
8974
|
};
|
|
@@ -7691,13 +8984,97 @@ function getCollectionPredicateContext(node) {
|
|
|
7691
8984
|
}
|
|
7692
8985
|
__name(getCollectionPredicateContext, "getCollectionPredicateContext");
|
|
7693
8986
|
|
|
8987
|
+
// src/zmodel-semantic.ts
|
|
8988
|
+
var import_lsp4 = require("langium/lsp");
|
|
8989
|
+
var import_vscode_languageserver3 = require("vscode-languageserver");
|
|
8990
|
+
var ZModelSemanticTokenProvider = class extends import_lsp4.AbstractSemanticTokenProvider {
|
|
8991
|
+
static {
|
|
8992
|
+
__name(this, "ZModelSemanticTokenProvider");
|
|
8993
|
+
}
|
|
8994
|
+
highlightElement(node, acceptor) {
|
|
8995
|
+
if (isDataModel(node)) {
|
|
8996
|
+
acceptor({
|
|
8997
|
+
node,
|
|
8998
|
+
property: "name",
|
|
8999
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.type
|
|
9000
|
+
});
|
|
9001
|
+
acceptor({
|
|
9002
|
+
node,
|
|
9003
|
+
property: "mixins",
|
|
9004
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.type
|
|
9005
|
+
});
|
|
9006
|
+
acceptor({
|
|
9007
|
+
node,
|
|
9008
|
+
property: "baseModel",
|
|
9009
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.type
|
|
9010
|
+
});
|
|
9011
|
+
} else if (isDataSource(node) || isGeneratorDecl(node) || isPlugin(node) || isEnum(node) || isTypeDef(node)) {
|
|
9012
|
+
acceptor({
|
|
9013
|
+
node,
|
|
9014
|
+
property: "name",
|
|
9015
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.type
|
|
9016
|
+
});
|
|
9017
|
+
} else if (isDataField(node) || isConfigField(node) || isAttributeArg(node) || isPluginField(node) || isEnumField(node)) {
|
|
9018
|
+
acceptor({
|
|
9019
|
+
node,
|
|
9020
|
+
property: "name",
|
|
9021
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.variable
|
|
9022
|
+
});
|
|
9023
|
+
} else if (isDataFieldType(node)) {
|
|
9024
|
+
if (node.type) {
|
|
9025
|
+
acceptor({
|
|
9026
|
+
node,
|
|
9027
|
+
property: "type",
|
|
9028
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.type
|
|
9029
|
+
});
|
|
9030
|
+
} else {
|
|
9031
|
+
acceptor({
|
|
9032
|
+
node,
|
|
9033
|
+
property: "reference",
|
|
9034
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.macro
|
|
9035
|
+
});
|
|
9036
|
+
}
|
|
9037
|
+
} else if (isDataModelAttribute(node) || isDataFieldAttribute(node) || isInternalAttribute(node)) {
|
|
9038
|
+
acceptor({
|
|
9039
|
+
node,
|
|
9040
|
+
property: "decl",
|
|
9041
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.function
|
|
9042
|
+
});
|
|
9043
|
+
} else if (isInvocationExpr(node)) {
|
|
9044
|
+
acceptor({
|
|
9045
|
+
node,
|
|
9046
|
+
property: "function",
|
|
9047
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.function
|
|
9048
|
+
});
|
|
9049
|
+
} else if (isFunctionDecl(node) || isAttribute(node)) {
|
|
9050
|
+
acceptor({
|
|
9051
|
+
node,
|
|
9052
|
+
property: "name",
|
|
9053
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.function
|
|
9054
|
+
});
|
|
9055
|
+
} else if (isReferenceExpr(node)) {
|
|
9056
|
+
acceptor({
|
|
9057
|
+
node,
|
|
9058
|
+
property: "target",
|
|
9059
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.variable
|
|
9060
|
+
});
|
|
9061
|
+
} else if (isMemberAccessExpr(node)) {
|
|
9062
|
+
acceptor({
|
|
9063
|
+
node,
|
|
9064
|
+
property: "member",
|
|
9065
|
+
type: import_vscode_languageserver3.SemanticTokenTypes.property
|
|
9066
|
+
});
|
|
9067
|
+
}
|
|
9068
|
+
}
|
|
9069
|
+
};
|
|
9070
|
+
|
|
7694
9071
|
// src/zmodel-workspace-manager.ts
|
|
7695
|
-
var
|
|
7696
|
-
var
|
|
7697
|
-
var
|
|
7698
|
-
var
|
|
7699
|
-
var
|
|
7700
|
-
var ZModelWorkspaceManager = class extends
|
|
9072
|
+
var import_langium12 = require("langium");
|
|
9073
|
+
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
9074
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
9075
|
+
var import_node_url2 = require("url");
|
|
9076
|
+
var import_meta2 = {};
|
|
9077
|
+
var ZModelWorkspaceManager = class extends import_langium12.DefaultWorkspaceManager {
|
|
7701
9078
|
static {
|
|
7702
9079
|
__name(this, "ZModelWorkspaceManager");
|
|
7703
9080
|
}
|
|
@@ -7718,9 +9095,9 @@ var ZModelWorkspaceManager = class extends import_langium10.DefaultWorkspaceMana
|
|
|
7718
9095
|
folderPath
|
|
7719
9096
|
]
|
|
7720
9097
|
});
|
|
7721
|
-
const languagePackageDir =
|
|
7722
|
-
const candidateStdlibPath =
|
|
7723
|
-
if (
|
|
9098
|
+
const languagePackageDir = import_node_path2.default.dirname(languagePackagePath);
|
|
9099
|
+
const candidateStdlibPath = import_node_path2.default.join(languagePackageDir, "res", STD_LIB_MODULE_NAME);
|
|
9100
|
+
if (import_node_fs3.default.existsSync(candidateStdlibPath)) {
|
|
7724
9101
|
installedStdlibPath = candidateStdlibPath;
|
|
7725
9102
|
console.log(`Found installed zenstack package stdlib at: ${installedStdlibPath}`);
|
|
7726
9103
|
break;
|
|
@@ -7732,73 +9109,12 @@ var ZModelWorkspaceManager = class extends import_langium10.DefaultWorkspaceMana
|
|
|
7732
9109
|
if (installedStdlibPath) {
|
|
7733
9110
|
stdLibPath = installedStdlibPath;
|
|
7734
9111
|
} else {
|
|
7735
|
-
const _dirname = typeof __dirname !== "undefined" ? __dirname :
|
|
7736
|
-
stdLibPath =
|
|
9112
|
+
const _dirname = typeof __dirname !== "undefined" ? __dirname : import_node_path2.default.dirname((0, import_node_url2.fileURLToPath)(import_meta2.url));
|
|
9113
|
+
stdLibPath = import_node_path2.default.join(_dirname, "../res", STD_LIB_MODULE_NAME);
|
|
7737
9114
|
console.log(`Using bundled stdlib in extension:`, stdLibPath);
|
|
7738
9115
|
}
|
|
7739
|
-
const stdlib = await this.documentFactory.fromUri(
|
|
9116
|
+
const stdlib = await this.documentFactory.fromUri(import_langium12.URI.file(stdLibPath));
|
|
7740
9117
|
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
9118
|
}
|
|
7803
9119
|
};
|
|
7804
9120
|
|
|
@@ -7811,6 +9127,16 @@ var ZModelLanguageModule = {
|
|
|
7811
9127
|
},
|
|
7812
9128
|
validation: {
|
|
7813
9129
|
ZModelValidator: /* @__PURE__ */ __name((services) => new ZModelValidator(services), "ZModelValidator")
|
|
9130
|
+
},
|
|
9131
|
+
lsp: {
|
|
9132
|
+
Formatter: /* @__PURE__ */ __name((services) => new ZModelFormatter(services), "Formatter"),
|
|
9133
|
+
DefinitionProvider: /* @__PURE__ */ __name((services) => new ZModelDefinitionProvider(services), "DefinitionProvider"),
|
|
9134
|
+
CompletionProvider: /* @__PURE__ */ __name((services) => new ZModelCompletionProvider(services), "CompletionProvider"),
|
|
9135
|
+
SemanticTokenProvider: /* @__PURE__ */ __name((services) => new ZModelSemanticTokenProvider(services), "SemanticTokenProvider")
|
|
9136
|
+
},
|
|
9137
|
+
documentation: {
|
|
9138
|
+
CommentProvider: /* @__PURE__ */ __name((services) => new ZModelCommentProvider(services), "CommentProvider"),
|
|
9139
|
+
DocumentationProvider: /* @__PURE__ */ __name((services) => new ZModelDocumentationProvider(services), "DocumentationProvider")
|
|
7814
9140
|
}
|
|
7815
9141
|
};
|
|
7816
9142
|
var ZModelSharedModule = {
|
|
@@ -7819,9 +9145,9 @@ var ZModelSharedModule = {
|
|
|
7819
9145
|
WorkspaceManager: /* @__PURE__ */ __name((services) => new ZModelWorkspaceManager(services), "WorkspaceManager")
|
|
7820
9146
|
}
|
|
7821
9147
|
};
|
|
7822
|
-
function createZModelLanguageServices(context) {
|
|
7823
|
-
const shared = (0,
|
|
7824
|
-
const ZModelLanguage = (0,
|
|
9148
|
+
function createZModelLanguageServices(context, logToConsole = false) {
|
|
9149
|
+
const shared = (0, import_langium13.inject)((0, import_lsp5.createDefaultSharedModule)(context), ZModelGeneratedSharedModule, ZModelSharedModule);
|
|
9150
|
+
const ZModelLanguage = (0, import_langium13.inject)((0, import_lsp5.createDefaultModule)({
|
|
7825
9151
|
shared
|
|
7826
9152
|
}), ZModelGeneratedModule, ZModelLanguageModule);
|
|
7827
9153
|
shared.ServiceRegistry.register(ZModelLanguage);
|
|
@@ -7829,31 +9155,48 @@ function createZModelLanguageServices(context) {
|
|
|
7829
9155
|
if (!context.connection) {
|
|
7830
9156
|
shared.workspace.ConfigurationProvider.initialized({});
|
|
7831
9157
|
}
|
|
9158
|
+
shared.workspace.DocumentBuilder.onBuildPhase(import_langium13.DocumentState.Parsed, async (documents) => {
|
|
9159
|
+
for (const doc of documents) {
|
|
9160
|
+
if (doc.parseResult.lexerErrors.length > 0 || doc.parseResult.parserErrors.length > 0) {
|
|
9161
|
+
continue;
|
|
9162
|
+
}
|
|
9163
|
+
if (doc.uri.scheme !== "file") {
|
|
9164
|
+
continue;
|
|
9165
|
+
}
|
|
9166
|
+
const schemaPath = (0, import_node_url3.fileURLToPath)(doc.uri.toString());
|
|
9167
|
+
const pluginSchemas = getPluginDocuments(doc.parseResult.value, schemaPath);
|
|
9168
|
+
for (const plugin of pluginSchemas) {
|
|
9169
|
+
const pluginDocUri = import_langium13.URI.file(import_node_path3.default.resolve(plugin));
|
|
9170
|
+
let pluginDoc = shared.workspace.LangiumDocuments.getDocument(pluginDocUri);
|
|
9171
|
+
if (!pluginDoc) {
|
|
9172
|
+
pluginDoc = await shared.workspace.LangiumDocuments.getOrCreateDocument(pluginDocUri);
|
|
9173
|
+
if (pluginDoc) {
|
|
9174
|
+
shared.workspace.IndexManager.updateContent(pluginDoc);
|
|
9175
|
+
if (logToConsole) {
|
|
9176
|
+
console.log(`Loaded plugin model: ${plugin}`);
|
|
9177
|
+
}
|
|
9178
|
+
}
|
|
9179
|
+
}
|
|
9180
|
+
}
|
|
9181
|
+
}
|
|
9182
|
+
});
|
|
7832
9183
|
return {
|
|
7833
9184
|
shared,
|
|
7834
9185
|
ZModelLanguage
|
|
7835
9186
|
};
|
|
7836
9187
|
}
|
|
7837
9188
|
__name(createZModelLanguageServices, "createZModelLanguageServices");
|
|
7838
|
-
|
|
7839
|
-
|
|
7840
|
-
var import_meta2 = {};
|
|
7841
|
-
function createZModelServices() {
|
|
7842
|
-
return createZModelLanguageServices(import_node.NodeFileSystem);
|
|
9189
|
+
function createZModelServices(logToConsole = false) {
|
|
9190
|
+
return createZModelLanguageServices(import_node.NodeFileSystem, logToConsole);
|
|
7843
9191
|
}
|
|
7844
9192
|
__name(createZModelServices, "createZModelServices");
|
|
7845
|
-
|
|
7846
|
-
|
|
7847
|
-
|
|
7848
|
-
}
|
|
7849
|
-
constructor(message) {
|
|
7850
|
-
super(message);
|
|
7851
|
-
}
|
|
7852
|
-
};
|
|
9193
|
+
|
|
9194
|
+
// src/document.ts
|
|
9195
|
+
var import_meta3 = {};
|
|
7853
9196
|
async function loadDocument(fileName, additionalModelFiles = []) {
|
|
7854
|
-
const { ZModelLanguage: services } = createZModelServices();
|
|
9197
|
+
const { ZModelLanguage: services } = createZModelServices(false);
|
|
7855
9198
|
const extensions = services.LanguageMetaData.fileExtensions;
|
|
7856
|
-
if (!extensions.includes(
|
|
9199
|
+
if (!extensions.includes(import_node_path4.default.extname(fileName))) {
|
|
7857
9200
|
return {
|
|
7858
9201
|
success: false,
|
|
7859
9202
|
errors: [
|
|
@@ -7862,7 +9205,7 @@ async function loadDocument(fileName, additionalModelFiles = []) {
|
|
|
7862
9205
|
warnings: []
|
|
7863
9206
|
};
|
|
7864
9207
|
}
|
|
7865
|
-
if (!
|
|
9208
|
+
if (!import_node_fs4.default.existsSync(fileName)) {
|
|
7866
9209
|
return {
|
|
7867
9210
|
success: false,
|
|
7868
9211
|
errors: [
|
|
@@ -7871,19 +9214,19 @@ async function loadDocument(fileName, additionalModelFiles = []) {
|
|
|
7871
9214
|
warnings: []
|
|
7872
9215
|
};
|
|
7873
9216
|
}
|
|
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)))));
|
|
9217
|
+
const _dirname = typeof __dirname !== "undefined" ? __dirname : import_node_path4.default.dirname((0, import_node_url4.fileURLToPath)(import_meta3.url));
|
|
9218
|
+
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
9219
|
const langiumDocuments = services.shared.workspace.LangiumDocuments;
|
|
7878
|
-
const document = await langiumDocuments.getOrCreateDocument(
|
|
9220
|
+
const document = await langiumDocuments.getOrCreateDocument(import_langium14.URI.file(import_node_path4.default.resolve(fileName)));
|
|
7879
9221
|
const importedURIs = await loadImports(document, langiumDocuments);
|
|
7880
9222
|
const importedDocuments = [];
|
|
7881
9223
|
for (const uri of importedURIs) {
|
|
7882
9224
|
importedDocuments.push(await langiumDocuments.getOrCreateDocument(uri));
|
|
7883
9225
|
}
|
|
9226
|
+
const additionalDocs = await Promise.all(additionalModelFiles.map((file) => services.shared.workspace.LangiumDocuments.getOrCreateDocument(import_langium14.URI.file(import_node_path4.default.resolve(file)))));
|
|
7884
9227
|
await services.shared.workspace.DocumentBuilder.build([
|
|
7885
9228
|
stdLib,
|
|
7886
|
-
...
|
|
9229
|
+
...additionalDocs,
|
|
7887
9230
|
document,
|
|
7888
9231
|
...importedDocuments
|
|
7889
9232
|
], {
|
|
@@ -7901,7 +9244,7 @@ async function loadDocument(fileName, additionalModelFiles = []) {
|
|
|
7901
9244
|
const warnings = [];
|
|
7902
9245
|
if (diagnostics.length > 0) {
|
|
7903
9246
|
for (const { doc, diag } of diagnostics) {
|
|
7904
|
-
const message = `${
|
|
9247
|
+
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
9248
|
if (diag.severity === 1) {
|
|
7906
9249
|
errors.push(message);
|
|
7907
9250
|
} else {
|
|
@@ -7950,7 +9293,7 @@ async function loadImports(document, documents, uris = /* @__PURE__ */ new Set()
|
|
|
7950
9293
|
}
|
|
7951
9294
|
}
|
|
7952
9295
|
}
|
|
7953
|
-
return Array.from(uris).filter((x) => uriString != x).map((e) =>
|
|
9296
|
+
return Array.from(uris).filter((x) => uriString != x).map((e) => import_langium14.URI.parse(e));
|
|
7954
9297
|
}
|
|
7955
9298
|
__name(loadImports, "loadImports");
|
|
7956
9299
|
function mergeImportsDeclarations(documents, model) {
|
|
@@ -7967,13 +9310,13 @@ function linkContentToContainer(node) {
|
|
|
7967
9310
|
if (!name.startsWith("$")) {
|
|
7968
9311
|
if (Array.isArray(value)) {
|
|
7969
9312
|
value.forEach((item, index) => {
|
|
7970
|
-
if ((0,
|
|
9313
|
+
if ((0, import_langium14.isAstNode)(item)) {
|
|
7971
9314
|
item.$container = node;
|
|
7972
9315
|
item.$containerProperty = name;
|
|
7973
9316
|
item.$containerIndex = index;
|
|
7974
9317
|
}
|
|
7975
9318
|
});
|
|
7976
|
-
} else if ((0,
|
|
9319
|
+
} else if ((0, import_langium14.isAstNode)(value)) {
|
|
7977
9320
|
value.$container = node;
|
|
7978
9321
|
value.$containerProperty = name;
|
|
7979
9322
|
}
|
|
@@ -7999,14 +9342,34 @@ function validationAfterImportMerge(model) {
|
|
|
7999
9342
|
return errors;
|
|
8000
9343
|
}
|
|
8001
9344
|
__name(validationAfterImportMerge, "validationAfterImportMerge");
|
|
9345
|
+
async function formatDocument(content) {
|
|
9346
|
+
const services = createZModelServices().ZModelLanguage;
|
|
9347
|
+
const langiumDocuments = services.shared.workspace.LangiumDocuments;
|
|
9348
|
+
const document = langiumDocuments.createDocument(import_langium14.URI.parse("memory://schema.zmodel"), content);
|
|
9349
|
+
const formatter = services.lsp.Formatter;
|
|
9350
|
+
const identifier = {
|
|
9351
|
+
uri: document.uri.toString()
|
|
9352
|
+
};
|
|
9353
|
+
const options = formatter.getFormatOptions() ?? {
|
|
9354
|
+
insertSpaces: true,
|
|
9355
|
+
tabSize: 4
|
|
9356
|
+
};
|
|
9357
|
+
const edits = await formatter.formatDocument(document, {
|
|
9358
|
+
options,
|
|
9359
|
+
textDocument: identifier
|
|
9360
|
+
});
|
|
9361
|
+
return import_langium14.TextDocument.applyEdits(document.textDocument, edits);
|
|
9362
|
+
}
|
|
9363
|
+
__name(formatDocument, "formatDocument");
|
|
8002
9364
|
// Annotate the CommonJS export names for ESM import in node:
|
|
8003
9365
|
0 && (module.exports = {
|
|
8004
|
-
|
|
9366
|
+
ZModelCodeGenerator,
|
|
8005
9367
|
ZModelLanguageMetaData,
|
|
8006
9368
|
ZModelLanguageModule,
|
|
8007
9369
|
ZModelSharedModule,
|
|
8008
9370
|
createZModelLanguageServices,
|
|
8009
9371
|
createZModelServices,
|
|
9372
|
+
formatDocument,
|
|
8010
9373
|
loadDocument
|
|
8011
9374
|
});
|
|
8012
9375
|
//# sourceMappingURL=index.cjs.map
|