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