1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-23 15:23:29 +03:00

Filter out switches when completing commands

Fixes #4625
Fixes #4209
Fixes #4040
This commit is contained in:
Maxime Coste 2022-05-26 19:42:15 +10:00
parent a63465aba8
commit d9ea62666b
2 changed files with 14 additions and 12 deletions

View File

@ -760,7 +760,9 @@ Completions CommandManager::complete(const Context& context,
auto& command = command_it->value;
if (token.content.substr(0_byte, 1_byte) == "-")
auto is_switch = [](StringView s) { return s.substr(0_byte, 1_byte) == "-"; };
if (is_switch(token.content))
{
auto switches = Kakoune::complete(token.content.substr(1_byte), pos_in_token,
command.param_desc.switches |
@ -771,7 +773,7 @@ Completions CommandManager::complete(const Context& context,
if (not command.completer)
return Completions{};
auto params = tokens | skip(1) | transform(&Token::content) | gather<Vector>();
auto params = tokens | skip(1) | transform(&Token::content) | filter(std::not_fn(is_switch)) | gather<Vector>();
auto index = params.size() - 1;
return offset_pos(requote(command.completer(context, flags, params, index, pos_in_token), token.type), start);

View File

@ -1655,18 +1655,18 @@ const CommandDesc set_option_cmd = {
static constexpr auto scopes = { "global", "buffer", "window", "current" };
if (token_to_complete == start)
return { 0_byte, params[start].length(),
complete(params[start], pos_in_token, scopes) };
else if (token_to_complete == start + 1)
return { 0_byte, params[start + 1].length(),
GlobalScope::instance().option_registry().complete_option_name(params[start + 1], pos_in_token) };
else if (not add and token_to_complete == start + 2 and params[start + 2].empty() and
GlobalScope::instance().option_registry().option_exists(params[start + 1]))
if (token_to_complete == 0)
return { 0_byte, params[0].length(),
complete(params[0], pos_in_token, scopes) };
else if (token_to_complete == 1)
return { 0_byte, params[1].length(),
GlobalScope::instance().option_registry().complete_option_name(params[1], pos_in_token) };
else if (token_to_complete == 2 and params[2].empty() and
GlobalScope::instance().option_registry().option_exists(params[1]))
{
OptionManager& options = get_scope(params[start], context).options();
return {0_byte, params[start + 2].length(),
{options[params[start + 1]].get_as_string(Quoting::Kakoune)},
return {0_byte, params[2].length(),
{options[params[1]].get_as_string(Quoting::Kakoune)},
Completions::Flags::Quoted};
}
return Completions{};