mirror of
https://github.com/nushell/nushell.git
synced 2025-04-18 18:28:19 +02:00
add variables to $scope (#3316)
This commit is contained in:
parent
ea0205f2ff
commit
a148c640b2
@ -232,6 +232,7 @@ fn evaluate_reference(name: &str, ctx: &EvaluationContext, tag: Tag) -> Result<V
|
|||||||
"$scope" => crate::evaluate::variables::scope(
|
"$scope" => crate::evaluate::variables::scope(
|
||||||
&ctx.scope.get_aliases(),
|
&ctx.scope.get_aliases(),
|
||||||
&ctx.scope.get_commands(),
|
&ctx.scope.get_commands(),
|
||||||
|
&ctx.scope.get_vars(),
|
||||||
tag,
|
tag,
|
||||||
),
|
),
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ use crate::{evaluate::scope::Scope, EvaluationContext};
|
|||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use nu_data::config::path::{default_history_path, history_path};
|
use nu_data::config::path::{default_history_path, history_path};
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{Signature, TaggedDictBuilder, UntaggedValue, Value};
|
use nu_protocol::{ShellTypeName, Signature, TaggedDictBuilder, UntaggedValue, Value};
|
||||||
use nu_source::{Spanned, Tag};
|
use nu_source::{Spanned, Tag};
|
||||||
|
|
||||||
pub fn nu(
|
pub fn nu(
|
||||||
@ -84,6 +84,7 @@ pub fn nu(
|
|||||||
pub fn scope(
|
pub fn scope(
|
||||||
aliases: &IndexMap<String, Vec<Spanned<String>>>,
|
aliases: &IndexMap<String, Vec<Spanned<String>>>,
|
||||||
commands: &IndexMap<String, Signature>,
|
commands: &IndexMap<String, Signature>,
|
||||||
|
variables: &IndexMap<String, Value>,
|
||||||
tag: impl Into<Tag>,
|
tag: impl Into<Tag>,
|
||||||
) -> Result<Value, ShellError> {
|
) -> Result<Value, ShellError> {
|
||||||
let tag = tag.into();
|
let tag = tag.into();
|
||||||
@ -109,9 +110,21 @@ pub fn scope(
|
|||||||
commands_dict.insert_untagged(name, UntaggedValue::string(&signature.allowed().join(" ")))
|
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("aliases", aliases_dict.into_value());
|
||||||
|
|
||||||
scope_dict.insert_value("commands", commands_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())
|
Ok(scope_dict.into_value())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user