diff options
author | ridiculousfish <corydoras@ridiculousfish.com> | 2015-10-07 18:59:41 -0700 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2015-10-07 18:59:41 -0700 |
commit | d9d2f61ba6ecb9ac26bfbc0d1e52e899a60971c5 (patch) | |
tree | 58e0664ad3c1fd73af0305632f49e20d69bd717b | |
parent | 434eabb7878178a095b8508ccbf5d232461e8d95 (diff) |
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.
-rw-r--r-- | src/complete.cpp | 9 | ||||
-rw-r--r-- | src/complete.h | 13 | ||||
-rw-r--r-- | src/function.cpp | 9 | ||||
-rw-r--r-- | src/function.h | 3 |
4 files changed, 20 insertions, 14 deletions
diff --git a/src/complete.cpp b/src/complete.cpp index 3d79de04..74cc19e2 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 2083517e..e69e89cf 100644 --- a/src/complete.h +++ b/src/complete.h @@ -235,19 +235,6 @@ bool complete_is_valid_argument(const wcstring &str, /** - 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 \param completions The array of completions to append to diff --git a/src/function.cpp b/src/function.cpp index a06e2993..71182030 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 1dd9d613..5a993fec 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. */ |