From 0de1611bf10962ca634523326beb17b6998efc61 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 28 Apr 2019 16:41:58 -0700 Subject: [PATCH] Migrate builtin_complete recursion_level into parser_t::libdata --- src/builtin_complete.cpp | 7 +++---- src/parser.h | 3 +++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/builtin_complete.cpp b/src/builtin_complete.cpp index 67365caff..1f3dcb6d4 100644 --- a/src/builtin_complete.cpp +++ b/src/builtin_complete.cpp @@ -110,7 +110,6 @@ static void builtin_complete_remove(const wcstring_list_t &cmds, const wcstring_ // complete.cpp for any heavy lifting. int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) { ASSERT_IS_MAIN_THREAD(); - static int recursion_level = 0; wchar_t *cmd = argv[0]; int argc = builtin_count_args(argv); @@ -325,8 +324,8 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) { // argument, not the reader buffer. builtin_commandline_scoped_transient_t temp_buffer(do_complete_param); - if (recursion_level < 1) { - recursion_level++; + if (parser.libdata().builtin_complete_recursion_level < 1) { + parser.libdata().builtin_complete_recursion_level++; std::vector comp; complete(do_complete_param, &comp, completion_request_t::fuzzy_match, parser.vars(), @@ -364,7 +363,7 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) { streams.out.push_back(L'\n'); } - recursion_level--; + parser.libdata().builtin_complete_recursion_level--; } } else if (cmd_to_complete.empty() && path.empty()) { // No arguments specified, meaning we print the definitions of all specified completions diff --git a/src/parser.h b/src/parser.h index b00c54a6a..ec3fde14f 100644 --- a/src/parser.h +++ b/src/parser.h @@ -151,6 +151,9 @@ class completion_t; struct library_data_t { /// A counter incremented every time a command executes. uint64_t exec_count{0}; + + /// Number of recursive calls to builtin_complete(). + uint32_t builtin_complete_recursion_level{0}; }; class parser_t : public std::enable_shared_from_this {