Move Value to helpers, separate span call (#10121)

# Description

As part of the refactor to split spans off of Value, this moves to using
helper functions to create values, and using `.span()` instead of
matching span out of Value directly.

Hoping to get a few more helping hands to finish this, as there are a
lot of commands to update :)

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

# Tests + Formatting
<!--
Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
Co-authored-by: WindSoilder <windsoilder@outlook.com>
This commit is contained in:
JT
2023-09-04 02:27:29 +12:00
committed by GitHub
parent af79eb2943
commit 6cdfee3573
372 changed files with 5811 additions and 7448 deletions

View File

@@ -115,7 +115,7 @@ impl EvaluatedCall {
/// # positional: Vec::new(),
/// # named: vec![(
/// # Spanned { item: "foo".to_owned(), span: null_span},
/// # Some(Value::Int { val: 123, span: null_span })
/// # Some(Value::int(123, null_span))
/// # )],
/// # };
/// let opt_foo = match call.get_flag_value("foo") {
@@ -164,9 +164,9 @@ impl EvaluatedCall {
/// # let call = EvaluatedCall {
/// # head: null_span,
/// # positional: vec![
/// # Value::String { val: "a".to_owned(), span: null_span },
/// # Value::String { val: "b".to_owned(), span: null_span },
/// # Value::String { val: "c".to_owned(), span: null_span },
/// # Value::string("a".to_owned(), null_span),
/// # Value::string("b".to_owned(), null_span),
/// # Value::string("c".to_owned(), null_span),
/// # ],
/// # named: vec![],
/// # };
@@ -196,7 +196,7 @@ impl EvaluatedCall {
/// # positional: Vec::new(),
/// # named: vec![(
/// # Spanned { item: "foo".to_owned(), span: null_span},
/// # Some(Value::Int { val: 123, span: null_span })
/// # Some(Value::int(123, null_span))
/// # )],
/// # };
/// let foo = call.get_flag::<i64>("foo");
@@ -213,7 +213,7 @@ impl EvaluatedCall {
/// # positional: Vec::new(),
/// # named: vec![(
/// # Spanned { item: "bar".to_owned(), span: null_span},
/// # Some(Value::Int { val: 123, span: null_span })
/// # Some(Value::int(123, null_span))
/// # )],
/// # };
/// let foo = call.get_flag::<i64>("foo");
@@ -230,7 +230,7 @@ impl EvaluatedCall {
/// # positional: Vec::new(),
/// # named: vec![(
/// # Spanned { item: "foo".to_owned(), span: null_span},
/// # Some(Value::String { val: "abc".to_owned(), span: null_span })
/// # Some(Value::string("abc".to_owned(), null_span))
/// # )],
/// # };
/// let foo = call.get_flag::<i64>("foo");
@@ -255,10 +255,10 @@ impl EvaluatedCall {
/// # let call = EvaluatedCall {
/// # head: null_span,
/// # positional: vec![
/// # Value::String { val: "zero".to_owned(), span: null_span },
/// # Value::String { val: "one".to_owned(), span: null_span },
/// # Value::String { val: "two".to_owned(), span: null_span },
/// # Value::String { val: "three".to_owned(), span: null_span },
/// # Value::string("zero".to_owned(), null_span),
/// # Value::string("one".to_owned(), null_span),
/// # Value::string("two".to_owned(), null_span),
/// # Value::string("three".to_owned(), null_span),
/// # ],
/// # named: Vec::new(),
/// # };
@@ -318,14 +318,8 @@ mod test {
let call = EvaluatedCall {
head: Span::new(0, 10),
positional: vec![
Value::Float {
val: 1.0,
span: Span::new(0, 10),
},
Value::String {
val: "something".into(),
span: Span::new(0, 10),
},
Value::float(1.0, Span::new(0, 10)),
Value::string("something", Span::new(0, 10)),
],
named: vec![
(
@@ -333,10 +327,7 @@ mod test {
item: "name".to_string(),
span: Span::new(0, 10),
},
Some(Value::Float {
val: 1.0,
span: Span::new(0, 10),
}),
Some(Value::float(1.0, Span::new(0, 10))),
),
(
Spanned {

View File

@@ -34,10 +34,7 @@ pub struct PluginCustomValue {
impl CustomValue for PluginCustomValue {
fn clone_value(&self, span: nu_protocol::Span) -> nu_protocol::Value {
Value::CustomValue {
val: Box::new(self.clone()),
span,
}
Value::custom_value(Box::new(self.clone()), span)
}
fn value_string(&self) -> String {