diff --git a/src/builtins/complete.rs b/src/builtins/complete.rs index 0ddaaab7a..c98365ff3 100644 --- a/src/builtins/complete.rs +++ b/src/builtins/complete.rs @@ -177,7 +177,7 @@ fn builtin_complete_remove_cmd( if !removed { // This means that all loops were empty. - complete_remove_all(cmd.to_owned(), cmd_is_path); + complete_remove_all(cmd.to_owned(), cmd_is_path, /*explicit=*/ true); } } diff --git a/src/complete.rs b/src/complete.rs index 7c0343b96..5ed0cf0d2 100644 --- a/src/complete.rs +++ b/src/complete.rs @@ -2343,14 +2343,14 @@ pub fn complete_remove(cmd: WString, cmd_is_path: bool, option: &wstr, typ: Comp } /// Removes all completions for a given command. -pub fn complete_remove_all(cmd: WString, cmd_is_path: bool) { +pub fn complete_remove_all(cmd: WString, cmd_is_path: bool, explicit: bool) { let mut completion_map = COMPLETION_MAP.lock().expect("mutex poisoned"); let idx = CompletionEntryIndex { name: cmd, is_path: cmd_is_path, }; let removed = completion_map.remove(&idx).is_some(); - if !removed && !idx.is_path { + if explicit && !removed && !idx.is_path { COMPLETION_TOMBSTONES.lock().unwrap().insert(idx.name); } } @@ -2523,7 +2523,7 @@ pub fn complete_invalidate_path() { .expect("mutex poisoned") .get_autoloaded_commands(); for cmd in cmds { - complete_remove_all(cmd, false /* not a path */); + complete_remove_all(cmd, /*cmd_is_path=*/ false, /*explicit=*/ false); } } diff --git a/tests/checks/autoload.fish b/tests/checks/autoload.fish index cf98218e8..35a8f62fd 100644 --- a/tests/checks/autoload.fish +++ b/tests/checks/autoload.fish @@ -1,9 +1,21 @@ #RUN: %fish %s +set -g fish_complete_path c1 c2 +mkdir c1 c2 + function foo; end -mkdir $__fish_config_dir/completions -echo >$__fish_config_dir/completions/foo.fish "echo auto-loading foo.fish" +for i in c1 c2 + echo >$i/foo.fish "echo auto-loading $i/foo.fish" +end complete -C "foo " >/dev/null -# CHECK: auto-loading foo.fish +# CHECK: auto-loading c1/foo.fish complete -C "foo " >/dev/null # already loaded + +set -g fish_complete_path c2 +complete -C "foo " >/dev/null +# CHECK: auto-loading c2/foo.fish + +set -g fish_complete_path c1 c2 +complete -C "foo " >/dev/null +# CHECK: auto-loading c1/foo.fish