Skip to content

Commit

Permalink
fix: allow tripple comments at the end of the field
Browse files Browse the repository at this point in the history
  • Loading branch information
jiashengguo committed Dec 31, 2023
1 parent e4aeee3 commit 33b62ce
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
26 changes: 26 additions & 0 deletions packages/language/src/generated/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2143,6 +2143,19 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"arguments": []
},
"cardinality": "*"
},
{
"$type": "Assignment",
"feature": "comments",
"operator": "+=",
"terminal": {
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@69"
},
"arguments": []
},
"cardinality": "*"
}
]
},
Expand Down Expand Up @@ -2409,6 +2422,19 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"arguments": []
},
"cardinality": "*"
},
{
"$type": "Assignment",
"feature": "comments",
"operator": "+=",
"terminal": {
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@69"
},
"arguments": []
},
"cardinality": "*"
}
]
},
Expand Down
4 changes: 2 additions & 2 deletions packages/language/src/zmodel.langium
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ DataModel:

DataModelField:
(comments+=TRIPLE_SLASH_COMMENT)*
name=RegularID type=DataModelFieldType (attributes+=DataModelFieldAttribute)*;
name=RegularID type=DataModelFieldType (attributes+=DataModelFieldAttribute)* (comments+=TRIPLE_SLASH_COMMENT)*;

DataModelFieldType:
(type=BuiltinType | unsupported=UnsupportedFieldType | reference=[TypeDeclaration:RegularID]) (array?='[' ']')? (optional?='?')?;
Expand All @@ -209,7 +209,7 @@ Enum:

EnumField:
(comments+=TRIPLE_SLASH_COMMENT)*
name=RegularID (attributes+=DataModelFieldAttribute)*;
name=RegularID (attributes+=DataModelFieldAttribute)* (comments+=TRIPLE_SLASH_COMMENT)*;

// function
FunctionDecl:
Expand Down
30 changes: 30 additions & 0 deletions packages/schema/tests/generator/prisma-generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,36 @@ describe('Prisma generator test', () => {
expect(content).toContain(`/// @TypeGraphQL.field(name: 'bar')`);
});

it('triple slash comments complex', async () => {
const model = await loadModel(`
datasource db {
provider = 'sqlite'
url = 'file:dev.db'
}
/// This is a comment
model Foo {
id String @id
/// Supposed to be for value, but will be counted for id
value Int /// comment for value
}
`);

const { name } = tmp.fileSync({ postfix: '.prisma' });
await new PrismaSchemaGenerator().generate(model, {
name: 'Prisma',
provider: '@core/prisma',
schemaPath: 'schema.zmodel',
output: name,
});

const content = fs.readFileSync(name, 'utf-8');
await getDMMF({ datamodel: content });

expect(content).toContain('/// Supposed to be for value, but will be counted for id');
expect(content).toContain('/// comment for value');
});

it('model and field mapping', async () => {
const model = await loadModel(`
datasource db {
Expand Down

0 comments on commit 33b62ce

Please sign in to comment.