Thread variables into autoload_names

Stop fetching a global set of variables.
This commit is contained in:
Peter Ammon 2024-06-19 12:37:56 -07:00
parent d2d2d8cb45
commit 7fcbe5b8ab
No known key found for this signature in database
3 changed files with 5 additions and 7 deletions

View File

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

View File

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

View File

@ -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<WString>, get_hidden: bool) {
// TODO: justify this.
let vars = EnvStack::principal();
fn autoload_names(names: &mut HashSet<WString>, 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<WString> {
pub fn get_names(get_hidden: bool, vars: &dyn Environment) -> Vec<WString> {
let mut names = HashSet::<WString>::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) == '_') {