From 4bb18eaf4225ce98b9100bc17da0bef9f2229b62 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 15 Jan 2020 16:13:41 -0800 Subject: [PATCH] Use completion_list_t naming everywhere std::vector -> completion_list_t --- src/builtin.cpp | 2 +- src/builtin.h | 3 ++- src/builtin_complete.cpp | 2 +- src/complete.cpp | 29 +++++++++++------------- src/complete.h | 13 ++++++----- src/expand.cpp | 48 +++++++++++++++++++--------------------- src/expand.h | 3 ++- src/fish_tests.cpp | 10 ++++----- src/pager.cpp | 2 +- src/pager.h | 2 -- src/parse_execution.cpp | 6 ++--- src/parser.cpp | 9 ++++---- src/parser.h | 7 +++--- src/reader.cpp | 14 ++++++------ src/reader.h | 2 +- src/wildcard.cpp | 15 ++++++------- src/wildcard.h | 6 ++--- 17 files changed, 82 insertions(+), 91 deletions(-) diff --git a/src/builtin.cpp b/src/builtin.cpp index c41dc09d9..cf4bb57ec 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -479,7 +479,7 @@ wcstring_list_t builtin_get_names() { } /// Insert all builtin names into list. -void builtin_get_names(std::vector *list) { +void builtin_get_names(completion_list_t *list) { assert(list != nullptr); list->reserve(list->size() + BUILTIN_COUNT); for (const auto &builtin_data : builtin_datas) { diff --git a/src/builtin.h b/src/builtin.h index 2d37cbff1..9b89cdee6 100644 --- a/src/builtin.h +++ b/src/builtin.h @@ -13,6 +13,7 @@ class parser_t; class proc_status_t; class output_stream_t; struct io_streams_t; +using completion_list_t = std::vector; /// Data structure to describe a builtin. struct builtin_data_t { @@ -83,7 +84,7 @@ bool builtin_exists(const wcstring &cmd); proc_status_t builtin_run(parser_t &parser, int job_pgid, wchar_t **argv, io_streams_t &streams); wcstring_list_t builtin_get_names(); -void builtin_get_names(std::vector *list); +void builtin_get_names(completion_list_t *list); const wchar_t *builtin_get_desc(const wcstring &name); wcstring builtin_help_get(parser_t &parser, const wchar_t *cmd); diff --git a/src/builtin_complete.cpp b/src/builtin_complete.cpp index 3e2372826..bdabbd98c 100644 --- a/src/builtin_complete.cpp +++ b/src/builtin_complete.cpp @@ -347,7 +347,7 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) { if (!have_do_complete_param) parser.libdata().builtin_complete_current_commandline = true; - std::vector comp; + completion_list_t comp; complete(do_complete_param, &comp, completion_request_t::fuzzy_match, parser.vars(), parser.shared()); diff --git a/src/complete.cpp b/src/complete.cpp index c67284ee4..83f25f07a 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -257,7 +257,7 @@ __attribute__((always_inline)) static inline bool compare_completions_by_tilde( } /// Unique the list of completions, without perturbing their order. -static void unique_completions_retaining_order(std::vector *comps) { +static void unique_completions_retaining_order(completion_list_t *comps) { std::unordered_set seen; seen.reserve(comps->size()); auto pred = [&seen](const completion_t &c) { @@ -268,8 +268,7 @@ static void unique_completions_retaining_order(std::vector *comps) comps->erase(std::remove_if(comps->begin(), comps->end(), pred), comps->end()); } -void completions_sort_and_prioritize(std::vector *comps, - completion_request_flags_t flags) { +void completions_sort_and_prioritize(completion_list_t *comps, completion_request_flags_t flags) { // Find the best match type. fuzzy_match_type_t best_type = fuzzy_match_none; for (const auto &comp : *comps) { @@ -326,7 +325,7 @@ class completer_t { const completion_request_flags_t flags; /// The output completions. - std::vector completions; + completion_list_t completions; /// Table of completions conditions that have already been tested and the corresponding test /// results. @@ -374,7 +373,7 @@ class completer_t { bool condition_test(const wcstring &condition); void complete_strings(const wcstring &wc_escaped, const description_func_t &desc_func, - const std::vector &possible_comp, complete_flags_t flags); + const completion_list_t &possible_comp, complete_flags_t flags); expand_flags_t expand_flags() const { // Never do command substitution in autosuggestions. Sadly, we also can't yet do job @@ -402,14 +401,14 @@ class completer_t { void perform(); - std::vector acquire_completions() { return std::move(completions); } + completion_list_t acquire_completions() { return std::move(completions); } }; // Autoloader for completions. static owning_lock completion_autoloader{autoload_t(L"fish_complete_path")}; /// Create a new completion entry. -void append_completion(std::vector *completions, wcstring comp, wcstring desc, +void append_completion(completion_list_t *completions, wcstring comp, wcstring desc, complete_flags_t flags, string_fuzzy_match_t &&match) { completions->emplace_back(std::move(comp), std::move(desc), match, flags); } @@ -555,8 +554,7 @@ static void parse_cmd_string(const wcstring &str, wcstring *path, wcstring *cmd, /// @param flags /// The flags void completer_t::complete_strings(const wcstring &wc_escaped, const description_func_t &desc_func, - const std::vector &possible_comp, - complete_flags_t flags) { + const completion_list_t &possible_comp, complete_flags_t flags) { wcstring tmp = wc_escaped; if (!expand_one(tmp, this->expand_flags() | expand_flag::skip_cmdsubst | expand_flag::skip_wildcards, @@ -678,7 +676,7 @@ static wcstring complete_function_desc(const wcstring &fn) { /// /// \param str_cmd the command string to find completions for void completer_t::complete_cmd(const wcstring &str_cmd) { - std::vector possible_comp; + completion_list_t possible_comp; // Append all possible executables expand_result_t result = @@ -720,7 +718,7 @@ void completer_t::complete_cmd(const wcstring &str_cmd) { void completer_t::complete_abbr(const wcstring &cmd) { std::map abbrs = get_abbreviations(vars); - std::vector possible_comp; + completion_list_t possible_comp; possible_comp.reserve(abbrs.size()); for (const auto &kv : abbrs) { possible_comp.emplace_back(kv.first); @@ -765,8 +763,7 @@ void completer_t::complete_from_args(const wcstring &str, const wcstring &args, eflags |= expand_flag::skip_cmdsubst; } - std::vector possible_comp = - parser_t::expand_argument_list(args, eflags, vars, parser); + completion_list_t possible_comp = parser_t::expand_argument_list(args, eflags, vars, parser); if (parser) { parser->libdata().is_interactive = saved_interactive; @@ -1139,7 +1136,7 @@ void completer_t::complete_param_expand(const wcstring &str, bool do_file, // so any quoting or braces gets lost. // See #4954. const wcstring sep_string = wcstring(str, sep_index + 1); - std::vector local_completions; + completion_list_t local_completions; if (expand_string(sep_string, &local_completions, flags, vars, parser, nullptr) == expand_result_t::error) { debug(3, L"Error while expanding string '%ls'", sep_string.c_str()); @@ -1598,7 +1595,7 @@ void completer_t::perform() { parser->libdata().transient_commandlines.push_back(unaliased_cmd); cleanup_t remove_transient( [&] { parser->libdata().transient_commandlines.pop_back(); }); - std::vector comp; + completion_list_t comp; complete(unaliased_cmd, &comp, completion_request_t::fuzzy_match, parser->vars(), parser->shared()); this->completions.insert(completions.end(), comp.begin(), comp.end()); @@ -1638,7 +1635,7 @@ void completer_t::perform() { mark_completions_duplicating_arguments(current_token, tokens); } -void complete(const wcstring &cmd_with_subcmds, std::vector *out_comps, +void complete(const wcstring &cmd_with_subcmds, completion_list_t *out_comps, completion_request_flags_t flags, const environment_t &vars, const std::shared_ptr &parser) { // Determine the innermost subcommand. diff --git a/src/complete.h b/src/complete.h index 8ba5373b3..03c0147df 100644 --- a/src/complete.h +++ b/src/complete.h @@ -101,6 +101,8 @@ class completion_t { void prepend_token_prefix(const wcstring &prefix); }; +using completion_list_t = std::vector; + enum class completion_request_t { autosuggestion, // indicates the completion is for an autosuggestion descriptions, // indicates that we want descriptions @@ -124,7 +126,7 @@ enum complete_option_type_t { /// Sorts and remove any duplicate completions in the completion list, then puts them in priority /// order. -void completions_sort_and_prioritize(std::vector *comps, +void completions_sort_and_prioritize(completion_list_t *comps, completion_request_flags_t flags = {}); /// Add a completion. @@ -171,9 +173,8 @@ void complete_remove_all(const wcstring &cmd, bool cmd_is_path); /// Find all completions of the command cmd, insert them into out. class parser_t; -void complete(const wcstring &cmd, std::vector *out_comps, - completion_request_flags_t flags, const environment_t &vars, - const std::shared_ptr &parser); +void complete(const wcstring &cmd, completion_list_t *out_comps, completion_request_flags_t flags, + const environment_t &vars, const std::shared_ptr &parser); /// Return a list of all current completions. wcstring complete_print(); @@ -191,8 +192,8 @@ bool complete_is_valid_argument(const wcstring &str, const wcstring &opt, const /// \param comp The completion string /// \param desc The description of the completion /// \param flags completion flags -void append_completion(std::vector *completions, wcstring comp, - wcstring desc = wcstring(), int flags = 0, +void append_completion(completion_list_t *completions, wcstring comp, wcstring desc = wcstring(), + int flags = 0, string_fuzzy_match_t &&match = string_fuzzy_match_t(fuzzy_match_exact)); /// Support for "wrap targets." A wrap target is a command that completes like another command. diff --git a/src/expand.cpp b/src/expand.cpp index 1f677e5a7..ee342e29f 100644 --- a/src/expand.cpp +++ b/src/expand.cpp @@ -268,7 +268,7 @@ static size_t parse_slice(const wchar_t *in, wchar_t **end_ptr, std::vector *out, size_t last_idx, +static bool expand_variables(wcstring instr, completion_list_t *out, size_t last_idx, const environment_t &vars, parse_error_list_t *errors) { const size_t insize = instr.size(); @@ -466,7 +466,7 @@ static bool expand_variables(wcstring instr, std::vector *out, siz /// Perform brace expansion. static expand_result_t expand_braces(const wcstring &instr, expand_flags_t flags, - std::vector *out, parse_error_list_t *errors) { + completion_list_t *out, parse_error_list_t *errors) { bool syntax_error = false; int brace_count = 0; @@ -575,7 +575,7 @@ static expand_result_t expand_braces(const wcstring &instr, expand_flags_t flags } /// Perform cmdsubst expansion. -static bool expand_cmdsubst(wcstring input, parser_t &parser, std::vector *out_list, +static bool expand_cmdsubst(wcstring input, parser_t &parser, completion_list_t *out_list, parse_error_list_t *errors) { wchar_t *paren_begin = nullptr, *paren_end = nullptr; wchar_t *tail_begin = nullptr; @@ -649,7 +649,7 @@ static bool expand_cmdsubst(wcstring input, parser_t &parser, std::vector tail_expand; + completion_list_t tail_expand; expand_cmdsubst(tail_begin, parser, &tail_expand, errors); // TODO: offset error locations // Combine the result of the current command substitution with the result of the recursive tail @@ -761,7 +761,7 @@ void expand_tilde(wcstring &input, const environment_t &vars) { } static void unexpand_tildes(const wcstring &input, const environment_t &vars, - std::vector *completions) { + completion_list_t *completions) { // If input begins with tilde, then try to replace the corresponding string in each completion // with the tilde. If it does not, there's nothing to do. if (input.empty() || input.at(0) != L'~') return; @@ -865,26 +865,26 @@ class expander_t { /// An expansion stage is a member function pointer. /// It accepts the input string (transferring ownership) and returns the list of output /// completions by reference. It may return an error, which halts expansion. - using stage_t = expand_result_t (expander_t::*)(wcstring, std::vector *); + using stage_t = expand_result_t (expander_t::*)(wcstring, completion_list_t *); - expand_result_t stage_cmdsubst(wcstring input, std::vector *out); - expand_result_t stage_variables(wcstring input, std::vector *out); - expand_result_t stage_braces(wcstring input, std::vector *out); - expand_result_t stage_home_and_self(wcstring input, std::vector *out); - expand_result_t stage_wildcards(wcstring path_to_expand, std::vector *out); + expand_result_t stage_cmdsubst(wcstring input, completion_list_t *out); + expand_result_t stage_variables(wcstring input, completion_list_t *out); + expand_result_t stage_braces(wcstring input, completion_list_t *out); + expand_result_t stage_home_and_self(wcstring input, completion_list_t *out); + expand_result_t stage_wildcards(wcstring path_to_expand, completion_list_t *out); expander_t(const environment_t &vars, std::shared_ptr parser, expand_flags_t flags, parse_error_list_t *errors) : vars(vars), parser(std::move(parser)), flags(flags), errors(errors) {} public: - static expand_result_t expand_string(wcstring input, std::vector *out_completions, + static expand_result_t expand_string(wcstring input, completion_list_t *out_completions, expand_flags_t flags, const environment_t &vars, const std::shared_ptr &parser, parse_error_list_t *errors); }; -expand_result_t expander_t::stage_cmdsubst(wcstring input, std::vector *out) { +expand_result_t expander_t::stage_cmdsubst(wcstring input, completion_list_t *out) { if (flags & expand_flag::skip_cmdsubst) { size_t cur = 0, start = 0, end; switch (parse_util_locate_cmdsubst_range(input, &cur, nullptr, &start, &end, true)) { @@ -907,7 +907,7 @@ expand_result_t expander_t::stage_cmdsubst(wcstring input, std::vector *out) { +expand_result_t expander_t::stage_variables(wcstring input, completion_list_t *out) { // We accept incomplete strings here, since complete uses expand_string to expand incomplete // strings from the commandline. wcstring next; @@ -929,12 +929,12 @@ expand_result_t expander_t::stage_variables(wcstring input, std::vector *out) { +expand_result_t expander_t::stage_braces(wcstring input, completion_list_t *out) { UNUSED(vars); return expand_braces(input, flags, out, errors); } -expand_result_t expander_t::stage_home_and_self(wcstring input, std::vector *out) { +expand_result_t expander_t::stage_home_and_self(wcstring input, completion_list_t *out) { if (!(flags & expand_flag::skip_home_directories)) { expand_home_directory(input, vars); } @@ -943,8 +943,7 @@ expand_result_t expander_t::stage_home_and_self(wcstring input, std::vector *out) { +expand_result_t expander_t::stage_wildcards(wcstring path_to_expand, completion_list_t *out) { expand_result_t result = expand_result_t::ok; remove_internal_separator(&path_to_expand, flags & expand_flag::skip_wildcards); @@ -1008,7 +1007,7 @@ expand_result_t expander_t::stage_wildcards(wcstring path_to_expand, } result = expand_result_t::wildcard_no_match; - std::vector expanded; + completion_list_t expanded; for (const auto &effective_working_dir : effective_working_dirs) { wildcard_expand_result_t expand_res = wildcard_expand_string(path_to_expand, effective_working_dir, flags, &expanded); @@ -1038,8 +1037,7 @@ expand_result_t expander_t::stage_wildcards(wcstring path_to_expand, return result; } -expand_result_t expander_t::expand_string(wcstring input, - std::vector *out_completions, +expand_result_t expander_t::expand_string(wcstring input, completion_list_t *out_completions, expand_flags_t flags, const environment_t &vars, const std::shared_ptr &parser, parse_error_list_t *errors) { @@ -1059,7 +1057,7 @@ expand_result_t expander_t::expand_string(wcstring input, &expander_t::stage_wildcards}; // Load up our single initial completion. - std::vector completions, output_storage; + completion_list_t completions, output_storage; append_completion(&completions, input); expand_result_t total_result = expand_result_t::ok; @@ -1099,7 +1097,7 @@ expand_result_t expander_t::expand_string(wcstring input, } } // namespace -expand_result_t expand_string(wcstring input, std::vector *out_completions, +expand_result_t expand_string(wcstring input, completion_list_t *out_completions, expand_flags_t flags, const environment_t &vars, const shared_ptr &parser, parse_error_list_t *errors) { return expander_t::expand_string(std::move(input), out_completions, flags, vars, parser, @@ -1108,7 +1106,7 @@ expand_result_t expand_string(wcstring input, std::vector *out_com bool expand_one(wcstring &string, expand_flags_t flags, const environment_t &vars, const shared_ptr &parser, parse_error_list_t *errors) { - std::vector completions; + completion_list_t completions; if (!flags.get(expand_flag::for_completions) && expand_is_clean(string)) { return true; @@ -1132,7 +1130,7 @@ expand_result_t expand_to_command_and_args(const wcstring &instr, const environm return expand_result_t::ok; } - std::vector completions; + completion_list_t completions; expand_result_t expand_err = expand_string( instr, &completions, {expand_flag::skip_cmdsubst, expand_flag::no_descriptions, expand_flag::skip_jobs}, vars, diff --git a/src/expand.h b/src/expand.h index 8a0380dea..6f7e56e27 100644 --- a/src/expand.h +++ b/src/expand.h @@ -69,6 +69,7 @@ struct enum_info_t { using expand_flags_t = enum_set_t; class completion_t; +using completion_list_t = std::vector; enum : wchar_t { /// Character representing a home directory. @@ -132,7 +133,7 @@ enum class expand_result_t { /// wildcard_no_match and wildcard_match are normal exit conditions used only on /// strings containing wildcards to tell if the wildcard produced any matches. class parser_t; -__warn_unused expand_result_t expand_string(wcstring input, std::vector *output, +__warn_unused expand_result_t expand_string(wcstring input, completion_list_t *output, expand_flags_t flags, const environment_t &vars, const std::shared_ptr &parser, parse_error_list_t *errors); diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index b791fb5bd..a73aa6e52 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -1639,7 +1639,7 @@ struct pwd_environment_t : public environment_t { /// After the zero terminator comes one more arg, a string, which is the error /// message to print if the test fails. static bool expand_test(const wchar_t *in, expand_flags_t flags, ...) { - std::vector output; + completion_list_t output; va_list va; bool res = true; wchar_t *arg; @@ -1665,7 +1665,7 @@ static bool expand_test(const wchar_t *in, expand_flags_t flags, ...) { va_end(va); std::set remaining(expected.begin(), expected.end()); - std::vector::const_iterator out_it = output.begin(), out_end = output.end(); + completion_list_t::const_iterator out_it = output.begin(), out_end = output.end(); for (; out_it != out_end; ++out_it) { if (!remaining.erase(out_it->completion)) { res = false; @@ -1690,7 +1690,7 @@ static bool expand_test(const wchar_t *in, expand_flags_t flags, ...) { } msg += L"], found ["; first = true; - for (std::vector::const_iterator it = output.begin(), end = output.end(); + for (completion_list_t::const_iterator it = output.begin(), end = output.end(); it != end; ++it) { if (!first) msg += L", "; first = false; @@ -2898,7 +2898,7 @@ static void test_completion_insertions() { static void perform_one_autosuggestion_cd_test(const wcstring &command, const wcstring &expected, const environment_t &vars, long line) { - std::vector comps; + completion_list_t comps; complete(command, &comps, completion_request_t::autosuggestion, vars, nullptr); bool expects_error = (expected == L""); @@ -2934,7 +2934,7 @@ static void perform_one_autosuggestion_cd_test(const wcstring &command, const wc static void perform_one_completion_cd_test(const wcstring &command, const wcstring &expected, const environment_t &vars, long line) { - std::vector comps; + completion_list_t comps; complete(command, &comps, {}, vars, nullptr); bool expects_error = (expected == L""); diff --git a/src/pager.cpp b/src/pager.cpp index a26711a41..327bb3cac 100644 --- a/src/pager.cpp +++ b/src/pager.cpp @@ -21,7 +21,7 @@ #include "wutil.h" // IWYU pragma: keep using comp_t = pager_t::comp_t; -using completion_list_t = std::vector; +using completion_list_t = completion_list_t; using comp_info_list_t = std::vector; /// The minimum width (in characters) the terminal must to show completions at all. diff --git a/src/pager.h b/src/pager.h index 943f2ff47..2b60efef7 100644 --- a/src/pager.h +++ b/src/pager.h @@ -60,8 +60,6 @@ enum class selection_motion_t { // How many rows we will show in the "initial" pager. #define PAGER_UNDISCLOSED_MAX_ROWS 4 -typedef std::vector completion_list_t; - class pager_t { size_t available_term_width; size_t available_term_height; diff --git a/src/parse_execution.cpp b/src/parse_execution.cpp index f5849651a..56bcfcf0d 100644 --- a/src/parse_execution.cpp +++ b/src/parse_execution.cpp @@ -456,7 +456,7 @@ eval_result_t parse_execution_context_t::run_switch_statement( const wcstring switch_value = get_source(switch_value_n); // Expand it. We need to offset any errors by the position of the string. - std::vector switch_values_expanded; + completion_list_t switch_values_expanded; parse_error_list_t errors; auto expand_ret = expand_string(switch_value, &switch_values_expanded, expand_flag::no_descriptions, @@ -868,7 +868,7 @@ eval_result_t parse_execution_context_t::expand_arguments_from_nodes( // Get all argument nodes underneath the statement. We guess we'll have that many arguments (but // may have more or fewer, if there are wildcards involved). out_arguments->reserve(out_arguments->size() + argument_nodes.size()); - std::vector arg_expanded; + completion_list_t arg_expanded; for (const auto &arg_node : argument_nodes) { // Expect all arguments to have source. assert(arg_node.has_source()); @@ -1023,7 +1023,7 @@ eval_result_t parse_execution_context_t::apply_variable_assignments( assert(equals_pos); const wcstring &variable_name = source.substr(0, *equals_pos); const wcstring expression = source.substr(*equals_pos + 1); - std::vector expression_expanded; + completion_list_t expression_expanded; parse_error_list_t errors; // TODO this is mostly copied from expand_arguments_from_nodes, maybe extract to function auto expand_ret = diff --git a/src/parser.cpp b/src/parser.cpp index c989e888c..1ebb6a2ea 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -305,10 +305,9 @@ void parser_t::emit_profiling(const char *path) const { } } -std::vector parser_t::expand_argument_list(const wcstring &arg_list_src, - expand_flags_t eflags, - const environment_t &vars, - const std::shared_ptr &parser) { +completion_list_t parser_t::expand_argument_list(const wcstring &arg_list_src, + expand_flags_t eflags, const environment_t &vars, + const std::shared_ptr &parser) { // Parse the string as an argument list. parse_node_tree_t tree; if (!parse_tree_from_string(arg_list_src, parse_flag_none, &tree, nullptr /* errors */, @@ -318,7 +317,7 @@ std::vector parser_t::expand_argument_list(const wcstring &arg_lis } // Get the root argument list and extract arguments from it. - std::vector result; + completion_list_t result; assert(!tree.empty()); tnode_t arg_list(&tree, &tree.at(0)); while (auto arg = arg_list.next_in_list()) { diff --git a/src/parser.h b/src/parser.h index 43d42ec42..c5863927e 100644 --- a/src/parser.h +++ b/src/parser.h @@ -279,10 +279,9 @@ class parser_t : public std::enable_shared_from_this { /// Evaluate line as a list of parameters, i.e. tokenize it and perform parameter expansion and /// cmdsubst execution on the tokens. Errors are ignored. If a parser is provided, it is used /// for command substitution expansion. - static std::vector expand_argument_list(const wcstring &arg_list_src, - expand_flags_t flags, - const environment_t &vars, - const std::shared_ptr &parser); + static completion_list_t expand_argument_list(const wcstring &arg_list_src, + expand_flags_t flags, const environment_t &vars, + const std::shared_ptr &parser); /// Returns a string describing the current parser position in the format 'FILENAME (line /// LINE_NUMBER): LINE'. Example: diff --git a/src/reader.cpp b/src/reader.cpp index 61136d032..b67d34d51 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -478,8 +478,8 @@ class reader_data_t : public std::enable_shared_from_this { bool jump(jump_direction_t dir, jump_precision_t precision, editable_line_t *el, wchar_t target); - bool handle_completions(const std::vector &comp, size_t token_begin, - size_t token_end, bool cont_after_prefix_insertion); + bool handle_completions(const completion_list_t &comp, size_t token_begin, size_t token_end, + bool cont_after_prefix_insertion); void sanity_check() const; void set_command_line_and_position(editable_line_t *el, const wcstring &new_str, size_t pos); @@ -1325,7 +1325,7 @@ static std::function get_autosuggestion_performer // Try normal completions. completion_request_flags_t complete_flags = completion_request_t::autosuggestion; - std::vector completions; + completion_list_t completions; complete(search_string, &completions, complete_flags, *vars, nullptr); completions_sort_and_prioritize(&completions, complete_flags); if (!completions.empty()) { @@ -1466,7 +1466,7 @@ static bool reader_can_replace(const wcstring &in, int flags) { } /// Determine the best match type for a set of completions. -static fuzzy_match_type_t get_best_match_type(const std::vector &comp) { +static fuzzy_match_type_t get_best_match_type(const completion_list_t &comp) { fuzzy_match_type_t best_type = fuzzy_match_none; for (const auto &i : comp) { best_type = std::min(best_type, i.match.type); @@ -1497,7 +1497,7 @@ static fuzzy_match_type_t get_best_match_type(const std::vector &c /// completions after inserting it. /// /// Return true if we inserted text into the command line, false if we did not. -bool reader_data_t::handle_completions(const std::vector &comp, size_t token_begin, +bool reader_data_t::handle_completions(const completion_list_t &comp, size_t token_begin, size_t token_end, bool cont_after_prefix_insertion) { bool done = false; bool success = false; @@ -1543,7 +1543,7 @@ bool reader_data_t::handle_completions(const std::vector &comp, si // Decide which completions survived. There may be a lot of them; it would be nice if we could // figure out how to avoid copying them here. - std::vector surviving_completions; + completion_list_t surviving_completions; for (const completion_t &el : comp) { // Ignore completions with a less suitable match type than the best. if (el.match.type > best_match_type) continue; @@ -2381,7 +2381,7 @@ struct readline_loop_state_t { bool comp_empty{true}; /// List of completions. - std::vector comp; + completion_list_t comp; /// Whether we are skipping redundant repaints. bool coalescing_repaints = false; diff --git a/src/reader.h b/src/reader.h index ee90940c1..39eec1ba2 100644 --- a/src/reader.h +++ b/src/reader.h @@ -147,7 +147,7 @@ void reader_push(parser_t &parser, const wcstring &name); void reader_pop(); /// Specify function to use for finding possible tab completions. -typedef void (*complete_function_t)(const wcstring &, std::vector *, +typedef void (*complete_function_t)(const wcstring &, completion_list_t *, completion_request_flags_t, const environment_t &, const std::shared_ptr &parser); void reader_set_complete_function(complete_function_t); diff --git a/src/wildcard.cpp b/src/wildcard.cpp index d3c7ad12b..52c33ad0c 100644 --- a/src/wildcard.cpp +++ b/src/wildcard.cpp @@ -184,7 +184,7 @@ struct wc_complete_pack_t { }; // Weirdly specific and non-reusable helper function that makes its one call site much clearer. -static bool has_prefix_match(const std::vector *comps, size_t first) { +static bool has_prefix_match(const completion_list_t *comps, size_t first) { if (comps != nullptr) { const size_t after_count = comps->size(); for (size_t j = first; j < after_count; j++) { @@ -203,7 +203,7 @@ static bool has_prefix_match(const std::vector *comps, size_t firs /// wildcards. This is historic behavior. static bool wildcard_complete_internal(const wchar_t *str, const wchar_t *wc, const wc_complete_pack_t ¶ms, complete_flags_t flags, - std::vector *out, bool is_first_call = false) { + completion_list_t *out, bool is_first_call = false) { assert(str != nullptr); assert(wc != nullptr); @@ -315,7 +315,7 @@ static bool wildcard_complete_internal(const wchar_t *str, const wchar_t *wc, bool wildcard_complete(const wcstring &str, const wchar_t *wc, const std::function &desc_func, - std::vector *out, expand_flags_t expand_flags, + completion_list_t *out, expand_flags_t expand_flags, complete_flags_t flags) { // Note out may be NULL. assert(wc != nullptr); @@ -390,7 +390,7 @@ static const wchar_t *file_get_desc(const wcstring &filename, int lstat_res, /// up. Note that the filename came from a readdir() call, so we know it exists. static bool wildcard_test_flags_then_complete(const wcstring &filepath, const wcstring &filename, const wchar_t *wc, expand_flags_t expand_flags, - std::vector *out) { + completion_list_t *out) { // Check if it will match before stat(). if (!wildcard_complete(filename, wc, {}, nullptr, expand_flags, 0)) { return false; @@ -465,7 +465,7 @@ class wildcard_expander_t { // Flags controlling expansion. const expand_flags_t flags; // Resolved items get inserted into here. This is transient of course. - std::vector *resolved_completions; + completion_list_t *resolved_completions; // Whether we have been interrupted. bool did_interrupt{false}; // Whether we have successfully added any completions. @@ -629,7 +629,7 @@ class wildcard_expander_t { } public: - wildcard_expander_t(wcstring wd, expand_flags_t f, std::vector *r) + wildcard_expander_t(wcstring wd, expand_flags_t f, completion_list_t *r) : working_directory(std::move(wd)), flags(f), resolved_completions(r) { assert(resolved_completions != nullptr); @@ -897,8 +897,7 @@ void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc, wildcard_expand_result_t wildcard_expand_string(const wcstring &wc, const wcstring &working_directory, - expand_flags_t flags, - std::vector *output) { + expand_flags_t flags, completion_list_t *output) { assert(output != nullptr); // Fuzzy matching only if we're doing completions. assert(flags.get(expand_flag::for_completions) || !flags.get(expand_flag::fuzzy_match)); diff --git a/src/wildcard.h b/src/wildcard.h index 506e8a4a7..1b03e6e2f 100644 --- a/src/wildcard.h +++ b/src/wildcard.h @@ -48,8 +48,7 @@ enum class wildcard_expand_result_t { }; wildcard_expand_result_t wildcard_expand_string(const wcstring &wc, const wcstring &working_directory, - expand_flags_t flags, - std::vector *out); + expand_flags_t flags, completion_list_t *out); /// Test whether the given wildcard matches the string. Does not perform any I/O. /// @@ -68,7 +67,6 @@ bool wildcard_has(const wchar_t *, bool internal); /// Test wildcard completion. bool wildcard_complete(const wcstring &str, const wchar_t *wc, const description_func_t &desc_func, - std::vector *out, expand_flags_t expand_flags, - complete_flags_t flags); + completion_list_t *out, expand_flags_t expand_flags, complete_flags_t flags); #endif