More command completer code cleanup

This commit is contained in:
Maxime Coste 2016-09-18 16:27:34 +01:00
parent d14c39ebdd
commit 44e9da3bee

View File

@ -166,6 +166,21 @@ const ParameterDesc single_optional_name_param{ {}, ParameterDesc::Flags::None,
static constexpr auto scopes = { "global", "buffer", "window" }; static constexpr auto scopes = { "global", "buffer", "window" };
static Completions complete_scope(const Context&, CompletionFlags,
const String& prefix, ByteCount cursor_pos)
{
return { 0_byte, cursor_pos, complete(prefix, cursor_pos, scopes) };
}
static Completions complete_command_name(const Context& context, CompletionFlags,
const String& prefix, ByteCount cursor_pos)
{
return CommandManager::instance().complete_command_name(
context, prefix.substr(0, cursor_pos), false);
}
Scope* get_scope_ifp(StringView scope, const Context& context) Scope* get_scope_ifp(StringView scope, const Context& context)
{ {
if (prefix_match("global", scope)) if (prefix_match("global", scope))
@ -740,20 +755,11 @@ const CommandDesc add_hook_cmd = {
}, },
CommandFlags::None, CommandFlags::None,
CommandHelper{}, CommandHelper{},
make_completer(&complete_scope, &complete_nothing, &complete_nothing,
[](const Context& context, CompletionFlags flags, [](const Context& context, CompletionFlags flags,
CommandParameters params, size_t token_to_complete, const String& prefix, ByteCount cursor_pos)
ByteCount pos_in_token) -> Completions { return CommandManager::instance().complete(
{ context, flags, prefix, cursor_pos); }),
if (token_to_complete == 0)
return { 0_byte, params[0].length(),
complete(params[0], pos_in_token, scopes) };
else if (token_to_complete == 3)
{
auto& cm = CommandManager::instance();
return cm.complete(context, flags, params[3], pos_in_token);
}
return {};
},
[](const ParametersParser& parser, Context& context, const ShellContext&) [](const ParametersParser& parser, Context& context, const ShellContext&)
{ {
Regex regex(parser[2], Regex::optimize | Regex::nosubs | Regex::ECMAScript); Regex regex(parser[2], Regex::optimize | Regex::nosubs | Regex::ECMAScript);
@ -1004,21 +1010,6 @@ const CommandDesc define_command_cmd = {
define_command define_command
}; };
static Completions complete_scope(const Context&, CompletionFlags,
const String& prefix, ByteCount cursor_pos)
{
auto scopes = {"global", "buffer", "window"};
return { 0_byte, cursor_pos, complete(prefix, cursor_pos, scopes) };
}
static Completions complete_command_name(const Context& context, CompletionFlags,
const String& prefix, ByteCount cursor_pos)
{
return CommandManager::instance().complete_command_name(
context, prefix.substr(0, cursor_pos), false);
}
const CommandDesc alias_cmd = { const CommandDesc alias_cmd = {
"alias", "alias",
nullptr, nullptr,