Allow comments in setting and keymap JSON files

This commit is contained in:
Max Brunsfeld 2022-04-21 11:58:18 -07:00
parent 066e572767
commit 3a28f09979
10 changed files with 47 additions and 18 deletions

View file

@ -9,13 +9,13 @@ use schemars::{
},
JsonSchema,
};
use serde::Deserialize;
use serde::{de::DeserializeOwned, Deserialize};
use serde_json::Value;
use std::{collections::HashMap, sync::Arc};
use theme::{Theme, ThemeRegistry};
use util::ResultExt as _;
pub use keymap_file::KeymapFile;
pub use keymap_file::KeymapFileContent;
#[derive(Clone)]
pub struct Settings {
@ -260,3 +260,9 @@ fn merge_option<T: Copy>(target: &mut Option<T>, value: Option<T>) {
*target = value;
}
}
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()),
)?)
}