diff --git a/crates/nu-cli/src/completions.rs b/crates/nu-cli/src/completions.rs index 837d633f6..7e3e4f08d 100644 --- a/crates/nu-cli/src/completions.rs +++ b/crates/nu-cli/src/completions.rs @@ -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; diff --git a/crates/nu-cli/src/validation.rs b/crates/nu-cli/src/validation.rs index 058bc303c..9e306596c 100644 --- a/crates/nu-cli/src/validation.rs +++ b/crates/nu-cli/src/validation.rs @@ -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}; diff --git a/crates/nu-command/src/conversions/into/binary.rs b/crates/nu-command/src/conversions/into/binary.rs index e6c697e56..c1f39e26e 100644 --- a/crates/nu-command/src/conversions/into/binary.rs +++ b/crates/nu-command/src/conversions/into/binary.rs @@ -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 { diff --git a/crates/nu-command/src/conversions/into/command.rs b/crates/nu-command/src/conversions/into/command.rs index a745834dc..605401058 100644 --- a/crates/nu-command/src/conversions/into/command.rs +++ b/crates/nu-command/src/conversions/into/command.rs @@ -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, }; diff --git a/crates/nu-command/src/conversions/into/filesize.rs b/crates/nu-command/src/conversions/into/filesize.rs index a5aa0d6c1..1fa67ef94 100644 --- a/crates/nu-command/src/conversions/into/filesize.rs +++ b/crates/nu-command/src/conversions/into/filesize.rs @@ -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, }; diff --git a/crates/nu-command/src/conversions/into/int.rs b/crates/nu-command/src/conversions/into/int.rs index a4f31f2d7..c8f018fc5 100644 --- a/crates/nu-command/src/conversions/into/int.rs +++ b/crates/nu-command/src/conversions/into/int.rs @@ -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, }; diff --git a/crates/nu-command/src/core_commands/alias.rs b/crates/nu-command/src/core_commands/alias.rs index 3ed9b97d8..e9c585c23 100644 --- a/crates/nu-command/src/core_commands/alias.rs +++ b/crates/nu-command/src/core_commands/alias.rs @@ -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 { Ok(PipelineData::new()) diff --git a/crates/nu-command/src/core_commands/def.rs b/crates/nu-command/src/core_commands/def.rs index 3eb3a6307..f83e1f3ca 100644 --- a/crates/nu-command/src/core_commands/def.rs +++ b/crates/nu-command/src/core_commands/def.rs @@ -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 { Ok(PipelineData::new()) diff --git a/crates/nu-command/src/core_commands/do_.rs b/crates/nu-command/src/core_commands/do_.rs index 2b38dd427..2ddf48ed2 100644 --- a/crates/nu-command/src/core_commands/do_.rs +++ b/crates/nu-command/src/core_commands/do_.rs @@ -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) } } diff --git a/crates/nu-command/src/core_commands/export_def.rs b/crates/nu-command/src/core_commands/export_def.rs index 910716c9f..d56add47c 100644 --- a/crates/nu-command/src/core_commands/export_def.rs +++ b/crates/nu-command/src/core_commands/export_def.rs @@ -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 { Ok(PipelineData::new()) diff --git a/crates/nu-command/src/core_commands/for_.rs b/crates/nu-command/src/core_commands/for_.rs index 1539690e2..4714d31cd 100644 --- a/crates/nu-command/src/core_commands/for_.rs +++ b/crates/nu-command/src/core_commands/for_.rs @@ -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 diff --git a/crates/nu-command/src/core_commands/help.rs b/crates/nu-command/src/core_commands/help.rs index 990acb4c7..06f0e208f 100644 --- a/crates/nu-command/src/core_commands/help.rs +++ b/crates/nu-command/src/core_commands/help.rs @@ -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, }; diff --git a/crates/nu-command/src/core_commands/hide.rs b/crates/nu-command/src/core_commands/hide.rs index 57f2a1092..843299aba 100644 --- a/crates/nu-command/src/core_commands/hide.rs +++ b/crates/nu-command/src/core_commands/hide.rs @@ -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 { Ok(PipelineData::new()) diff --git a/crates/nu-command/src/core_commands/if_.rs b/crates/nu-command/src/core_commands/if_.rs index 0ea5c8785..431145d15 100644 --- a/crates/nu-command/src/core_commands/if_.rs +++ b/crates/nu-command/src/core_commands/if_.rs @@ -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 { diff --git a/crates/nu-command/src/core_commands/let_.rs b/crates/nu-command/src/core_commands/let_.rs index 3e3a942cd..7ccde47e7 100644 --- a/crates/nu-command/src/core_commands/let_.rs +++ b/crates/nu-command/src/core_commands/let_.rs @@ -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); diff --git a/crates/nu-command/src/core_commands/module.rs b/crates/nu-command/src/core_commands/module.rs index 2476e6ab9..4fe16f615 100644 --- a/crates/nu-command/src/core_commands/module.rs +++ b/crates/nu-command/src/core_commands/module.rs @@ -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 { Ok(PipelineData::new()) diff --git a/crates/nu-command/src/core_commands/source.rs b/crates/nu-command/src/core_commands/source.rs index 6b9cc7885..d60f330d3 100644 --- a/crates/nu-command/src/core_commands/source.rs +++ b/crates/nu-command/src/core_commands/source.rs @@ -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)] diff --git a/crates/nu-command/src/core_commands/use_.rs b/crates/nu-command/src/core_commands/use_.rs index dfcc0124e..27635687d 100644 --- a/crates/nu-command/src/core_commands/use_.rs +++ b/crates/nu-command/src/core_commands/use_.rs @@ -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 { Ok(PipelineData::new()) diff --git a/crates/nu-command/src/env/let_env.rs b/crates/nu-command/src/env/let_env.rs index 21801939c..16e742f85 100644 --- a/crates/nu-command/src/env/let_env.rs +++ b/crates/nu-command/src/env/let_env.rs @@ -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; diff --git a/crates/nu-command/src/example_test.rs b/crates/nu-command/src/example_test.rs index 8bda299ba..c7ca4f001 100644 --- a/crates/nu-command/src/example_test.rs +++ b/crates/nu-command/src/example_test.rs @@ -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}; diff --git a/crates/nu-command/src/experimental/git.rs b/crates/nu-command/src/experimental/git.rs index f4c9cf1f1..bb1463bcb 100644 --- a/crates/nu-command/src/experimental/git.rs +++ b/crates/nu-command/src/experimental/git.rs @@ -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)] diff --git a/crates/nu-command/src/experimental/git_checkout.rs b/crates/nu-command/src/experimental/git_checkout.rs index 0c8be2564..66b68c533 100644 --- a/crates/nu-command/src/experimental/git_checkout.rs +++ b/crates/nu-command/src/experimental/git_checkout.rs @@ -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)] diff --git a/crates/nu-command/src/experimental/list_git_branches.rs b/crates/nu-command/src/experimental/list_git_branches.rs index a11c85efb..19c171bce 100644 --- a/crates/nu-command/src/experimental/list_git_branches.rs +++ b/crates/nu-command/src/experimental/list_git_branches.rs @@ -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| { diff --git a/crates/nu-command/src/filesystem/cd.rs b/crates/nu-command/src/filesystem/cd.rs index 5bb1dd928..2986413be 100644 --- a/crates/nu-command/src/filesystem/cd.rs +++ b/crates/nu-command/src/filesystem/cd.rs @@ -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; diff --git a/crates/nu-command/src/filesystem/cp.rs b/crates/nu-command/src/filesystem/cp.rs index 0283f8d1a..4de1af2a1 100644 --- a/crates/nu-command/src/filesystem/cp.rs +++ b/crates/nu-command/src/filesystem/cp.rs @@ -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; diff --git a/crates/nu-command/src/filesystem/ls.rs b/crates/nu-command/src/filesystem/ls.rs index 6458af7b9..a21acafb0 100644 --- a/crates/nu-command/src/filesystem/ls.rs +++ b/crates/nu-command/src/filesystem/ls.rs @@ -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)] diff --git a/crates/nu-command/src/filesystem/mkdir.rs b/crates/nu-command/src/filesystem/mkdir.rs index adb91f5d8..c4ecc874b 100644 --- a/crates/nu-command/src/filesystem/mkdir.rs +++ b/crates/nu-command/src/filesystem/mkdir.rs @@ -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; diff --git a/crates/nu-command/src/filesystem/mv.rs b/crates/nu-command/src/filesystem/mv.rs index 1e6069b8b..74a759cdd 100644 --- a/crates/nu-command/src/filesystem/mv.rs +++ b/crates/nu-command/src/filesystem/mv.rs @@ -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; diff --git a/crates/nu-command/src/filesystem/rm.rs b/crates/nu-command/src/filesystem/rm.rs index 35d0f252a..685141082 100644 --- a/crates/nu-command/src/filesystem/rm.rs +++ b/crates/nu-command/src/filesystem/rm.rs @@ -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; diff --git a/crates/nu-command/src/filesystem/touch.rs b/crates/nu-command/src/filesystem/touch.rs index 85c79d0a2..04188d9ec 100644 --- a/crates/nu-command/src/filesystem/touch.rs +++ b/crates/nu-command/src/filesystem/touch.rs @@ -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; diff --git a/crates/nu-command/src/filters/each.rs b/crates/nu-command/src/filters/each.rs index 789c42c75..b7feafe07 100644 --- a/crates/nu-command/src/filters/each.rs +++ b/crates/nu-command/src/filters/each.rs @@ -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 { diff --git a/crates/nu-command/src/filters/get.rs b/crates/nu-command/src/filters/get.rs index e7b38df85..ffaf6a98a 100644 --- a/crates/nu-command/src/filters/get.rs +++ b/crates/nu-command/src/filters/get.rs @@ -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; diff --git a/crates/nu-command/src/filters/length.rs b/crates/nu-command/src/filters/length.rs index 9fa4543dd..0ab8690cf 100644 --- a/crates/nu-command/src/filters/length.rs +++ b/crates/nu-command/src/filters/length.rs @@ -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)] diff --git a/crates/nu-command/src/filters/lines.rs b/crates/nu-command/src/filters/lines.rs index bb1db993a..b1a11b576 100644 --- a/crates/nu-command/src/filters/lines.rs +++ b/crates/nu-command/src/filters/lines.rs @@ -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 { - let span = call.head; match input { #[allow(clippy::needless_collect)] // Collect is needed because the string may not live long enough for diff --git a/crates/nu-command/src/filters/select.rs b/crates/nu-command/src/filters/select.rs index 5c4c7f472..1a43094ec 100644 --- a/crates/nu-command/src/filters/select.rs +++ b/crates/nu-command/src/filters/select.rs @@ -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, }; diff --git a/crates/nu-command/src/filters/where_.rs b/crates/nu-command/src/filters/where_.rs index 5397cddd0..16b74efcc 100644 --- a/crates/nu-command/src/filters/where_.rs +++ b/crates/nu-command/src/filters/where_.rs @@ -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()); diff --git a/crates/nu-command/src/filters/wrap.rs b/crates/nu-command/src/filters/wrap.rs index 311f72dbe..d06324725 100644 --- a/crates/nu-command/src/filters/wrap.rs +++ b/crates/nu-command/src/filters/wrap.rs @@ -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)] diff --git a/crates/nu-command/src/formats/from/command.rs b/crates/nu-command/src/formats/from/command.rs index 36dd21af8..8aede1def 100644 --- a/crates/nu-command/src/formats/from/command.rs +++ b/crates/nu-command/src/formats/from/command.rs @@ -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; diff --git a/crates/nu-command/src/formats/from/json.rs b/crates/nu-command/src/formats/from/json.rs index db5af6719..fab0cf968 100644 --- a/crates/nu-command/src/formats/from/json.rs +++ b/crates/nu-command/src/formats/from/json.rs @@ -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)] diff --git a/crates/nu-command/src/strings/build_string.rs b/crates/nu-command/src/strings/build_string.rs index 1cea5a1a4..7e87b01ff 100644 --- a/crates/nu-command/src/strings/build_string.rs +++ b/crates/nu-command/src/strings/build_string.rs @@ -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, }; diff --git a/crates/nu-command/src/strings/size.rs b/crates/nu-command/src/strings/size.rs index 0f919f577..251a6b1c7 100644 --- a/crates/nu-command/src/strings/size.rs +++ b/crates/nu-command/src/strings/size.rs @@ -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, }; diff --git a/crates/nu-command/src/strings/split/chars.rs b/crates/nu-command/src/strings/split/chars.rs index f71f8913a..f553e41b8 100644 --- a/crates/nu-command/src/strings/split/chars.rs +++ b/crates/nu-command/src/strings/split/chars.rs @@ -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, }; diff --git a/crates/nu-command/src/strings/split/column.rs b/crates/nu-command/src/strings/split/column.rs index d2b370d9d..8090c4d23 100644 --- a/crates/nu-command/src/strings/split/column.rs +++ b/crates/nu-command/src/strings/split/column.rs @@ -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, }; diff --git a/crates/nu-command/src/strings/split/command.rs b/crates/nu-command/src/strings/split/command.rs index e25ea589b..e6b30b3cc 100644 --- a/crates/nu-command/src/strings/split/command.rs +++ b/crates/nu-command/src/strings/split/command.rs @@ -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, }; diff --git a/crates/nu-command/src/strings/split/row.rs b/crates/nu-command/src/strings/split/row.rs index 5bf8ae02a..80bd30394 100644 --- a/crates/nu-command/src/strings/split/row.rs +++ b/crates/nu-command/src/strings/split/row.rs @@ -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, }; diff --git a/crates/nu-command/src/system/benchmark.rs b/crates/nu-command/src/system/benchmark.rs index 7913c1671..f1b6edbfc 100644 --- a/crates/nu-command/src/system/benchmark.rs +++ b/crates/nu-command/src/system/benchmark.rs @@ -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()) diff --git a/crates/nu-command/src/system/ps.rs b/crates/nu-command/src/system/ps.rs index d816a4472..efff137da 100644 --- a/crates/nu-command/src/system/ps.rs +++ b/crates/nu-command/src/system/ps.rs @@ -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}; diff --git a/crates/nu-command/src/system/run_external.rs b/crates/nu-command/src/system/run_external.rs index 84a74dc97..75e551cee 100644 --- a/crates/nu-command/src/system/run_external.rs +++ b/crates/nu-command/src/system/run_external.rs @@ -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; diff --git a/crates/nu-command/src/system/sys.rs b/crates/nu-command/src/system/sys.rs index b1aa54daa..442a4136c 100644 --- a/crates/nu-command/src/system/sys.rs +++ b/crates/nu-command/src/system/sys.rs @@ -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}; diff --git a/crates/nu-command/src/viewers/griddle.rs b/crates/nu-command/src/viewers/griddle.rs index fb752a58a..07faac1c2 100644 --- a/crates/nu-command/src/viewers/griddle.rs +++ b/crates/nu-command/src/viewers/griddle.rs @@ -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}; diff --git a/crates/nu-command/src/viewers/table.rs b/crates/nu-command/src/viewers/table.rs index 2fca815b6..bd1a432c5 100644 --- a/crates/nu-command/src/viewers/table.rs +++ b/crates/nu-command/src/viewers/table.rs @@ -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; diff --git a/crates/nu-engine/src/call_ext.rs b/crates/nu-engine/src/call_ext.rs index 1ea0ef163..256320b56 100644 --- a/crates/nu-engine/src/call_ext.rs +++ b/crates/nu-engine/src/call_ext.rs @@ -1,6 +1,6 @@ use nu_protocol::{ ast::Call, - engine::{EngineState, EvaluationContext, Stack}, + engine::{EngineState, Stack}, ShellError, }; diff --git a/crates/nu-engine/src/documentation.rs b/crates/nu-engine/src/documentation.rs index ce9c3b52b..ea0bb17e6 100644 --- a/crates/nu-engine/src/documentation.rs +++ b/crates/nu-engine/src/documentation.rs @@ -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"; diff --git a/crates/nu-engine/src/eval.rs b/crates/nu-engine/src/eval.rs index 91901b3de..b75419e76 100644 --- a/crates/nu-engine/src/eval.rs +++ b/crates/nu-engine/src/eval.rs @@ -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 { diff --git a/crates/nu-protocol/src/engine/command.rs b/crates/nu-protocol/src/engine/command.rs index 6a6955c18..295898207 100644 --- a/crates/nu-protocol/src/engine/command.rs +++ b/crates/nu-protocol/src/engine/command.rs @@ -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; diff --git a/crates/nu-protocol/src/engine/engine_state.rs b/crates/nu-protocol/src/engine/engine_state.rs index c6f2ea11a..de240af11 100644 --- a/crates/nu-protocol/src/engine/engine_state.rs +++ b/crates/nu-protocol/src/engine/engine_state.rs @@ -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 { @@ -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)]; } } diff --git a/crates/nu-protocol/src/engine/evaluation_context.rs b/crates/nu-protocol/src/engine/evaluation_context.rs index 5fd4d17bc..a67318bd5 100644 --- a/crates/nu-protocol/src/engine/evaluation_context.rs +++ b/crates/nu-protocol/src/engine/evaluation_context.rs @@ -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}; diff --git a/crates/nu-protocol/src/signature.rs b/crates/nu-protocol/src/signature.rs index b7037a4bc..caeda6636 100644 --- a/crates/nu-protocol/src/signature.rs +++ b/crates/nu-protocol/src/signature.rs @@ -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)] diff --git a/src/main.rs b/src/main.rs index eb724c347..02ded94a1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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; }