diff --git a/src/builtins/complete.rs b/src/builtins/complete.rs index e744570f4..1c4c238b9 100644 --- a/src/builtins/complete.rs +++ b/src/builtins/complete.rs @@ -176,7 +176,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 5f984c123..947085caa 100644 --- a/src/complete.rs +++ b/src/complete.rs @@ -2339,14 +2339,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); } } @@ -2519,7 +2519,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 new file mode 100644 index 000000000..35a8f62fd --- /dev/null +++ b/tests/checks/autoload.fish @@ -0,0 +1,21 @@ +#RUN: %fish %s + +set -g fish_complete_path c1 c2 +mkdir c1 c2 + +function foo; end +for i in c1 c2 + echo >$i/foo.fish "echo auto-loading $i/foo.fish" +end +complete -C "foo " >/dev/null +# 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