@zenstackhq/language 3.0.0-beta.19 → 3.0.0-beta.20

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.js CHANGED
@@ -9,13 +9,17 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
9
9
 
10
10
  // src/document.ts
11
11
  import { isAstNode, URI as URI4 } from "langium";
12
- import fs3 from "fs";
12
+ import fs4 from "fs";
13
13
  import path4 from "path";
14
14
  import { fileURLToPath as fileURLToPath4 } from "url";
15
15
 
16
16
  // src/generated/ast.ts
17
17
  import * as langium from "langium";
18
18
  var AbstractDeclaration = "AbstractDeclaration";
19
+ function isAbstractDeclaration(item) {
20
+ return reflection.isInstance(item, AbstractDeclaration);
21
+ }
22
+ __name(isAbstractDeclaration, "isAbstractDeclaration");
19
23
  var ConfigExpr = "ConfigExpr";
20
24
  var Expression = "Expression";
21
25
  function isExpression(item) {
@@ -42,6 +46,10 @@ function isAttribute(item) {
42
46
  }
43
47
  __name(isAttribute, "isAttribute");
44
48
  var AttributeArg = "AttributeArg";
49
+ function isAttributeArg(item) {
50
+ return reflection.isInstance(item, AttributeArg);
51
+ }
52
+ __name(isAttributeArg, "isAttributeArg");
45
53
  var AttributeParam = "AttributeParam";
46
54
  var AttributeParamType = "AttributeParamType";
47
55
  var BinaryExpr = "BinaryExpr";
@@ -60,6 +68,10 @@ function isConfigArrayExpr(item) {
60
68
  }
61
69
  __name(isConfigArrayExpr, "isConfigArrayExpr");
62
70
  var ConfigField = "ConfigField";
71
+ function isConfigField(item) {
72
+ return reflection.isInstance(item, ConfigField);
73
+ }
74
+ __name(isConfigField, "isConfigField");
63
75
  var ConfigInvocationArg = "ConfigInvocationArg";
64
76
  var ConfigInvocationExpr = "ConfigInvocationExpr";
65
77
  var DataField = "DataField";
@@ -104,10 +116,22 @@ function isEnumField(item) {
104
116
  __name(isEnumField, "isEnumField");
105
117
  var FieldInitializer = "FieldInitializer";
106
118
  var FunctionDecl = "FunctionDecl";
119
+ function isFunctionDecl(item) {
120
+ return reflection.isInstance(item, FunctionDecl);
121
+ }
122
+ __name(isFunctionDecl, "isFunctionDecl");
107
123
  var FunctionParam = "FunctionParam";
108
124
  var FunctionParamType = "FunctionParamType";
109
125
  var GeneratorDecl = "GeneratorDecl";
126
+ function isGeneratorDecl(item) {
127
+ return reflection.isInstance(item, GeneratorDecl);
128
+ }
129
+ __name(isGeneratorDecl, "isGeneratorDecl");
110
130
  var InternalAttribute = "InternalAttribute";
131
+ function isInternalAttribute(item) {
132
+ return reflection.isInstance(item, InternalAttribute);
133
+ }
134
+ __name(isInternalAttribute, "isInternalAttribute");
111
135
  var InvocationExpr = "InvocationExpr";
112
136
  function isInvocationExpr(item) {
113
137
  return reflection.isInstance(item, InvocationExpr);
@@ -124,6 +148,10 @@ function isModel(item) {
124
148
  }
125
149
  __name(isModel, "isModel");
126
150
  var ModelImport = "ModelImport";
151
+ function isModelImport(item) {
152
+ return reflection.isInstance(item, ModelImport);
153
+ }
154
+ __name(isModelImport, "isModelImport");
127
155
  var NullExpr = "NullExpr";
128
156
  function isNullExpr(item) {
129
157
  return reflection.isInstance(item, NullExpr);
@@ -145,6 +173,10 @@ function isPlugin(item) {
145
173
  }
146
174
  __name(isPlugin, "isPlugin");
147
175
  var PluginField = "PluginField";
176
+ function isPluginField(item) {
177
+ return reflection.isInstance(item, PluginField);
178
+ }
179
+ __name(isPluginField, "isPluginField");
148
180
  var Procedure = "Procedure";
149
181
  var ProcedureParam = "ProcedureParam";
150
182
  var ReferenceArg = "ReferenceArg";
@@ -1011,6 +1043,26 @@ var ZModelAstReflection = class extends langium.AbstractAstReflection {
1011
1043
  };
1012
1044
  var reflection = new ZModelAstReflection();
1013
1045
 
1046
+ // src/ast.ts
1047
+ var BinaryExprOperatorPriority = {
1048
+ //LogicalExpr
1049
+ "||": 1,
1050
+ "&&": 1,
1051
+ //EqualityExpr
1052
+ "==": 2,
1053
+ "!=": 2,
1054
+ //ComparisonExpr
1055
+ ">": 3,
1056
+ "<": 3,
1057
+ ">=": 3,
1058
+ "<=": 3,
1059
+ in: 4,
1060
+ //CollectionPredicateExpr
1061
+ "^": 5,
1062
+ "?": 5,
1063
+ "!": 5
1064
+ };
1065
+
1014
1066
  // src/constants.ts
1015
1067
  var SUPPORTED_PROVIDERS = [
1016
1068
  "sqlite",
@@ -7170,6 +7222,873 @@ var ZModelValidator = class {
7170
7222
  }
7171
7223
  };
7172
7224
 
7225
+ // src/zmodel-comment-provider.ts
7226
+ import { DefaultCommentProvider } from "langium";
7227
+ import { match as match2 } from "ts-pattern";
7228
+ var ZModelCommentProvider = class extends DefaultCommentProvider {
7229
+ static {
7230
+ __name(this, "ZModelCommentProvider");
7231
+ }
7232
+ getComment(node) {
7233
+ let comment = super.getComment(node);
7234
+ if (!comment) {
7235
+ comment = match2(node).when(isDataModel, (d) => `/**
7236
+ * Model *${d.name}*
7237
+ */`).when(isTypeDef, (d) => `/**
7238
+ * Type *${d.name}*
7239
+ */`).when(isEnum, (e) => `/**
7240
+ * Enum *${e.name}*
7241
+ */`).when(isEnumField, (f) => `/**
7242
+ * Value of enum *${f.$container?.name}*
7243
+ */`).when(isDataField, (f) => `/**
7244
+ * Field of *${f.$container?.name}*
7245
+ */`).when(isFunctionDecl, (f) => `/**
7246
+ * Function *${f.name}*
7247
+ */`).otherwise(() => "");
7248
+ }
7249
+ return comment;
7250
+ }
7251
+ };
7252
+
7253
+ // src/zmodel-completion-provider.ts
7254
+ import { DefaultCompletionProvider } from "langium/lsp";
7255
+ import fs2 from "fs";
7256
+ import { P as P2, match as match3 } from "ts-pattern";
7257
+ import { CompletionItemKind } from "vscode-languageserver";
7258
+
7259
+ // src/zmodel-code-generator.ts
7260
+ function _ts_decorate3(decorators, target, key, desc) {
7261
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
7262
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
7263
+ 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;
7264
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7265
+ }
7266
+ __name(_ts_decorate3, "_ts_decorate");
7267
+ function _ts_metadata3(k, v) {
7268
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
7269
+ }
7270
+ __name(_ts_metadata3, "_ts_metadata");
7271
+ var generationHandlers = /* @__PURE__ */ new Map();
7272
+ function gen(name) {
7273
+ return function(_target, _propertyKey, descriptor) {
7274
+ if (!generationHandlers.get(name)) {
7275
+ generationHandlers.set(name, descriptor);
7276
+ }
7277
+ return descriptor;
7278
+ };
7279
+ }
7280
+ __name(gen, "gen");
7281
+ var ZModelCodeGenerator = class {
7282
+ static {
7283
+ __name(this, "ZModelCodeGenerator");
7284
+ }
7285
+ options;
7286
+ constructor(options) {
7287
+ this.options = {
7288
+ binaryExprNumberOfSpaces: options?.binaryExprNumberOfSpaces ?? 1,
7289
+ unaryExprNumberOfSpaces: options?.unaryExprNumberOfSpaces ?? 0,
7290
+ indent: options?.indent ?? 4,
7291
+ quote: options?.quote ?? "single"
7292
+ };
7293
+ }
7294
+ /**
7295
+ * Generates ZModel source code from AST.
7296
+ */
7297
+ generate(ast) {
7298
+ const handler = generationHandlers.get(ast.$type);
7299
+ if (!handler) {
7300
+ throw new Error(`No generation handler found for ${ast.$type}`);
7301
+ }
7302
+ return handler.value.call(this, ast);
7303
+ }
7304
+ _generateModel(ast) {
7305
+ return ast.declarations.map((d) => this.generate(d)).join("\n\n");
7306
+ }
7307
+ _generateDataSource(ast) {
7308
+ return `datasource ${ast.name} {
7309
+ ${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
7310
+ }`;
7311
+ }
7312
+ _generateEnum(ast) {
7313
+ return `enum ${ast.name} {
7314
+ ${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
7315
+ }`;
7316
+ }
7317
+ _generateEnumField(ast) {
7318
+ return `${ast.name}${ast.attributes.length > 0 ? " " + ast.attributes.map((x) => this.generate(x)).join(" ") : ""}`;
7319
+ }
7320
+ _generateGenerator(ast) {
7321
+ return `generator ${ast.name} {
7322
+ ${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
7323
+ }`;
7324
+ }
7325
+ _generateConfigField(ast) {
7326
+ return `${ast.name} = ${this.generate(ast.value)}`;
7327
+ }
7328
+ _generateConfigArrayExpr(ast) {
7329
+ return `[${ast.items.map((x) => this.generate(x)).join(", ")}]`;
7330
+ }
7331
+ _generateConfigInvocationExpr(ast) {
7332
+ if (ast.args.length === 0) {
7333
+ return ast.name;
7334
+ } else {
7335
+ return `${ast.name}(${ast.args.map((x) => (x.name ? x.name + ": " : "") + this.generate(x.value)).join(", ")})`;
7336
+ }
7337
+ }
7338
+ _generatePlugin(ast) {
7339
+ return `plugin ${ast.name} {
7340
+ ${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
7341
+ }`;
7342
+ }
7343
+ _generatePluginField(ast) {
7344
+ return `${ast.name} = ${this.generate(ast.value)}`;
7345
+ }
7346
+ _generateDataModel(ast) {
7347
+ return `${ast.isView ? "view" : "model"} ${ast.name}${ast.mixins.length > 0 ? " mixes " + ast.mixins.map((x) => x.ref?.name).join(", ") : ""} {
7348
+ ${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") : ""}
7349
+ }`;
7350
+ }
7351
+ _generateDataField(ast) {
7352
+ return `${ast.name} ${this.fieldType(ast.type)}${ast.attributes.length > 0 ? " " + ast.attributes.map((x) => this.generate(x)).join(" ") : ""}`;
7353
+ }
7354
+ fieldType(type) {
7355
+ const baseType = type.type ? type.type : type.$type == "DataFieldType" && type.unsupported ? "Unsupported(" + this.generate(type.unsupported.value) + ")" : type.reference?.$refText;
7356
+ return `${baseType}${type.array ? "[]" : ""}${type.optional ? "?" : ""}`;
7357
+ }
7358
+ _generateDataModelAttribute(ast) {
7359
+ return this.attribute(ast);
7360
+ }
7361
+ _generateDataFieldAttribute(ast) {
7362
+ return this.attribute(ast);
7363
+ }
7364
+ attribute(ast) {
7365
+ const args = ast.args.length ? `(${ast.args.map((x) => this.generate(x)).join(", ")})` : "";
7366
+ return `${resolved(ast.decl).name}${args}`;
7367
+ }
7368
+ _generateAttributeArg(ast) {
7369
+ if (ast.name) {
7370
+ return `${ast.name}: ${this.generate(ast.value)}`;
7371
+ } else {
7372
+ return this.generate(ast.value);
7373
+ }
7374
+ }
7375
+ _generateObjectExpr(ast) {
7376
+ return `{ ${ast.fields.map((field) => this.objectField(field)).join(", ")} }`;
7377
+ }
7378
+ objectField(field) {
7379
+ return `${field.name}: ${this.generate(field.value)}`;
7380
+ }
7381
+ _generateArrayExpr(ast) {
7382
+ return `[${ast.items.map((item) => this.generate(item)).join(", ")}]`;
7383
+ }
7384
+ _generateLiteralExpr(ast) {
7385
+ return this.options.quote === "single" ? `'${ast.value}'` : `"${ast.value}"`;
7386
+ }
7387
+ _generateNumberLiteral(ast) {
7388
+ return ast.value.toString();
7389
+ }
7390
+ _generateBooleanLiteral(ast) {
7391
+ return ast.value.toString();
7392
+ }
7393
+ _generateUnaryExpr(ast) {
7394
+ return `${ast.operator}${this.unaryExprSpace}${this.generate(ast.operand)}`;
7395
+ }
7396
+ _generateBinaryExpr(ast) {
7397
+ const operator = ast.operator;
7398
+ const isCollectionPredicate2 = this.isCollectionPredicateOperator(operator);
7399
+ const rightExpr = this.generate(ast.right);
7400
+ const { left: isLeftParenthesis, right: isRightParenthesis } = this.isParenthesesNeededForBinaryExpr(ast);
7401
+ return `${isLeftParenthesis ? "(" : ""}${this.generate(ast.left)}${isLeftParenthesis ? ")" : ""}${isCollectionPredicate2 ? "" : this.binaryExprSpace}${operator}${isCollectionPredicate2 ? "" : this.binaryExprSpace}${isRightParenthesis ? "(" : ""}${isCollectionPredicate2 ? `[${rightExpr}]` : rightExpr}${isRightParenthesis ? ")" : ""}`;
7402
+ }
7403
+ _generateReferenceExpr(ast) {
7404
+ const args = ast.args.length ? `(${ast.args.map((x) => this.generate(x)).join(", ")})` : "";
7405
+ return `${ast.target.ref?.name}${args}`;
7406
+ }
7407
+ _generateReferenceArg(ast) {
7408
+ return `${ast.name}:${this.generate(ast.value)}`;
7409
+ }
7410
+ _generateMemberExpr(ast) {
7411
+ return `${this.generate(ast.operand)}.${ast.member.ref?.name}`;
7412
+ }
7413
+ _generateInvocationExpr(ast) {
7414
+ return `${ast.function.ref?.name}(${ast.args.map((x) => this.argument(x)).join(", ")})`;
7415
+ }
7416
+ _generateNullExpr() {
7417
+ return "null";
7418
+ }
7419
+ _generateThisExpr() {
7420
+ return "this";
7421
+ }
7422
+ _generateAttribute(ast) {
7423
+ return `attribute ${ast.name}(${ast.params.map((x) => this.generate(x)).join(", ")})`;
7424
+ }
7425
+ _generateAttributeParam(ast) {
7426
+ return `${ast.default ? "_ " : ""}${ast.name}: ${this.generate(ast.type)}`;
7427
+ }
7428
+ _generateAttributeParamType(ast) {
7429
+ return `${ast.type ?? ast.reference?.$refText}${ast.array ? "[]" : ""}${ast.optional ? "?" : ""}`;
7430
+ }
7431
+ _generateFunctionDecl(ast) {
7432
+ return `function ${ast.name}(${ast.params.map((x) => this.generate(x)).join(", ")}) ${ast.returnType ? ": " + this.generate(ast.returnType) : ""} {}`;
7433
+ }
7434
+ _generateFunctionParam(ast) {
7435
+ return `${ast.name}: ${this.generate(ast.type)}`;
7436
+ }
7437
+ _generateFunctionParamType(ast) {
7438
+ return `${ast.type ?? ast.reference?.$refText}${ast.array ? "[]" : ""}`;
7439
+ }
7440
+ _generateTypeDef(ast) {
7441
+ return `type ${ast.name} {
7442
+ ${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") : ""}
7443
+ }`;
7444
+ }
7445
+ argument(ast) {
7446
+ return this.generate(ast.value);
7447
+ }
7448
+ get binaryExprSpace() {
7449
+ return " ".repeat(this.options.binaryExprNumberOfSpaces);
7450
+ }
7451
+ get unaryExprSpace() {
7452
+ return " ".repeat(this.options.unaryExprNumberOfSpaces);
7453
+ }
7454
+ get indent() {
7455
+ return " ".repeat(this.options.indent);
7456
+ }
7457
+ isParenthesesNeededForBinaryExpr(ast) {
7458
+ const result = {
7459
+ left: false,
7460
+ right: false
7461
+ };
7462
+ const operator = ast.operator;
7463
+ const isCollectionPredicate2 = this.isCollectionPredicateOperator(operator);
7464
+ const currentPriority = BinaryExprOperatorPriority[operator];
7465
+ if (ast.left.$type === BinaryExpr && BinaryExprOperatorPriority[ast.left["operator"]] < currentPriority) {
7466
+ result.left = true;
7467
+ }
7468
+ if (!isCollectionPredicate2 && ast.right.$type === BinaryExpr && BinaryExprOperatorPriority[ast.right["operator"]] <= currentPriority) {
7469
+ result.right = true;
7470
+ }
7471
+ return result;
7472
+ }
7473
+ isCollectionPredicateOperator(op) {
7474
+ return [
7475
+ "?",
7476
+ "!",
7477
+ "^"
7478
+ ].includes(op);
7479
+ }
7480
+ };
7481
+ _ts_decorate3([
7482
+ gen(Model),
7483
+ _ts_metadata3("design:type", Function),
7484
+ _ts_metadata3("design:paramtypes", [
7485
+ typeof Model === "undefined" ? Object : Model
7486
+ ]),
7487
+ _ts_metadata3("design:returntype", void 0)
7488
+ ], ZModelCodeGenerator.prototype, "_generateModel", null);
7489
+ _ts_decorate3([
7490
+ gen(DataSource),
7491
+ _ts_metadata3("design:type", Function),
7492
+ _ts_metadata3("design:paramtypes", [
7493
+ typeof DataSource === "undefined" ? Object : DataSource
7494
+ ]),
7495
+ _ts_metadata3("design:returntype", void 0)
7496
+ ], ZModelCodeGenerator.prototype, "_generateDataSource", null);
7497
+ _ts_decorate3([
7498
+ gen(Enum),
7499
+ _ts_metadata3("design:type", Function),
7500
+ _ts_metadata3("design:paramtypes", [
7501
+ typeof Enum === "undefined" ? Object : Enum
7502
+ ]),
7503
+ _ts_metadata3("design:returntype", void 0)
7504
+ ], ZModelCodeGenerator.prototype, "_generateEnum", null);
7505
+ _ts_decorate3([
7506
+ gen(EnumField),
7507
+ _ts_metadata3("design:type", Function),
7508
+ _ts_metadata3("design:paramtypes", [
7509
+ typeof EnumField === "undefined" ? Object : EnumField
7510
+ ]),
7511
+ _ts_metadata3("design:returntype", void 0)
7512
+ ], ZModelCodeGenerator.prototype, "_generateEnumField", null);
7513
+ _ts_decorate3([
7514
+ gen(GeneratorDecl),
7515
+ _ts_metadata3("design:type", Function),
7516
+ _ts_metadata3("design:paramtypes", [
7517
+ typeof GeneratorDecl === "undefined" ? Object : GeneratorDecl
7518
+ ]),
7519
+ _ts_metadata3("design:returntype", void 0)
7520
+ ], ZModelCodeGenerator.prototype, "_generateGenerator", null);
7521
+ _ts_decorate3([
7522
+ gen(ConfigField),
7523
+ _ts_metadata3("design:type", Function),
7524
+ _ts_metadata3("design:paramtypes", [
7525
+ typeof ConfigField === "undefined" ? Object : ConfigField
7526
+ ]),
7527
+ _ts_metadata3("design:returntype", void 0)
7528
+ ], ZModelCodeGenerator.prototype, "_generateConfigField", null);
7529
+ _ts_decorate3([
7530
+ gen(ConfigArrayExpr),
7531
+ _ts_metadata3("design:type", Function),
7532
+ _ts_metadata3("design:paramtypes", [
7533
+ typeof ConfigArrayExpr === "undefined" ? Object : ConfigArrayExpr
7534
+ ]),
7535
+ _ts_metadata3("design:returntype", void 0)
7536
+ ], ZModelCodeGenerator.prototype, "_generateConfigArrayExpr", null);
7537
+ _ts_decorate3([
7538
+ gen(ConfigInvocationExpr),
7539
+ _ts_metadata3("design:type", Function),
7540
+ _ts_metadata3("design:paramtypes", [
7541
+ typeof ConfigInvocationExpr === "undefined" ? Object : ConfigInvocationExpr
7542
+ ]),
7543
+ _ts_metadata3("design:returntype", void 0)
7544
+ ], ZModelCodeGenerator.prototype, "_generateConfigInvocationExpr", null);
7545
+ _ts_decorate3([
7546
+ gen(Plugin),
7547
+ _ts_metadata3("design:type", Function),
7548
+ _ts_metadata3("design:paramtypes", [
7549
+ typeof Plugin === "undefined" ? Object : Plugin
7550
+ ]),
7551
+ _ts_metadata3("design:returntype", void 0)
7552
+ ], ZModelCodeGenerator.prototype, "_generatePlugin", null);
7553
+ _ts_decorate3([
7554
+ gen(PluginField),
7555
+ _ts_metadata3("design:type", Function),
7556
+ _ts_metadata3("design:paramtypes", [
7557
+ typeof PluginField === "undefined" ? Object : PluginField
7558
+ ]),
7559
+ _ts_metadata3("design:returntype", void 0)
7560
+ ], ZModelCodeGenerator.prototype, "_generatePluginField", null);
7561
+ _ts_decorate3([
7562
+ gen(DataModel),
7563
+ _ts_metadata3("design:type", Function),
7564
+ _ts_metadata3("design:paramtypes", [
7565
+ typeof DataModel === "undefined" ? Object : DataModel
7566
+ ]),
7567
+ _ts_metadata3("design:returntype", void 0)
7568
+ ], ZModelCodeGenerator.prototype, "_generateDataModel", null);
7569
+ _ts_decorate3([
7570
+ gen(DataField),
7571
+ _ts_metadata3("design:type", Function),
7572
+ _ts_metadata3("design:paramtypes", [
7573
+ typeof DataField === "undefined" ? Object : DataField
7574
+ ]),
7575
+ _ts_metadata3("design:returntype", void 0)
7576
+ ], ZModelCodeGenerator.prototype, "_generateDataField", null);
7577
+ _ts_decorate3([
7578
+ gen(DataModelAttribute),
7579
+ _ts_metadata3("design:type", Function),
7580
+ _ts_metadata3("design:paramtypes", [
7581
+ typeof DataModelAttribute === "undefined" ? Object : DataModelAttribute
7582
+ ]),
7583
+ _ts_metadata3("design:returntype", void 0)
7584
+ ], ZModelCodeGenerator.prototype, "_generateDataModelAttribute", null);
7585
+ _ts_decorate3([
7586
+ gen(DataFieldAttribute),
7587
+ _ts_metadata3("design:type", Function),
7588
+ _ts_metadata3("design:paramtypes", [
7589
+ typeof DataFieldAttribute === "undefined" ? Object : DataFieldAttribute
7590
+ ]),
7591
+ _ts_metadata3("design:returntype", void 0)
7592
+ ], ZModelCodeGenerator.prototype, "_generateDataFieldAttribute", null);
7593
+ _ts_decorate3([
7594
+ gen(AttributeArg),
7595
+ _ts_metadata3("design:type", Function),
7596
+ _ts_metadata3("design:paramtypes", [
7597
+ typeof AttributeArg === "undefined" ? Object : AttributeArg
7598
+ ]),
7599
+ _ts_metadata3("design:returntype", void 0)
7600
+ ], ZModelCodeGenerator.prototype, "_generateAttributeArg", null);
7601
+ _ts_decorate3([
7602
+ gen(ObjectExpr),
7603
+ _ts_metadata3("design:type", Function),
7604
+ _ts_metadata3("design:paramtypes", [
7605
+ typeof ObjectExpr === "undefined" ? Object : ObjectExpr
7606
+ ]),
7607
+ _ts_metadata3("design:returntype", void 0)
7608
+ ], ZModelCodeGenerator.prototype, "_generateObjectExpr", null);
7609
+ _ts_decorate3([
7610
+ gen(ArrayExpr),
7611
+ _ts_metadata3("design:type", Function),
7612
+ _ts_metadata3("design:paramtypes", [
7613
+ typeof ArrayExpr === "undefined" ? Object : ArrayExpr
7614
+ ]),
7615
+ _ts_metadata3("design:returntype", void 0)
7616
+ ], ZModelCodeGenerator.prototype, "_generateArrayExpr", null);
7617
+ _ts_decorate3([
7618
+ gen(StringLiteral),
7619
+ _ts_metadata3("design:type", Function),
7620
+ _ts_metadata3("design:paramtypes", [
7621
+ typeof LiteralExpr === "undefined" ? Object : LiteralExpr
7622
+ ]),
7623
+ _ts_metadata3("design:returntype", void 0)
7624
+ ], ZModelCodeGenerator.prototype, "_generateLiteralExpr", null);
7625
+ _ts_decorate3([
7626
+ gen(NumberLiteral),
7627
+ _ts_metadata3("design:type", Function),
7628
+ _ts_metadata3("design:paramtypes", [
7629
+ typeof NumberLiteral === "undefined" ? Object : NumberLiteral
7630
+ ]),
7631
+ _ts_metadata3("design:returntype", void 0)
7632
+ ], ZModelCodeGenerator.prototype, "_generateNumberLiteral", null);
7633
+ _ts_decorate3([
7634
+ gen(BooleanLiteral),
7635
+ _ts_metadata3("design:type", Function),
7636
+ _ts_metadata3("design:paramtypes", [
7637
+ typeof BooleanLiteral === "undefined" ? Object : BooleanLiteral
7638
+ ]),
7639
+ _ts_metadata3("design:returntype", void 0)
7640
+ ], ZModelCodeGenerator.prototype, "_generateBooleanLiteral", null);
7641
+ _ts_decorate3([
7642
+ gen(UnaryExpr),
7643
+ _ts_metadata3("design:type", Function),
7644
+ _ts_metadata3("design:paramtypes", [
7645
+ typeof UnaryExpr === "undefined" ? Object : UnaryExpr
7646
+ ]),
7647
+ _ts_metadata3("design:returntype", void 0)
7648
+ ], ZModelCodeGenerator.prototype, "_generateUnaryExpr", null);
7649
+ _ts_decorate3([
7650
+ gen(BinaryExpr),
7651
+ _ts_metadata3("design:type", Function),
7652
+ _ts_metadata3("design:paramtypes", [
7653
+ typeof BinaryExpr === "undefined" ? Object : BinaryExpr
7654
+ ]),
7655
+ _ts_metadata3("design:returntype", void 0)
7656
+ ], ZModelCodeGenerator.prototype, "_generateBinaryExpr", null);
7657
+ _ts_decorate3([
7658
+ gen(ReferenceExpr),
7659
+ _ts_metadata3("design:type", Function),
7660
+ _ts_metadata3("design:paramtypes", [
7661
+ typeof ReferenceExpr === "undefined" ? Object : ReferenceExpr
7662
+ ]),
7663
+ _ts_metadata3("design:returntype", void 0)
7664
+ ], ZModelCodeGenerator.prototype, "_generateReferenceExpr", null);
7665
+ _ts_decorate3([
7666
+ gen(ReferenceArg),
7667
+ _ts_metadata3("design:type", Function),
7668
+ _ts_metadata3("design:paramtypes", [
7669
+ typeof ReferenceArg === "undefined" ? Object : ReferenceArg
7670
+ ]),
7671
+ _ts_metadata3("design:returntype", void 0)
7672
+ ], ZModelCodeGenerator.prototype, "_generateReferenceArg", null);
7673
+ _ts_decorate3([
7674
+ gen(MemberAccessExpr),
7675
+ _ts_metadata3("design:type", Function),
7676
+ _ts_metadata3("design:paramtypes", [
7677
+ typeof MemberAccessExpr === "undefined" ? Object : MemberAccessExpr
7678
+ ]),
7679
+ _ts_metadata3("design:returntype", void 0)
7680
+ ], ZModelCodeGenerator.prototype, "_generateMemberExpr", null);
7681
+ _ts_decorate3([
7682
+ gen(InvocationExpr),
7683
+ _ts_metadata3("design:type", Function),
7684
+ _ts_metadata3("design:paramtypes", [
7685
+ typeof InvocationExpr === "undefined" ? Object : InvocationExpr
7686
+ ]),
7687
+ _ts_metadata3("design:returntype", void 0)
7688
+ ], ZModelCodeGenerator.prototype, "_generateInvocationExpr", null);
7689
+ _ts_decorate3([
7690
+ gen(NullExpr),
7691
+ _ts_metadata3("design:type", Function),
7692
+ _ts_metadata3("design:paramtypes", []),
7693
+ _ts_metadata3("design:returntype", void 0)
7694
+ ], ZModelCodeGenerator.prototype, "_generateNullExpr", null);
7695
+ _ts_decorate3([
7696
+ gen(ThisExpr),
7697
+ _ts_metadata3("design:type", Function),
7698
+ _ts_metadata3("design:paramtypes", []),
7699
+ _ts_metadata3("design:returntype", void 0)
7700
+ ], ZModelCodeGenerator.prototype, "_generateThisExpr", null);
7701
+ _ts_decorate3([
7702
+ gen(Attribute),
7703
+ _ts_metadata3("design:type", Function),
7704
+ _ts_metadata3("design:paramtypes", [
7705
+ typeof Attribute === "undefined" ? Object : Attribute
7706
+ ]),
7707
+ _ts_metadata3("design:returntype", void 0)
7708
+ ], ZModelCodeGenerator.prototype, "_generateAttribute", null);
7709
+ _ts_decorate3([
7710
+ gen(AttributeParam),
7711
+ _ts_metadata3("design:type", Function),
7712
+ _ts_metadata3("design:paramtypes", [
7713
+ typeof AttributeParam === "undefined" ? Object : AttributeParam
7714
+ ]),
7715
+ _ts_metadata3("design:returntype", void 0)
7716
+ ], ZModelCodeGenerator.prototype, "_generateAttributeParam", null);
7717
+ _ts_decorate3([
7718
+ gen(AttributeParamType),
7719
+ _ts_metadata3("design:type", Function),
7720
+ _ts_metadata3("design:paramtypes", [
7721
+ typeof AttributeParamType === "undefined" ? Object : AttributeParamType
7722
+ ]),
7723
+ _ts_metadata3("design:returntype", void 0)
7724
+ ], ZModelCodeGenerator.prototype, "_generateAttributeParamType", null);
7725
+ _ts_decorate3([
7726
+ gen(FunctionDecl),
7727
+ _ts_metadata3("design:type", Function),
7728
+ _ts_metadata3("design:paramtypes", [
7729
+ typeof FunctionDecl === "undefined" ? Object : FunctionDecl
7730
+ ]),
7731
+ _ts_metadata3("design:returntype", void 0)
7732
+ ], ZModelCodeGenerator.prototype, "_generateFunctionDecl", null);
7733
+ _ts_decorate3([
7734
+ gen(FunctionParam),
7735
+ _ts_metadata3("design:type", Function),
7736
+ _ts_metadata3("design:paramtypes", [
7737
+ typeof FunctionParam === "undefined" ? Object : FunctionParam
7738
+ ]),
7739
+ _ts_metadata3("design:returntype", void 0)
7740
+ ], ZModelCodeGenerator.prototype, "_generateFunctionParam", null);
7741
+ _ts_decorate3([
7742
+ gen(FunctionParamType),
7743
+ _ts_metadata3("design:type", Function),
7744
+ _ts_metadata3("design:paramtypes", [
7745
+ typeof FunctionParamType === "undefined" ? Object : FunctionParamType
7746
+ ]),
7747
+ _ts_metadata3("design:returntype", void 0)
7748
+ ], ZModelCodeGenerator.prototype, "_generateFunctionParamType", null);
7749
+ _ts_decorate3([
7750
+ gen(TypeDef),
7751
+ _ts_metadata3("design:type", Function),
7752
+ _ts_metadata3("design:paramtypes", [
7753
+ typeof TypeDef === "undefined" ? Object : TypeDef
7754
+ ]),
7755
+ _ts_metadata3("design:returntype", void 0)
7756
+ ], ZModelCodeGenerator.prototype, "_generateTypeDef", null);
7757
+
7758
+ // src/zmodel-completion-provider.ts
7759
+ var ZModelCompletionProvider = class extends DefaultCompletionProvider {
7760
+ static {
7761
+ __name(this, "ZModelCompletionProvider");
7762
+ }
7763
+ services;
7764
+ constructor(services) {
7765
+ super(services), this.services = services;
7766
+ }
7767
+ completionOptions = {
7768
+ triggerCharacters: [
7769
+ "@",
7770
+ "(",
7771
+ ",",
7772
+ "."
7773
+ ]
7774
+ };
7775
+ async getCompletion(document, params) {
7776
+ try {
7777
+ return await super.getCompletion(document, params);
7778
+ } catch (e) {
7779
+ console.error("Completion error:", e.message);
7780
+ return void 0;
7781
+ }
7782
+ }
7783
+ completionFor(context, next, acceptor) {
7784
+ if (isDataModelAttribute(context.node) || isDataFieldAttribute(context.node)) {
7785
+ const completions = this.getCompletionFromHint(context.node);
7786
+ if (completions) {
7787
+ completions.forEach((c) => acceptor(context, c));
7788
+ return;
7789
+ }
7790
+ }
7791
+ return super.completionFor(context, next, acceptor);
7792
+ }
7793
+ getCompletionFromHint(contextNode) {
7794
+ const unfilledParams = this.getUnfilledAttributeParams(contextNode);
7795
+ const nextParam = unfilledParams[0];
7796
+ if (!nextParam) {
7797
+ return void 0;
7798
+ }
7799
+ const hintAttr = getAttribute(nextParam, "@@@completionHint");
7800
+ if (hintAttr) {
7801
+ const hint = hintAttr.args[0];
7802
+ if (hint?.value) {
7803
+ if (isArrayExpr(hint.value)) {
7804
+ return hint.value.items.map((item) => {
7805
+ return {
7806
+ label: `${item.value}`,
7807
+ kind: CompletionItemKind.Value,
7808
+ detail: "Parameter",
7809
+ sortText: "0"
7810
+ };
7811
+ });
7812
+ }
7813
+ }
7814
+ }
7815
+ return void 0;
7816
+ }
7817
+ // TODO: this doesn't work when the file contains parse errors
7818
+ getUnfilledAttributeParams(contextNode) {
7819
+ try {
7820
+ const params = contextNode.decl.ref?.params;
7821
+ if (params) {
7822
+ const args = contextNode.args;
7823
+ let unfilledParams = [
7824
+ ...params
7825
+ ];
7826
+ args.forEach((arg) => {
7827
+ if (arg.name) {
7828
+ unfilledParams = unfilledParams.filter((p) => p.name !== arg.name);
7829
+ } else {
7830
+ unfilledParams.shift();
7831
+ }
7832
+ });
7833
+ return unfilledParams;
7834
+ }
7835
+ } catch {
7836
+ }
7837
+ return [];
7838
+ }
7839
+ completionForCrossReference(context, crossRef, acceptor) {
7840
+ if (crossRef.property === "member" && !isMemberAccessExpr(context.node)) {
7841
+ return;
7842
+ }
7843
+ const customAcceptor = /* @__PURE__ */ __name((context2, item) => {
7844
+ if (item.insertText?.startsWith("@@@") || item.label?.startsWith("@@@")) {
7845
+ return;
7846
+ }
7847
+ if ("nodeDescription" in item) {
7848
+ const node = this.getAstNode(item.nodeDescription);
7849
+ if (!node) {
7850
+ return;
7851
+ }
7852
+ if ((isEnum(node) || isEnumField(node)) && isFromStdlib(node)) {
7853
+ return;
7854
+ }
7855
+ if ((isDataModelAttribute(context2.node) || isDataFieldAttribute(context2.node)) && !this.filterAttributeApplicationCompletion(context2.node, node)) {
7856
+ return;
7857
+ }
7858
+ }
7859
+ acceptor(context2, item);
7860
+ }, "customAcceptor");
7861
+ return super.completionForCrossReference(context, crossRef, customAcceptor);
7862
+ }
7863
+ completionForKeyword(context, keyword, acceptor) {
7864
+ const customAcceptor = /* @__PURE__ */ __name((context2, item) => {
7865
+ if (!this.filterKeywordForContext(context2, keyword.value)) {
7866
+ return;
7867
+ }
7868
+ acceptor(context2, item);
7869
+ }, "customAcceptor");
7870
+ return super.completionForKeyword(context, keyword, customAcceptor);
7871
+ }
7872
+ filterKeywordForContext(context, keyword) {
7873
+ if (isInvocationExpr(context.node)) {
7874
+ return [
7875
+ "true",
7876
+ "false",
7877
+ "null",
7878
+ "this"
7879
+ ].includes(keyword);
7880
+ } else if (isDataModelAttribute(context.node) || isDataFieldAttribute(context.node)) {
7881
+ const exprContext = this.getAttributeContextType(context.node);
7882
+ if (exprContext === "DefaultValue") {
7883
+ return [
7884
+ "true",
7885
+ "false",
7886
+ "null"
7887
+ ].includes(keyword);
7888
+ } else {
7889
+ return [
7890
+ "true",
7891
+ "false",
7892
+ "null",
7893
+ "this"
7894
+ ].includes(keyword);
7895
+ }
7896
+ } else {
7897
+ return true;
7898
+ }
7899
+ }
7900
+ filterAttributeApplicationCompletion(contextNode, node) {
7901
+ const attrContextType = this.getAttributeContextType(contextNode);
7902
+ if (isFunctionDecl(node) && attrContextType) {
7903
+ const funcExprContextAttr = getAttribute(node, "@@@expressionContext");
7904
+ if (funcExprContextAttr && funcExprContextAttr.args[0]) {
7905
+ const arg = funcExprContextAttr.args[0];
7906
+ if (isArrayExpr(arg.value)) {
7907
+ return arg.value.items.some((item) => isEnumFieldReference(item) && item.target.$refText === attrContextType);
7908
+ }
7909
+ }
7910
+ return false;
7911
+ }
7912
+ if (isDataField(node)) {
7913
+ return attrContextType !== "DefaultValue";
7914
+ }
7915
+ return true;
7916
+ }
7917
+ getAttributeContextType(node) {
7918
+ return match3(node.decl.$refText).with("@default", () => "DefaultValue").with(P2.union("@@allow", "@allow", "@@deny", "@deny"), () => "AccessPolicy").with("@@validate", () => "ValidationRule").otherwise(() => void 0);
7919
+ }
7920
+ createReferenceCompletionItem(nodeDescription) {
7921
+ const node = this.getAstNode(nodeDescription);
7922
+ const documentation = this.getNodeDocumentation(node);
7923
+ return match3(node).when(isDataModel, () => ({
7924
+ nodeDescription,
7925
+ kind: CompletionItemKind.Class,
7926
+ detail: "Model",
7927
+ sortText: "1",
7928
+ documentation
7929
+ })).when(isTypeDef, () => ({
7930
+ nodeDescription,
7931
+ kind: CompletionItemKind.Class,
7932
+ detail: "Type",
7933
+ sortText: "1",
7934
+ documentation
7935
+ })).when(isDataField, () => ({
7936
+ nodeDescription,
7937
+ kind: CompletionItemKind.Field,
7938
+ detail: "Field",
7939
+ sortText: "0",
7940
+ documentation
7941
+ })).when(isEnum, () => ({
7942
+ nodeDescription,
7943
+ kind: CompletionItemKind.Class,
7944
+ detail: "Enum",
7945
+ sortText: "1",
7946
+ documentation
7947
+ })).when(isEnumField, (d) => {
7948
+ const container = d.$container;
7949
+ return {
7950
+ nodeDescription,
7951
+ kind: CompletionItemKind.Enum,
7952
+ detail: `Value of enum "${container.name}"`,
7953
+ sortText: "1",
7954
+ documentation
7955
+ };
7956
+ }).when(isFunctionDecl, () => ({
7957
+ nodeDescription,
7958
+ insertText: this.getFunctionInsertText(nodeDescription),
7959
+ kind: CompletionItemKind.Function,
7960
+ detail: "Function",
7961
+ sortText: "1",
7962
+ documentation
7963
+ })).when(isAttribute, () => ({
7964
+ nodeDescription,
7965
+ insertText: this.getAttributeInsertText(nodeDescription),
7966
+ kind: CompletionItemKind.Property,
7967
+ detail: "Attribute",
7968
+ sortText: "1",
7969
+ documentation
7970
+ })).otherwise(() => ({
7971
+ nodeDescription,
7972
+ kind: CompletionItemKind.Reference,
7973
+ detail: nodeDescription.type,
7974
+ sortText: "2",
7975
+ documentation
7976
+ }));
7977
+ }
7978
+ getFunctionInsertText(nodeDescription) {
7979
+ const node = this.getAstNode(nodeDescription);
7980
+ if (isFunctionDecl(node)) {
7981
+ if (node.params.some((p) => !p.optional)) {
7982
+ return nodeDescription.name;
7983
+ }
7984
+ }
7985
+ return `${nodeDescription.name}()`;
7986
+ }
7987
+ getAttributeInsertText(nodeDescription) {
7988
+ const node = this.getAstNode(nodeDescription);
7989
+ if (isAttribute(node)) {
7990
+ if (node.name === "@relation") {
7991
+ return `${nodeDescription.name}(fields: [], references: [])`;
7992
+ }
7993
+ }
7994
+ return nodeDescription.name;
7995
+ }
7996
+ getAstNode(nodeDescription) {
7997
+ let node = nodeDescription.node;
7998
+ if (!node) {
7999
+ const doc = this.getOrCreateDocumentSync(nodeDescription);
8000
+ if (!doc) {
8001
+ return void 0;
8002
+ }
8003
+ node = this.services.workspace.AstNodeLocator.getAstNode(doc.parseResult.value, nodeDescription.path);
8004
+ if (!node) {
8005
+ return void 0;
8006
+ }
8007
+ }
8008
+ return node;
8009
+ }
8010
+ getOrCreateDocumentSync(nodeDescription) {
8011
+ let doc = this.services.shared.workspace.LangiumDocuments.getDocument(nodeDescription.documentUri);
8012
+ if (!doc) {
8013
+ try {
8014
+ const content = fs2.readFileSync(nodeDescription.documentUri.fsPath, "utf-8");
8015
+ doc = this.services.shared.workspace.LangiumDocuments.createDocument(nodeDescription.documentUri, content);
8016
+ } catch {
8017
+ console.warn("Failed to read or create document:", nodeDescription.documentUri);
8018
+ return void 0;
8019
+ }
8020
+ }
8021
+ return doc;
8022
+ }
8023
+ getNodeDocumentation(node) {
8024
+ if (!node) {
8025
+ return void 0;
8026
+ }
8027
+ const md = this.commentsToMarkdown(node);
8028
+ return {
8029
+ kind: "markdown",
8030
+ value: md
8031
+ };
8032
+ }
8033
+ commentsToMarkdown(node) {
8034
+ const md = this.services.documentation.DocumentationProvider.getDocumentation(node) ?? "";
8035
+ const zModelGenerator = new ZModelCodeGenerator();
8036
+ const docs = [];
8037
+ try {
8038
+ match3(node).when(isAttribute, (attr) => {
8039
+ docs.push("```prisma", zModelGenerator.generate(attr), "```");
8040
+ }).when(isFunctionDecl, (func2) => {
8041
+ docs.push("```ts", zModelGenerator.generate(func2), "```");
8042
+ }).when(isDataModel, (model) => {
8043
+ docs.push("```prisma", `model ${model.name} { ... }`, "```");
8044
+ }).when(isEnum, (enumDecl) => {
8045
+ docs.push("```prisma", zModelGenerator.generate(enumDecl), "```");
8046
+ }).when(isDataField, (field) => {
8047
+ docs.push(`${field.name}: ${field.type.type ?? field.type.reference?.$refText}`);
8048
+ }).otherwise((ast) => {
8049
+ const name = ast.name;
8050
+ if (name) {
8051
+ docs.push(name);
8052
+ }
8053
+ });
8054
+ } catch {
8055
+ }
8056
+ if (md) {
8057
+ docs.push("___", md);
8058
+ }
8059
+ return docs.join("\n");
8060
+ }
8061
+ };
8062
+
8063
+ // src/zmodel-definition.ts
8064
+ import { DefaultDefinitionProvider } from "langium/lsp";
8065
+ import { LocationLink, Range } from "vscode-languageserver";
8066
+ var ZModelDefinitionProvider = class extends DefaultDefinitionProvider {
8067
+ static {
8068
+ __name(this, "ZModelDefinitionProvider");
8069
+ }
8070
+ documents;
8071
+ constructor(services) {
8072
+ super(services);
8073
+ this.documents = services.shared.workspace.LangiumDocuments;
8074
+ }
8075
+ collectLocationLinks(sourceCstNode, _params) {
8076
+ if (isModelImport(sourceCstNode.astNode)) {
8077
+ const importedModel = resolveImport(this.documents, sourceCstNode.astNode);
8078
+ if (importedModel?.$document) {
8079
+ const targetObject = importedModel;
8080
+ const selectionRange = this.nameProvider.getNameNode(targetObject)?.range ?? Range.create(0, 0, 0, 0);
8081
+ const previewRange = targetObject.$cstNode?.range ?? Range.create(0, 0, 0, 0);
8082
+ return [
8083
+ LocationLink.create(importedModel.$document.uri.toString(), previewRange, selectionRange, sourceCstNode.range)
8084
+ ];
8085
+ }
8086
+ return void 0;
8087
+ }
8088
+ return super.collectLocationLinks(sourceCstNode, _params);
8089
+ }
8090
+ };
8091
+
7173
8092
  // src/zmodel-document-builder.ts
7174
8093
  import { DefaultDocumentBuilder } from "langium";
7175
8094
  var ZModelDocumentBuilder = class extends DefaultDocumentBuilder {
@@ -7199,9 +8118,114 @@ var ZModelDocumentBuilder = class extends DefaultDocumentBuilder {
7199
8118
  }
7200
8119
  };
7201
8120
 
8121
+ // src/zmodel-documentation-provider.ts
8122
+ import { JSDocDocumentationProvider } from "langium";
8123
+ var ZModelDocumentationProvider = class extends JSDocDocumentationProvider {
8124
+ static {
8125
+ __name(this, "ZModelDocumentationProvider");
8126
+ }
8127
+ getDocumentation(node) {
8128
+ if ("comments" in node && Array.isArray(node.comments) && node.comments.length > 0) {
8129
+ return node.comments.map((c) => c.replace(/^[/]*\s*/, "")).join("\n");
8130
+ }
8131
+ return super.getDocumentation(node);
8132
+ }
8133
+ };
8134
+
8135
+ // src/zmodel-formatter.ts
8136
+ import { AbstractFormatter, Formatting } from "langium/lsp";
8137
+ var ZModelFormatter = class extends AbstractFormatter {
8138
+ static {
8139
+ __name(this, "ZModelFormatter");
8140
+ }
8141
+ formatOptions;
8142
+ configurationProvider;
8143
+ constructor(services) {
8144
+ super();
8145
+ this.configurationProvider = services.shared.workspace.ConfigurationProvider;
8146
+ }
8147
+ format(node) {
8148
+ const formatter = this.getNodeFormatter(node);
8149
+ if (isDataField(node)) {
8150
+ if (isDataModel(node.$container) || isTypeDef(node.$container)) {
8151
+ const dataModel = node.$container;
8152
+ const compareFn = /* @__PURE__ */ __name((a, b) => b - a, "compareFn");
8153
+ const maxNameLength = dataModel.fields.map((x) => x.name.length).sort(compareFn)[0] ?? 0;
8154
+ const maxTypeLength = dataModel.fields.map(this.getFieldTypeLength).sort(compareFn)[0] ?? 0;
8155
+ formatter.property("type").prepend(Formatting.spaces(maxNameLength - node.name.length + 1));
8156
+ if (node.attributes.length > 0) {
8157
+ formatter.node(node.attributes[0]).prepend(Formatting.spaces(maxTypeLength - this.getFieldTypeLength(node) + 1));
8158
+ formatter.nodes(...node.attributes.slice(1)).prepend(Formatting.oneSpace());
8159
+ }
8160
+ } else {
8161
+ formatter.property("type").prepend(Formatting.oneSpace());
8162
+ if (node.attributes.length > 0) {
8163
+ formatter.properties("attributes").prepend(Formatting.oneSpace());
8164
+ }
8165
+ }
8166
+ } else if (isDataFieldAttribute(node)) {
8167
+ formatter.keyword("(").surround(Formatting.noSpace());
8168
+ formatter.keyword(")").prepend(Formatting.noSpace());
8169
+ formatter.keyword(",").append(Formatting.oneSpace());
8170
+ if (node.args.length > 1) {
8171
+ formatter.nodes(...node.args.slice(1)).prepend(Formatting.oneSpace());
8172
+ }
8173
+ } else if (isAttributeArg(node)) {
8174
+ formatter.keyword(":").prepend(Formatting.noSpace());
8175
+ formatter.keyword(":").append(Formatting.oneSpace());
8176
+ } else if (isAbstractDeclaration(node)) {
8177
+ const bracesOpen = formatter.keyword("{");
8178
+ const bracesClose = formatter.keyword("}");
8179
+ formatter.interior(bracesOpen, bracesClose).prepend(Formatting.indent({
8180
+ allowMore: true
8181
+ }));
8182
+ bracesOpen.prepend(Formatting.oneSpace());
8183
+ bracesClose.prepend(Formatting.newLine());
8184
+ } else if (isModel(node)) {
8185
+ const model = node;
8186
+ const nodes = formatter.nodes(...model.declarations);
8187
+ nodes.prepend(Formatting.noIndent());
8188
+ }
8189
+ }
8190
+ formatDocument(document, params) {
8191
+ this.formatOptions = params.options;
8192
+ this.configurationProvider.getConfiguration(ZModelLanguageMetaData.languageId, "format").then((config) => {
8193
+ if (config) {
8194
+ }
8195
+ });
8196
+ return super.formatDocument(document, params);
8197
+ }
8198
+ getFormatOptions() {
8199
+ return this.formatOptions;
8200
+ }
8201
+ getIndent() {
8202
+ return 1;
8203
+ }
8204
+ getFieldTypeLength(field) {
8205
+ let length;
8206
+ if (field.type.type) {
8207
+ length = field.type.type.length;
8208
+ } else if (field.type.reference) {
8209
+ length = field.type.reference.$refText.length;
8210
+ } else if (isDataField(field) && field.type.unsupported) {
8211
+ const name = `Unsupported("${field.type.unsupported.value.value}")`;
8212
+ length = name.length;
8213
+ } else {
8214
+ length = 1;
8215
+ }
8216
+ if (field.type.optional) {
8217
+ length += 1;
8218
+ }
8219
+ if (field.type.array) {
8220
+ length += 2;
8221
+ }
8222
+ return length;
8223
+ }
8224
+ };
8225
+
7202
8226
  // src/zmodel-linker.ts
7203
8227
  import { AstUtils as AstUtils6, Cancellation, DefaultLinker, DocumentState, interruptAndCheck } from "langium";
7204
- import { match as match2 } from "ts-pattern";
8228
+ import { match as match4 } from "ts-pattern";
7205
8229
  var ZModelLinker = class extends DefaultLinker {
7206
8230
  static {
7207
8231
  __name(this, "ZModelLinker");
@@ -7390,7 +8414,7 @@ var ZModelLinker = class extends DefaultLinker {
7390
8414
  }
7391
8415
  }
7392
8416
  resolveLiteral(node) {
7393
- const type = match2(node).when(isStringLiteral, () => "String").when(isBooleanLiteral, () => "Boolean").when(isNumberLiteral, () => "Int").exhaustive();
8417
+ const type = match4(node).when(isStringLiteral, () => "String").when(isBooleanLiteral, () => "Boolean").when(isNumberLiteral, () => "Int").exhaustive();
7394
8418
  if (type) {
7395
8419
  this.resolveToBuiltinTypeOrDecl(node, type);
7396
8420
  }
@@ -7558,7 +8582,7 @@ var ZModelLinker = class extends DefaultLinker {
7558
8582
 
7559
8583
  // src/zmodel-scope.ts
7560
8584
  import { AstUtils as AstUtils7, DefaultScopeComputation, DefaultScopeProvider, EMPTY_SCOPE, StreamScope, UriUtils, interruptAndCheck as interruptAndCheck2 } from "langium";
7561
- import { match as match3 } from "ts-pattern";
8585
+ import { match as match5 } from "ts-pattern";
7562
8586
  var ZModelScopeComputation = class extends DefaultScopeComputation {
7563
8587
  static {
7564
8588
  __name(this, "ZModelScopeComputation");
@@ -7635,7 +8659,7 @@ var ZModelScopeProvider = class extends DefaultScopeProvider {
7635
8659
  // isAuthOrAuthMemberAccess(node.operand) ||
7636
8660
  !!AstUtils7.getContainerOfType(node, isTypeDef)
7637
8661
  );
7638
- return match3(node.operand).when(isReferenceExpr, (operand) => {
8662
+ return match5(node.operand).when(isReferenceExpr, (operand) => {
7639
8663
  const ref = operand.target.ref;
7640
8664
  if (isDataField(ref)) {
7641
8665
  return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
@@ -7664,7 +8688,7 @@ var ZModelScopeProvider = class extends DefaultScopeProvider {
7664
8688
  const globalScope = this.getGlobalScope(referenceType, context);
7665
8689
  const collection = collectionPredicate.left;
7666
8690
  const allowTypeDefScope = false;
7667
- return match3(collection).when(isReferenceExpr, (expr) => {
8691
+ return match5(collection).when(isReferenceExpr, (expr) => {
7668
8692
  const ref = expr.target.ref;
7669
8693
  if (isDataField(ref)) {
7670
8694
  return this.createScopeForContainer(ref.type.reference?.ref, globalScope, allowTypeDefScope);
@@ -7726,9 +8750,93 @@ function getCollectionPredicateContext(node) {
7726
8750
  }
7727
8751
  __name(getCollectionPredicateContext, "getCollectionPredicateContext");
7728
8752
 
8753
+ // src/zmodel-semantic.ts
8754
+ import { AbstractSemanticTokenProvider } from "langium/lsp";
8755
+ import { SemanticTokenTypes } from "vscode-languageserver";
8756
+ var ZModelSemanticTokenProvider = class extends AbstractSemanticTokenProvider {
8757
+ static {
8758
+ __name(this, "ZModelSemanticTokenProvider");
8759
+ }
8760
+ highlightElement(node, acceptor) {
8761
+ if (isDataModel(node)) {
8762
+ acceptor({
8763
+ node,
8764
+ property: "name",
8765
+ type: SemanticTokenTypes.type
8766
+ });
8767
+ acceptor({
8768
+ node,
8769
+ property: "mixins",
8770
+ type: SemanticTokenTypes.type
8771
+ });
8772
+ acceptor({
8773
+ node,
8774
+ property: "baseModel",
8775
+ type: SemanticTokenTypes.type
8776
+ });
8777
+ } else if (isDataSource(node) || isGeneratorDecl(node) || isPlugin(node) || isEnum(node) || isTypeDef(node)) {
8778
+ acceptor({
8779
+ node,
8780
+ property: "name",
8781
+ type: SemanticTokenTypes.type
8782
+ });
8783
+ } else if (isDataField(node) || isConfigField(node) || isAttributeArg(node) || isPluginField(node) || isEnumField(node)) {
8784
+ acceptor({
8785
+ node,
8786
+ property: "name",
8787
+ type: SemanticTokenTypes.variable
8788
+ });
8789
+ } else if (isDataFieldType(node)) {
8790
+ if (node.type) {
8791
+ acceptor({
8792
+ node,
8793
+ property: "type",
8794
+ type: SemanticTokenTypes.type
8795
+ });
8796
+ } else {
8797
+ acceptor({
8798
+ node,
8799
+ property: "reference",
8800
+ type: SemanticTokenTypes.macro
8801
+ });
8802
+ }
8803
+ } else if (isDataModelAttribute(node) || isDataFieldAttribute(node) || isInternalAttribute(node)) {
8804
+ acceptor({
8805
+ node,
8806
+ property: "decl",
8807
+ type: SemanticTokenTypes.function
8808
+ });
8809
+ } else if (isInvocationExpr(node)) {
8810
+ acceptor({
8811
+ node,
8812
+ property: "function",
8813
+ type: SemanticTokenTypes.function
8814
+ });
8815
+ } else if (isFunctionDecl(node) || isAttribute(node)) {
8816
+ acceptor({
8817
+ node,
8818
+ property: "name",
8819
+ type: SemanticTokenTypes.function
8820
+ });
8821
+ } else if (isReferenceExpr(node)) {
8822
+ acceptor({
8823
+ node,
8824
+ property: "target",
8825
+ type: SemanticTokenTypes.variable
8826
+ });
8827
+ } else if (isMemberAccessExpr(node)) {
8828
+ acceptor({
8829
+ node,
8830
+ property: "member",
8831
+ type: SemanticTokenTypes.property
8832
+ });
8833
+ }
8834
+ }
8835
+ };
8836
+
7729
8837
  // src/zmodel-workspace-manager.ts
7730
8838
  import { DefaultWorkspaceManager, URI as URI2 } from "langium";
7731
- import fs2 from "fs";
8839
+ import fs3 from "fs";
7732
8840
  import path2 from "path";
7733
8841
  import { fileURLToPath as fileURLToPath2 } from "url";
7734
8842
  var ZModelWorkspaceManager = class extends DefaultWorkspaceManager {
@@ -7754,7 +8862,7 @@ var ZModelWorkspaceManager = class extends DefaultWorkspaceManager {
7754
8862
  });
7755
8863
  const languagePackageDir = path2.dirname(languagePackagePath);
7756
8864
  const candidateStdlibPath = path2.join(languagePackageDir, "res", STD_LIB_MODULE_NAME);
7757
- if (fs2.existsSync(candidateStdlibPath)) {
8865
+ if (fs3.existsSync(candidateStdlibPath)) {
7758
8866
  installedStdlibPath = candidateStdlibPath;
7759
8867
  console.log(`Found installed zenstack package stdlib at: ${installedStdlibPath}`);
7760
8868
  break;
@@ -7784,6 +8892,16 @@ var ZModelLanguageModule = {
7784
8892
  },
7785
8893
  validation: {
7786
8894
  ZModelValidator: /* @__PURE__ */ __name((services) => new ZModelValidator(services), "ZModelValidator")
8895
+ },
8896
+ lsp: {
8897
+ Formatter: /* @__PURE__ */ __name((services) => new ZModelFormatter(services), "Formatter"),
8898
+ DefinitionProvider: /* @__PURE__ */ __name((services) => new ZModelDefinitionProvider(services), "DefinitionProvider"),
8899
+ CompletionProvider: /* @__PURE__ */ __name((services) => new ZModelCompletionProvider(services), "CompletionProvider"),
8900
+ SemanticTokenProvider: /* @__PURE__ */ __name((services) => new ZModelSemanticTokenProvider(services), "SemanticTokenProvider")
8901
+ },
8902
+ documentation: {
8903
+ CommentProvider: /* @__PURE__ */ __name((services) => new ZModelCommentProvider(services), "CommentProvider"),
8904
+ DocumentationProvider: /* @__PURE__ */ __name((services) => new ZModelDocumentationProvider(services), "DocumentationProvider")
7787
8905
  }
7788
8906
  };
7789
8907
  var ZModelSharedModule = {
@@ -7813,10 +8931,16 @@ function createZModelLanguageServices(context, logToConsole = false) {
7813
8931
  const schemaPath = fileURLToPath3(doc.uri.toString());
7814
8932
  const pluginSchemas = getPluginDocuments(doc.parseResult.value, schemaPath);
7815
8933
  for (const plugin of pluginSchemas) {
7816
- const pluginDoc = await shared.workspace.LangiumDocuments.getOrCreateDocument(URI3.file(path3.resolve(plugin)));
7817
- shared.workspace.IndexManager.updateContent(pluginDoc);
7818
- if (logToConsole) {
7819
- console.log(`Loaded plugin model: ${plugin}`);
8934
+ const pluginDocUri = URI3.file(path3.resolve(plugin));
8935
+ let pluginDoc = shared.workspace.LangiumDocuments.getDocument(pluginDocUri);
8936
+ if (!pluginDoc) {
8937
+ pluginDoc = await shared.workspace.LangiumDocuments.getOrCreateDocument(pluginDocUri);
8938
+ if (pluginDoc) {
8939
+ shared.workspace.IndexManager.updateContent(pluginDoc);
8940
+ if (logToConsole) {
8941
+ console.log(`Loaded plugin model: ${plugin}`);
8942
+ }
8943
+ }
7820
8944
  }
7821
8945
  }
7822
8946
  }
@@ -7845,7 +8969,7 @@ async function loadDocument(fileName, additionalModelFiles = []) {
7845
8969
  warnings: []
7846
8970
  };
7847
8971
  }
7848
- if (!fs3.existsSync(fileName)) {
8972
+ if (!fs4.existsSync(fileName)) {
7849
8973
  return {
7850
8974
  success: false,
7851
8975
  errors: [
@@ -7983,6 +9107,7 @@ function validationAfterImportMerge(model) {
7983
9107
  }
7984
9108
  __name(validationAfterImportMerge, "validationAfterImportMerge");
7985
9109
  export {
9110
+ ZModelCodeGenerator,
7986
9111
  ZModelLanguageMetaData,
7987
9112
  ZModelLanguageModule,
7988
9113
  ZModelSharedModule,