Make function_add take the filename directly instead of a parser

This commit is contained in:
ridiculousfish 2019-11-12 10:00:42 -08:00
parent b51edcfcac
commit 6d7a66592b
4 changed files with 5 additions and 6 deletions

View file

@ -273,7 +273,7 @@ int builtin_function(parser_t &parser, io_streams_t &streams, const wcstring_lis
d.props = props;
d.events = std::move(opts.events);
function_add(std::move(d), parser);
function_add(std::move(d), parser.libdata().current_filename);
// Handle wrap targets by creating the appropriate completions.
for (const wcstring &wt : opts.wrap_targets) complete_add_wrapper(function_name, wt);

View file

@ -2716,7 +2716,7 @@ static void test_complete() {
// body_node.
struct function_data_t func_data = {};
func_data.name = L"scuttlebutt";
function_add(func_data, parser_t::principal_parser());
function_add(func_data, nullptr);
// Complete a function name.
completions.clear();
@ -2830,7 +2830,7 @@ static void test_complete() {
auto &pvars = parser_t::principal_parser().vars();
function_data_t fd;
fd.name = L"testabbrsonetwothreefour";
function_add(fd, parser_t::principal_parser());
function_add(fd, nullptr);
int ret = pvars.set_one(L"_fish_abbr_testabbrsonetwothreezero", ENV_LOCAL, L"expansion");
complete(L"testabbrsonetwothree", &completions, {}, pvars, parser);
do_test(ret == 0);

View file

@ -148,7 +148,7 @@ function_info_t::function_info_t(function_properties_ref_t props, wcstring desc,
definition_file(intern(def_file)),
is_autoload(autoload) {}
void function_add(const function_data_t &data, const parser_t &parser) {
void function_add(const function_data_t &data, const wchar_t *filename) {
ASSERT_IS_MAIN_THREAD();
auto funcset = function_set.acquire();
@ -164,7 +164,6 @@ void function_add(const function_data_t &data, const parser_t &parser) {
bool is_autoload = funcset->autoloader.autoload_in_progress(data.name);
// Create and store a new function.
const wchar_t *filename = parser.libdata().current_filename;
auto ins = funcset->funcs.emplace(
data.name, function_info_t(data.props, data.description, filename, is_autoload));
assert(ins.second && "Function should not already be present in the table");

View file

@ -51,7 +51,7 @@ struct function_data_t {
};
/// Add a function.
void function_add(const function_data_t &data, const parser_t &parser);
void function_add(const function_data_t &data, const wchar_t *filename);
/// Remove the function with the specified name.
void function_remove(const wcstring &name);