5858on_difference (callback, old_val, new_val, path:: Tuple{Vararg{Symbol}} ) =
5959 old_val != = new_val ? callback (old_val, new_val, path) : old_val
6060
61+ function parse_config_dict (config_dict:: AbstractDict{String} , filepath:: Union{Nothing,AbstractString} = nothing )
62+ try
63+ return Configurations. from_dict (JETLSConfig, config_dict)
64+ catch e
65+ # TODO : remove this when Configurations.jl support to report
66+ # full path of unknown key.
67+ if e isa Configurations. InvalidKeyError
68+ unknown_keys = collect_unmatched_keys (to_untyped_config_dict (config_dict))
69+ if ! isempty (unknown_keys)
70+ if isnothing (filepath)
71+ return unmatched_keys_in_config_file_msg (unknown_keys)
72+ else
73+ return unmatched_keys_in_config_file_msg (filepath, unknown_keys)
74+ end
75+ end
76+ elseif e isa DiagnosticConfigError
77+ if isnothing (filepath)
78+ return " Invalid diagnostic configuration: $(e. msg) "
79+ else
80+ return """
81+ Invalid diagnostic configuration in $filepath :
82+ $(e. msg)
83+ """
84+ end
85+ end
86+ if isnothing (filepath)
87+ return " Failed to parse LSP configuration: $(e) "
88+ else
89+ return """
90+ Failed to load configuration file at $filepath :
91+ $(e)
92+ """
93+ end
94+ end
95+ end
96+
6197"""
6298 merge_setting(base::T, overlay::T) where {T<:ConfigSection} -> T
6399
@@ -69,36 +105,37 @@ merge_setting(base::T, overlay::T) where {T<:ConfigSection} =
69105
70106# TODO : remove this.
71107# (now this is used for `collect_unmatched_keys` only. see that's comment)
72- const ConfigDict = Base. PersistentDict{String, Any}
73- to_config_dict (dict:: AbstractDict ) = ConfigDict ((k => (v isa AbstractDict ? to_config_dict (v) : v) for (k, v) in dict). .. )
108+ const UntypedConfigDict = Base. PersistentDict{String, Any}
109+ to_untyped_config_dict (dict:: AbstractDict ) =
110+ UntypedConfigDict ((k => (v isa AbstractDict ? to_untyped_config_dict (v) : v) for (k, v) in dict). .. )
74111
75- const DEFAULT_CONFIG_DICT = to_config_dict (Configurations. to_dict (DEFAULT_CONFIG))
112+ const DEFAULT_UNTYPED_CONFIG_DICT = to_untyped_config_dict (Configurations. to_dict (DEFAULT_CONFIG))
76113
77114"""
78- collect_unmatched_keys(this::ConfigDict , ref::ConfigDict ) -> Vector{Vector{String}}
115+ collect_unmatched_keys(this::UntypedConfigDict , ref::UntypedConfigDict ) -> Vector{Vector{String}}
79116
80117Traverses the keys of `this` and returns a list of key paths that are not present in `ref`.
81118Note that this function does *not* perform deep structural comparison for keys whose values are dictionaries.
82119
83120# Examples
84121```julia-repl
85122julia> collect_unmatched_keys(
86- ConfigDict ("key1" => ConfigDict ("key2" => 0, "key3" => 0, "key4" => 0)),
87- ConfigDict ("key1" => ConfigDict ("key2" => 0, "diff1" => 0, "diff2" => 0))
123+ UntypedConfigDict ("key1" => UntypedConfigDict ("key2" => 0, "key3" => 0, "key4" => 0)),
124+ UntypedConfigDict ("key1" => UntypedConfigDict ("key2" => 0, "diff1" => 0, "diff2" => 0))
88125 )
891262-element Vector{Vector{String}}:
90127 ["key1", "key3"]
91128 ["key1", "key4"]
92129
93130julia> collect_unmatched_keys(
94- ConfigDict ("key1" => 0, "key2" => 0),
95- ConfigDict ("key1" => 1, "key2" => 1)
131+ UntypedConfigDict ("key1" => 0, "key2" => 0),
132+ UntypedConfigDict ("key1" => 1, "key2" => 1)
96133 )
97134Vector{String}[]
98135
99136julia> collect_unmatched_keys(
100- ConfigDict ("key1" => ConfigDict ("key2" => 0, "key3" => 0)),
101- ConfigDict ("diff" => ConfigDict ("diff" => 0, "key3" => 0))
137+ UntypedConfigDict ("key1" => UntypedConfigDict ("key2" => 0, "key3" => 0)),
138+ UntypedConfigDict ("diff" => UntypedConfigDict ("diff" => 0, "key3" => 0))
102139 )
1031401-element Vector{Vector{String}}:
104141 ["key1"]
@@ -107,15 +144,15 @@ julia> collect_unmatched_keys(
107144TODO: remove this. This is a temporary workaround to report unknown keys in the config file
108145 until Configurations.jl supports reporting full path of unknown keys.
109146"""
110- function collect_unmatched_keys (this:: ConfigDict , ref:: ConfigDict = DEFAULT_CONFIG_DICT )
147+ function collect_unmatched_keys (this:: UntypedConfigDict , ref:: UntypedConfigDict = DEFAULT_UNTYPED_CONFIG_DICT )
111148 unknown_keys = Vector{String}[]
112149 collect_unmatched_keys! (unknown_keys, this, ref, String[])
113150 return unknown_keys
114151end
115152
116153function collect_unmatched_keys! (
117154 unknown_keys:: Vector{Vector{String}} ,
118- this:: ConfigDict , ref:: ConfigDict , key_path:: Vector{String}
155+ this:: UntypedConfigDict , ref:: UntypedConfigDict , key_path:: Vector{String}
119156 )
120157 for (k, v) in this
121158 current_path = [key_path; k]
@@ -144,9 +181,9 @@ so `config` is guaranteed to not be `nothing`.
144181Base. @constprop :aggressive function get_config (manager:: ConfigManager , key_path:: Symbol... )
145182 data = load (manager)
146183 config = if is_static_setting (key_path... )
147- getobjpath (merge_setting (DEFAULT_CONFIG, data. static_settings) , key_path... )
184+ getobjpath (data. __filled_static_settings__ , key_path... )
148185 else
149- getobjpath (merge_setting (DEFAULT_CONFIG, get_settings ( data)) , key_path... )
186+ getobjpath (data. __filled_settings__ , key_path... )
150187 end
151188 @assert ! isnothing (config) " Invalid default configuration values"
152189 return config
0 commit comments