From d9d2f61ba6ecb9ac26bfbc0d1e52e899a60971c5 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 7 Oct 2015 18:59:41 -0700 Subject: [PATCH] When autoloading a completion, also autoload the function Fixes a case where a --wraps declaration would be missed because the function would not be loaded. Fixes #2466. --- src/complete.cpp | 9 ++++++++- src/complete.h | 13 ------------- src/function.cpp | 9 +++++++++ src/function.h | 3 +++ 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/complete.cpp b/src/complete.cpp index 3d79de045..74cc19e2b 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -75,6 +75,8 @@ static const wcstring &C_(const wcstring &s) } #endif +static void complete_load(const wcstring &name, bool reload); + /* Testing apparatus */ const wcstring_list_t *s_override_variable_names = NULL; @@ -1316,8 +1318,13 @@ static int short_ok(const wcstring &arg_str, wchar_t nextopt, const wcstring &al return 1; } -void complete_load(const wcstring &name, bool reload) + +/* Load command-specific completions for the specified command. */ +static void complete_load(const wcstring &name, bool reload) { + // we have to load this as a function, since it may define a --wraps or signature + // see #2466 + function_load(name); completion_autoloader.load(name, reload); } diff --git a/src/complete.h b/src/complete.h index 2083517ed..e69e89cf5 100644 --- a/src/complete.h +++ b/src/complete.h @@ -234,19 +234,6 @@ bool complete_is_valid_argument(const wcstring &str, const wcstring &arg); -/** - Load command-specific completions for the specified command. This - is done automatically whenever completing any given command, so - there is no need to call this except in the case of completions - with internal dependencies. - - \param cmd the command for which to load command-specific completions - \param reload should the commands completions be reloaded, even if they where - previously loaded. (This is set to true on actual completions, so that - changed completion are updated in running shells) -*/ -void complete_load(const wcstring &cmd, bool reload); - /** Create a new completion entry diff --git a/src/function.cpp b/src/function.cpp index a06e29936..711820302 100644 --- a/src/function.cpp +++ b/src/function.cpp @@ -222,6 +222,15 @@ int function_exists(const wcstring &cmd) return loaded_functions.find(cmd) != loaded_functions.end(); } +void function_load(const wcstring &cmd) +{ + if (! parser_keywords_is_reserved(cmd)) + { + scoped_lock lock(functions_lock); + load(cmd); + } +} + int function_exists_no_autoload(const wcstring &cmd, const env_vars_snapshot_t &vars) { if (parser_keywords_is_reserved(cmd)) diff --git a/src/function.h b/src/function.h index 1dd9d6138..5a993fec8 100644 --- a/src/function.h +++ b/src/function.h @@ -130,6 +130,9 @@ void function_set_desc(const wcstring &name, const wcstring &desc); */ int function_exists(const wcstring &name); +/** Attempts to load a function if not yet loaded. This is used by the completion machinery. */ +void function_load(const wcstring &name); + /** Returns true if the function with the name name exists, without triggering autoload. */