From 23846ecd84172737683830ea73beaa8552be4492 Mon Sep 17 00:00:00 2001 From: Gwendolyn Date: Wed, 31 Jul 2024 10:35:26 +0200 Subject: [PATCH] small fixes - take a working set instead of engine state in `make_main_call()` - improve panic message in `make_main_call()` --- crates/nu-cli/src/eval_file.rs | 4 +++- crates/nu-cli/src/util.rs | 21 +++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/crates/nu-cli/src/eval_file.rs b/crates/nu-cli/src/eval_file.rs index 7396c222b4..b368113689 100644 --- a/crates/nu-cli/src/eval_file.rs +++ b/crates/nu-cli/src/eval_file.rs @@ -126,12 +126,14 @@ pub fn evaluate_file( // Invoke the main command with arguments. // Arguments with whitespaces are quoted, thus can be safely concatenated by whitespace. + let mut working_set = StateWorkingSet::new(engine_state); let main_call_block = make_main_call( - engine_state, + &mut working_set, source_filename.to_string_lossy().to_string(), args, true, )?; + engine_state.merge_delta(working_set.delta)?; evaluate_block_with_exit_code( engine_state, diff --git a/crates/nu-cli/src/util.rs b/crates/nu-cli/src/util.rs index e53771c2f2..ec9ae5e985 100644 --- a/crates/nu-cli/src/util.rs +++ b/crates/nu-cli/src/util.rs @@ -205,12 +205,11 @@ fn gather_env_vars( } pub fn make_main_call( - engine_state: &mut EngineState, + working_set: &mut StateWorkingSet, fname: String, args: &[String], redirect_env: bool, ) -> Result, ShellError> { - let mut working_set = StateWorkingSet::new(engine_state); let source = format!("{} {}", fname, args.join(" ")); let source = source.as_bytes(); let file_id = working_set.add_file("".to_string(), source); @@ -226,35 +225,35 @@ pub fn make_main_call( let lite_command = &lite_block.block[0].commands[0]; let (decl_id, command_len) = - find_longest_command(&working_set, b"main", &lite_command.parts[1..]) - .expect("already checked that a main def exists"); + find_longest_command(working_set, b"main", &lite_command.parts[1..]) + .expect("make_main_call() called, but 'main' definition not found in state"); let parsed_call = parse_internal_call( - &mut working_set, + working_set, Span::concat(&lite_command.parts[..command_len + 1]), &lite_command.parts[(command_len + 1)..], decl_id, ); let expression = Expression::new( - &mut working_set, + working_set, Expr::Call(parsed_call.call), Span::concat(lite_command.parts.as_slice()), parsed_call.output, ); if let Some(warning) = working_set.parse_warnings.first() { - report_error(&working_set, warning); + report_error(working_set, warning); } // If any parse errors were found, report the first error and exit. if let Some(err) = working_set.parse_errors.first() { - report_error(&working_set, err); + report_error(working_set, err); std::process::exit(1); } if let Some(err) = working_set.compile_errors.first() { - report_error(&working_set, err); + report_error(working_set, err); // Not a fatal error, for now } @@ -267,15 +266,13 @@ pub fn make_main_call( span: Some(file_span), }; - match nu_engine::compile(&working_set, &block) { + match nu_engine::compile(working_set, &block) { Ok(ir_block) => { block.ir_block = Some(ir_block); } Err(err) => working_set.compile_errors.push(err), } - engine_state.merge_delta(working_set.delta)?; - Ok(Arc::new(block)) }