1use figment::{providers::Serialized, Figment};
2use jsona_util::HashMap;
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5use url::Url;
6
7pub const DEFAULT_CONFIGURATION_SECTION: &str = "jsona";
8
9#[derive(Debug, Clone, Serialize, Deserialize, Default)]
10#[serde(rename_all = "camelCase")]
11pub struct InitializationOptions {
12 pub cache_path: Option<Url>,
13}
14
15#[derive(Debug, Clone, Default, Serialize, Deserialize)]
16#[serde(rename_all = "camelCase")]
17pub struct LspConfig {
18 pub schema: SchemaConfig,
19 pub formatter: jsona::formatter::OptionsIncompleteCamel,
20}
21
22impl LspConfig {
23 pub fn update_from_json(&mut self, json: &Value) -> Result<(), anyhow::Error> {
24 *self = Figment::new()
25 .merge(Serialized::defaults(&self))
26 .merge(Serialized::defaults(json))
27 .extract()?;
28 Ok(())
29 }
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(rename_all = "camelCase")]
34pub struct SchemaConfig {
35 pub enabled: bool,
36 pub associations: HashMap<String, Vec<String>>,
37 pub cache: bool,
38 pub store_url: Option<Url>,
39}
40
41impl Default for SchemaConfig {
42 fn default() -> Self {
43 Self {
44 enabled: true,
45 cache: true,
46 associations: Default::default(),
47 store_url: None,
48 }
49 }
50}