Properly print leading comments and indentation in functions

Store the entire function declaration, not just its job list.
This allows us to extract the body of the function complete with any
leading comments and indents.

Fixes #5285
This commit is contained in:
ridiculousfish
2020-01-03 14:40:28 -08:00
parent c3374edc59
commit 62302ee172
9 changed files with 71 additions and 25 deletions

View File

@@ -207,7 +207,8 @@ static int validate_function_name(int argc, const wchar_t *const *argv, wcstring
/// Define a function. Calls into `function.cpp` to perform the heavy lifting of defining a
/// function.
int builtin_function(parser_t &parser, io_streams_t &streams, const wcstring_list_t &c_args,
const parsed_source_ref_t &source, tnode_t<grammar::job_list> body) {
const parsed_source_ref_t &source,
tnode_t<grammar::block_statement> func_node) {
assert(source && "Missing source in builtin_function");
// The wgetopt function expects 'function' as the first argument. Make a new wcstring_list with
// that property. This is needed because this builtin has a different signature than the other
@@ -258,7 +259,7 @@ int builtin_function(parser_t &parser, io_streams_t &streams, const wcstring_lis
props->shadow_scope = opts.shadow_scope;
props->named_arguments = std::move(opts.named_arguments);
props->parsed_source = source;
props->body_node = body;
props->func_node = func_node;
// Populate inherit_vars.
for (const wcstring &name : opts.inherit_vars) {