summaryrefslogtreecommitdiff
path: root/src/command_manager.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2015-06-26 13:52:01 +0100
committerMaxime Coste <frrrwww@gmail.com>2015-06-26 13:57:23 +0100
commit5b554ff4749bade238b09f919681aa1d1e050515 (patch)
tree25c721d534f23c698394f2f5aa67fb1f7f4dee6c /src/command_manager.cc
parentb579f90baedaf6ff5030e5ff9e6eaf6ea2017f1c (diff)
Add support for command completion on commands, use it for :new
That means commands can be completed using other commands and their completers. Yes that does makes sense. Closes #296
Diffstat (limited to 'src/command_manager.cc')
-rw-r--r--src/command_manager.cc36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/command_manager.cc b/src/command_manager.cc
index 9ac3a8d4..16ac290c 100644
--- a/src/command_manager.cc
+++ b/src/command_manager.cc
@@ -506,7 +506,7 @@ Completions CommandManager::complete(const Context& context,
}
}
- // command name completion
+ // command name completion
if (tokens.empty() or
(tok_idx == cmd_idx and (tok_idx == tokens.size() or
tokens[tok_idx].type() == Token::Type::Raw)))
@@ -589,6 +589,40 @@ Completions CommandManager::complete(const Context& context,
return Completions{};
}
+Completions CommandManager::complete(const Context& context,
+ CompletionFlags flags,
+ CommandParameters params,
+ size_t token_to_complete,
+ ByteCount pos_in_token)
+{
+ StringView prefix = params[token_to_complete].substr(0, pos_in_token);
+
+ if (token_to_complete == 0)
+ {
+ CandidateList candidates;
+ for (auto& command : m_commands)
+ {
+ if (command.second.flags & CommandFlags::Hidden)
+ continue;
+ if (prefix_match(command.first, prefix))
+ candidates.push_back(command.first);
+ }
+ std::sort(candidates.begin(), candidates.end());
+ return {0, pos_in_token, std::move(candidates)};
+ }
+ else
+ {
+ const String& command_name = params[0];
+
+ auto command_it = find_command(context, command_name);
+ if (command_it != m_commands.end() and command_it->second.completer)
+ return command_it->second.completer(
+ context, flags, params.subrange(1, params.size()-1),
+ token_to_complete-1, pos_in_token);
+ }
+ return Completions{};
+}
+
Completions PerArgumentCommandCompleter::operator()(const Context& context,
CompletionFlags flags,
CommandParameters params,