Allow trailing commas in builtin JSONC schemas (#43854)
The JSON language server looks for a top-level `allowTrailingCommas` flag to decide whether it should warn for trailing commas. Since the JSONC parser for these builtin files can handles trailing commas, adding this flag to the schema also prevents a warning for those commas. I don't think there's an issue that is only for this specific issue, but it relates to *many* existing / older issues: - #18509 - #17487 - #40970 - #18509 - #21303 Release Notes: - Suppress warning for trailing commas in builtin JSON files (`settings.json`, `keymap.json`, etc.)
This commit is contained in:
@@ -53,3 +53,20 @@ impl schemars::transform::Transform for DefaultDenyUnknownFields {
|
||||
transform_subschemas(self, schema);
|
||||
}
|
||||
}
|
||||
|
||||
/// Defaults `allowTrailingCommas` to `true`, for use with `json-language-server`.
|
||||
/// This can be applied to any schema that will be treated as `jsonc`.
|
||||
///
|
||||
/// Note that this is non-recursive and only applied to the root schema.
|
||||
#[derive(Clone)]
|
||||
pub struct AllowTrailingCommas;
|
||||
|
||||
impl schemars::transform::Transform for AllowTrailingCommas {
|
||||
fn transform(&mut self, schema: &mut schemars::Schema) {
|
||||
if let Some(object) = schema.as_object_mut()
|
||||
&& !object.contains_key("allowTrailingCommas")
|
||||
{
|
||||
object.insert("allowTrailingCommas".to_string(), true.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user