Skip to content

Commit 20d5bfc

Browse files
authored
fix: enable auto completion inside attribute (#949)
1 parent acb23d1 commit 20d5bfc

16 files changed

+783
-356
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
<a href="https://www.npmjs.com/package/zenstack">
1010
<img src="https://img.shields.io/npm/v/zenstack">
1111
</a>
12+
<a href="https://www.npmjs.com/package/zenstack">
13+
<img src="https://img.shields.io/npm/dm/zenstack">
14+
</a>
1215
<img src="https://github.com/zenstackhq/zenstack/actions/workflows/build-test.yml/badge.svg">
1316
<a href="https://twitter.com/zenstackhq">
1417
<img src="https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Fgithub.com%2Fzenstackhq%2Fzenstack">

packages/language/src/generated/ast.ts

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ export function isAbstractDeclaration(item: unknown): item is AbstractDeclaratio
1414
return reflection.isInstance(item, AbstractDeclaration);
1515
}
1616

17-
export type AttributeName = DataModelAttributeName | DataModelFieldAttributeName | InternalAttributeName;
18-
19-
export function isAttributeName(item: unknown): item is AttributeName {
20-
return isDataModelAttributeName(item) || isDataModelFieldAttributeName(item) || isInternalAttributeName(item);
21-
}
22-
2317
export type Boolean = boolean;
2418

2519
export function isBoolean(item: unknown): item is Boolean {
@@ -40,18 +34,6 @@ export function isConfigExpr(item: unknown): item is ConfigExpr {
4034
return reflection.isInstance(item, ConfigExpr);
4135
}
4236

43-
export type DataModelAttributeName = string;
44-
45-
export function isDataModelAttributeName(item: unknown): item is DataModelAttributeName {
46-
return typeof item === 'string';
47-
}
48-
49-
export type DataModelFieldAttributeName = string;
50-
51-
export function isDataModelFieldAttributeName(item: unknown): item is DataModelFieldAttributeName {
52-
return typeof item === 'string';
53-
}
54-
5537
export type Expression = ArrayExpr | BinaryExpr | InvocationExpr | LiteralExpr | MemberAccessExpr | NullExpr | ObjectExpr | ReferenceExpr | ThisExpr | UnaryExpr;
5638

5739
export const Expression = 'Expression';
@@ -66,12 +48,6 @@ export function isExpressionType(item: unknown): item is ExpressionType {
6648
return item === 'String' || item === 'Int' || item === 'Float' || item === 'Boolean' || item === 'DateTime' || item === 'Null' || item === 'Object' || item === 'Any' || item === 'Unsupported';
6749
}
6850

69-
export type InternalAttributeName = string;
70-
71-
export function isInternalAttributeName(item: unknown): item is InternalAttributeName {
72-
return typeof item === 'string';
73-
}
74-
7551
export type LiteralExpr = BooleanLiteral | NumberLiteral | StringLiteral;
7652

7753
export const LiteralExpr = 'LiteralExpr';
@@ -80,12 +56,6 @@ export function isLiteralExpr(item: unknown): item is LiteralExpr {
8056
return reflection.isInstance(item, LiteralExpr);
8157
}
8258

83-
export type QualifiedName = string;
84-
85-
export function isQualifiedName(item: unknown): item is QualifiedName {
86-
return typeof item === 'string';
87-
}
88-
8959
export type ReferenceTarget = DataModelField | EnumField | FunctionParam;
9060

9161
export const ReferenceTarget = 'ReferenceTarget';
@@ -137,7 +107,8 @@ export interface Attribute extends AstNode {
137107
readonly $container: Model;
138108
readonly $type: 'Attribute';
139109
attributes: Array<InternalAttribute>
140-
name: AttributeName
110+
comments: Array<string>
111+
name: string
141112
params: Array<AttributeParam>
142113
}
143114

@@ -163,6 +134,8 @@ export function isAttributeArg(item: unknown): item is AttributeArg {
163134
export interface AttributeParam extends AstNode {
164135
readonly $container: Attribute;
165136
readonly $type: 'AttributeParam';
137+
attributes: Array<InternalAttribute>
138+
comments: Array<string>
166139
default: boolean
167140
name: RegularID
168141
type: AttributeParamType
@@ -454,7 +427,7 @@ export function isGeneratorDecl(item: unknown): item is GeneratorDecl {
454427
}
455428

456429
export interface InternalAttribute extends AstNode {
457-
readonly $container: Attribute | FunctionDecl;
430+
readonly $container: Attribute | AttributeParam | FunctionDecl;
458431
readonly $type: 'InternalAttribute';
459432
args: Array<AttributeArg>
460433
decl: Reference<Attribute>
@@ -519,7 +492,7 @@ export function isModelImport(item: unknown): item is ModelImport {
519492
export interface NullExpr extends AstNode {
520493
readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | UnaryExpr | UnsupportedFieldType;
521494
readonly $type: 'NullExpr';
522-
value: string
495+
value: 'null'
523496
}
524497

525498
export const NullExpr = 'NullExpr';
@@ -619,7 +592,7 @@ export function isStringLiteral(item: unknown): item is StringLiteral {
619592
export interface ThisExpr extends AstNode {
620593
readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | UnaryExpr | UnsupportedFieldType;
621594
readonly $type: 'ThisExpr';
622-
value: string
595+
value: 'this'
623596
}
624597

625598
export const ThisExpr = 'ThisExpr';
@@ -801,6 +774,7 @@ export class ZModelAstReflection extends AbstractAstReflection {
801774
name: 'Attribute',
802775
mandatory: [
803776
{ name: 'attributes', type: 'array' },
777+
{ name: 'comments', type: 'array' },
804778
{ name: 'params', type: 'array' }
805779
]
806780
};
@@ -809,6 +783,8 @@ export class ZModelAstReflection extends AbstractAstReflection {
809783
return {
810784
name: 'AttributeParam',
811785
mandatory: [
786+
{ name: 'attributes', type: 'array' },
787+
{ name: 'comments', type: 'array' },
812788
{ name: 'default', type: 'boolean' }
813789
]
814790
};

0 commit comments

Comments
 (0)