Change how word splitting works when completing

Previously, I relied on replxx to correctly split words based on
word-splitting characters. However, as completion gets more complex and
completions possibly insert word-splitting characters, it starts to do
weird stuff like deleting some of your input. Fortunately, replxx allows
you to set the context length for completion - that is, how many
character it should consider as part of the word you're completing.

Change-Id: I035ac5059c8ab125efedb90cbeb2910f20da04a7
diff --git a/src/parser.cpp b/src/parser.cpp
index de375f8..c3dc088 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -21,6 +21,11 @@
     m_curDir.m_scope = Scope::Absolute;
 }
 
+bool Completions::operator==(const Completions& b) const
+{
+    return this->m_completions == b.m_completions && this->m_contextLength == b.m_contextLength;
+}
+
 command_ Parser::parseCommand(const std::string& line, std::ostream& errorStream)
 {
     command_ parsedCommand;
@@ -42,7 +47,7 @@
     return parsedCommand;
 }
 
-std::set<std::string> Parser::completeCommand(const std::string& line, std::ostream& errorStream) const
+Completions Parser::completeCommand(const std::string& line, std::ostream& errorStream) const
 {
     std::set<std::string> completions;
     command_ parsedCommand;
@@ -57,11 +62,15 @@
     ];
     x3::phrase_parse(it, line.end(), grammar, space, parsedCommand);
 
-    auto set = filterByPrefix(ctx.m_suggestions, std::string(ctx.m_completionIterator, line.end()));
+    auto completionIterator = ctx.m_completionIterator ? *ctx.m_completionIterator : line.end();
+
+    int completionContext = line.end() - completionIterator;
+
+    auto set = filterByPrefix(ctx.m_suggestions, std::string(completionIterator, line.end()));
     if (set.size() == 1) {
-        return {(*set.begin()) + ctx.m_completionSuffix};
+        return {{(*set.begin()) + ctx.m_completionSuffix}, completionContext};
     }
-    return set;
+    return {set, completionContext};
 }
 
 void Parser::changeNode(const dataPath_& name)