- Notifications
You must be signed in to change notification settings - Fork 56
(GH-538) Add VS Code keywords, vocabulary, and dialect to dsc-lib-jsonschema #1276
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
base: main
Are you sure you want to change the base?
(GH-538) Add VS Code keywords, vocabulary, and dialect to dsc-lib-jsonschema #1276
Conversation
dsc-lib-jsonschema b2cb10f to de60313 Compare There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request adds comprehensive support for VS Code's custom JSON Schema keywords, vocabulary, and dialect to the dsc-lib-jsonschema crate. The implementation enables programmatic validation and processing of schemas that use VS Code's extended keywords for enhancing the JSON authoring experience.
Key Changes:
- Implements 14 VS Code annotation keywords (e.g.,
markdownDescription,defaultSnippets,enumDescriptions) with full validation support - Defines VS Code vocabulary and dialect meta-schemas for use in schema validation
- Adds extension methods for
SchemaandValidationOptionsto simplify working with VS Code keywords - Extends schema utility functions with methods for handling schema references and bundled resources
Reviewed changes
Copilot reviewed 53 out of 54 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
lib/dsc-lib-jsonschema/src/vscode/keywords/*.rs | Individual keyword implementations with validation logic |
lib/dsc-lib-jsonschema/src/vscode/vocabulary.rs | VS Code vocabulary schema definition with static lazy initialization |
lib/dsc-lib-jsonschema/src/vscode/dialect.rs | VS Code dialect meta schema combining Draft 2020-12 and VS Code vocabulary |
lib/dsc-lib-jsonschema/src/vscode/schema_extensions.rs | Extension methods for retrieving VS Code keyword values from schemas |
lib/dsc-lib-jsonschema/src/vscode/validation_options_extensions.rs | Extension methods for registering VS Code keywords with validators |
lib/dsc-lib-jsonschema/src/schema_utility_extensions.rs | New utility methods for reference handling and bundled resource management |
lib/dsc-lib-jsonschema/locales/*.{toml,yaml} | Internationalized strings for keyword error messages and documentation |
lib/dsc-lib-jsonschema/src/tests/vscode/**/*.rs | Comprehensive test coverage for all new functionality |
lib/dsc-lib/src/schemas/mod.rs | Added documentation cross-references for schema form variants |
build.helpers.psm1 | Enhanced i18n testing infrastructure with YAML support |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
de60313 to a98f208 Compare This change addresses the need for parsing, validating, and processing the custom JSON Schema keywords that VS Code recognizes for use in the DSC schemas and resource schemas. This change: - Defines every custom keyword that the VS Code language server for JSON recognizes as custom keywords in the `jsonschema` crate so that we can correctly validate schemas that use those keywords programmatically. The implementation in `jsonschema` is primarily intended for custom validation keywords. Every custom keyword that VS Code recognizes is an annotation keyword. They don't affect validation for instances of data. This implementation ensures that we can parse those keywords for our own use and validate that our schema definitions correctly define values for those keywords. - Defines the VS Code vocabulary, which includes the keywords. This enables us to define our own dialects which recognize the VS Code keywords. - Defines a VS Code dialect, which includes the Draft 2020-12 vocabularies and the VS Code vocabulary. - Defines the `VSCodeKeyword` enum for easier selection of keywords, given that you can't ergonomically or safely pass a _type_ in Rust functions. This replaces the previous `VSCODE_KEYWORDS` struct. - Updates the `idiomaticize_externally_tagged_enum` transform function to use the `VSCodeKeyword` enum now that `VSCODE_KEYWORDS` is removed. - Defines extension methods for the `ValidationOptions` struct from the `jsonschema` crate to make adding VS Code keywords, vocabulary, and dialect simpler and more ergonomic, participating in the builder pattern that `jsonschema` uses when creating a validator. - Defines extension methods for the `Schema` struct from the `schemars` crate to simplify working with VS COde keywords in schemas, such as retrieving the value for a keyword or checking whether the schema uses the VS Code dialect. - Adds three new extension methods to the `SchemaUtilityExtensions` trait: - `get_bundled_schema_resource_ids`, which retrieves the value of the `$id` keyword from entries in the `$defs` keyword, each of which represents a bundled schema resource. - `get_references`, which recursively retrieves the value for every `$ref` keyword in the schema. - `replace_references`, which recursively replaces the value of the `$ref` keyword from a given value to a new one specified by the caller. - `reference_is_for_bundled_resource`, which indicates whether a given value for a `$ref` keyword points to a bundled schema resource in the `$defs` keyword for the schema. This change lays the groundwork for incorporating the VS Code keywords into the schemas generated from Rust code and for defining our own vocabulary for DSC as needed.
Prior to this change, the i18n tests used simple string matching to search for translation keys in the `en-us.toml` file and the project Rust code. This change defines a new `DscProjectRustTranslationInfo` class and `Get-TranslationKey` function in the `build.helpers` module. This change reimplements the i18n tests to use the new class and function for retrieving and analyzing translation strings for Rust projects, building in support for both TOML and YAML translation files. This is required to support the translation strings for JSON Schema annotations, which are lengthy. It enables us to keep the translations for messages in the code in the `en-us.toml` file and all schema-related translation strings in separate YAML files, where the hierarchy and multi-line strings fit more naturally. This change ensures that we can continue to accurately test our translation strings, checking: - That each project with a `locales` folder defines and uses at least one translation string. - That no translation keys are defined more than once across all translation files. - That every defined translation key is used in the Rust code. - That every translation key the Rust code references is defined in a translation file for `en-us`.
a98f208 to 8d72e8b Compare There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 53 out of 54 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
| } | ||
| #endregion Documenting project functions | ||
| | ||
| #region Rust i18n type definitions and functions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used anywhere outside of the i18n tests? If not, would prefer to keep that code together in the test ps1 rather than creating a dependency on the helper module for that test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put it here for easier access to checking translations during normal development workflow, since the i18n tests are in the dsc project - when working locally I was testing against the dsc-lib-jsonschema and dsc-lib crates independently.
Happy to move it though if that's preferable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My preference would be to move it since someone reading this in the future wouldn't be aware of the separation of the code. If it was used across multiple scripts, then it would make more sense to me to have it centralized here.
PR Summary
This change:
Defines every custom keyword that the VS Code language server for JSON recognizes as custom keywords in the
jsonschemacrate so that we can correctly validate schemas that use those keywords programmatically.The implementation in
jsonschemais primarily intended for custom validation keywords. Every custom keyword that VS Code recognizes is an annotation keyword. They don't affect validation for instances of data. This implementation ensures that we can parse those keywords for our own use and validate that our schema definitions correctly define values for those keywords.Defines the VS Code vocabulary, which includes the keywords. This enables us to define our own dialects which recognize the VS Code keywords.
Defines a VS Code dialect, which includes the Draft 2020-12 vocabularies and the VS Code vocabulary.
Defines the
VSCodeKeywordenum for easier selection of keywords, given that you can't ergonomically or safely pass a type in Rust functions.This replaces the previous
VSCODE_KEYWORDSstruct.Updates the
idiomaticize_externally_tagged_enumtransform function to use theVSCodeKeywordenum now thatVSCODE_KEYWORDSis removed.Defines extension methods for the
ValidationOptionsstruct from thejsonschemacrate to make adding VS Code keywords, vocabulary, and dialect simpler and more ergonomic, participating in the builder pattern thatjsonschemauses when creating a validator.Defines extension methods for the
Schemastruct from theschemarscrate to simplify working with VS COde keywords in schemas, such as retrieving the value for a keyword or checking whether the schema uses the VS Code dialect.Adds three new extension methods to the
SchemaUtilityExtensionstrait:get_bundled_schema_resource_ids, which retrieves the value of the$idkeyword from entries in the$defskeyword, each of which represents a bundled schema resource.get_references, which recursively retrieves the value for every$refkeyword in the schema.replace_references, which recursively replaces the value of the$refkeyword from a given value to a new one specified by the caller.reference_is_for_bundled_resource, which indicates whether a given value for a$refkeyword points to a bundled schema resource in the$defskeyword for the schema.PR Context
This change addresses the need for parsing, validating, and processing the custom JSON Schema keywords that VS Code recognizes for use in the DSC schemas and resource schemas. This change lays the groundwork for incorporating the VS Code keywords into the schemas generated from Rust code and for defining our own vocabulary for DSC as needed.