From dc96c01c934a210159ca014162342d33c653aa86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radom=C3=ADr=20Bos=C3=A1k?= Date: Mon, 19 Dec 2016 18:05:18 +0100 Subject: [PATCH] Remove --authoritative leftovers from complete The complete builtin had once -A / --authoritative and -u / --unauthoritative switches which indicated whether all possibilities for completion are specified and would cause an error if the completion was authoritative and an unknown option was encountered. This feature was functionally removed during one of the past parser rewritings, but -A and -u still remained in parts of the code and command completions, although having no effect. This commit removes the leftovers and prints an warning whenever user tries to run the complete command with -A / -u / --authoritative / --unauthoritative switches. Fixes #3640. --- src/builtin_complete.cpp | 27 ++++++++++----------------- src/complete.cpp | 20 +++++--------------- src/complete.h | 4 ---- 3 files changed, 15 insertions(+), 36 deletions(-) diff --git a/src/builtin_complete.cpp b/src/builtin_complete.cpp index 434b5a118..bca0d85d9 100644 --- a/src/builtin_complete.cpp +++ b/src/builtin_complete.cpp @@ -58,25 +58,17 @@ static void builtin_complete_add2(const wchar_t *cmd, int cmd_type, const wchar_ /// Silly function. static void builtin_complete_add(const wcstring_list_t &cmd, const wcstring_list_t &path, const wchar_t *short_opt, wcstring_list_t &gnu_opt, - wcstring_list_t &old_opt, int result_mode, int authoritative, + wcstring_list_t &old_opt, int result_mode, const wchar_t *condition, const wchar_t *comp, const wchar_t *desc, int flags) { for (size_t i = 0; i < cmd.size(); i++) { builtin_complete_add2(cmd.at(i).c_str(), COMMAND, short_opt, gnu_opt, old_opt, result_mode, condition, comp, desc, flags); - - if (authoritative != -1) { - complete_set_authoritative(cmd.at(i).c_str(), COMMAND, authoritative); - } } for (size_t i = 0; i < path.size(); i++) { builtin_complete_add2(path.at(i).c_str(), PATH, short_opt, gnu_opt, old_opt, result_mode, condition, comp, desc, flags); - - if (authoritative != -1) { - complete_set_authoritative(path.at(i).c_str(), PATH, authoritative); - } } } @@ -128,7 +120,6 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) { int argc = builtin_count_args(argv); int result_mode = SHARED; int remove = 0; - int authoritative = -1; wcstring short_opt; wcstring_list_t gnu_opt, old_opt; const wchar_t *comp = L"", *desc = L"", *condition = L""; @@ -183,7 +174,7 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) { else cmd_to_complete.push_back(tmp); } else { - streams.err.append_format(L"%ls: Invalid token '%ls'\n", cmd, w.woptarg); + streams.err.append_format(_(L"%ls: Invalid token '%ls'\n"), cmd, w.woptarg); return STATUS_BUILTIN_ERROR; } break; @@ -193,17 +184,19 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) { break; } case 'u': { - authoritative = 0; + streams.err.append_format( + _(L"%ls: -u / --unauthoritative flags have been removed\n"), cmd); break; } case 'A': { - authoritative = 1; + streams.err.append_format(_(L"%ls: -A / --authoritative flags have been removed\n"), + cmd); break; } case 's': { short_opt.append(w.woptarg); if (w.woptarg[0] == '\0') { - streams.err.append_format(L"%ls: -s requires a non-empty string\n", cmd); + streams.err.append_format(_(L"%ls: -s requires a non-empty string\n"), cmd); return STATUS_BUILTIN_ERROR; } break; @@ -211,7 +204,7 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) { case 'l': { gnu_opt.push_back(w.woptarg); if (w.woptarg[0] == '\0') { - streams.err.append_format(L"%ls: -l requires a non-empty string\n", cmd); + streams.err.append_format(_(L"%ls: -l requires a non-empty string\n"), cmd); return STATUS_BUILTIN_ERROR; } break; @@ -219,7 +212,7 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) { case 'o': { old_opt.push_back(w.woptarg); if (w.woptarg[0] == '\0') { - streams.err.append_format(L"%ls: -o requires a non-empty string\n", cmd); + streams.err.append_format(_(L"%ls: -o requires a non-empty string\n"), cmd); return STATUS_BUILTIN_ERROR; } break; @@ -369,7 +362,7 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) { builtin_complete_remove(cmd_to_complete, path, short_opt.c_str(), gnu_opt, old_opt); } else { builtin_complete_add(cmd_to_complete, path, short_opt.c_str(), gnu_opt, old_opt, - result_mode, authoritative, condition, comp, desc, flags); + result_mode, condition, comp, desc, flags); } // Handle wrap targets (probably empty). We only wrap commands, not paths. diff --git a/src/complete.cpp b/src/complete.cpp index a56493063..acab87c15 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -138,8 +138,6 @@ class completion_entry_t { const wcstring cmd; /// True if command is a path. const bool cmd_is_path; - /// True if no other options than the ones supplied are possible. - bool authoritative; /// Order for when this completion was created. This aids in outputting completions sorted by /// time. const unsigned int order; @@ -151,8 +149,8 @@ class completion_entry_t { void add_option(const complete_entry_opt_t &opt); bool remove_option(const wcstring &option, complete_option_type_t type); - completion_entry_t(const wcstring &c, bool type, bool author) - : cmd(c), cmd_is_path(type), authoritative(author), order(++kCompleteOrder) {} + completion_entry_t(const wcstring &c, bool type) + : cmd(c), cmd_is_path(type), order(++kCompleteOrder) {} }; /// Set of all completion entries. @@ -418,7 +416,7 @@ static completion_entry_t &complete_get_exact_entry(const wcstring &cmd, bool cm ASSERT_IS_LOCKED(completion_lock); std::pair ins = - completion_set.insert(completion_entry_t(cmd, cmd_is_path, false)); + completion_set.insert(completion_entry_t(cmd, cmd_is_path)); // NOTE SET_ELEMENTS_ARE_IMMUTABLE: Exposing mutable access here is only okay as long as callers // do not change any field that matters to ordering - affecting order without telling std::set @@ -426,14 +424,6 @@ static completion_entry_t &complete_get_exact_entry(const wcstring &cmd, bool cm return const_cast(*ins.first); } -void complete_set_authoritative(const wchar_t *cmd, bool cmd_is_path, bool authoritative) { - CHECK(cmd, ); - scoped_lock lock(completion_lock); - - completion_entry_t &c = complete_get_exact_entry(cmd, cmd_is_path); - c.authoritative = authoritative; -} - void complete_add(const wchar_t *cmd, bool cmd_is_path, const wcstring &option, complete_option_type_t option_type, int result_mode, const wchar_t *condition, const wchar_t *comp, const wchar_t *desc, complete_flags_t flags) { @@ -481,7 +471,7 @@ void complete_remove(const wcstring &cmd, bool cmd_is_path, const wcstring &opti complete_option_type_t type) { scoped_lock lock(completion_lock); - completion_entry_t tmp_entry(cmd, cmd_is_path, false); + completion_entry_t tmp_entry(cmd, cmd_is_path); completion_entry_set_t::iterator iter = completion_set.find(tmp_entry); if (iter != completion_set.end()) { // const_cast: See SET_ELEMENTS_ARE_IMMUTABLE. @@ -498,7 +488,7 @@ void complete_remove(const wcstring &cmd, bool cmd_is_path, const wcstring &opti void complete_remove_all(const wcstring &cmd, bool cmd_is_path) { scoped_lock lock(completion_lock); - completion_entry_t tmp_entry(cmd, cmd_is_path, false); + completion_entry_t tmp_entry(cmd, cmd_is_path); completion_set.erase(tmp_entry); } diff --git a/src/complete.h b/src/complete.h index e573ad3d6..0820f0dce 100644 --- a/src/complete.h +++ b/src/complete.h @@ -143,10 +143,6 @@ void complete_add(const wchar_t *cmd, bool cmd_is_path, const wcstring &option, complete_option_type_t option_type, int result_mode, const wchar_t *condition, const wchar_t *comp, const wchar_t *desc, int flags); -/// Sets whether the completion list for this command is complete. If true, any options not matching -/// one of the provided options will be flagged as an error by syntax highlighting. -void complete_set_authoritative(const wchar_t *cmd, bool cmd_type, bool authoritative); - /// Remove a previously defined completion. void complete_remove(const wcstring &cmd, bool cmd_is_path, const wcstring &option, complete_option_type_t type);