Change return value of Schema::childNodes
I'll need to use this method to generate what can be parsed as paths in
the upcoming path parser rework. As a side effect, path completion
generation gets a little bit simpler, because now I don't have to parse
the strings of format "[module:]node" and just trust whatever the schema
gives me.
Change-Id: I881cdbbd8254b846c21cee1ac0a3b7af1e40a696
diff --git a/src/ast_handlers.hpp b/src/ast_handlers.hpp
index 5f7b922..2a1b360 100644
--- a/src/ast_handlers.hpp
+++ b/src/ast_handlers.hpp
@@ -461,27 +461,20 @@
auto suggestions = schema.availableNodes(parserContext.currentSchemaPath(), Recursion::NonRecursive);
std::set<Completion> suffixesAdded;
std::transform(suggestions.begin(), suggestions.end(),
- std::inserter(suffixesAdded, suffixesAdded.end()),
- [&parserContext, &schema] (auto it) {
- ModuleNodePair node;
- if (auto colonPos = it.find(":"); colonPos != it.npos) {
- node.first = it.substr(0, colonPos);
- node.second = it.substr(colonPos + 1, node.second.npos);
- } else {
- node.first = boost::none;
- node.second = it;
- }
+ std::inserter(suffixesAdded, suffixesAdded.end()),
+ [&parserContext, &schema](const ModuleNodePair& node) {
+ std::string completion = (node.first ? *node.first + ":" : "") + node.second;
- if (schema.isLeaf(parserContext.currentSchemaPath(), node)) {
- return Completion{it + " "};
- }
- if (schema.isContainer(parserContext.currentSchemaPath(), node)) {
- return Completion{it + "/"};
- }
- if (schema.isList(parserContext.currentSchemaPath(), node)) {
- return Completion{it, "[", Completion::WhenToAdd::IfFullMatch};
- }
- return Completion{it};
+ if (schema.isLeaf(parserContext.currentSchemaPath(), node)) {
+ return Completion{completion + " "};
+ }
+ if (schema.isContainer(parserContext.currentSchemaPath(), node)) {
+ return Completion{completion + "/"};
+ }
+ if (schema.isList(parserContext.currentSchemaPath(), node)) {
+ return Completion{completion, "[", Completion::WhenToAdd::IfFullMatch};
+ }
+ return Completion{completion};
});
parserContext.m_suggestions = suffixesAdded;
}