Fix leaf_data completion
Completion for enums and identities was setting m_completionIterator
even though it supplied no new completions.
Issue: https://tree.taiga.io/project/jktjkt-netconf-cli/issue/150
Change-Id: I0f8252bc011b0a6418c1a616521027c784080b9b
diff --git a/src/ast_handlers.hpp b/src/ast_handlers.hpp
index d99e020..e59fc36 100644
--- a/src/ast_handlers.hpp
+++ b/src/ast_handlers.hpp
@@ -650,12 +650,12 @@
auto& parserContext = x3::get<parser_context_tag>(context);
const Schema& schema = parserContext.m_schema;
- parserContext.m_completionIterator = begin;
-
// Only generate completions if the type is enum 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) == yang::LeafDataTypes::Enum) {
+ parserContext.m_completionIterator = begin;
parserContext.m_suggestions = schema.enumValues(parserContext.m_tmpListKeyLeafPath.m_location, parserContext.m_tmpListKeyLeafPath.m_node);
+ }
}
};
@@ -667,11 +667,11 @@
auto& parserContext = x3::get<parser_context_tag>(context);
const Schema& schema = parserContext.m_schema;
- parserContext.m_completionIterator = begin;
-
// 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)
+ 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);
+ }
}
};
diff --git a/tests/path_completion.cpp b/tests/path_completion.cpp
index f84ae4f..832110d 100644
--- a/tests/path_completion.cpp
+++ b/tests/path_completion.cpp
@@ -185,6 +185,13 @@
expectedContextLength = 6;
}
+ SECTION("cd example:list[number=")
+ {
+ input = "cd example:list[number=";
+ expectedCompletions = {"number="};
+ expectedContextLength = 7;
+ }
+
SECTION("cd example:list[number=12")
{
input = "cd example:list[number=12";