Add support for env var name completion

Fixes #659
This commit is contained in:
Maxime Coste 2016-04-17 19:21:43 +01:00
parent e784db4ad6
commit 2435949fae
3 changed files with 16 additions and 0 deletions

View File

@ -582,6 +582,11 @@ Completions CommandManager::complete(const Context& context,
return offset_pos(shell_complete(context, flags, tokens[tok_idx].content(),
cursor_pos_in_token), start);
case Token::Type::ValExpand:
return {start , cursor_pos,
ShellManager::instance().complete_env_var(
tokens[tok_idx].content(), cursor_pos_in_token) };
case Token::Type::Raw:
case Token::Type::RawQuoted:
case Token::Type::RawEval:

View File

@ -234,4 +234,12 @@ String ShellManager::get_val(StringView name, const Context& context) const
return env_var->func(name, context);
}
CandidateList ShellManager::complete_env_var(StringView prefix,
ByteCount cursor_pos) const
{
return complete(prefix, cursor_pos, m_env_vars |
transform([](const EnvVarDesc& desc) -> const String&
{ return desc.str; }));
}
}

View File

@ -6,6 +6,7 @@
#include "flags.hh"
#include "string.hh"
#include "utils.hh"
#include "completion.hh"
namespace Kakoune
{
@ -39,6 +40,8 @@ public:
void register_env_var(StringView str, bool prefix, EnvVarRetriever retriever);
String get_val(StringView name, const Context& context) const;
CandidateList complete_env_var(StringView prefix, ByteCount cursor_pos) const;
private:
struct EnvVarDesc { String str; bool prefix; EnvVarRetriever func; };
Vector<EnvVarDesc> m_env_vars;