Fix "set fish_complete_path" accidentally disabling autoloading

Commit 5918bca1eb (Make "complete -e" prevent completion autoloading,
2024-08-24) makes "complete -e foo" add a tombstone for "foo", meaning we
will never again load completions for "foo".

Due to an oversight, the same tombstone is added when we clear cached
completions after changing "fish_complete_path", preventing completions from
being loaded in that case.  Fix this by restoring the old behavior unless
the user actually used "complete -e".
This commit is contained in:
Johannes Altmanninger
2025-05-29 14:20:11 +02:00
parent 52f23b9752
commit a7c04890c9
3 changed files with 19 additions and 7 deletions

View File

@@ -177,7 +177,7 @@ fn builtin_complete_remove_cmd(
if !removed { if !removed {
// This means that all loops were empty. // 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);
} }
} }

View File

@@ -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. /// 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 mut completion_map = COMPLETION_MAP.lock().expect("mutex poisoned");
let idx = CompletionEntryIndex { let idx = CompletionEntryIndex {
name: cmd, name: cmd,
is_path: cmd_is_path, is_path: cmd_is_path,
}; };
let removed = completion_map.remove(&idx).is_some(); 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); COMPLETION_TOMBSTONES.lock().unwrap().insert(idx.name);
} }
} }
@@ -2523,7 +2523,7 @@ pub fn complete_invalidate_path() {
.expect("mutex poisoned") .expect("mutex poisoned")
.get_autoloaded_commands(); .get_autoloaded_commands();
for cmd in cmds { for cmd in cmds {
complete_remove_all(cmd, false /* not a path */); complete_remove_all(cmd, /*cmd_is_path=*/ false, /*explicit=*/ false);
} }
} }

View File

@@ -1,9 +1,21 @@
#RUN: %fish %s #RUN: %fish %s
set -g fish_complete_path c1 c2
mkdir c1 c2
function foo; end function foo; end
mkdir $__fish_config_dir/completions for i in c1 c2
echo >$__fish_config_dir/completions/foo.fish "echo auto-loading foo.fish" echo >$i/foo.fish "echo auto-loading $i/foo.fish"
end
complete -C "foo " >/dev/null complete -C "foo " >/dev/null
# CHECK: auto-loading foo.fish # CHECK: auto-loading c1/foo.fish
complete -C "foo " >/dev/null complete -C "foo " >/dev/null
# already loaded # 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