mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-29 05:03:46 +08:00
Eliminate complete_set_variable_names
This commit is contained in:
parent
e6b13c6bac
commit
94adb53b1f
|
@ -74,20 +74,6 @@ static const wcstring &C_(const wcstring &s) { return s; }
|
|||
|
||||
static void complete_load(const wcstring &name, bool reload);
|
||||
|
||||
/// Testing apparatus.
|
||||
const wcstring_list_t *s_override_variable_names = NULL;
|
||||
|
||||
void complete_set_variable_names(const wcstring_list_t *names) {
|
||||
s_override_variable_names = names;
|
||||
}
|
||||
|
||||
static inline wcstring_list_t complete_get_variable_names(const environment_t &vars) {
|
||||
if (s_override_variable_names != NULL) {
|
||||
return *s_override_variable_names;
|
||||
}
|
||||
return vars.get_names(0);
|
||||
}
|
||||
|
||||
/// Struct describing a completion option entry.
|
||||
///
|
||||
/// If option is empty, the comp field must not be empty and contains a list of arguments to the
|
||||
|
@ -1125,10 +1111,8 @@ bool completer_t::complete_variable(const wcstring &str, size_t start_offset) {
|
|||
size_t varlen = str.length() - start_offset;
|
||||
bool res = false;
|
||||
|
||||
const wcstring_list_t names = complete_get_variable_names(vars);
|
||||
for (size_t i = 0; i < names.size(); i++) {
|
||||
const wcstring &env_name = names.at(i);
|
||||
|
||||
const wcstring_list_t names = vars.get_names(0);
|
||||
for (const wcstring &env_name : vars.get_names(0)) {
|
||||
string_fuzzy_match_t match =
|
||||
string_fuzzy_match_string(var, env_name, this->max_fuzzy_match_type());
|
||||
if (match.type == fuzzy_match_none) {
|
||||
|
|
|
@ -196,8 +196,6 @@ void append_completion(std::vector<completion_t> *completions, wcstring comp,
|
|||
wcstring desc = wcstring(), int flags = 0,
|
||||
string_fuzzy_match_t match = string_fuzzy_match_t(fuzzy_match_exact));
|
||||
|
||||
/// Function used for testing.
|
||||
void complete_set_variable_names(const wcstring_list_t *names);
|
||||
|
||||
/// Support for "wrap targets." A wrap target is a command that completes like another command.
|
||||
bool complete_add_wrapper(const wcstring &command, const wcstring &wrap_target);
|
||||
|
|
|
@ -2333,13 +2333,19 @@ static void test_colors() {
|
|||
static void test_complete() {
|
||||
say(L"Testing complete");
|
||||
|
||||
const wchar_t *name_strs[] = {L"Foo1", L"Foo2", L"Foo3", L"Bar1", L"Bar2", L"Bar3"};
|
||||
size_t count = sizeof name_strs / sizeof *name_strs;
|
||||
const wcstring_list_t names(name_strs, name_strs + count);
|
||||
std::vector<completion_t> completions;
|
||||
complete_set_variable_names(&names);
|
||||
env_vars_snapshot_t vars;
|
||||
struct test_complete_vars_t : environment_t {
|
||||
wcstring_list_t get_names(int flags) const override {
|
||||
return {L"Foo1", L"Foo2", L"Foo3", L"Bar1", L"Bar2", L"Bar3"};
|
||||
}
|
||||
|
||||
maybe_t<env_var_t> get(const wcstring &key,
|
||||
env_mode_flags_t mode = ENV_DEFAULT) const override {
|
||||
return {};
|
||||
}
|
||||
};
|
||||
test_complete_vars_t vars;
|
||||
|
||||
completion_list_t completions;
|
||||
complete(L"$", &completions, COMPLETION_REQUEST_DEFAULT, vars);
|
||||
completions_sort_and_prioritize(&completions);
|
||||
do_test(completions.size() == 6);
|
||||
|
@ -2510,7 +2516,6 @@ static void test_complete() {
|
|||
|
||||
popd();
|
||||
completions.clear();
|
||||
complete_set_variable_names(NULL);
|
||||
|
||||
// Test abbreviations.
|
||||
auto &pvars = parser_t::principal_parser().vars();
|
||||
|
|
Loading…
Reference in New Issue
Block a user