From 5bae7e56ef0990312a7becf8280b2f06899db6ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Wed, 8 Jun 2022 21:31:36 +0300 Subject: [PATCH] Add `$nu.scope.engine_state` (#5739) * Add number of items present in engine state * Rename num_decls column to num_commands --- crates/nu-engine/src/eval.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/crates/nu-engine/src/eval.rs b/crates/nu-engine/src/eval.rs index 0469f30434..e7df663ceb 100644 --- a/crates/nu-engine/src/eval.rs +++ b/crates/nu-engine/src/eval.rs @@ -1174,6 +1174,40 @@ pub fn create_scope( span, }); + let engine_state_cols = vec![ + "source_bytes".to_string(), + "num_vars".to_string(), + "num_commands".to_string(), + "num_aliases".to_string(), + "num_blocks".to_string(), + "num_modules".to_string(), + "num_env_vars".to_string(), + ]; + + let engine_state_vals = vec![ + Value::int(engine_state.next_span_start() as i64, span), + Value::int(engine_state.num_vars() as i64, span), + Value::int(engine_state.num_decls() as i64, span), + Value::int(engine_state.num_aliases() as i64, span), + Value::int(engine_state.num_blocks() as i64, span), + Value::int(engine_state.num_modules() as i64, span), + Value::int( + engine_state + .env_vars + .values() + .map(|overlay| overlay.len() as i64) + .sum(), + span, + ), + ]; + + output_cols.push("engine_state".to_string()); + output_vals.push(Value::Record { + cols: engine_state_cols, + vals: engine_state_vals, + span, + }); + Ok(Value::Record { cols: output_cols, vals: output_vals,