This commit is contained in:
JT 2021-10-26 05:58:58 +13:00
parent baac60a5a7
commit 5d19017603
59 changed files with 125 additions and 140 deletions

View file

@ -1,10 +1,8 @@
use std::{cell::RefCell, rc::Rc};
use nu_engine::eval_block;
use nu_parser::{flatten_block, parse};
use nu_protocol::{
engine::{EngineState, EvaluationContext, Stack, StateWorkingSet},
PipelineData, Value,
engine::{EngineState, Stack, StateWorkingSet},
PipelineData,
};
use reedline::Completer;

View file

@ -1,5 +1,3 @@
use std::{cell::RefCell, rc::Rc};
use nu_parser::{parse, ParseError};
use nu_protocol::engine::{EngineState, StateWorkingSet};
use reedline::{ValidationResult, Validator};

View file

@ -1,6 +1,6 @@
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, EvaluationContext, Stack},
engine::{Command, EngineState, Stack},
Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
};
@ -26,8 +26,8 @@ impl Command for SubCommand {
fn run(
&self,
engine_state: &EngineState,
stack: &mut Stack,
_engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {

View file

@ -1,7 +1,7 @@
use nu_engine::get_full_help;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, EvaluationContext, Stack},
engine::{Command, EngineState, Stack},
IntoPipelineData, PipelineData, Signature, Value,
};

View file

@ -1,6 +1,6 @@
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, EvaluationContext, Stack},
engine::{Command, EngineState, Stack},
Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
};

View file

@ -1,6 +1,6 @@
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, EvaluationContext, Stack},
engine::{Command, EngineState, Stack},
Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
};

View file

@ -1,6 +1,6 @@
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{PipelineData, Signature, SyntaxShape, Value};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{PipelineData, Signature, SyntaxShape};
#[derive(Clone)]
pub struct Alias;
@ -28,7 +28,7 @@ impl Command for Alias {
&self,
_engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
_call: &Call,
_input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
Ok(PipelineData::new())

View file

@ -1,6 +1,6 @@
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{PipelineData, Signature, SyntaxShape, Value};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{PipelineData, Signature, SyntaxShape};
#[derive(Clone)]
pub struct Def;
@ -29,7 +29,7 @@ impl Command for Def {
&self,
_engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
_call: &Call,
_input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
Ok(PipelineData::new())

View file

@ -1,6 +1,6 @@
use nu_engine::{eval_block, CallExt};
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{PipelineData, Signature, SyntaxShape, Value};
#[derive(Clone)]
@ -80,6 +80,6 @@ impl Command for Do {
)
}
}
eval_block(&engine_state, &mut stack, block, input)
eval_block(engine_state, &mut stack, block, input)
}
}

View file

