mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-25 09:17:12 +08:00
Make "complete -e" prevent completion autoloading
We do the same for functions. Closes #6716
This commit is contained in:
parent
f3d59abc46
commit
5918bca1eb
|
@ -157,6 +157,7 @@ Interactive improvements
|
||||||
- Measuring a command with ``time`` now considers the time taken for command substitution (:issue:`9100`).
|
- 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_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`).
|
- 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
|
New or improved bindings
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::{
|
use std::{
|
||||||
cmp::Ordering,
|
cmp::Ordering,
|
||||||
collections::{BTreeMap, HashMap, HashSet},
|
collections::{BTreeMap, BTreeSet, HashMap, HashSet},
|
||||||
mem,
|
mem,
|
||||||
sync::{
|
sync::{
|
||||||
atomic::{self, AtomicUsize},
|
atomic::{self, AtomicUsize},
|
||||||
|
@ -452,6 +452,7 @@ struct CompletionEntryIndex {
|
||||||
}
|
}
|
||||||
type CompletionEntryMap = BTreeMap<CompletionEntryIndex, CompletionEntry>;
|
type CompletionEntryMap = BTreeMap<CompletionEntryIndex, CompletionEntry>;
|
||||||
static COMPLETION_MAP: Mutex<CompletionEntryMap> = Mutex::new(BTreeMap::new());
|
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.
|
/// Completion "wrapper" support. The map goes from wrapping-command to wrapped-command-list.
|
||||||
type WrapperMap = HashMap<WString, Vec<WString>>;
|
type WrapperMap = HashMap<WString, Vec<WString>>;
|
||||||
|
@ -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.
|
/// 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) {
|
||||||
let mut completion_map = COMPLETION_MAP.lock().expect("mutex poisoned");
|
let mut completion_map = COMPLETION_MAP.lock().expect("mutex poisoned");
|
||||||
completion_map.remove(&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();
|
||||||
|
if !removed && !idx.is_path {
|
||||||
|
COMPLETION_TOMBSTONES.lock().unwrap().insert(idx.name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns all completions of the command cmd.
|
/// Returns all completions of the command cmd.
|
||||||
|
@ -2433,6 +2438,10 @@ fn completion2string(index: &CompletionEntryIndex, o: &CompleteEntryOpt) -> WStr
|
||||||
/// Load command-specific completions for the specified command.
|
/// Load command-specific completions for the specified command.
|
||||||
/// Returns `true` if something new was loaded, `false` if not.
|
/// Returns `true` if something new was loaded, `false` if not.
|
||||||
pub fn complete_load(cmd: &wstr, parser: &Parser) -> bool {
|
pub fn complete_load(cmd: &wstr, parser: &Parser) -> bool {
|
||||||
|
if COMPLETION_TOMBSTONES.lock().unwrap().contains(cmd) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
let mut loaded_new = false;
|
let mut loaded_new = false;
|
||||||
|
|
||||||
// We have to load this as a function, since it may define a --wraps or signature.
|
// We have to load this as a function, since it may define a --wraps or signature.
|
||||||
|
|
6
tests/checks/completion-autoload-tombstone.fish
Normal file
6
tests/checks/completion-autoload-tombstone.fish
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#RUN: %fish %s
|
||||||
|
|
||||||
|
complete -e cat
|
||||||
|
|
||||||
|
complete -C"cat -" | wc -l
|
||||||
|
# CHECK: 0
|
Loading…
Reference in New Issue
Block a user