2020-01-16 09:14:47 +08:00
|
|
|
#ifndef FISH_OPERATION_CONTEXT_H
|
|
|
|
#define FISH_OPERATION_CONTEXT_H
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
class environment_t;
|
|
|
|
class parser_t;
|
2020-05-31 05:05:07 +08:00
|
|
|
class job_group_t;
|
2020-01-16 09:14:47 +08:00
|
|
|
|
|
|
|
/// A common helper which always returns false.
|
|
|
|
bool no_cancel();
|
|
|
|
|
2020-12-21 03:58:26 +08:00
|
|
|
/// Default limits for expansion.
|
|
|
|
enum expansion_limit_t : size_t {
|
|
|
|
/// The default maximum number of items from expansion.
|
|
|
|
kExpansionLimitDefault = 512 * 1024,
|
|
|
|
|
|
|
|
/// A smaller limit for background operations like syntax highlighting.
|
|
|
|
kExpansionLimitBackground = 512,
|
|
|
|
};
|
|
|
|
|
2020-01-16 09:14:47 +08:00
|
|
|
/// A operation_context_t is a simple property bag which wraps up data needed for highlighting,
|
|
|
|
/// expansion, completion, and more.
|
|
|
|
class operation_context_t {
|
|
|
|
public:
|
|
|
|
// The parser, if this is a foreground operation. If this is a background operation, this may be
|
|
|
|
// nullptr.
|
|
|
|
std::shared_ptr<parser_t> parser;
|
|
|
|
|
|
|
|
// The set of variables. It is the creator's responsibility to ensure this lives as log as the
|
|
|
|
// context itself.
|
|
|
|
const environment_t &vars;
|
|
|
|
|
2020-12-21 03:58:26 +08:00
|
|
|
// The limit in the number of expansions which should be produced.
|
|
|
|
const size_t expansion_limit;
|
|
|
|
|
2020-05-31 05:05:07 +08:00
|
|
|
/// The job group of the parental job.
|
2020-03-12 02:06:52 +08:00
|
|
|
/// This is used only when expanding command substitutions. If this is set, any jobs created by
|
2020-02-09 06:34:10 +08:00
|
|
|
/// the command substitions should use this tree.
|
2020-05-31 05:05:07 +08:00
|
|
|
std::shared_ptr<job_group_t> job_group{};
|
2020-03-12 02:06:52 +08:00
|
|
|
|
2020-01-16 09:14:47 +08:00
|
|
|
// A function which may be used to poll for cancellation.
|
|
|
|
cancel_checker_t cancel_checker;
|
|
|
|
|
|
|
|
// Invoke the cancel checker. \return if we should cancel.
|
|
|
|
bool check_cancel() const { return cancel_checker(); }
|
|
|
|
|
|
|
|
// \return an "empty" context which contains no variables, no parser, and never cancels.
|
|
|
|
static operation_context_t empty();
|
|
|
|
|
|
|
|
// \return an operation context that contains only global variables, no parser, and never
|
|
|
|
// cancels.
|
|
|
|
static operation_context_t globals();
|
|
|
|
|
2020-12-21 03:58:26 +08:00
|
|
|
/// Construct from a full set of properties.
|
2020-01-16 09:14:47 +08:00
|
|
|
operation_context_t(std::shared_ptr<parser_t> parser, const environment_t &vars,
|
2020-12-21 03:58:26 +08:00
|
|
|
cancel_checker_t cancel_checker,
|
|
|
|
size_t expansion_limit = kExpansionLimitDefault);
|
2020-01-16 09:14:47 +08:00
|
|
|
|
|
|
|
/// Construct from vars alone.
|
2021-01-01 05:30:58 +08:00
|
|
|
explicit operation_context_t(const environment_t &vars,
|
|
|
|
size_t expansion_limit = kExpansionLimitDefault)
|
|
|
|
: operation_context_t(nullptr, vars, no_cancel, expansion_limit) {}
|
2020-01-16 09:14:47 +08:00
|
|
|
|
|
|
|
~operation_context_t();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|