mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-25 20:33:08 +00:00
Make autoload_t no longer virtual
Equip it instead with a function pointer that it invokes when a command is removed
This commit is contained in:
parent
c5d9e7e391
commit
8aab725782
4 changed files with 22 additions and 37 deletions
|
@ -46,12 +46,14 @@ file_access_attempt_t access_file(const wcstring &path, int mode) {
|
|||
return result;
|
||||
}
|
||||
|
||||
autoload_t::autoload_t(const wcstring &env_var_name_var, const builtin_script_t *const scripts,
|
||||
size_t script_count)
|
||||
autoload_t::autoload_t(const wcstring &env_var_name_var,
|
||||
command_removed_function_t cmd_removed_callback,
|
||||
const builtin_script_t *const scripts, size_t script_count)
|
||||
: lock(),
|
||||
env_var_name(env_var_name_var),
|
||||
builtin_scripts(scripts),
|
||||
builtin_script_count(script_count) {
|
||||
builtin_script_count(script_count),
|
||||
command_removed(cmd_removed_callback) {
|
||||
pthread_mutex_init(&lock, NULL);
|
||||
}
|
||||
|
||||
|
|
|
@ -65,6 +65,9 @@ class autoload_t : public lru_cache_t<autoload_t, autoload_function_t> {
|
|||
/// A table containing all the files that are currently being loaded.
|
||||
/// This is here to help prevent recursion.
|
||||
std::set<wcstring> is_loading_set;
|
||||
// Function invoked when a command is removed
|
||||
typedef void (*command_removed_function_t)(const wcstring &);
|
||||
const command_removed_function_t command_removed;
|
||||
|
||||
void remove_all_functions() { this->evict_all_nodes(); }
|
||||
|
||||
|
@ -74,19 +77,17 @@ class autoload_t : public lru_cache_t<autoload_t, autoload_function_t> {
|
|||
autoload_function_t *get_autoloaded_function_with_creation(const wcstring &cmd,
|
||||
bool allow_eviction);
|
||||
|
||||
protected:
|
||||
/// Overridable callback for when a command is removed.
|
||||
virtual void command_removed(const wcstring &cmd) { UNUSED(cmd); }
|
||||
|
||||
public:
|
||||
// CRTP override
|
||||
void entry_was_evicted(wcstring key, autoload_function_t node);
|
||||
|
||||
// Create an autoload_t for the given environment variable name.
|
||||
autoload_t(const wcstring &env_var_name_var, const builtin_script_t *scripts,
|
||||
size_t script_count);
|
||||
autoload_t(const wcstring &env_var_name_var,
|
||||
command_removed_function_t callback,
|
||||
const builtin_script_t *scripts = NULL,
|
||||
size_t script_count = 0);
|
||||
|
||||
virtual ~autoload_t();
|
||||
~autoload_t();
|
||||
|
||||
/// Autoload the specified file, if it exists in the specified path. Do not load it multiple
|
||||
/// times unless its timestamp changes or parse_util_unload is called.
|
||||
|
|
|
@ -346,23 +346,14 @@ class completer_t {
|
|||
}
|
||||
};
|
||||
|
||||
/// Autoloader for completions.
|
||||
class completion_autoload_t : public autoload_t {
|
||||
public:
|
||||
completion_autoload_t();
|
||||
virtual void command_removed(const wcstring &cmd);
|
||||
};
|
||||
|
||||
static completion_autoload_t completion_autoloader;
|
||||
|
||||
// Constructor
|
||||
completion_autoload_t::completion_autoload_t() : autoload_t(L"fish_complete_path", NULL, 0) {}
|
||||
|
||||
/// Callback when an autoloaded completion is removed.
|
||||
void completion_autoload_t::command_removed(const wcstring &cmd) {
|
||||
// Callback when an autoloaded completion is removed.
|
||||
static void autoloaded_completion_removed(const wcstring &cmd) {
|
||||
complete_remove_all(cmd, false /* not a path */);
|
||||
}
|
||||
|
||||
// Autoloader for completions
|
||||
static autoload_t completion_autoloader(L"fish_complete_path", autoloaded_completion_removed);
|
||||
|
||||
/// Create a new completion entry.
|
||||
void append_completion(std::vector<completion_t> *completions, const wcstring &comp,
|
||||
const wcstring &desc, complete_flags_t flags, string_fuzzy_match_t match) {
|
||||
|
|
|
@ -37,25 +37,16 @@ static std::set<wcstring> function_tombstones;
|
|||
/// Lock for functions.
|
||||
static pthread_mutex_t functions_lock;
|
||||
|
||||
/// Autoloader for functions.
|
||||
class function_autoload_t : public autoload_t {
|
||||
public:
|
||||
function_autoload_t();
|
||||
virtual void command_removed(const wcstring &cmd);
|
||||
};
|
||||
|
||||
static function_autoload_t function_autoloader;
|
||||
|
||||
/// Constructor
|
||||
function_autoload_t::function_autoload_t() : autoload_t(L"fish_function_path", NULL, 0) {}
|
||||
|
||||
static bool function_remove_ignore_autoload(const wcstring &name, bool tombstone = true);
|
||||
|
||||
/// Callback when an autoloaded function is removed.
|
||||
void function_autoload_t::command_removed(const wcstring &cmd) {
|
||||
void autoloaded_function_removed(const wcstring &cmd) {
|
||||
function_remove_ignore_autoload(cmd, false);
|
||||
}
|
||||
|
||||
// Function autoloader
|
||||
static autoload_t function_autoloader(L"fish_function_path", autoloaded_function_removed);
|
||||
|
||||
/// Kludgy flag set by the load function in order to tell function_add that the function being
|
||||
/// defined is autoloaded. There should be a better way to do this...
|
||||
static bool is_autoload = false;
|
||||
|
|
Loading…
Reference in a new issue