blob: 6fde52cfcabc66ea8041353301323c1a588497e9 [file] [log] [blame]
Václav Kubernát329c6c32019-02-06 16:41:53 +01001#include "ast_handlers.hpp"
Václav Kubernátc15fe822020-06-04 11:28:39 +02002std::set<Completion> generateMissingKeyCompletionSet(std::set<std::string> keysNeeded, ListInstance currentKeys)
Václav Kubernát329c6c32019-02-06 16:41:53 +01003{
4 std::set<std::string> missingKeys;
Václav Kubernát43908fb2020-01-02 19:05:51 +01005
6 for (const auto& key : keysNeeded) {
7 if (currentKeys.find(key) == currentKeys.end()) {
8 missingKeys.insert(key);
9 }
10 }
Václav Kubernát329c6c32019-02-06 16:41:53 +010011
Václav Kubernátcb3af402020-02-12 16:49:17 +010012 std::set<Completion> res;
Václav Kubernát329c6c32019-02-06 16:41:53 +010013
Václav Kubernátcb3af402020-02-12 16:49:17 +010014 std::transform(missingKeys.begin(), missingKeys.end(), std::inserter(res, res.end()), [](auto it) { return Completion{it + "="}; });
Václav Kubernát329c6c32019-02-06 16:41:53 +010015 return res;
16}
Václav Kubernát43908fb2020-01-02 19:05:51 +010017
18std::string leafDataToCompletion(const leaf_data_& value)
19{
20 // Only string-like values need to be quoted
21 if (value.type() == typeid(std::string)) {
22 return escapeListKeyString(leafDataToString(value));
23 }
24 return leafDataToString(value);
25}
Václav Kubernát2db124c2020-05-28 21:58:36 +020026
27boost::optional<std::string> optModuleToOptString(const boost::optional<module_> module)
28{
Václav Kubernátb4e5b182020-11-16 19:55:09 +010029 return module.flat_map([](const auto& module) { return boost::optional<std::string>(module.m_name); });
Václav Kubernát2db124c2020-05-28 21:58:36 +020030}