Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of validate for Model Statement and Scalar. #2100

Closed
wants to merge 2 commits into from

Conversation

marron-at-work
Copy link

Adds support for validate on Model Statements and Scalars (issue #2041):

 model M {
    ii: int64;

    @doc("Check that ii is greater than or equal to 0")
    validate chkii: ii >= 0;
}
scalar S extends int64 {
    validate chkv: value >= 0;
}

Tests for basic functionality.
TODO: prettier formatting.

@github-actions
Copy link
Contributor

Changes in this PR will be published to the following url to try(check status of TypeSpec Pull Request Try It pipeline for publish status):
Playground: https://cadlplayground.z22.web.core.windows.net/prs/2100/

Website: https://cadlwebsite.z1.web.core.windows.net/prs/2100/

@bterlson bterlson changed the base branch from main to validate June 29, 2023 23:22
});

if (id.sv === "validate" && token() === Token.Identifier) {
const vid = parseIdentifier({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should make the id optional. It is super annoying to have to add an id, but will be needed depending on how you want to use it. Linter can of course enforce that you have id.

allowStringLiteral: true,
});

if (id.sv === "validate" && token() === Token.Identifier) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like validates reads better but I don't feel super strongly. Anyone else have feelings?

@bterlson
Copy link
Member

I've taken a look at the parser and related bits, looks great, you handled a lot of the fiddly bits. I think the only thing missing is an update to the grammar file and keyword colorization - see src/server/tmlanguage.ts. May also need updates to getSemanticTokens since validate is a conditional keyword, though would have to check what we're doing for other conditional keywords.

I will check into the checker bits tomorrow!

This was referenced Jun 30, 2023
@bterlson
Copy link
Member

bterlson commented Jul 5, 2023

@marron-at-work I think this is superceded by #2141?

@bterlson bterlson closed this Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants