(GH-538) Add schema_i18n! helper macro#1482
Open
michaeltlombardi wants to merge 5 commits intoPowerShell:mainfrom
Open
(GH-538) Add schema_i18n! helper macro#1482michaeltlombardi wants to merge 5 commits intoPowerShell:mainfrom
schema_i18n! helper macro#1482michaeltlombardi wants to merge 5 commits intoPowerShell:mainfrom
Conversation
Prior to this change, defining the documentation keywords for schemas
in `dsc-lib` and other crates required passing long lookup keys for
i18n, like:
```rust
t!("schemas.definitions.resourceVersionReq.semanticVariant.description")
```
This change:
1. Adds the new `schema_i18n()` helper method to the `DscRepoSchema`
trait, which concatenates the input value to the root key defined in
the new `SCHEMA_I18N_ROOT_KEY` associated constant.
This method retrieves the translation and returns an _error_ if the
translation isn't defined. This is different from the behavior for
calling `t!()` directly, which emits the lookup key as the output
string when that key isn't defined.
Returning an error allows us to call `unwrap()` on the lookup, raising
a panic on missing values and stopping the tests.
1. Defines the `schema_i18n!()` macro, which simplifies invoking the
new method for more readable type and schema definitions.
1. Updates the derive macro for `DscRepoSchema` to automatically define
the value of `SCHEMA_I18N_ROOT_KEY` as the joining of the
`SCHEMA_FOLDER_PATH` and `SCHEMA_FILE_BASE_NAME` associated constants.
The path separators are replaced with periods (`.`) and the two values
are joined with a period.
This change is also a necessary precursor to programmatically munging the
documentation for these fields to insert links to the online documentation,
ensure line breaks where needed, and so on.
This change updates the type defininitons to use the newly available `schema_i18n!()` macro to lookup translations for schema documentation keywords, panicking when the translation doesn't exist. This makes the type definitions more readable and maintainable.
This change removes the search for translations defined in YAML files from the `dsc_i18n` test suite to drop false positives for unused translations. Testing whether a schema uses an undefined translation for a documentation keyword is redundant, now that the implementation causes schema generation to _panic_ when it uses an undefined translation key.
This change updates the `dsc-lib-jsonschema` crate to fix failing i18n tests by: - Moving the VS Code schema keywords into the `toml` translation definition file. Because these keywords must generate their documentation regardless of whether the library is being used with the `DscRepoSchema` trait, the types need to be able to use the normative translation files for i18n tests to function corectly. - Renaming the `tests/locales` folder to `tests/integration_locales` to avoid incorrectly testing those translations in the `dsc_i18n` pester test suite.
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a schema-specific i18n helper (schema_i18n() + schema_i18n!()) to make JSON Schema documentation keyword lookups shorter and fail-fast, then migrates schema/type definitions and tests to rely on it.
Changes:
- Introduces
SCHEMA_I18N_ROOT_KEY+schema_i18n()onDscRepoSchema, plus theschema_i18n!()macro. - Updates
dsc-libtype schemas to useschema_i18n!()instead of longt!(...)keys. - Updates jsonschema integration tests/locales and refactors VS Code keyword locale keys (YAML → TOML, camelCase → snake_case).
Reviewed changes
Copilot reviewed 34 out of 34 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/dsc-lib/src/types/tag_list.rs | Switches schema docs to schema_i18n!() and updates schema metadata attributes. |
| lib/dsc-lib/src/types/tag.rs | Uses schema_i18n!() for schema docs and derives DscRepoSchema. |
| lib/dsc-lib/src/types/semantic_version_req.rs | Uses schema_i18n!() and changes schema base name for SemanticVersionReq. |
| lib/dsc-lib/src/types/semantic_version.rs | Uses schema_i18n!() for schema docs. |
| lib/dsc-lib/src/types/resource_version_req.rs | Uses schema_i18n!() for schema docs for enum + variants. |
| lib/dsc-lib/src/types/resource_version.rs | Uses schema_i18n!() for schema docs for enum + variants. |
| lib/dsc-lib/src/types/fully_qualified_type_name.rs | Uses schema_i18n!() for schema docs. |
| lib/dsc-lib/src/types/exit_codes_map.rs | Uses schema_i18n!() for schema docs in JsonSchema impl. |
| lib/dsc-lib/src/types/date_version.rs | Uses schema_i18n!() for schema docs in JsonSchema impl. |
| lib/dsc-lib-jsonschema/tests/integration_locales/schemas.yaml | Adds YAML test locales for schema doc keyword integration tests. |
| lib/dsc-lib-jsonschema/tests/integration/main.rs | Enables rust_i18n for integration tests. |
| lib/dsc-lib-jsonschema/tests/integration/dsc_repo/derive_dsc_repo_schema.rs | Adds integration assertions validating translated schema doc keywords. |
| lib/dsc-lib-jsonschema/src/vscode/keywords/suggest_sort_text.rs | Renames i18n lookup keys to snake_case. |
| lib/dsc-lib-jsonschema/src/vscode/keywords/pattern_error_message.rs | Renames i18n lookup keys to snake_case. |
| lib/dsc-lib-jsonschema/src/vscode/keywords/markdown_enum_descriptions.rs | Renames i18n lookup keys to snake_case. |
| lib/dsc-lib-jsonschema/src/vscode/keywords/markdown_description.rs | Renames i18n lookup keys to snake_case. |
| lib/dsc-lib-jsonschema/src/vscode/keywords/error_message.rs | Renames i18n lookup keys to snake_case. |
| lib/dsc-lib-jsonschema/src/vscode/keywords/enum_sort_texts.rs | Renames i18n lookup keys to snake_case. |
| lib/dsc-lib-jsonschema/src/vscode/keywords/enum_details.rs | Renames i18n lookup keys to snake_case. |
| lib/dsc-lib-jsonschema/src/vscode/keywords/enum_descriptions.rs | Renames i18n lookup keys to snake_case. |
| lib/dsc-lib-jsonschema/src/vscode/keywords/do_not_suggest.rs | Renames i18n lookup keys to snake_case. |
| lib/dsc-lib-jsonschema/src/vscode/keywords/deprecation_message.rs | Renames i18n lookup keys to snake_case. |
| lib/dsc-lib-jsonschema/src/vscode/keywords/default_snippets.rs | Renames i18n lookup keys to snake_case (nested keys). |
| lib/dsc-lib-jsonschema/src/vscode/keywords/completion_detail.rs | Renames i18n lookup keys to snake_case. |
| lib/dsc-lib-jsonschema/src/vscode/keywords/allow_trailing_commas.rs | Renames i18n lookup keys to snake_case. |
| lib/dsc-lib-jsonschema/src/vscode/keywords/allow_comments.rs | Renames i18n lookup keys to snake_case. |
| lib/dsc-lib-jsonschema/src/tests/dsc_repo.rs | Updates test trait impls for new SCHEMA_I18N_ROOT_KEY + schema_i18n(). |
| lib/dsc-lib-jsonschema/src/dsc_repo/mod.rs | Re-exports missing translation error + macro wiring. |
| lib/dsc-lib-jsonschema/src/dsc_repo/macros.rs | Adds schema_i18n!() helper macro. |
| lib/dsc-lib-jsonschema/src/dsc_repo/dsc_repo_schema.rs | Extends DscRepoSchema with i18n const + lookup fn and adds missing-translation error type. |
| lib/dsc-lib-jsonschema/locales/vscode.yaml | Removes VS Code locales from YAML. |
| lib/dsc-lib-jsonschema/locales/en-us.toml | Adds VS Code locales and new missing-translation error message. |
| lib/dsc-lib-jsonschema-macros/src/derive/dsc_repo_schema.rs | Derive macro now generates SCHEMA_I18N_ROOT_KEY and schema_i18n() implementation. |
| dsc/tests/dsc_i18n.tests.ps1 | Stops loading YAML locale files for i18n usage/definition checks. |
Comments suppressed due to low confidence (1)
lib/dsc-lib/src/types/semantic_version_req.rs:1
- Changing
base_namechanges the generated schema$id/URI and likely the emitted schema filename/path, which can be a breaking change for external consumers. If the goal is only to align i18n lookup roots, consider keeping the existingbase_nameand overridingi18n_root_keyvia#[dsc_repo_schema(i18n_root_key = \"...\")]instead; otherwise, document this as an intentional schema ID change (and align any published schema references/versioning accordingly).
lib/dsc-lib-jsonschema/tests/integration/dsc_repo/derive_dsc_repo_schema.rs
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary
This change:
Adds the new
schema_i18n()helper method to theDscRepoSchematrait, which concatenates the input value to the root key defined in the newSCHEMA_I18N_ROOT_KEYassociated constant.This method retrieves the translation and returns an error if the translation isn't defined. This is different from the behavior for calling
t!()directly, which emits the lookup key as the output string when that key isn't defined.Returning an error allows us to call
unwrap()on the lookup, raising a panic on missing values and stopping the tests.Defines the
schema_i18n!()macro, which simplifies invoking the new method for more readable type and schema definitions.Updates the derive macro for
DscRepoSchemato automatically define the value ofSCHEMA_I18N_ROOT_KEYas the joining of theSCHEMA_FOLDER_PATHandSCHEMA_FILE_BASE_NAMEassociated constants. The path separators are replaced with periods (.) and the two values are joined with a period.Updates the type definitions in
dsc-lib::typesto use the new macro.Updates the
dsc_i18ntest suite to ignore YAML files, which should exclusively be used for schema documentation keywords. This shifts the testing logic for schemas to ensuring they don't panic during generation, as with theschema_for!()macro.PR Context
Prior to this change, defining the documentation keywords for schemas in
dsc-liband other crates required passing long lookup keys for i18n, like:These long lines require a lot of repetition and make the code more difficult to read and maintain. We rely on the pester tests in
dsc/tests/dsc_i18n.tests.ps1to verify i18n.Currently, we define all program-specific translation strings in
<language>.tomlfiles for every crate. We define schema-specific translations in YAML files. We previously updated the i18n tests to account for this and check that every defined translation is used and that every used translation is defined.With a new helper macro for looking up schema documentation, we can instead panic when a schema documentation translation entry isn't defined, which is caught by the rust testing for schemas (a missing translation triggers a panic on
schema_for!()). In the future, we may be able to drive improved static analysis and testing for type definitions to ensure they are fully documented and that all defined translations are being used.For now, we can improve the maintainability and readability of our type definitions while ensuring that we raise a panic when an expected documentation keyword isn't defined.