Introduce operation_context_t

This commit recognizes an existing pattern: many operations need some
combination of a set of variables, a way to detect cancellation, and
sometimes a parser. For example, tab completion needs a parser to execute
custom completions, the variable set, should cancel on SIGINT. Background
autosuggestions don't need a parser, but they do need the variables and
should cancel if the user types something new. Etc.

This introduces a new triple operation_context_t that wraps these concepts
up. This simplifies many method signatures and argument passing.
This commit is contained in:
ridiculousfish
2020-01-15 17:14:47 -08:00
parent db98ee13a9
commit 0f7bba5f0e
24 changed files with 337 additions and 238 deletions

View File

@@ -1129,8 +1129,8 @@ static bool detect_errors_in_plain_statement(const wcstring &buff_src,
if (maybe_t<wcstring> unexp_command = command_for_plain_statement(pst, buff_src)) {
wcstring command;
// Check that we can expand the command.
if (expand_to_command_and_args(*unexp_command, null_environment_t{}, &command, nullptr,
parse_errors) == expand_result_t::error) {
if (expand_to_command_and_args(*unexp_command, operation_context_t::empty(), &command,
nullptr, parse_errors) == expand_result_t::error) {
errored = true;
parse_error_offset_source_start(parse_errors, source_start);
}
@@ -1193,7 +1193,7 @@ static bool detect_errors_in_plain_statement(const wcstring &buff_src,
// Check that we don't do an invalid builtin (issue #1252).
if (!errored && decoration == parse_statement_decoration_builtin &&
expand_one(*unexp_command, expand_flag::skip_cmdsubst, null_environment_t{}, nullptr,
expand_one(*unexp_command, expand_flag::skip_cmdsubst, operation_context_t::empty(),
parse_errors) &&
!builtin_exists(*unexp_command)) {
errored = append_syntax_error(parse_errors, source_start, UNKNOWN_BUILTIN_ERR_MSG,