@zenstackhq/language 3.0.0-beta.6 → 3.0.0-beta.8
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 +152 -114
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +105 -67
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +18 -21
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +2 -3
- package/dist/utils.d.ts +2 -3
- package/dist/utils.js +17 -19
- package/dist/utils.js.map +1 -1
- package/package.json +5 -5
- package/res/stdlib.zmodel +4 -4
package/dist/index.cjs
CHANGED
|
@@ -40,7 +40,7 @@ __export(src_exports, {
|
|
|
40
40
|
loadDocument: () => loadDocument
|
|
41
41
|
});
|
|
42
42
|
module.exports = __toCommonJS(src_exports);
|
|
43
|
-
var
|
|
43
|
+
var import_langium12 = require("langium");
|
|
44
44
|
var import_node = require("langium/node");
|
|
45
45
|
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
46
46
|
var import_node_path2 = __toESM(require("path"), 1);
|
|
@@ -1074,7 +1074,7 @@ var ExpressionContext = /* @__PURE__ */ function(ExpressionContext2) {
|
|
|
1074
1074
|
}({});
|
|
1075
1075
|
|
|
1076
1076
|
// src/module.ts
|
|
1077
|
-
var
|
|
1077
|
+
var import_langium11 = require("langium");
|
|
1078
1078
|
var import_lsp = require("langium/lsp");
|
|
1079
1079
|
|
|
1080
1080
|
// src/generated/grammar.ts
|
|
@@ -5141,7 +5141,6 @@ var import_langium3 = require("langium");
|
|
|
5141
5141
|
var import_pluralize = __toESM(require("pluralize"), 1);
|
|
5142
5142
|
|
|
5143
5143
|
// src/utils.ts
|
|
5144
|
-
var import_common_helpers = require("@zenstackhq/common-helpers");
|
|
5145
5144
|
var import_langium2 = require("langium");
|
|
5146
5145
|
var import_node_fs = __toESM(require("fs"), 1);
|
|
5147
5146
|
var import_path = __toESM(require("path"), 1);
|
|
@@ -5224,10 +5223,6 @@ function isRelationshipField(field) {
|
|
|
5224
5223
|
return isDataModel(field.type.reference?.ref);
|
|
5225
5224
|
}
|
|
5226
5225
|
__name(isRelationshipField, "isRelationshipField");
|
|
5227
|
-
function isFutureExpr(node) {
|
|
5228
|
-
return isInvocationExpr(node) && node.function.ref?.name === "future" && isFromStdlib(node.function.ref);
|
|
5229
|
-
}
|
|
5230
|
-
__name(isFutureExpr, "isFutureExpr");
|
|
5231
5226
|
function isDelegateModel(node) {
|
|
5232
5227
|
return isDataModel(node) && hasAttribute(node, "@@delegate");
|
|
5233
5228
|
}
|
|
@@ -5246,7 +5241,7 @@ function getRecursiveBases(decl, includeDelegate = true, seen = /* @__PURE__ */
|
|
|
5246
5241
|
}
|
|
5247
5242
|
seen.add(decl);
|
|
5248
5243
|
decl.mixins.forEach((mixin) => {
|
|
5249
|
-
const baseDecl = mixin
|
|
5244
|
+
const baseDecl = decl.$container.declarations.find((d) => isTypeDef(d) && d.name === mixin.$refText);
|
|
5250
5245
|
if (baseDecl) {
|
|
5251
5246
|
if (!includeDelegate && isDelegateModel(baseDecl)) {
|
|
5252
5247
|
return;
|
|
@@ -5463,10 +5458,10 @@ function getAuthDecl(decls) {
|
|
|
5463
5458
|
return authModel;
|
|
5464
5459
|
}
|
|
5465
5460
|
__name(getAuthDecl, "getAuthDecl");
|
|
5466
|
-
function
|
|
5467
|
-
return isInvocationExpr(node) && node.function.ref?.name === "
|
|
5461
|
+
function isBeforeInvocation(node) {
|
|
5462
|
+
return isInvocationExpr(node) && node.function.ref?.name === "before" && isFromStdlib(node.function.ref);
|
|
5468
5463
|
}
|
|
5469
|
-
__name(
|
|
5464
|
+
__name(isBeforeInvocation, "isBeforeInvocation");
|
|
5470
5465
|
function isCollectionPredicate(node) {
|
|
5471
5466
|
return isBinaryExpr(node) && [
|
|
5472
5467
|
"?",
|
|
@@ -5521,12 +5516,14 @@ function getAllFields(decl, includeIgnored = false, seen = /* @__PURE__ */ new S
|
|
|
5521
5516
|
seen.add(decl);
|
|
5522
5517
|
const fields = [];
|
|
5523
5518
|
for (const mixin of decl.mixins) {
|
|
5524
|
-
|
|
5525
|
-
|
|
5519
|
+
if (mixin.ref) {
|
|
5520
|
+
fields.push(...getAllFields(mixin.ref, includeIgnored, seen));
|
|
5521
|
+
}
|
|
5526
5522
|
}
|
|
5527
5523
|
if (isDataModel(decl) && decl.baseModel) {
|
|
5528
|
-
|
|
5529
|
-
|
|
5524
|
+
if (decl.baseModel.ref) {
|
|
5525
|
+
fields.push(...getAllFields(decl.baseModel.ref, includeIgnored, seen));
|
|
5526
|
+
}
|
|
5530
5527
|
}
|
|
5531
5528
|
fields.push(...decl.fields.filter((f) => includeIgnored || !hasAttribute(f, "@ignore")));
|
|
5532
5529
|
return fields;
|
|
@@ -5539,12 +5536,14 @@ function getAllAttributes(decl, seen = /* @__PURE__ */ new Set()) {
|
|
|
5539
5536
|
seen.add(decl);
|
|
5540
5537
|
const attributes = [];
|
|
5541
5538
|
for (const mixin of decl.mixins) {
|
|
5542
|
-
|
|
5543
|
-
|
|
5539
|
+
if (mixin.ref) {
|
|
5540
|
+
attributes.push(...getAllAttributes(mixin.ref, seen));
|
|
5541
|
+
}
|
|
5544
5542
|
}
|
|
5545
5543
|
if (isDataModel(decl) && decl.baseModel) {
|
|
5546
|
-
|
|
5547
|
-
|
|
5544
|
+
if (decl.baseModel.ref) {
|
|
5545
|
+
attributes.push(...getAllAttributes(decl.baseModel.ref, seen));
|
|
5546
|
+
}
|
|
5548
5547
|
}
|
|
5549
5548
|
attributes.push(...decl.attributes);
|
|
5550
5549
|
return attributes;
|
|
@@ -5694,12 +5693,21 @@ var AttributeApplicationValidator = class {
|
|
|
5694
5693
|
"create",
|
|
5695
5694
|
"read",
|
|
5696
5695
|
"update",
|
|
5696
|
+
"post-update",
|
|
5697
5697
|
"delete",
|
|
5698
5698
|
"all"
|
|
5699
5699
|
], attr, accept);
|
|
5700
5700
|
if ((kind === "create" || kind === "all") && attr.args[1]?.value) {
|
|
5701
5701
|
this.rejectNonOwnedRelationInExpression(attr.args[1].value, accept);
|
|
5702
5702
|
}
|
|
5703
|
+
if (kind !== "post-update" && attr.args[1]?.value) {
|
|
5704
|
+
const beforeCall = import_langium3.AstUtils.streamAst(attr.args[1]?.value).find(isBeforeInvocation);
|
|
5705
|
+
if (beforeCall) {
|
|
5706
|
+
accept("error", `"before()" is only allowed in "post-update" policy rules`, {
|
|
5707
|
+
node: beforeCall
|
|
5708
|
+
});
|
|
5709
|
+
}
|
|
5710
|
+
}
|
|
5703
5711
|
}
|
|
5704
5712
|
rejectNonOwnedRelationInExpression(expr, accept) {
|
|
5705
5713
|
const contextModel = import_langium3.AstUtils.getContainerOfType(expr, isDataModel);
|
|
@@ -5754,8 +5762,8 @@ var AttributeApplicationValidator = class {
|
|
|
5754
5762
|
"all"
|
|
5755
5763
|
], attr, accept);
|
|
5756
5764
|
const expr = attr.args[1]?.value;
|
|
5757
|
-
if (expr && import_langium3.AstUtils.streamAst(expr).some((node) =>
|
|
5758
|
-
accept("error", `"
|
|
5765
|
+
if (expr && import_langium3.AstUtils.streamAst(expr).some((node) => isBeforeInvocation(node))) {
|
|
5766
|
+
accept("error", `"before()" is not allowed in field-level policy rules`, {
|
|
5759
5767
|
node: expr
|
|
5760
5768
|
});
|
|
5761
5769
|
}
|
|
@@ -5993,7 +6001,7 @@ var AttributeValidator = class {
|
|
|
5993
6001
|
};
|
|
5994
6002
|
|
|
5995
6003
|
// src/validators/datamodel-validator.ts
|
|
5996
|
-
var
|
|
6004
|
+
var import_common_helpers = require("@zenstackhq/common-helpers");
|
|
5997
6005
|
var import_langium4 = require("langium");
|
|
5998
6006
|
|
|
5999
6007
|
// src/validators/common.ts
|
|
@@ -6364,7 +6372,7 @@ var DataModelValidator = class {
|
|
|
6364
6372
|
if (!model.baseModel) {
|
|
6365
6373
|
return;
|
|
6366
6374
|
}
|
|
6367
|
-
(0,
|
|
6375
|
+
(0, import_common_helpers.invariant)(model.baseModel.ref, "baseModel must be resolved");
|
|
6368
6376
|
if (!isDelegateModel(model.baseModel.ref)) {
|
|
6369
6377
|
accept("error", `Model ${model.baseModel.$refText} cannot be extended because it's not a delegate model`, {
|
|
6370
6378
|
node: model,
|
|
@@ -6386,7 +6394,7 @@ var DataModelValidator = class {
|
|
|
6386
6394
|
}
|
|
6387
6395
|
seen.push(current);
|
|
6388
6396
|
if (current.baseModel) {
|
|
6389
|
-
(0,
|
|
6397
|
+
(0, import_common_helpers.invariant)(current.baseModel.ref, "baseModel must be resolved");
|
|
6390
6398
|
todo.push(current.baseModel.ref);
|
|
6391
6399
|
}
|
|
6392
6400
|
}
|
|
@@ -6516,11 +6524,21 @@ var ExpressionValidator = class {
|
|
|
6516
6524
|
}
|
|
6517
6525
|
}
|
|
6518
6526
|
switch (expr.$type) {
|
|
6527
|
+
case "MemberAccessExpr":
|
|
6528
|
+
this.validateMemberAccessExpr(expr, accept);
|
|
6529
|
+
break;
|
|
6519
6530
|
case "BinaryExpr":
|
|
6520
6531
|
this.validateBinaryExpr(expr, accept);
|
|
6521
6532
|
break;
|
|
6522
6533
|
}
|
|
6523
6534
|
}
|
|
6535
|
+
validateMemberAccessExpr(expr, accept) {
|
|
6536
|
+
if (isBeforeInvocation(expr.operand) && isDataModel(expr.$resolvedType?.decl)) {
|
|
6537
|
+
accept("error", "relation fields cannot be accessed from `before()`", {
|
|
6538
|
+
node: expr
|
|
6539
|
+
});
|
|
6540
|
+
}
|
|
6541
|
+
}
|
|
6524
6542
|
validateBinaryExpr(expr, accept) {
|
|
6525
6543
|
switch (expr.operator) {
|
|
6526
6544
|
case "in": {
|
|
@@ -7008,51 +7026,68 @@ var ZModelValidator = class {
|
|
|
7008
7026
|
constructor(services) {
|
|
7009
7027
|
this.services = services;
|
|
7010
7028
|
}
|
|
7011
|
-
shouldCheck(node) {
|
|
7012
|
-
let doc;
|
|
7013
|
-
let currNode = node;
|
|
7014
|
-
while (currNode) {
|
|
7015
|
-
if (currNode.$document) {
|
|
7016
|
-
doc = currNode.$document;
|
|
7017
|
-
break;
|
|
7018
|
-
}
|
|
7019
|
-
currNode = currNode.$container;
|
|
7020
|
-
}
|
|
7021
|
-
return doc?.parseResult.lexerErrors.length === 0 && doc?.parseResult.parserErrors.length === 0;
|
|
7022
|
-
}
|
|
7023
7029
|
checkModel(node, accept) {
|
|
7024
|
-
|
|
7030
|
+
new SchemaValidator(this.services.shared.workspace.LangiumDocuments).validate(node, accept);
|
|
7025
7031
|
}
|
|
7026
7032
|
checkDataSource(node, accept) {
|
|
7027
|
-
|
|
7033
|
+
new DataSourceValidator().validate(node, accept);
|
|
7028
7034
|
}
|
|
7029
7035
|
checkDataModel(node, accept) {
|
|
7030
|
-
|
|
7036
|
+
new DataModelValidator().validate(node, accept);
|
|
7031
7037
|
}
|
|
7032
7038
|
checkTypeDef(node, accept) {
|
|
7033
|
-
|
|
7039
|
+
new TypeDefValidator().validate(node, accept);
|
|
7034
7040
|
}
|
|
7035
7041
|
checkEnum(node, accept) {
|
|
7036
|
-
|
|
7042
|
+
new EnumValidator().validate(node, accept);
|
|
7037
7043
|
}
|
|
7038
7044
|
checkAttribute(node, accept) {
|
|
7039
|
-
|
|
7045
|
+
new AttributeValidator().validate(node, accept);
|
|
7040
7046
|
}
|
|
7041
7047
|
checkExpression(node, accept) {
|
|
7042
|
-
|
|
7048
|
+
new ExpressionValidator().validate(node, accept);
|
|
7043
7049
|
}
|
|
7044
7050
|
checkFunctionInvocation(node, accept) {
|
|
7045
|
-
|
|
7051
|
+
new FunctionInvocationValidator().validate(node, accept);
|
|
7046
7052
|
}
|
|
7047
7053
|
checkFunctionDecl(node, accept) {
|
|
7048
|
-
|
|
7054
|
+
new FunctionDeclValidator().validate(node, accept);
|
|
7049
7055
|
}
|
|
7050
7056
|
};
|
|
7051
7057
|
|
|
7052
|
-
// src/zmodel-
|
|
7058
|
+
// src/zmodel-document-builder.ts
|
|
7053
7059
|
var import_langium7 = require("langium");
|
|
7060
|
+
var ZModelDocumentBuilder = class extends import_langium7.DefaultDocumentBuilder {
|
|
7061
|
+
static {
|
|
7062
|
+
__name(this, "ZModelDocumentBuilder");
|
|
7063
|
+
}
|
|
7064
|
+
constructor(services) {
|
|
7065
|
+
super(services);
|
|
7066
|
+
let validationOptions = this.updateBuildOptions.validation;
|
|
7067
|
+
const stopFlags = {
|
|
7068
|
+
stopAfterLinkingErrors: true,
|
|
7069
|
+
stopAfterLexingErrors: true,
|
|
7070
|
+
stopAfterParsingErrors: true
|
|
7071
|
+
};
|
|
7072
|
+
if (validationOptions === true) {
|
|
7073
|
+
validationOptions = stopFlags;
|
|
7074
|
+
} else if (typeof validationOptions === "object") {
|
|
7075
|
+
validationOptions = {
|
|
7076
|
+
...validationOptions,
|
|
7077
|
+
...stopFlags
|
|
7078
|
+
};
|
|
7079
|
+
}
|
|
7080
|
+
this.updateBuildOptions = {
|
|
7081
|
+
...this.updateBuildOptions,
|
|
7082
|
+
validation: validationOptions
|
|
7083
|
+
};
|
|
7084
|
+
}
|
|
7085
|
+
};
|
|
7086
|
+
|
|
7087
|
+
// src/zmodel-linker.ts
|
|
7088
|
+
var import_langium8 = require("langium");
|
|
7054
7089
|
var import_ts_pattern2 = require("ts-pattern");
|
|
7055
|
-
var ZModelLinker = class extends
|
|
7090
|
+
var ZModelLinker = class extends import_langium8.DefaultLinker {
|
|
7056
7091
|
static {
|
|
7057
7092
|
__name(this, "ZModelLinker");
|
|
7058
7093
|
}
|
|
@@ -7062,31 +7097,29 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
|
|
|
7062
7097
|
this.descriptions = services.workspace.AstNodeDescriptionProvider;
|
|
7063
7098
|
}
|
|
7064
7099
|
//#region Reference linking
|
|
7065
|
-
async link(document, cancelToken =
|
|
7100
|
+
async link(document, cancelToken = import_langium8.Cancellation.CancellationToken.None) {
|
|
7066
7101
|
if (document.parseResult.lexerErrors?.length > 0 || document.parseResult.parserErrors?.length > 0) {
|
|
7067
7102
|
return;
|
|
7068
7103
|
}
|
|
7069
|
-
for (const node of
|
|
7070
|
-
await (0,
|
|
7104
|
+
for (const node of import_langium8.AstUtils.streamContents(document.parseResult.value)) {
|
|
7105
|
+
await (0, import_langium8.interruptAndCheck)(cancelToken);
|
|
7071
7106
|
this.resolve(node, document);
|
|
7072
7107
|
}
|
|
7073
|
-
document.state =
|
|
7108
|
+
document.state = import_langium8.DocumentState.Linked;
|
|
7074
7109
|
}
|
|
7075
|
-
linkReference(
|
|
7076
|
-
|
|
7110
|
+
linkReference(refInfo, document, extraScopes) {
|
|
7111
|
+
const defaultRef = refInfo.reference;
|
|
7112
|
+
if (defaultRef._ref) {
|
|
7077
7113
|
return;
|
|
7078
7114
|
}
|
|
7079
|
-
|
|
7080
|
-
|
|
7081
|
-
|
|
7082
|
-
|
|
7083
|
-
property
|
|
7084
|
-
}, document);
|
|
7115
|
+
if (this.resolveFromScopeProviders(refInfo.reference, document, extraScopes)) {
|
|
7116
|
+
return;
|
|
7117
|
+
}
|
|
7118
|
+
this.doLink(refInfo, document);
|
|
7085
7119
|
}
|
|
7086
7120
|
//#endregion
|
|
7087
7121
|
//#region Expression type resolving
|
|
7088
|
-
resolveFromScopeProviders(
|
|
7089
|
-
const reference = node[property];
|
|
7122
|
+
resolveFromScopeProviders(reference, document, providers) {
|
|
7090
7123
|
for (const provider of providers) {
|
|
7091
7124
|
const target = provider(reference.$refText);
|
|
7092
7125
|
if (target) {
|
|
@@ -7215,12 +7248,16 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
|
|
|
7215
7248
|
}
|
|
7216
7249
|
}
|
|
7217
7250
|
resolveInvocation(node, document, extraScopes) {
|
|
7218
|
-
this.linkReference(
|
|
7251
|
+
this.linkReference({
|
|
7252
|
+
reference: node.function,
|
|
7253
|
+
container: node,
|
|
7254
|
+
property: "function"
|
|
7255
|
+
}, document, extraScopes);
|
|
7219
7256
|
node.args.forEach((arg) => this.resolve(arg, document, extraScopes));
|
|
7220
7257
|
if (node.function.ref) {
|
|
7221
7258
|
const funcDecl = node.function.ref;
|
|
7222
7259
|
if (isAuthInvocation(node)) {
|
|
7223
|
-
const allDecls = getAllLoadedAndReachableDataModelsAndTypeDefs(this.langiumDocuments(),
|
|
7260
|
+
const allDecls = getAllLoadedAndReachableDataModelsAndTypeDefs(this.langiumDocuments(), import_langium8.AstUtils.getContainerOfType(node, isDataModel));
|
|
7224
7261
|
const authDecl = getAuthDecl(allDecls);
|
|
7225
7262
|
if (authDecl) {
|
|
7226
7263
|
node.$resolvedType = {
|
|
@@ -7228,7 +7265,7 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
|
|
|
7228
7265
|
nullable: true
|
|
7229
7266
|
};
|
|
7230
7267
|
}
|
|
7231
|
-
} else if (
|
|
7268
|
+
} else if (isBeforeInvocation(node)) {
|
|
7232
7269
|
node.$resolvedType = {
|
|
7233
7270
|
decl: getContainingDataModel(node)
|
|
7234
7271
|
};
|
|
@@ -7292,7 +7329,7 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
|
|
|
7292
7329
|
if (isArrayExpr(node.value)) {
|
|
7293
7330
|
node.value.items.forEach((item) => {
|
|
7294
7331
|
if (isReferenceExpr(item)) {
|
|
7295
|
-
const resolved2 = this.resolveFromScopeProviders(item
|
|
7332
|
+
const resolved2 = this.resolveFromScopeProviders(item.target, document, [
|
|
7296
7333
|
scopeProvider
|
|
7297
7334
|
]);
|
|
7298
7335
|
if (resolved2) {
|
|
@@ -7306,7 +7343,7 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
|
|
|
7306
7343
|
this.resolveToBuiltinTypeOrDecl(node.value, node.value.items[0].$resolvedType.decl, true);
|
|
7307
7344
|
}
|
|
7308
7345
|
} else if (isReferenceExpr(node.value)) {
|
|
7309
|
-
const resolved2 = this.resolveFromScopeProviders(node.value
|
|
7346
|
+
const resolved2 = this.resolveFromScopeProviders(node.value.target, document, [
|
|
7310
7347
|
scopeProvider
|
|
7311
7348
|
]);
|
|
7312
7349
|
if (resolved2) {
|
|
@@ -7358,14 +7395,10 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
|
|
|
7358
7395
|
this.resolveDefault(node, document, scopes);
|
|
7359
7396
|
}
|
|
7360
7397
|
resolveDefault(node, document, extraScopes) {
|
|
7361
|
-
|
|
7362
|
-
|
|
7363
|
-
|
|
7364
|
-
|
|
7365
|
-
}
|
|
7366
|
-
}
|
|
7367
|
-
}
|
|
7368
|
-
for (const child of import_langium7.AstUtils.streamContents(node)) {
|
|
7398
|
+
import_langium8.AstUtils.streamReferences(node).forEach((ref) => {
|
|
7399
|
+
this.linkReference(ref, document, extraScopes);
|
|
7400
|
+
});
|
|
7401
|
+
for (const child of import_langium8.AstUtils.streamContents(node)) {
|
|
7369
7402
|
this.resolve(child, document, extraScopes);
|
|
7370
7403
|
}
|
|
7371
7404
|
}
|
|
@@ -7409,9 +7442,9 @@ var ZModelLinker = class extends import_langium7.DefaultLinker {
|
|
|
7409
7442
|
};
|
|
7410
7443
|
|
|
7411
7444
|
// src/zmodel-scope.ts
|
|
7412
|
-
var
|
|
7445
|
+
var import_langium9 = require("langium");
|
|
7413
7446
|
var import_ts_pattern3 = require("ts-pattern");
|
|
7414
|
-
var ZModelScopeComputation = class extends
|
|
7447
|
+
var ZModelScopeComputation = class extends import_langium9.DefaultScopeComputation {
|
|
7415
7448
|
static {
|
|
7416
7449
|
__name(this, "ZModelScopeComputation");
|
|
7417
7450
|
}
|
|
@@ -7421,9 +7454,9 @@ var ZModelScopeComputation = class extends import_langium8.DefaultScopeComputati
|
|
|
7421
7454
|
}
|
|
7422
7455
|
async computeExports(document, cancelToken) {
|
|
7423
7456
|
const result = await super.computeExports(document, cancelToken);
|
|
7424
|
-
for (const node of
|
|
7457
|
+
for (const node of import_langium9.AstUtils.streamAllContents(document.parseResult.value)) {
|
|
7425
7458
|
if (cancelToken) {
|
|
7426
|
-
await (0,
|
|
7459
|
+
await (0, import_langium9.interruptAndCheck)(cancelToken);
|
|
7427
7460
|
}
|
|
7428
7461
|
if (isEnumField(node)) {
|
|
7429
7462
|
const desc = this.services.workspace.AstNodeDescriptionProvider.createDescription(node, node.name, document);
|
|
@@ -7444,7 +7477,7 @@ var ZModelScopeComputation = class extends import_langium8.DefaultScopeComputati
|
|
|
7444
7477
|
}
|
|
7445
7478
|
}
|
|
7446
7479
|
};
|
|
7447
|
-
var ZModelScopeProvider = class extends
|
|
7480
|
+
var ZModelScopeProvider = class extends import_langium9.DefaultScopeProvider {
|
|
7448
7481
|
static {
|
|
7449
7482
|
__name(this, "ZModelScopeProvider");
|
|
7450
7483
|
}
|
|
@@ -7453,19 +7486,19 @@ var ZModelScopeProvider = class extends import_langium8.DefaultScopeProvider {
|
|
|
7453
7486
|
super(services), this.services = services;
|
|
7454
7487
|
}
|
|
7455
7488
|
getGlobalScope(referenceType, context) {
|
|
7456
|
-
const model =
|
|
7489
|
+
const model = import_langium9.AstUtils.getContainerOfType(context.container, isModel);
|
|
7457
7490
|
if (!model) {
|
|
7458
|
-
return
|
|
7491
|
+
return import_langium9.EMPTY_SCOPE;
|
|
7459
7492
|
}
|
|
7460
7493
|
const importedUris = model.imports.map(resolveImportUri).filter((url) => !!url);
|
|
7461
7494
|
const importedElements = this.indexManager.allElements(referenceType).filter((des) => (
|
|
7462
7495
|
// allow current document
|
|
7463
|
-
|
|
7496
|
+
import_langium9.UriUtils.equals(des.documentUri, model.$document?.uri) || // allow stdlib
|
|
7464
7497
|
des.documentUri.path.endsWith(STD_LIB_MODULE_NAME) || // allow plugin models
|
|
7465
7498
|
des.documentUri.path.endsWith(PLUGIN_MODULE_NAME) || // allow imported documents
|
|
7466
|
-
importedUris.some((importedUri) =>
|
|
7499
|
+
importedUris.some((importedUri) => import_langium9.UriUtils.equals(des.documentUri, importedUri))
|
|
7467
7500
|
));
|
|
7468
|
-
return new
|
|
7501
|
+
return new import_langium9.StreamScope(importedElements);
|
|
7469
7502
|
}
|
|
7470
7503
|
getScope(context) {
|
|
7471
7504
|
if (isMemberAccessExpr(context.container) && context.container.operand && context.property === "member") {
|
|
@@ -7485,31 +7518,31 @@ var ZModelScopeProvider = class extends import_langium8.DefaultScopeProvider {
|
|
|
7485
7518
|
const node = context.container;
|
|
7486
7519
|
const allowTypeDefScope = (
|
|
7487
7520
|
// isAuthOrAuthMemberAccess(node.operand) ||
|
|
7488
|
-
!!
|
|
7521
|
+
!!import_langium9.AstUtils.getContainerOfType(node, isTypeDef)
|
|
7489
7522
|
);
|
|
7490
7523
|
return (0, import_ts_pattern3.match)(node.operand).when(isReferenceExpr, (operand) => {
|
|
7491
7524
|
const ref = operand.target.ref;
|
|
7492
7525
|
if (isDataField(ref)) {
|
|
7493
7526
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7494
7527
|
}
|
|
7495
|
-
return
|
|
7528
|
+
return import_langium9.EMPTY_SCOPE;
|
|
7496
7529
|
}).when(isMemberAccessExpr, (operand) => {
|
|
7497
7530
|
const ref = operand.member.ref;
|
|
7498
7531
|
if (isDataField(ref) && !ref.type.array) {
|
|
7499
7532
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7500
7533
|
}
|
|
7501
|
-
return
|
|
7534
|
+
return import_langium9.EMPTY_SCOPE;
|
|
7502
7535
|
}).when(isThisExpr, () => {
|
|
7503
7536
|
return this.createScopeForContainingModel(node, globalScope);
|
|
7504
7537
|
}).when(isInvocationExpr, (operand) => {
|
|
7505
7538
|
if (isAuthInvocation(operand)) {
|
|
7506
7539
|
return this.createScopeForAuth(node, globalScope);
|
|
7507
7540
|
}
|
|
7508
|
-
if (
|
|
7541
|
+
if (isBeforeInvocation(operand)) {
|
|
7509
7542
|
return this.createScopeForContainingModel(node, globalScope);
|
|
7510
7543
|
}
|
|
7511
|
-
return
|
|
7512
|
-
}).otherwise(() =>
|
|
7544
|
+
return import_langium9.EMPTY_SCOPE;
|
|
7545
|
+
}).otherwise(() => import_langium9.EMPTY_SCOPE);
|
|
7513
7546
|
}
|
|
7514
7547
|
getCollectionPredicateScope(context, collectionPredicate) {
|
|
7515
7548
|
const referenceType = this.reflection.getReferenceType(context);
|
|
@@ -7521,30 +7554,30 @@ var ZModelScopeProvider = class extends import_langium8.DefaultScopeProvider {
|
|
|
7521
7554
|
if (isDataField(ref)) {
|
|
7522
7555
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7523
7556
|
}
|
|
7524
|
-
return
|
|
7557
|
+
return import_langium9.EMPTY_SCOPE;
|
|
7525
7558
|
}).when(isMemberAccessExpr, (expr) => {
|
|
7526
7559
|
const ref = expr.member.ref;
|
|
7527
7560
|
if (isDataField(ref)) {
|
|
7528
7561
|
return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
|
|
7529
7562
|
}
|
|
7530
|
-
return
|
|
7563
|
+
return import_langium9.EMPTY_SCOPE;
|
|
7531
7564
|
}).when(isInvocationExpr, (expr) => {
|
|
7532
7565
|
const returnTypeDecl = expr.function.ref?.returnType.reference?.ref;
|
|
7533
7566
|
if (isDataModel(returnTypeDecl)) {
|
|
7534
7567
|
return this.createScopeForContainer(returnTypeDecl, globalScope, allowTypeDefScope);
|
|
7535
7568
|
} else {
|
|
7536
|
-
return
|
|
7569
|
+
return import_langium9.EMPTY_SCOPE;
|
|
7537
7570
|
}
|
|
7538
7571
|
}).when(isAuthInvocation, (expr) => {
|
|
7539
7572
|
return this.createScopeForAuth(expr, globalScope);
|
|
7540
|
-
}).otherwise(() =>
|
|
7573
|
+
}).otherwise(() => import_langium9.EMPTY_SCOPE);
|
|
7541
7574
|
}
|
|
7542
7575
|
createScopeForContainingModel(node, globalScope) {
|
|
7543
|
-
const model =
|
|
7576
|
+
const model = import_langium9.AstUtils.getContainerOfType(node, isDataModel);
|
|
7544
7577
|
if (model) {
|
|
7545
7578
|
return this.createScopeForContainer(model, globalScope);
|
|
7546
7579
|
} else {
|
|
7547
|
-
return
|
|
7580
|
+
return import_langium9.EMPTY_SCOPE;
|
|
7548
7581
|
}
|
|
7549
7582
|
}
|
|
7550
7583
|
createScopeForContainer(node, globalScope, includeTypeDefScope = false) {
|
|
@@ -7553,16 +7586,16 @@ var ZModelScopeProvider = class extends import_langium8.DefaultScopeProvider {
|
|
|
7553
7586
|
} else if (includeTypeDefScope && isTypeDef(node)) {
|
|
7554
7587
|
return this.createScopeForNodes(node.fields, globalScope);
|
|
7555
7588
|
} else {
|
|
7556
|
-
return
|
|
7589
|
+
return import_langium9.EMPTY_SCOPE;
|
|
7557
7590
|
}
|
|
7558
7591
|
}
|
|
7559
7592
|
createScopeForAuth(node, globalScope) {
|
|
7560
|
-
const decls = getAllLoadedAndReachableDataModelsAndTypeDefs(this.services.shared.workspace.LangiumDocuments,
|
|
7593
|
+
const decls = getAllLoadedAndReachableDataModelsAndTypeDefs(this.services.shared.workspace.LangiumDocuments, import_langium9.AstUtils.getContainerOfType(node, isDataModel));
|
|
7561
7594
|
const authDecl = getAuthDecl(decls);
|
|
7562
7595
|
if (authDecl) {
|
|
7563
7596
|
return this.createScopeForContainer(authDecl, globalScope, true);
|
|
7564
7597
|
} else {
|
|
7565
|
-
return
|
|
7598
|
+
return import_langium9.EMPTY_SCOPE;
|
|
7566
7599
|
}
|
|
7567
7600
|
}
|
|
7568
7601
|
};
|
|
@@ -7579,12 +7612,12 @@ function getCollectionPredicateContext(node) {
|
|
|
7579
7612
|
__name(getCollectionPredicateContext, "getCollectionPredicateContext");
|
|
7580
7613
|
|
|
7581
7614
|
// src/zmodel-workspace-manager.ts
|
|
7582
|
-
var
|
|
7615
|
+
var import_langium10 = require("langium");
|
|
7583
7616
|
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
7584
7617
|
var import_node_path = __toESM(require("path"), 1);
|
|
7585
7618
|
var import_node_url = require("url");
|
|
7586
7619
|
var import_meta = {};
|
|
7587
|
-
var ZModelWorkspaceManager = class extends
|
|
7620
|
+
var ZModelWorkspaceManager = class extends import_langium10.DefaultWorkspaceManager {
|
|
7588
7621
|
static {
|
|
7589
7622
|
__name(this, "ZModelWorkspaceManager");
|
|
7590
7623
|
}
|
|
@@ -7623,7 +7656,7 @@ var ZModelWorkspaceManager = class extends import_langium9.DefaultWorkspaceManag
|
|
|
7623
7656
|
stdLibPath = import_node_path.default.join(_dirname, "../res", STD_LIB_MODULE_NAME);
|
|
7624
7657
|
console.log(`Using bundled stdlib in extension:`, stdLibPath);
|
|
7625
7658
|
}
|
|
7626
|
-
const stdlib = await this.documentFactory.fromUri(
|
|
7659
|
+
const stdlib = await this.documentFactory.fromUri(import_langium10.URI.file(stdLibPath));
|
|
7627
7660
|
collector(stdlib);
|
|
7628
7661
|
const documents = this.langiumDocuments.all;
|
|
7629
7662
|
const pluginModels = /* @__PURE__ */ new Set();
|
|
@@ -7653,7 +7686,7 @@ var ZModelWorkspaceManager = class extends import_langium9.DefaultWorkspaceManag
|
|
|
7653
7686
|
async loadPluginModels(workspaceFolder, folderPath, pendingPluginModels, collector) {
|
|
7654
7687
|
const content = (await this.fileSystemProvider.readDirectory(folderPath)).sort((a, b) => {
|
|
7655
7688
|
if (a.isDirectory && b.isDirectory) {
|
|
7656
|
-
const aName =
|
|
7689
|
+
const aName = import_langium10.UriUtils.basename(a.uri);
|
|
7657
7690
|
if (aName === "node_modules") {
|
|
7658
7691
|
return -1;
|
|
7659
7692
|
} else {
|
|
@@ -7665,10 +7698,10 @@ var ZModelWorkspaceManager = class extends import_langium9.DefaultWorkspaceManag
|
|
|
7665
7698
|
});
|
|
7666
7699
|
for (const entry of content) {
|
|
7667
7700
|
if (entry.isDirectory) {
|
|
7668
|
-
const name =
|
|
7701
|
+
const name = import_langium10.UriUtils.basename(entry.uri);
|
|
7669
7702
|
if (name === "node_modules") {
|
|
7670
7703
|
for (const plugin of Array.from(pendingPluginModels)) {
|
|
7671
|
-
const path4 =
|
|
7704
|
+
const path4 = import_langium10.UriUtils.joinPath(entry.uri, plugin, PLUGIN_MODULE_NAME);
|
|
7672
7705
|
try {
|
|
7673
7706
|
await this.fileSystemProvider.readFile(path4);
|
|
7674
7707
|
const document = await this.langiumDocuments.getOrCreateDocument(path4);
|
|
@@ -7702,12 +7735,13 @@ var ZModelLanguageModule = {
|
|
|
7702
7735
|
};
|
|
7703
7736
|
var ZModelSharedModule = {
|
|
7704
7737
|
workspace: {
|
|
7738
|
+
DocumentBuilder: /* @__PURE__ */ __name((services) => new ZModelDocumentBuilder(services), "DocumentBuilder"),
|
|
7705
7739
|
WorkspaceManager: /* @__PURE__ */ __name((services) => new ZModelWorkspaceManager(services), "WorkspaceManager")
|
|
7706
7740
|
}
|
|
7707
7741
|
};
|
|
7708
7742
|
function createZModelLanguageServices(context) {
|
|
7709
|
-
const shared = (0,
|
|
7710
|
-
const ZModelLanguage = (0,
|
|
7743
|
+
const shared = (0, import_langium11.inject)((0, import_lsp.createDefaultSharedModule)(context), ZModelGeneratedSharedModule, ZModelSharedModule);
|
|
7744
|
+
const ZModelLanguage = (0, import_langium11.inject)((0, import_lsp.createDefaultModule)({
|
|
7711
7745
|
shared
|
|
7712
7746
|
}), ZModelGeneratedModule, ZModelLanguageModule);
|
|
7713
7747
|
shared.ServiceRegistry.register(ZModelLanguage);
|
|
@@ -7758,10 +7792,10 @@ async function loadDocument(fileName, pluginModelFiles = []) {
|
|
|
7758
7792
|
};
|
|
7759
7793
|
}
|
|
7760
7794
|
const _dirname = typeof __dirname !== "undefined" ? __dirname : import_node_path2.default.dirname((0, import_node_url2.fileURLToPath)(import_meta2.url));
|
|
7761
|
-
const stdLib = await services.shared.workspace.LangiumDocuments.getOrCreateDocument(
|
|
7762
|
-
const pluginDocs = await Promise.all(pluginModelFiles.map((file) => services.shared.workspace.LangiumDocuments.getOrCreateDocument(
|
|
7795
|
+
const stdLib = await services.shared.workspace.LangiumDocuments.getOrCreateDocument(import_langium12.URI.file(import_node_path2.default.resolve(import_node_path2.default.join(_dirname, "../res", STD_LIB_MODULE_NAME))));
|
|
7796
|
+
const pluginDocs = await Promise.all(pluginModelFiles.map((file) => services.shared.workspace.LangiumDocuments.getOrCreateDocument(import_langium12.URI.file(import_node_path2.default.resolve(file)))));
|
|
7763
7797
|
const langiumDocuments = services.shared.workspace.LangiumDocuments;
|
|
7764
|
-
const document = await langiumDocuments.getOrCreateDocument(
|
|
7798
|
+
const document = await langiumDocuments.getOrCreateDocument(import_langium12.URI.file(import_node_path2.default.resolve(fileName)));
|
|
7765
7799
|
const importedURIs = await loadImports(document, langiumDocuments);
|
|
7766
7800
|
const importedDocuments = [];
|
|
7767
7801
|
for (const uri of importedURIs) {
|
|
@@ -7773,7 +7807,11 @@ async function loadDocument(fileName, pluginModelFiles = []) {
|
|
|
7773
7807
|
document,
|
|
7774
7808
|
...importedDocuments
|
|
7775
7809
|
], {
|
|
7776
|
-
validation:
|
|
7810
|
+
validation: {
|
|
7811
|
+
stopAfterLexingErrors: true,
|
|
7812
|
+
stopAfterParsingErrors: true,
|
|
7813
|
+
stopAfterLinkingErrors: true
|
|
7814
|
+
}
|
|
7777
7815
|
});
|
|
7778
7816
|
const diagnostics = langiumDocuments.all.flatMap((doc) => (doc.diagnostics ?? []).map((diag) => ({
|
|
7779
7817
|
doc,
|
|
@@ -7832,7 +7870,7 @@ async function loadImports(document, documents, uris = /* @__PURE__ */ new Set()
|
|
|
7832
7870
|
}
|
|
7833
7871
|
}
|
|
7834
7872
|
}
|
|
7835
|
-
return Array.from(uris).filter((x) => uriString != x).map((e) =>
|
|
7873
|
+
return Array.from(uris).filter((x) => uriString != x).map((e) => import_langium12.URI.parse(e));
|
|
7836
7874
|
}
|
|
7837
7875
|
__name(loadImports, "loadImports");
|
|
7838
7876
|
function mergeImportsDeclarations(documents, model) {
|
|
@@ -7849,13 +7887,13 @@ function linkContentToContainer(node) {
|
|
|
7849
7887
|
if (!name.startsWith("$")) {
|
|
7850
7888
|
if (Array.isArray(value)) {
|
|
7851
7889
|
value.forEach((item, index) => {
|
|
7852
|
-
if ((0,
|
|
7890
|
+
if ((0, import_langium12.isAstNode)(item)) {
|
|
7853
7891
|
item.$container = node;
|
|
7854
7892
|
item.$containerProperty = name;
|
|
7855
7893
|
item.$containerIndex = index;
|
|
7856
7894
|
}
|
|
7857
7895
|
});
|
|
7858
|
-
} else if ((0,
|
|
7896
|
+
} else if ((0, import_langium12.isAstNode)(value)) {
|
|
7859
7897
|
value.$container = node;
|
|
7860
7898
|
value.$containerProperty = name;
|
|
7861
7899
|
}
|