mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-17 00:12:44 +08:00
Make OperationContext not hold a Parser via Rc
Exploit Rust's lifetimes. This will lead to simplifications.
This commit is contained in:
parent
d36f94d96c
commit
c9a76bd634
|
@ -143,7 +143,7 @@ fn write_part(
|
|||
&mut args,
|
||||
ExpandFlags::SKIP_CMDSUBST,
|
||||
&OperationContext::foreground(
|
||||
parser.shared(),
|
||||
parser,
|
||||
Box::new(no_cancel),
|
||||
COMMANDLINE_TOKENS_MAX_EXPANSION,
|
||||
),
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::common::CancelChecker;
|
||||
use crate::env::EnvDyn;
|
||||
use crate::env::{EnvStack, Environment};
|
||||
use crate::parser::{Parser, ParserRef};
|
||||
use crate::parser::Parser;
|
||||
use crate::proc::JobGroupRef;
|
||||
|
||||
use crate::reader::read_generation_count;
|
||||
|
@ -21,11 +21,11 @@ pub const EXPANSION_LIMIT_BACKGROUND: usize = 512;
|
|||
enum Vars<'a> {
|
||||
// The parser, if this is a foreground operation. If this is a background operation, this may be
|
||||
// nullptr.
|
||||
Parser(ParserRef),
|
||||
Parser(&'a Parser),
|
||||
// A set of variables.
|
||||
Vars(&'a dyn Environment),
|
||||
|
||||
TestOnly(ParserRef, &'a dyn Environment),
|
||||
TestOnly(&'a Parser, &'a dyn Environment),
|
||||
}
|
||||
|
||||
/// A operation_context_t is a simple property bag which wraps up data needed for highlighting,
|
||||
|
@ -70,7 +70,7 @@ impl<'a> OperationContext<'a> {
|
|||
|
||||
/// Construct from a full set of properties.
|
||||
pub fn foreground(
|
||||
parser: ParserRef,
|
||||
parser: &'a Parser,
|
||||
cancel_checker: CancelChecker,
|
||||
expansion_limit: usize,
|
||||
) -> OperationContext<'a> {
|
||||
|
@ -83,7 +83,7 @@ impl<'a> OperationContext<'a> {
|
|||
}
|
||||
|
||||
pub fn test_only_foreground(
|
||||
parser: ParserRef,
|
||||
parser: &'a Parser,
|
||||
vars: &'a dyn Environment,
|
||||
cancel_checker: CancelChecker,
|
||||
) -> OperationContext<'a> {
|
||||
|
|
|
@ -1134,9 +1134,9 @@ impl Parser {
|
|||
}
|
||||
|
||||
/// Return the operation context for this parser.
|
||||
pub fn context(&self) -> OperationContext<'static> {
|
||||
pub fn context(&self) -> OperationContext<'_> {
|
||||
OperationContext::foreground(
|
||||
self.shared(),
|
||||
self,
|
||||
Box::new(|| signal_check_cancel() != 0),
|
||||
EXPANSION_LIMIT_DEFAULT,
|
||||
)
|
||||
|
|
|
@ -43,8 +43,8 @@ fn test_complete() {
|
|||
},
|
||||
};
|
||||
|
||||
let parser = Parser::principal_parser().shared();
|
||||
let ctx = OperationContext::test_only_foreground(parser.clone(), &vars, Box::new(no_cancel));
|
||||
let parser = Parser::principal_parser();
|
||||
let ctx = OperationContext::test_only_foreground(parser, &vars, Box::new(no_cancel));
|
||||
|
||||
let do_complete = |cmd: &wstr, flags: CompletionRequestOptions| complete(cmd, flags, &ctx).0;
|
||||
|
||||
|
@ -489,7 +489,7 @@ fn test_autosuggest_suggest_special() {
|
|||
L!($command),
|
||||
CompletionRequestOptions::default(),
|
||||
&OperationContext::foreground(
|
||||
Parser::principal_parser().shared(),
|
||||
Parser::principal_parser(),
|
||||
Box::new(no_cancel),
|
||||
EXPANSION_LIMIT_DEFAULT,
|
||||
),
|
||||
|
|
|
@ -27,7 +27,7 @@ fn expand_test_impl(
|
|||
let mut errors = ParseErrorList::new();
|
||||
let pwd = PwdEnvironment::default();
|
||||
let ctx = OperationContext::test_only_foreground(
|
||||
Parser::principal_parser().shared(),
|
||||
Parser::principal_parser(),
|
||||
&pwd,
|
||||
Box::new(no_cancel),
|
||||
);
|
||||
|
@ -358,14 +358,13 @@ fn test_expand_overflow() {
|
|||
let vals: Vec<WString> = (1..=64).map(|i| i.to_wstring()).collect();
|
||||
let expansion = WString::from_str(&str::repeat("$bigvar", 64));
|
||||
|
||||
let parser = Parser::principal_parser().shared();
|
||||
let parser = Parser::principal_parser();
|
||||
parser.vars().push(true);
|
||||
let set = parser.vars().set(L!("bigvar"), EnvMode::LOCAL, vals);
|
||||
assert_eq!(set, EnvStackSetResult::Ok);
|
||||
|
||||
let mut errors = ParseErrorList::new();
|
||||
let ctx =
|
||||
OperationContext::foreground(parser.clone(), Box::new(no_cancel), EXPANSION_LIMIT_DEFAULT);
|
||||
let ctx = OperationContext::foreground(parser, Box::new(no_cancel), EXPANSION_LIMIT_DEFAULT);
|
||||
|
||||
// We accept only 1024 completions.
|
||||
let mut output = CompletionReceiver::new(1024);
|
||||
|
|
|
@ -614,7 +614,7 @@ fn test_eval_recursion_detection() {
|
|||
let _cleanup = test_init();
|
||||
// Ensure that we don't crash on infinite self recursion and mutual recursion. These must use
|
||||
// the principal parser because we cannot yet execute jobs on other parsers.
|
||||
let parser = Parser::principal_parser().shared();
|
||||
let parser = Parser::principal_parser();
|
||||
parser.eval(
|
||||
L!("function recursive ; recursive ; end ; recursive; "),
|
||||
&IoChain::new(),
|
||||
|
@ -665,7 +665,7 @@ fn test_eval_illegal_exit_code() {
|
|||
#[serial]
|
||||
fn test_eval_empty_function_name() {
|
||||
let _cleanup = test_init();
|
||||
let parser = Parser::principal_parser().shared();
|
||||
let parser = Parser::principal_parser();
|
||||
parser.eval(
|
||||
L!("function '' ; echo fail; exit 42 ; end ; ''"),
|
||||
&IoChain::new(),
|
||||
|
@ -676,7 +676,7 @@ fn test_eval_empty_function_name() {
|
|||
#[serial]
|
||||
fn test_expand_argument_list() {
|
||||
let _cleanup = test_init();
|
||||
let parser = Parser::principal_parser().shared();
|
||||
let parser = Parser::principal_parser();
|
||||
let comps: Vec<WString> = Parser::expand_argument_list(
|
||||
L!("alpha 'beta gamma' delta"),
|
||||
ExpandFlags::default(),
|
||||
|
|
Loading…
Reference in New Issue
Block a user