Replace autosuggestions "completions to load" mechanism with moderately

less hackish and far simpler "perform on main thread" mechanism
This commit is contained in:
ridiculousfish
2013-11-29 23:44:26 -08:00
parent 4aaa9e7d9f
commit 263f919beb
5 changed files with 24 additions and 57 deletions

View File

@@ -44,6 +44,7 @@
#include "parser_keywords.h"
#include "wutil.h"
#include "path.h"
#include "iothread.h"
/*
Completion description strings, mostly for different types of files, such as sockets, block devices, etc.
@@ -341,7 +342,6 @@ class completer_t
const completion_request_flags_t flags;
const wcstring initial_cmd;
std::vector<completion_t> completions;
wcstring_list_t commands_to_load;
/** Table of completions conditions that have already been tested and the corresponding test results */
typedef std::map<wcstring, bool> condition_cache_t;
@@ -438,18 +438,6 @@ public:
return result;
}
void get_commands_to_load(wcstring_list_t *lst)
{
if (lst)
lst->insert(lst->end(), commands_to_load.begin(), commands_to_load.end());
}
bool has_commands_to_load() const
{
return ! commands_to_load.empty();
}
};
/* Autoloader for completions */
@@ -1350,6 +1338,15 @@ void complete_load(const wcstring &name, bool reload)
completion_autoloader.load(name, reload);
}
// Performed on main thread, from background thread. Return type is ignored.
static int complete_load_no_reload(wcstring *name)
{
assert(name != NULL);
ASSERT_IS_MAIN_THREAD();
complete_load(*name, false);
return 0;
}
/**
Find completion for the argument str of command cmd_orig with
previous option popt. Insert results into comp_out. Return 0 if file
@@ -1372,14 +1369,15 @@ bool completer_t::complete_param(const wcstring &scmd_orig, const wcstring &spop
if (this->type() == COMPLETE_DEFAULT)
{
ASSERT_IS_MAIN_THREAD();
complete_load(cmd, true);
}
else if (this->type() == COMPLETE_AUTOSUGGEST)
{
/* Maybe indicate we should try loading this on the main thread */
if (! list_contains_string(this->commands_to_load, cmd) && ! completion_autoloader.has_tried_loading(cmd))
/* Maybe load this command (on the main thread) */
if (! completion_autoloader.has_tried_loading(cmd))
{
this->commands_to_load.push_back(cmd);
iothread_perform_on_main(complete_load_no_reload, &cmd);
}
}
@@ -1790,7 +1788,7 @@ bool completer_t::try_complete_user(const wcstring &str)
return res;
}
void complete(const wcstring &cmd, std::vector<completion_t> &comps, completion_request_flags_t flags, wcstring_list_t *commands_to_load)
void complete(const wcstring &cmd, std::vector<completion_t> &comps, completion_request_flags_t flags)
{
/* Make our completer */
completer_t completer(cmd, flags);
@@ -1999,12 +1997,7 @@ void complete(const wcstring &cmd, std::vector<completion_t> &comps, completion_
if (completer.empty())
do_file = true;
/* But if we are planning on loading commands, don't do file completions.
See https://github.com/fish-shell/fish-shell/issues/378 */
if (commands_to_load != NULL && completer.has_commands_to_load())
do_file = false;
/* And if we're autosuggesting, and the token is empty, don't do file suggestions */
/* If we're autosuggesting, and the token is empty, don't do file suggestions */
if ((flags & COMPLETION_REQUEST_AUTOSUGGESTION) && current_token_unescape.empty())
do_file = false;
@@ -2016,7 +2009,6 @@ void complete(const wcstring &cmd, std::vector<completion_t> &comps, completion_
}
comps = completer.get_completions();
completer.get_commands_to_load(commands_to_load);
}