Skip to content

Commit 3bd94cf

Browse files
committed
refactor(Config): config dom object update function
1 parent 1ef4e72 commit 3bd94cf

File tree

2 files changed

+72
-50
lines changed

2 files changed

+72
-50
lines changed

src/lib/ConfigImpl.cpp

Lines changed: 61 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -119,55 +119,7 @@ load(
119119
s.configYaml = publicSettings.configYaml;
120120

121121
// Config strings
122-
c->configObj_ = toDomObject(s.configYaml);
123-
c->settings_.visit([&c]<class T>(std::string_view name, T& value) {
124-
if (!c->configObj_.exists(name))
125-
{
126-
if constexpr (std::convertible_to<T, std::string_view>)
127-
{
128-
c->configObj_.set(name, std::string(value));
129-
}
130-
else if constexpr (range_of_tuple_like<T>)
131-
{
132-
dom::Object obj;
133-
auto keys = value | std::views::keys;
134-
auto vals = value | std::views::values;
135-
auto zip = std::views::zip(keys, vals);
136-
for (auto const& [k, v] : zip)
137-
{
138-
obj.set(k, v);
139-
}
140-
c->configObj_.set(name, std::move(obj));
141-
}
142-
else if constexpr (std::ranges::range<T>)
143-
{
144-
using ValueType = std::ranges::range_value_t<T>;
145-
dom::Array arr;
146-
for (auto const& v : value)
147-
{
148-
if constexpr (
149-
std::is_same_v<ValueType, PathGlobPattern> ||
150-
std::is_same_v<ValueType, SymbolGlobPattern>)
151-
{
152-
arr.emplace_back(v.pattern());
153-
}
154-
else
155-
{
156-
arr.emplace_back(v);
157-
}
158-
}
159-
c->configObj_.set(name, std::move(arr));
160-
}
161-
else if constexpr (std::is_enum_v<T>)
162-
{
163-
c->configObj_.set(name, to_string(value));
164-
}
165-
else
166-
{
167-
c->configObj_.set(name, value);
168-
}
169-
}
170-
});
122+
c->updateConfigDom();
171123
return c;
172124
}
173125

@@ -304,9 +256,68 @@ toDomObject(std::string_view yaml)
304256
} // (anon)
305257

306258
dom::Object const&
307-
ConfigImpl::object() const {
259+
ConfigImpl::
260+
object() const
261+
{
308262
return configObj_;
309263
}
310264

265+
void
266+
ConfigImpl::
267+
updateConfigDom()
268+
{
269+
SettingsImpl& s = this->settings_;
270+
configObj_ = toDomObject(s.configYaml);
271+
settings_.visit([this]<class T>(std::string_view name, T& value) {
272+
if (!configObj_.exists(name))
273+
{
274+
if constexpr (std::convertible_to<T, std::string_view>)
275+
{
276+
configObj_.set(name, std::string(value));
277+
}
278+
else if constexpr (range_of_tuple_like<T>)
279+
{
280+
dom::Object obj;
281+
auto keys = value | std::views::keys;
282+
auto vals = value | std::views::values;
283+
auto zip = std::views::zip(keys, vals);
284+
for (auto const& [k, v] : zip)
285+
{
286+
obj.set(k, v);
287+
}
288+
configObj_.set(name, std::move(obj));
289+
}
290+
else if constexpr (std::ranges::range<T>)
291+
{
292+
using ValueType = std::ranges::range_value_t<T>;
293+
dom::Array arr;
294+
for (auto const& v : value)
295+
{
296+
if constexpr (
297+
std::is_same_v<ValueType, PathGlobPattern> ||
298+
std::is_same_v<ValueType, SymbolGlobPattern>)
299+
{
300+
arr.emplace_back(v.pattern());
301+
}
302+
else
303+
{
304+
arr.emplace_back(v);
305+
}
306+
}
307+
configObj_.set(name, std::move(arr));
308+
}
309+
else if constexpr (std::is_enum_v<T>)
310+
{
311+
configObj_.set(name, to_string(value));
312+
}
313+
else
314+
{
315+
configObj_.set(name, value);
316+
}
317+
}
318+
});
319+
}
320+
321+
311322
} // mrdocs
312323
} // clang

src/lib/ConfigImpl.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ class ConfigImpl
6868
template<class T>
6969
friend struct llvm::yaml::MappingTraits;
7070

71+
/** Update the DOM object from the YAML string and the settings.
72+
73+
This function is called after the
74+
settings are loaded or modified to
75+
update the DOM object representing
76+
the configuration keys.
77+
*/
78+
void
79+
updateConfigDom();
80+
7181
public:
7282
ConfigImpl(access_token, ThreadPool& threadPool);
7383

@@ -142,6 +152,7 @@ class ConfigImpl
142152
shouldExtractFromFile(
143153
llvm::StringRef filePath,
144154
std::string& prefix) const noexcept;
155+
145156
};
146157

147158
//------------------------------------------------

0 commit comments

Comments
 (0)