Skip to content

Commit ee4ea07

Browse files
(GH-538) Define VS Code extended vocabulary and dialect
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.
1 parent befe473 commit ee4ea07

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+6226
-64
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ utfx = { version = "0.1" }
200200
uuid = { version = "1.18", features = ["v4"] }
201201
# dsc-lib, dsc-lib-jsonschema
202202
url = { version = "2.5" }
203-
# dsc-lib
203+
# dsc-lib, dsc-lib-jsonschema
204204
urlencoding = { version = "2.1" }
205205
# dsc-lib
206206
which = { version = "8.0" }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
doc-valid-idents = ["IntelliSense", ".."]

lib/dsc-lib-jsonschema/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ edition = "2024"
77
doctest = false # Disable doc tests by default for compilation speed
88

99
[dependencies]
10+
jsonschema = { workspace = true }
1011
regex = { workspace = true }
1112
rust-i18n = { workspace = true }
1213
schemars = { workspace = true }
1314
serde = { workspace = true }
1415
serde_json = { workspace = true }
1516
tracing = { workspace = true }
1617
url = { workspace = true }
18+
urlencoding = { workspace = true }
1719

1820
[dev-dependencies]
1921
# Helps review complex comparisons, like schemas

lib/dsc-lib-jsonschema/locales/en-us.toml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,56 @@ invalid item: %{invalid_item}
112112
113113
transforming schema: %{transforming_schema}
114114
"""
115+
116+
[vscode.keywords.allow_comments]
117+
factory_error_invalid_type = "The 'allowComments' VS Code keyword must be a boolean value."
118+
119+
[vscode.keywords.allow_trailing_commas]
120+
factory_error_invalid_type = "The 'allowTrailingCommas' VS Code keyword must be a boolean value."
121+
122+
[vscode.keywords.completion_detail]
123+
factory_error_invalid_type = "The 'completionDetail' VS Code keyword must be a string value."
124+
125+
[vscode.keywords.default_snippets]
126+
factory_error_suffix = "The 'defaultSnippets' VS Code keyword must be an array of objects. Every object must be a valid snippet definition."
127+
factory_error_not_array = "Non-array value is invalid."
128+
factory_error_invalid_item = "Invalid definition for an object in the array."
129+
factory_error_non_object_item = "Array containing non-object items is invalid."
130+
131+
[vscode.keywords.deprecation_message]
132+
factory_error_invalid_type = "The 'deprecationMessage' VS Code keyword must be a string value."
133+
134+
[vscode.keywords.do_not_suggest]
135+
factory_error_invalid_type = "The 'doNotSuggest' VS Code keyword must be a boolean value."
136+
137+
[vscode.keywords.enum_descriptions]
138+
factory_error_suffix = "The 'enumDescriptions' VS Code keyword must be an array of string values. The 'enumDescriptions' keyword should have the same number of items as the 'enum' keyword."
139+
factory_error_not_array = "Non-array value is invalid."
140+
factory_error_non_string_item = "Array containing non-string items is invalid."
141+
142+
[vscode.keywords.enum_details]
143+
factory_error_suffix = "The 'enumDetails' VS Code keyword must be an array of string values. The 'enumDetails' keyword should have the same number of items as the 'enum' keyword."
144+
factory_error_not_array = "Non-array value is invalid."
145+
factory_error_non_string_item = "Array containing non-string items is invalid."
146+
147+
[vscode.keywords.enum_sort_texts]
148+
factory_error_suffix = "The 'enumSortTexts' VS Code keyword must be an array of string values. The 'enumSortTexts' keyword should have the same number of items as the 'enum' keyword."
149+
factory_error_not_array = "Non-array value is invalid."
150+
factory_error_non_string_item = "Array containing non-string items is invalid."
151+
152+
[vscode.keywords.error_message]
153+
factory_error_invalid_type = "The 'errorMessage' VS Code keyword must be a string value."
154+
155+
[vscode.keywords.markdown_description]
156+
factory_error_invalid_type = "The 'markdownDescription' VS Code keyword must be a string value."
157+
158+
[vscode.keywords.markdown_enum_descriptions]
159+
factory_error_suffix = "The 'markdownEnumDescriptions' VS Code keyword must be an array of string values. The 'markdownEnumDescriptions' keyword should have the same number of items as the 'enum' keyword."
160+
factory_error_not_array = "Non-array value is invalid."
161+
factory_error_non_string_item = "Array containing non-string items is invalid."
162+
163+
[vscode.keywords.pattern_error_message]
164+
factory_error_invalid_type = "The 'allowTrailingCommas' VS Code keyword must be a string value."
165+
166+
[vscode.keywords.suggest_sort_text]
167+
factory_error_invalid_type = "The 'allowTrailingCommas' VS Code keyword must be a string value."

0 commit comments

Comments
 (0)