diff --git a/crates/nu-engine/src/evaluate/evaluator.rs b/crates/nu-engine/src/evaluate/evaluator.rs index 034af45625..91c0670b3d 100644 --- a/crates/nu-engine/src/evaluate/evaluator.rs +++ b/crates/nu-engine/src/evaluate/evaluator.rs @@ -232,6 +232,7 @@ fn evaluate_reference(name: &str, ctx: &EvaluationContext, tag: Tag) -> Result crate::evaluate::variables::scope( &ctx.scope.get_aliases(), &ctx.scope.get_commands(), + &ctx.scope.get_vars(), tag, ), diff --git a/crates/nu-engine/src/evaluate/variables.rs b/crates/nu-engine/src/evaluate/variables.rs index 05093cdecf..9f7479032d 100644 --- a/crates/nu-engine/src/evaluate/variables.rs +++ b/crates/nu-engine/src/evaluate/variables.rs @@ -2,7 +2,7 @@ use crate::{evaluate::scope::Scope, EvaluationContext}; use indexmap::IndexMap; use nu_data::config::path::{default_history_path, history_path}; use nu_errors::ShellError; -use nu_protocol::{Signature, TaggedDictBuilder, UntaggedValue, Value}; +use nu_protocol::{ShellTypeName, Signature, TaggedDictBuilder, UntaggedValue, Value}; use nu_source::{Spanned, Tag}; pub fn nu( @@ -84,6 +84,7 @@ pub fn nu( pub fn scope( aliases: &IndexMap>>, commands: &IndexMap, + variables: &IndexMap, tag: impl Into, ) -> Result { let tag = tag.into(); @@ -109,9 +110,21 @@ pub fn scope( commands_dict.insert_untagged(name, UntaggedValue::string(&signature.allowed().join(" "))) } + let mut vars_dict = TaggedDictBuilder::new(&tag); + for (name, val) in variables.iter() { + let val_type = UntaggedValue::string(format!( + "{} ({})", + val.convert_to_string(), + ShellTypeName::type_name(&val.clone()) + )); + vars_dict.insert_value(name, val_type) + } + scope_dict.insert_value("aliases", aliases_dict.into_value()); scope_dict.insert_value("commands", commands_dict.into_value()); + scope_dict.insert_value("variables", vars_dict.into_value()); + Ok(scope_dict.into_value()) }