Skip to content

Commit

Permalink
Make "complete -e" prevent completion autoloading
Browse files Browse the repository at this point in the history
We do the same for functions.

Closes fish-shell#6716
  • Loading branch information
krobelus committed Aug 24, 2024
1 parent f3d59ab commit 5918bca
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ Interactive improvements
- Measuring a command with ``time`` now considers the time taken for command substitution (:issue:`9100`).
- ``fish_add_path`` now automatically enables verbose mode when used interactively (in the commandline), in an effort to be clearer about what it does (:issue:`10532`).
- fish no longer adopts TTY modes of failed commands (:issue:`10603`).
- `complete -e cmd` now prevents autoloading completions for `cmd` (:issue:`6716`).

New or improved bindings
^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
15 changes: 12 additions & 3 deletions src/complete.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
cmp::Ordering,
collections::{BTreeMap, HashMap, HashSet},
collections::{BTreeMap, BTreeSet, HashMap, HashSet},
mem,
sync::{
atomic::{self, AtomicUsize},
Expand Down Expand Up @@ -452,6 +452,7 @@ struct CompletionEntryIndex {
}
type CompletionEntryMap = BTreeMap<CompletionEntryIndex, CompletionEntry>;
static COMPLETION_MAP: Mutex<CompletionEntryMap> = Mutex::new(BTreeMap::new());
static COMPLETION_TOMBSTONES: Mutex<BTreeSet<WString>> = Mutex::new(BTreeSet::new());

/// Completion "wrapper" support. The map goes from wrapping-command to wrapped-command-list.
type WrapperMap = HashMap<WString, Vec<WString>>;
Expand Down Expand Up @@ -2340,10 +2341,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) {
let mut completion_map = COMPLETION_MAP.lock().expect("mutex poisoned");
completion_map.remove(&CompletionEntryIndex {
let idx = CompletionEntryIndex {
name: cmd,
is_path: cmd_is_path,
});
};
let removed = completion_map.remove(&idx).is_some();
if !removed && !idx.is_path {
COMPLETION_TOMBSTONES.lock().unwrap().insert(idx.name);
}
}

/// Returns all completions of the command cmd.
Expand Down Expand Up @@ -2433,6 +2438,10 @@ fn completion2string(index: &CompletionEntryIndex, o: &CompleteEntryOpt) -> WStr
/// Load command-specific completions for the specified command.
/// Returns `true` if something new was loaded, `false` if not.
pub fn complete_load(cmd: &wstr, parser: &Parser) -> bool {
if COMPLETION_TOMBSTONES.lock().unwrap().contains(cmd) {
return false;
}

let mut loaded_new = false;

// We have to load this as a function, since it may define a --wraps or signature.
Expand Down
6 changes: 6 additions & 0 deletions tests/checks/completion-autoload-tombstone.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#RUN: %fish %s

complete -e cat

complete -C"cat -" | wc -l
# CHECK: 0

0 comments on commit 5918bca

Please sign in to comment.