From c8af566330968a491f024d4ff62b3c25bcbb31da Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Tue, 17 Apr 2018 14:53:34 -0500 Subject: [PATCH] Stop completion skipping in case of valid ./command complete.cpp strips the path from commands before parsing for completions, meaning that when we called `path_get_path()` against `cmd`, if `./cmd` were typed in at the command line but `cmd` does not exist in the PATH, then the command would incorrectly be flagged as not present and the completions would be skipped. This is also faster when an absolute/relative path is used for a command, as we now search with the original path which skips searching PATH directories unnecessarily. Found when debugging why completions for `./configure` wouldn't work. --- src/complete.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/complete.cpp b/src/complete.cpp index cb0ef776b..1df55e5a6 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -868,6 +868,7 @@ bool completer_t::complete_param(const wcstring &scmd_orig, const wcstring &spop // after a command, so the overhead of the additional env lookup should be negligible. env_vars_snapshot_t completion_snapshot; + // debug(0, L"\nThinking about looking up completions for %ls\n", cmd.c_str()); bool head_exists = builtin_exists(cmd); // Only reload environment variables if builtin_exists returned false, as an optimization if (head_exists == false) { @@ -878,7 +879,7 @@ bool completer_t::complete_param(const wcstring &scmd_orig, const wcstring &spop head_exists = function_exists_no_autoload(cmd.c_str(), completion_snapshot); // While it may seem like first testing `path_get_path` before resorting to an env lookup may be faster, path_get_path can potentially // do a lot of FS/IO access, so env.get() + function_exists() should still be faster. - head_exists = head_exists || path_get_path(cmd, nullptr); + head_exists = head_exists || path_get_path(cmd_orig, nullptr); //use cmd_orig here as it is potentially pathed } if (!head_exists) { @@ -886,7 +887,7 @@ bool completer_t::complete_param(const wcstring &scmd_orig, const wcstring &spop //This prevents errors caused during the execution of completion providers for //tools that do not exist. Applies to both manual completions ("cm", "cmd ") //and automatic completions ("gi" autosuggestion provider -> git) - // debug(0, "Skipping completions for non-existent head\n"); + debug(4, "Skipping completions for non-existent head\n"); } else { run_on_main_thread([&]() {