From 42d772acc88a2c57b5761b67918ae7f502a9a7f9 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Wed, 23 Dec 2015 20:53:11 +0100 Subject: allow commands to do their own completions --- akonadi2_cli/repl/replStates.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'akonadi2_cli/repl/replStates.cpp') diff --git a/akonadi2_cli/repl/replStates.cpp b/akonadi2_cli/repl/replStates.cpp index ceb95ed..62888d0 100644 --- a/akonadi2_cli/repl/replStates.cpp +++ b/akonadi2_cli/repl/replStates.cpp @@ -149,9 +149,19 @@ static char **akonadi2_cli_tab_completion(const char *text, int start, int end) static char *akonadi2_cli_next_tab_complete_match(const char *text, int state) { - Syntax::List nearest = SyntaxTree::self()->nearestSyntax(tab_completion_full_state, QString(text)); - - if (nearest.size() > state) { + const QString fragment(text); + Syntax::List nearest = SyntaxTree::self()->nearestSyntax(tab_completion_full_state, fragment); + //for (auto syntax: nearest) { qDebug() << "Nearest: " << syntax.keyword; } + + if (nearest.isEmpty()) { + SyntaxTree::Command command = SyntaxTree::self()->match(tab_completion_full_state); + if (command.first && command.first->completer) { + QStringList commandCompletions = command.first->completer(tab_completion_full_state, fragment); + if (commandCompletions.size() > state) { + return qstrdup(commandCompletions[state].toUtf8()); + } + } + } else if (nearest.size() > state) { return qstrdup(nearest[state].keyword.toUtf8()); } -- cgit v1.2.3