diff --git a/src/command_manager.cc b/src/command_manager.cc index 1fdfa34d..e4d52d76 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -624,6 +624,13 @@ Completions CommandManager::complete_command_name(const Context& context, String return {0, query.length(), Kakoune::complete(query, query.length(), concatenated(commands, aliases))}; } +Completions CommandManager::complete_module_name(StringView query) const +{ + return {0, query.length(), + Kakoune::complete(query, query.length(), m_modules | filter([](auto&& item) { return not item.value.loaded; }) + | transform(&ModuleMap::Item::key))}; +} + Completions CommandManager::complete(const Context& context, CompletionFlags flags, StringView command_line, diff --git a/src/command_manager.hh b/src/command_manager.hh index 329c24f2..774b8b2c 100644 --- a/src/command_manager.hh +++ b/src/command_manager.hh @@ -129,6 +129,8 @@ public: void load_module(StringView module_name, Context& context); + Completions complete_module_name(StringView query) const; + private: void execute_single_command(CommandParameters params, Context& context, diff --git a/src/commands.cc b/src/commands.cc index b1fe3580..e368dca8 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -2448,7 +2448,10 @@ const CommandDesc require_module_cmd = { ParameterDesc{ {}, ParameterDesc::Flags::None, 1, 1 }, CommandFlags::None, CommandHelper{}, - CommandCompleter{}, + make_completer( + [](const Context&, CompletionFlags, const String& prefix, ByteCount cursor_pos) { + return CommandManager::instance().complete_module_name(prefix.substr(0, cursor_pos)); + }), [](const ParametersParser& parser, Context& context, const ShellContext&) { CommandManager::instance().load_module(parser[0], context);