Refactor scope (#2602)

* Refactor scope to have parents

* Refactor scope to have parents

* Refactor scope to have parents

* Clippy

Co-authored-by: Jonathan Turner <jonathan@pop-os.localdomain>
This commit is contained in:
Jonathan Turner
2020-09-26 11:40:02 +12:00
committed by GitHub
parent 9dc88f8a95
commit cb7723f423
34 changed files with 288 additions and 423 deletions

View File

@@ -3,7 +3,7 @@ use crate::evaluate::evaluate_baseline_expr;
use crate::prelude::*;
use log::trace;
use nu_errors::ShellError;
use nu_protocol::{hir::ClassifiedCommand, Signature, SyntaxShape, UntaggedValue, Value};
use nu_protocol::{hir::ClassifiedCommand, Scope, Signature, SyntaxShape, UntaggedValue, Value};
pub struct SubCommand;
@@ -33,7 +33,7 @@ impl WholeStreamCommand for SubCommand {
registry: &CommandRegistry,
) -> Result<OutputStream, ShellError> {
let registry = Arc::new(registry.clone());
let scope = Arc::new(args.call_info.scope.clone());
let scope = args.call_info.scope.clone();
let call_info = args.evaluate_once(&registry).await?;
@@ -85,19 +85,11 @@ impl WholeStreamCommand for SubCommand {
.take_while(move |item| {
let condition = condition.clone();
let registry = registry.clone();
let scope = scope.clone();
let item = item.clone();
let scope = Scope::append_it(scope.clone(), item.clone());
trace!("ITEM = {:?}", item);
async move {
let result = evaluate_baseline_expr(
&*condition,
&registry,
&item,
&scope.vars,
&scope.env,
)
.await;
let result = evaluate_baseline_expr(&*condition, &registry, scope).await;
trace!("RESULT = {:?}", result);
!matches!(result, Ok(ref v) if v.is_true())