diff --git a/src/builtins/functions.rs b/src/builtins/functions.rs index 827db0d04..c6b5b3854 100644 --- a/src/builtins/functions.rs +++ b/src/builtins/functions.rs @@ -275,7 +275,7 @@ pub fn functions(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) - } if opts.list || args.is_empty() { - let mut names = function::get_names(opts.show_hidden); + let mut names = function::get_names(opts.show_hidden, parser.vars()); names.sort(); if streams.out_is_terminal() { let mut buff = WString::new(); diff --git a/src/complete.rs b/src/complete.rs index c905ec2b4..64ad59077 100644 --- a/src/complete.rs +++ b/src/complete.rs @@ -1086,7 +1086,7 @@ impl<'ctx> Completer<'ctx> { if str_cmd.is_empty() || (!str_cmd.contains('/') && str_cmd.as_char_slice()[0] != '~') { let include_hidden = str_cmd.as_char_slice().first() == Some(&'_'); // Append all known matching functions - let possible_comp: Vec<_> = function::get_names(include_hidden) + let possible_comp: Vec<_> = function::get_names(include_hidden, self.ctx.vars()) .into_iter() .map(Completion::from_completion) .collect(); diff --git a/src/function.rs b/src/function.rs index cef313d72..28d22b9d4 100644 --- a/src/function.rs +++ b/src/function.rs @@ -143,9 +143,7 @@ pub fn load(name: &wstr, parser: &Parser) -> bool { } /// Insert a list of all dynamically loaded functions into the specified list. -fn autoload_names(names: &mut HashSet, get_hidden: bool) { - // TODO: justify this. - let vars = EnvStack::principal(); +fn autoload_names(names: &mut HashSet, vars: &dyn Environment, get_hidden: bool) { let Some(path_var) = vars.get_unless_empty(L!("fish_function_path")) else { return; }; @@ -319,10 +317,10 @@ pub fn copy(name: &wstr, new_name: WString, parser: &Parser) -> bool { /// Returns all function names. /// /// \param get_hidden whether to include hidden functions, i.e. ones starting with an underscore. -pub fn get_names(get_hidden: bool) -> Vec { +pub fn get_names(get_hidden: bool, vars: &dyn Environment) -> Vec { let mut names = HashSet::::new(); let funcset = FUNCTION_SET.lock().unwrap(); - autoload_names(&mut names, get_hidden); + autoload_names(&mut names, vars, get_hidden); for name in funcset.funcs.keys() { // Maybe skip hidden. if !get_hidden && (name.is_empty() || name.char_at(0) == '_') {