@ -1,6 +1,6 @@
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{PipelineData, Signature, SyntaxShape, Value};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{PipelineData, Signature, SyntaxShape};
#[derive(Clone)]
pub struct ExportDef;
@ -29,7 +29,7 @@ impl Command for ExportDef {
&self,
_engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
_call: &Call,
_input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
Ok(PipelineData::new())

View file

@ -1,6 +1,6 @@
use nu_engine::{eval_block, eval_expression};
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Example, IntoPipelineData, PipelineData, Signature, Span, SyntaxShape, Value};
#[derive(Clone)]
@ -56,7 +56,7 @@ impl Command for For {
.expect("internal error: expected block");
let engine_state = engine_state.clone();
let mut stack = stack.enter_scope();
let stack = stack.enter_scope();
match values {
Value::List { vals, span } => Ok(vals

View file

@ -1,6 +1,6 @@
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, EvaluationContext, Stack},
engine::{Command, EngineState, Stack},
span, Example, IntoPipelineData, PipelineData, ShellError, Signature, Spanned, SyntaxShape,
Value,
};

View file

@ -1,6 +1,6 @@
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{PipelineData, Signature, SyntaxShape, Value};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{PipelineData, Signature, SyntaxShape};
#[derive(Clone)]
pub struct Hide;
@ -22,7 +22,7 @@ impl Command for Hide {
&self,
_engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
_call: &Call,
_input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
Ok(PipelineData::new())

View file

@ -1,6 +1,6 @@
use nu_engine::{eval_block, eval_expression};
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Value};
#[derive(Clone)]
@ -41,23 +41,23 @@ impl Command for If {
let result = eval_expression(engine_state, stack, cond)?;
match result {
Value::Bool { val, span } => {
Value::Bool { val, .. } => {
if val {
let block = engine_state.get_block(then_block);
let mut stack = stack.enter_scope();
eval_block(&engine_state, &mut stack, block, input)
eval_block(engine_state, &mut stack, block, input)
} else if let Some(else_case) = else_case {
if let Some(else_expr) = else_case.as_keyword() {
if let Some(block_id) = else_expr.as_block() {
let block = engine_state.get_block(block_id);
let mut stack = stack.enter_scope();
eval_block(&engine_state, &mut stack, block, input)
eval_block(engine_state, &mut stack, block, input)
} else {
eval_expression(&engine_state, stack, else_expr)
eval_expression(engine_state, stack, else_expr)
.map(|x| x.into_pipeline_data())
}
} else {
eval_expression(&engine_state, stack, else_case)
eval_expression(engine_state, stack, else_case)
.map(|x| x.into_pipeline_data())
}
} else {

View file

@ -1,7 +1,7 @@
use nu_engine::eval_expression;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{PipelineData, Signature, SyntaxShape, Value};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{PipelineData, Signature, SyntaxShape};
#[derive(Clone)]
pub struct Let;
@ -40,7 +40,7 @@ impl Command for Let {
.as_keyword()
.expect("internal error: missing keyword");
let rhs = eval_expression(&engine_state, stack, keyword_expr)?;
let rhs = eval_expression(engine_state, stack, keyword_expr)?;
//println!("Adding: {:?} to {}", rhs, var_id);

View file

@ -1,6 +1,6 @@
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{PipelineData, Signature, SyntaxShape, Value};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{PipelineData, Signature, SyntaxShape};
#[derive(Clone)]
pub struct Module;
@ -28,7 +28,7 @@ impl Command for Module {
&self,
_engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
_call: &Call,
_input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
Ok(PipelineData::new())

View file

@ -1,7 +1,7 @@
use nu_engine::{eval_block, CallExt};
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{PipelineData, ShellError, Signature, SyntaxShape, Value};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{PipelineData, ShellError, Signature, SyntaxShape};
/// Source a file for environment variables.
#[derive(Clone)]

View file

@ -1,6 +1,6 @@
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{PipelineData, Signature, SyntaxShape, Value};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{PipelineData, Signature, SyntaxShape};
#[derive(Clone)]
pub struct Use;
@ -22,7 +22,7 @@ impl Command for Use {
&self,
_engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
_call: &Call,
_input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
Ok(PipelineData::new())

View file

@ -1,7 +1,7 @@
use nu_engine::eval_expression;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{PipelineData, Signature, SyntaxShape, Value};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{PipelineData, Signature, SyntaxShape};
#[derive(Clone)]
pub struct LetEnv;

View file

@ -1,10 +1,8 @@
use std::{cell::RefCell, rc::Rc};
use nu_engine::eval_block;
use nu_parser::parse;
use nu_protocol::{
engine::{Command, EngineState, EvaluationContext, Stack, StateWorkingSet},
PipelineData, Value,
engine::{Command, EngineState, Stack, StateWorkingSet},
PipelineData,
};
use super::{From, Into, Split};

View file

@ -1,5 +1,5 @@
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{IntoPipelineData, PipelineData, Signature, Value};
#[derive(Clone)]

View file

@ -1,6 +1,6 @@
use nu_engine::eval_expression;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{IntoPipelineData, PipelineData, Signature, SyntaxShape, Value};
#[derive(Clone)]

View file

@ -4,9 +4,9 @@ use std::process::Command as ProcessCommand;
use std::process::Stdio;
use nu_protocol::ast::Call;
use nu_protocol::engine::Command;
use nu_protocol::engine::EngineState;
use nu_protocol::engine::Stack;
use nu_protocol::engine::{Command, EvaluationContext};
use nu_protocol::IntoPipelineData;
use nu_protocol::PipelineData;
use nu_protocol::{Signature, Value};
@ -46,6 +46,7 @@ impl Command for ListGitBranches {
let s = String::from_utf8_lossy(&val).to_string();
#[allow(clippy::needless_collect)]
let lines: Vec<_> = s
.lines()
.filter_map(|x| {

View file

@ -1,7 +1,7 @@
use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{PipelineData, Signature, SyntaxShape, Value};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{PipelineData, Signature, SyntaxShape};
#[derive(Clone)]
pub struct Cd;

View file

@ -5,8 +5,8 @@ use super::util::get_interactive_confirmation;
use nu_engine::CallExt;
use nu_path::canonicalize_with;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{PipelineData, ShellError, Signature, SyntaxShape, Value};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{PipelineData, ShellError, Signature, SyntaxShape};
use crate::filesystem::util::FileStructure;

View file

@ -1,7 +1,7 @@
use chrono::{DateTime, Utc};
use nu_engine::eval_expression;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{IntoPipelineData, PipelineData, Signature, SyntaxShape, Value};
#[derive(Clone)]

View file

@ -3,10 +3,8 @@ use std::env::current_dir;
use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{
IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Value, ValueStream,
};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Value};
#[derive(Clone)]
pub struct Mkdir;

View file

@ -4,8 +4,8 @@ use std::path::{Path, PathBuf};
use super::util::get_interactive_confirmation;
use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{PipelineData, ShellError, Signature, SyntaxShape, Value};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{PipelineData, ShellError, Signature, SyntaxShape};
#[derive(Clone)]
pub struct Mv;

View file

@ -7,10 +7,8 @@ use super::util::get_interactive_confirmation;
use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{
IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Value, ValueStream,
};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Value};
#[derive(Clone)]
pub struct Rm;

View file

@ -2,8 +2,8 @@ use std::fs::OpenOptions;
use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{PipelineData, ShellError, Signature, SyntaxShape, Value};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{PipelineData, ShellError, Signature, SyntaxShape};
#[derive(Clone)]
pub struct Touch;

View file

@ -1,6 +1,6 @@
use nu_engine::eval_block;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Example, IntoPipelineData, PipelineData, Signature, Span, SyntaxShape, Value};
#[derive(Clone)]
@ -64,7 +64,7 @@ impl Command for Each {
let numbered = call.has_flag("numbered");
let engine_state = engine_state.clone();
let mut stack = stack.clone();
let stack = stack.clone();
let span = call.head;
match input {

View file

@ -1,7 +1,7 @@
use nu_engine::CallExt;
use nu_protocol::ast::{Call, CellPath};
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{IntoPipelineData, PipelineData, Signature, SyntaxShape, Value};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{IntoPipelineData, PipelineData, Signature, SyntaxShape};
#[derive(Clone)]
pub struct Get;

View file

@ -1,5 +1,5 @@
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{IntoPipelineData, PipelineData, Signature, Value};
#[derive(Clone)]

View file

@ -1,9 +1,6 @@
use std::cell::RefCell;
use std::rc::Rc;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{IntoPipelineData, PipelineData, ShellError, Signature, Value, ValueStream};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{IntoPipelineData, PipelineData, ShellError, Signature, Value};
#[derive(Clone)]
pub struct Lines;
@ -30,7 +27,6 @@ impl Command for Lines {
call: &Call,
input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
let span = call.head;
match input {
#[allow(clippy::needless_collect)]
// Collect is needed because the string may not live long enough for

View file

@ -1,6 +1,6 @@
use nu_engine::CallExt;
use nu_protocol::ast::{Call, CellPath};
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{
Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
};

View file

@ -1,6 +1,6 @@
use nu_engine::eval_expression;
use nu_protocol::ast::{Call, Expr, Expression};
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Value};
#[derive(Clone)]
@ -52,7 +52,7 @@ impl Command for Where {
}
})
.into_pipeline_data()),
PipelineData::Value(Value::List { vals, span }) => Ok(vals
PipelineData::Value(Value::List { vals, .. }) => Ok(vals
.into_iter()
.filter(move |value| {
stack.add_var(var_id, value.clone());

View file

@ -1,6 +1,6 @@
use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{IntoPipelineData, PipelineData, Signature, SyntaxShape, Value};
#[derive(Clone)]

View file

@ -1,6 +1,6 @@
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{PipelineData, ShellError, Signature, Value};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{PipelineData, ShellError, Signature};
#[derive(Clone)]
pub struct From;

View file

@ -1,5 +1,5 @@
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Value};
#[derive(Clone)]

View file

@ -1,6 +1,6 @@
use nu_engine::eval_expression;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{
Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
};

View file

@ -3,7 +3,7 @@ extern crate unicode_segmentation;
use unicode_segmentation::UnicodeSegmentation;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{
Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Type, Value,
};

View file

@ -1,6 +1,6 @@
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, EvaluationContext, Stack},
engine::{Command, EngineState, Stack},
Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Type, Value,
};

View file

@ -1,7 +1,7 @@
use nu_engine::CallExt;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, EvaluationContext, Stack},
engine::{Command, EngineState, Stack},
IntoPipelineData, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
};

View file

@ -1,7 +1,7 @@
use nu_engine::get_full_help;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, EvaluationContext, Stack},
engine::{Command, EngineState, Stack},
IntoPipelineData, PipelineData, Signature, Value,
};

View file

@ -1,7 +1,7 @@
use nu_engine::CallExt;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, EvaluationContext, Stack},
engine::{Command, EngineState, Stack},
IntoPipelineData, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
};

View file

@ -2,8 +2,8 @@ use std::time::Instant;
use nu_engine::eval_block;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{PipelineData, Signature, SyntaxShape, Value};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{PipelineData, Signature, SyntaxShape};
#[derive(Clone)]
pub struct Benchmark;
@ -39,7 +39,8 @@ impl Command for Benchmark {
let mut stack = stack.enter_scope();
let start_time = Instant::now();
eval_block(&engine_state, &mut stack, block, PipelineData::new())?;
eval_block(engine_state, &mut stack, block, PipelineData::new())?.into_value();
let end_time = Instant::now();
println!("{} ms", (end_time - start_time).as_millis());
Ok(PipelineData::new())

View file

@ -1,6 +1,6 @@
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, EvaluationContext, Stack},
engine::{Command, EngineState, Stack},
Example, IntoPipelineData, PipelineData, ShellError, Signature, Value,
};
use sysinfo::{ProcessExt, System, SystemExt};

View file

@ -1,21 +1,15 @@
use std::borrow::Cow;
use std::cell::RefCell;
use std::collections::HashMap;
use std::env;
use std::io::{BufRead, BufReader, Write};
use std::process::{ChildStdin, Command as CommandSys, Stdio};
use std::rc::Rc;
use std::sync::mpsc;
use nu_protocol::engine::{EngineState, Stack};
use nu_protocol::{
ast::{Call, Expression},
engine::{Command, EvaluationContext},
ShellError, Signature, SyntaxShape, Value,
};
use nu_protocol::{IntoPipelineData, PipelineData, Span, Spanned, ValueStream};
use nu_protocol::{ast::Call, engine::Command, ShellError, Signature, SyntaxShape, Value};
use nu_protocol::{IntoPipelineData, PipelineData, Span, Spanned};
use nu_engine::{eval_expression, CallExt};
use nu_engine::CallExt;
const OUTPUT_BUFFER_SIZE: usize = 8192;

View file

@ -1,6 +1,6 @@
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, EvaluationContext, Stack},
engine::{Command, EngineState, Stack},
Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Value,
};
use sysinfo::{ComponentExt, DiskExt, NetworkExt, ProcessorExt, System, SystemExt, UserExt};

View file

@ -2,7 +2,7 @@ use lscolors::{LsColors, Style};
use nu_engine::CallExt;
use nu_protocol::{
ast::{Call, PathMember},
engine::{Command, EngineState, EvaluationContext, Stack},
engine::{Command, EngineState, Stack},
IntoPipelineData, PipelineData, Signature, Span, SyntaxShape, Value,
};
use nu_term_grid::grid::{Alignment, Cell, Direction, Filling, Grid, GridOptions};

View file

@ -1,5 +1,5 @@
use nu_protocol::ast::{Call, PathMember};
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{IntoPipelineData, PipelineData, ShellError, Signature, Span, Value};
use nu_table::StyledString;
use std::collections::HashMap;

View file

@ -1,6 +1,6 @@
use nu_protocol::{
ast::Call,
engine::{EngineState, EvaluationContext, Stack},
engine::{EngineState, Stack},
ShellError,
};

View file

@ -1,8 +1,5 @@
use itertools::Itertools;
use nu_protocol::{
engine::{EngineState, EvaluationContext},
Example, Signature, Span, Value,
};
use nu_protocol::{engine::EngineState, Example, Signature, Span, Value};
use std::collections::HashMap;
const COMMANDS_DOCS_DIR: &str = "docs/commands";

View file

@ -1,5 +1,5 @@
use nu_protocol::ast::{Block, Call, Expr, Expression, Operator, Statement};
use nu_protocol::engine::{EngineState, EvaluationContext, Stack};
use nu_protocol::engine::{EngineState, Stack};
use nu_protocol::{
IntoPipelineData, PipelineData, Range, ShellError, Span, Spanned, Type, Unit, Value,
};
@ -55,7 +55,7 @@ fn eval_call(
decl.signature().required_positional.len()
+ decl.signature().optional_positional.len(),
) {
let result = eval_expression(&engine_state, &mut stack, arg)?;
let result = eval_expression(engine_state, &mut stack, arg)?;
rest_items.push(result);
}
@ -82,7 +82,7 @@ fn eval_call(
for call_named in &call.named {
if call_named.0.item == named.long {
if let Some(arg) = &call_named.1 {
let result = eval_expression(&engine_state, &mut stack, arg)?;
let result = eval_expression(engine_state, &mut stack, arg)?;
stack.add_var(var_id, result);
} else {

View file

@ -1,6 +1,6 @@
use crate::{ast::Call, value::Value, BlockId, Example, PipelineData, ShellError, Signature};
use crate::{ast::Call, BlockId, Example, PipelineData, ShellError, Signature};
use super::{EngineState, EvaluationContext, Stack};
use super::{EngineState, Stack};
pub trait Command: Send + Sync + CommandClone {
fn name(&self) -> &str;

View file

@ -1,7 +1,7 @@
use super::Command;
use crate::{ast::Block, BlockId, DeclId, Example, Signature, Span, Type, VarId};
use core::panic;
use std::{collections::HashMap, slice::Iter};
use std::collections::HashMap;
#[derive(Clone)]
pub struct EngineState {
@ -167,7 +167,7 @@ impl EngineState {
pub fn print_contents(&self) {
for (contents, _, _) in self.file_contents.iter() {
let string = String::from_utf8_lossy(&contents);
let string = String::from_utf8_lossy(contents);
println!("{}", string);
}
}
@ -204,7 +204,7 @@ impl EngineState {
pub fn get_span_contents(&self, span: &Span) -> &[u8] {
for (contents, start, finish) in &self.file_contents {
if span.start >= *start && span.start <= *finish {
if span.start >= *start && span.end <= *finish {
return &contents[(span.start - start)..(span.end - start)];
}
}
@ -262,7 +262,11 @@ impl EngineState {
}
pub fn next_span_start(&self) -> usize {
self.file_contents.len()
if let Some((_, _, last)) = self.file_contents.last() {
*last
} else {
0
}
}
pub fn files(&self) -> impl Iterator<Item = &(String, usize, usize)> {
@ -494,7 +498,13 @@ impl<'a> StateWorkingSet<'a> {
}
pub fn next_span_start(&self) -> usize {
self.permanent_state.next_span_start() + self.delta.file_contents.len()
let permanent_span_start = self.permanent_state.next_span_start();
if let Some((_, _, last)) = self.delta.file_contents.last() {
permanent_span_start + *last
} else {
permanent_span_start
}
}
pub fn global_span_offset(&self) -> usize {
@ -550,7 +560,7 @@ impl<'a> StateWorkingSet<'a> {
let permanent_end = self.permanent_state.next_span_start();
if permanent_end <= span.start {
for (contents, start, finish) in &self.delta.file_contents {
if (span.start >= *start) && (span.start <= *finish) {
if (span.start >= *start) && (span.end <= *finish) {
return &contents[(span.start - permanent_end)..(span.end - permanent_end)];
}
}

View file

@ -1,5 +1,5 @@
use super::EngineState;
use std::{cell::RefCell, collections::HashMap, rc::Rc};
use std::collections::HashMap;
use crate::{Example, ShellError, Signature, Value, VarId};

View file

@ -1,13 +1,10 @@
use crate::ast::Call;
use crate::engine::Command;
use crate::engine::CommandClone;
use crate::engine::EngineState;
use crate::engine::EvaluationContext;
use crate::engine::Stack;
use crate::BlockId;
use crate::PipelineData;
use crate::SyntaxShape;
use crate::Value;
use crate::VarId;
#[derive(Debug, Clone, PartialEq, Eq)]

View file

@ -1,4 +1,4 @@
use std::{cell::RefCell, io::Write, rc::Rc};
use std::io::Write;
use dialoguer::{
console::{Style, Term},
@ -12,7 +12,7 @@ use nu_engine::eval_block;
use nu_parser::parse;
use nu_protocol::{
ast::Call,
engine::{EngineState, EvaluationContext, Stack, StateWorkingSet},
engine::{EngineState, Stack, StateWorkingSet},
IntoPipelineData, PipelineData, ShellError, Value,
};
use reedline::{Completer, CompletionActionHandler, DefaultPrompt, LineBuffer, Prompt};
@ -268,23 +268,22 @@ fn update_prompt<'prompt>(
return nu_prompt as &dyn Prompt;
}
let (block, delta) = {
let mut working_set = StateWorkingSet::new(&engine_state);
let block = {
let mut working_set = StateWorkingSet::new(engine_state);
let (output, err) = parse(&mut working_set, None, prompt_command.as_bytes(), false);
if let Some(err) = err {
report_error(&working_set, &err);
return default_prompt as &dyn Prompt;
}
(output, working_set.render())
output
};
let mut stack = stack.clone();
let evaluated_prompt = match eval_block(&engine_state, &mut stack, &block, PipelineData::new())
{
let evaluated_prompt = match eval_block(engine_state, &mut stack, &block, PipelineData::new()) {
Ok(pipeline_data) => pipeline_data.collect_string(),
Err(err) => {
let working_set = StateWorkingSet::new(&engine_state);
let working_set = StateWorkingSet::new(engine_state);
report_error(&working_set, &err);
return default_prompt as &dyn Prompt;
}