blob: 7738085980070c71fe1163d4d740e32f2283af67 [file] [log] [blame]
Václav Kubernát329c6c32019-02-06 16:41:53 +01001#include "ast_handlers.hpp"
Václav Kubernát43908fb2020-01-02 19:05:51 +01002std::set<std::string> generateMissingKeyCompletionSet(std::set<std::string> keysNeeded, std::map<std::string, leaf_data_> 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
12 std::set<std::string> res;
13
14 std::transform(missingKeys.begin(), missingKeys.end(),
15 std::inserter(res, res.end()),
16 [] (auto it) { return it + "="; });
17 return res;
18}
Václav Kubernát43908fb2020-01-02 19:05:51 +010019
20std::string leafDataToCompletion(const leaf_data_& value)
21{
22 // Only string-like values need to be quoted
23 if (value.type() == typeid(std::string)) {
24 return escapeListKeyString(leafDataToString(value));
25 }
26 return leafDataToString(value);
27}
Václav Kubernát4294a852020-02-14 15:07:14 +010028
29template<>
30decltype(ParserContext::m_suggestions) createSetSuggestions_class<yang::LeafDataTypes::Enum>::getSuggestions(const ParserContext& parserContext, const Schema& schema) const
31{
32 return schema.enumValues(parserContext.m_tmpListKeyLeafPath.m_location, parserContext.m_tmpListKeyLeafPath.m_node);
33}
34
35template<>
36decltype(ParserContext::m_suggestions) createSetSuggestions_class<yang::LeafDataTypes::IdentityRef>::getSuggestions(const ParserContext& parserContext, const Schema& schema) const
37{
38 return schema.validIdentities(parserContext.m_tmpListKeyLeafPath.m_location, parserContext.m_tmpListKeyLeafPath.m_node, Prefixes::WhenNeeded);
39}