blob: 7def513ea3cb938bf527fbbabd5c5f5afa109509 [file] [log] [blame]
Václav Kubernát329c6c32019-02-06 16:41:53 +01001#include "ast_handlers.hpp"
Václav Kubernátcb3af402020-02-12 16:49:17 +01002std::set<Completion> 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
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át4294a852020-02-14 15:07:14 +010026
Václav Kubernátcb3af402020-02-12 16:49:17 +010027template <>
28std::set<std::string> createSetSuggestions_class<yang::LeafDataTypes::Enum>::getSuggestions(const ParserContext& parserContext, const Schema& schema) const
Václav Kubernát4294a852020-02-14 15:07:14 +010029{
30 return schema.enumValues(parserContext.m_tmpListKeyLeafPath.m_location, parserContext.m_tmpListKeyLeafPath.m_node);
31}
32
Václav Kubernátcb3af402020-02-12 16:49:17 +010033template <>
34std::set<std::string> createSetSuggestions_class<yang::LeafDataTypes::IdentityRef>::getSuggestions(const ParserContext& parserContext, const Schema& schema) const
Václav Kubernát4294a852020-02-14 15:07:14 +010035{
36 return schema.validIdentities(parserContext.m_tmpListKeyLeafPath.m_location, parserContext.m_tmpListKeyLeafPath.m_node, Prefixes::WhenNeeded);
37}