Add $nu.scope.engine_state (#5739)

* Add number of items present in engine state

* Rename num_decls column to num_commands
This commit is contained in:
Jakub Žádník 2022-06-08 21:31:36 +03:00 committed by GitHub
parent b42ef45c7c
commit 5bae7e56ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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,