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".

(cherry picked from commit a7c04890c9)
This commit is contained in:
Johannes Altmanninger
2025-05-29 14:20:11 +02:00
parent b11e22d905
commit 028b60cad6
3 changed files with 25 additions and 4 deletions

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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