mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-07 10:01:14 -03:00
Minor cleanup of complete_param_for_command
This commit is contained in:
@@ -836,21 +836,15 @@ bool completer_t::complete_param_for_command(const wcstring &cmd_orig, const wcs
|
|||||||
wcstring cmd, path;
|
wcstring cmd, path;
|
||||||
parse_cmd_string(cmd_orig, &path, &cmd, ctx.vars);
|
parse_cmd_string(cmd_orig, &path, &cmd, ctx.vars);
|
||||||
|
|
||||||
// FLOGF(error, L"\nThinking about looking up completions for %ls\n", cmd.c_str());
|
// Use cmd_orig here for paths, as it is potentially pathed.
|
||||||
bool head_exists = builtin_exists(cmd);
|
bool cmd_exists = builtin_exists(cmd) || function_exists_no_autoload(cmd) ||
|
||||||
// Only reload environment variables if builtin_exists returned false, as an optimization
|
path_get_path(cmd_orig, ctx.vars).has_value();
|
||||||
if (!head_exists) {
|
if (!cmd_exists) {
|
||||||
head_exists = function_exists_no_autoload(cmd);
|
// Do not load custom completions if the command does not exist
|
||||||
// Use cmd_orig here as it is potentially pathed.
|
|
||||||
head_exists = head_exists || path_get_path(cmd_orig, ctx.vars).has_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!head_exists) {
|
|
||||||
// Do not load custom completions if the head does not exist
|
|
||||||
// This prevents errors caused during the execution of completion providers for
|
// This prevents errors caused during the execution of completion providers for
|
||||||
// tools that do not exist. Applies to both manual completions ("cm<TAB>", "cmd <TAB>")
|
// tools that do not exist. Applies to both manual completions ("cm<TAB>", "cmd <TAB>")
|
||||||
// and automatic completions ("gi" autosuggestion provider -> git)
|
// and automatic completions ("gi" autosuggestion provider -> git)
|
||||||
FLOG(complete, "Skipping completions for non-existent head");
|
FLOG(complete, "Skipping completions for non-existent command");
|
||||||
} else {
|
} else {
|
||||||
iothread_perform_on_main([&]() { complete_load(cmd); });
|
iothread_perform_on_main([&]() { complete_load(cmd); });
|
||||||
}
|
}
|
||||||
@@ -1347,10 +1341,9 @@ void completer_t::complete_custom(const wcstring &cmd, const wcstring &cmdline,
|
|||||||
cleanup_t restore_vars{apply_var_assignments(*ad->var_assignments)};
|
cleanup_t restore_vars{apply_var_assignments(*ad->var_assignments)};
|
||||||
if (ctx.check_cancel()) return;
|
if (ctx.check_cancel()) return;
|
||||||
|
|
||||||
if (!complete_param_for_command(
|
// Invoke any custom completions for this command.
|
||||||
cmd, ad->previous_argument, ad->current_argument, !ad->had_ddash,
|
(void)complete_param_for_command(cmd, ad->previous_argument, ad->current_argument,
|
||||||
&ad->do_file)) { // Invoke any custom completions for this command.
|
!ad->had_ddash, &ad->do_file);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool expand_command_token(const operation_context_t &ctx, wcstring &cmd_tok) {
|
static bool expand_command_token(const operation_context_t &ctx, wcstring &cmd_tok) {
|
||||||
|
|||||||
Reference in New Issue
Block a user