mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-25 14:51:15 -03:00
Replace autosuggestions "completions to load" mechanism with moderately
less hackish and far simpler "perform on main thread" mechanism
This commit is contained in:
28
reader.cpp
28
reader.cpp
@@ -1410,12 +1410,8 @@ struct autosuggestion_context_t
|
||||
file_detection_context_t detector;
|
||||
const wcstring working_directory;
|
||||
const env_vars_snapshot_t vars;
|
||||
wcstring_list_t commands_to_load;
|
||||
const unsigned int generation_count;
|
||||
|
||||
// don't reload more than once
|
||||
bool has_tried_reloading;
|
||||
|
||||
autosuggestion_context_t(history_t *history, const wcstring &term, size_t pos) :
|
||||
search_string(term),
|
||||
cursor_pos(pos),
|
||||
@@ -1423,8 +1419,7 @@ struct autosuggestion_context_t
|
||||
detector(history, term),
|
||||
working_directory(env_get_pwd_slash()),
|
||||
vars(env_vars_snapshot_t::highlighting_keys),
|
||||
generation_count(s_generation_count),
|
||||
has_tried_reloading(false)
|
||||
generation_count(s_generation_count)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1494,7 +1489,7 @@ struct autosuggestion_context_t
|
||||
|
||||
/* Try normal completions */
|
||||
std::vector<completion_t> completions;
|
||||
complete(search_string, completions, COMPLETION_REQUEST_AUTOSUGGESTION, &this->commands_to_load);
|
||||
complete(search_string, completions, COMPLETION_REQUEST_AUTOSUGGESTION);
|
||||
if (! completions.empty())
|
||||
{
|
||||
const completion_t &comp = completions.at(0);
|
||||
@@ -1523,23 +1518,6 @@ static bool can_autosuggest(void)
|
||||
|
||||
static void autosuggest_completed(autosuggestion_context_t *ctx, int result)
|
||||
{
|
||||
|
||||
/* Extract the commands to load */
|
||||
wcstring_list_t commands_to_load;
|
||||
ctx->commands_to_load.swap(commands_to_load);
|
||||
|
||||
/* If we have autosuggestions to load, load them and try again */
|
||||
if (! result && ! commands_to_load.empty() && ! ctx->has_tried_reloading)
|
||||
{
|
||||
ctx->has_tried_reloading = true;
|
||||
for (wcstring_list_t::const_iterator iter = commands_to_load.begin(); iter != commands_to_load.end(); ++iter)
|
||||
{
|
||||
complete_load(*iter, false);
|
||||
}
|
||||
iothread_perform(threaded_autosuggest, autosuggest_completed, ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
if (result &&
|
||||
can_autosuggest() &&
|
||||
ctx->search_string == data->command_line &&
|
||||
@@ -3271,7 +3249,7 @@ const wchar_t *reader_readline(void)
|
||||
const wcstring buffcpy = wcstring(cmdsub_begin, token_end);
|
||||
|
||||
//fprintf(stderr, "Complete (%ls)\n", buffcpy.c_str());
|
||||
data->complete_func(buffcpy, comp, COMPLETION_REQUEST_DEFAULT | COMPLETION_REQUEST_DESCRIPTIONS | COMPLETION_REQUEST_FUZZY_MATCH, NULL);
|
||||
data->complete_func(buffcpy, comp, COMPLETION_REQUEST_DEFAULT | COMPLETION_REQUEST_DESCRIPTIONS | COMPLETION_REQUEST_FUZZY_MATCH);
|
||||
|
||||
/* Munge our completions */
|
||||
sort_and_make_unique(comp);
|
||||
|
||||
Reference in New Issue
Block a user