Unify enum and identityref completion

I could reuse it in the end!

Change-Id: I20abc8eb9305c4420f422c6d99ef3d4552ae336a
diff --git a/src/ast_handlers.hpp b/src/ast_handlers.hpp
index 6ecfbc5..368d51e 100644
--- a/src/ast_handlers.hpp
+++ b/src/ast_handlers.hpp
@@ -14,6 +14,7 @@
 
 
 #include "ast_commands.hpp"
+#include "parser_context.hpp"
 #include "schema.hpp"
 #include "utils.hpp"
 namespace x3 = boost::spirit::x3;
@@ -679,35 +680,21 @@
     }
 };
 
-struct createEnumSuggestions_class {
+template<yang::LeafDataTypes TYPE>
+struct createSetSuggestions_class {
+    decltype(ParserContext::m_suggestions) getSuggestions(const ParserContext& ctx, const Schema& schema) const;
+
     template <typename T, typename Iterator, typename Context>
     void on_success(Iterator const& begin, Iterator const&, T&, Context const& context)
     {
         auto& parserContext = x3::get<parser_context_tag>(context);
         const Schema& schema = parserContext.m_schema;
 
-        // Only generate completions if the type is enum so that we don't
+        // Only generate completions if the type is correct so that we don't
         // overwrite some other completions.
-        if (schema.leafType(parserContext.m_tmpListKeyLeafPath.m_location, parserContext.m_tmpListKeyLeafPath.m_node) == yang::LeafDataTypes::Enum) {
+        if (schema.leafType(parserContext.m_tmpListKeyLeafPath.m_location, parserContext.m_tmpListKeyLeafPath.m_node) == TYPE) {
             parserContext.m_completionIterator = begin;
-            parserContext.m_suggestions = schema.enumValues(parserContext.m_tmpListKeyLeafPath.m_location, parserContext.m_tmpListKeyLeafPath.m_node);
-        }
-    }
-};
-
-// FIXME: can I reuse createEnumSuggestions?
-struct createIdentitySuggestions_class {
-    template <typename T, typename Iterator, typename Context>
-    void on_success(Iterator const& begin, Iterator const&, T&, Context const& context)
-    {
-        auto& parserContext = x3::get<parser_context_tag>(context);
-        const Schema& schema = parserContext.m_schema;
-
-        // Only generate completions if the type is identityref so that we
-        // don't overwrite some other completions.
-        if (schema.leafType(parserContext.m_tmpListKeyLeafPath.m_location, parserContext.m_tmpListKeyLeafPath.m_node) == yang::LeafDataTypes::IdentityRef) {
-            parserContext.m_completionIterator = begin;
-            parserContext.m_suggestions = schema.validIdentities(parserContext.m_tmpListKeyLeafPath.m_location, parserContext.m_tmpListKeyLeafPath.m_node, Prefixes::WhenNeeded);
+            parserContext.m_suggestions = getSuggestions(parserContext, schema);
         }
     }
 };