settings: accept trailing commas (#2606)
Z-2357 I've found a crate that handles both comments and trailing commas in JSON. It is a fork of `serde_json`, but it is maintained & up-to-date. Sadly RawValue seems to not play nicely with it; I've ran into deserialisation issues around use of RawValue. For this PR I've migrated to `Value` API. Obviously this is just a point of discussion, not something I'd merge straight away. There may be better solutions to this particular problem. I've also noticed that `serde_json_lenient` does not handle trailing commas after bindings array. I'm not sure how big of an issue that is. Release Notes: - Improved handling of trailing commas in settings files. [#1322](https://github.com/zed-industries/community/issues/1322)
This commit is contained in:
parent
70ccbbafc1
commit
2a3c660d1f
7 changed files with 81 additions and 40 deletions
|
@ -834,11 +834,8 @@ fn to_pretty_json(value: &impl Serialize, indent_size: usize, indent_prefix_len:
|
|||
}
|
||||
|
||||
pub fn parse_json_with_comments<T: DeserializeOwned>(content: &str) -> Result<T> {
|
||||
Ok(serde_json::from_reader(
|
||||
json_comments::CommentSettings::c_style().strip_comments(content.as_bytes()),
|
||||
)?)
|
||||
Ok(serde_json_lenient::from_str(content)?)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue