Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 1 | #include "ast_handlers.hpp" |
Václav Kubernát | 43908fb | 2020-01-02 19:05:51 +0100 | [diff] [blame] | 2 | std::set<std::string> generateMissingKeyCompletionSet(std::set<std::string> keysNeeded, std::map<std::string, leaf_data_> currentKeys) |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 3 | { |
| 4 | std::set<std::string> missingKeys; |
Václav Kubernát | 43908fb | 2020-01-02 19:05:51 +0100 | [diff] [blame] | 5 | |
| 6 | for (const auto& key : keysNeeded) { |
| 7 | if (currentKeys.find(key) == currentKeys.end()) { |
| 8 | missingKeys.insert(key); |
| 9 | } |
| 10 | } |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 11 | |
| 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át | 43908fb | 2020-01-02 19:05:51 +0100 | [diff] [blame] | 19 | |
| 20 | std::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át | 4294a85 | 2020-02-14 15:07:14 +0100 | [diff] [blame] | 28 | |
| 29 | template<> |
| 30 | decltype(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 | |
| 35 | template<> |
| 36 | decltype(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 | } |