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

@ -148,7 +148,8 @@ pub fn highlight_search_in_table(
let mut matches = vec![];
for record in table {
let (mut record, record_span) = if let Value::Record { val, span } = record {
let span = record.span();
let (mut record, record_span) = if let Value::Record { val, .. } = record {
(val, span)
} else {
return Err(ShellError::NushellFailedSpanned {
@ -165,17 +166,18 @@ pub fn highlight_search_in_table(
// don't search this column
return Ok(acc);
}
if let Value::String { val: s, span } = val {
let span = val.span();
if let Value::String { val: s, .. } = val {
if s.to_lowercase().contains(&search_string) {
*val = Value::String {
val: highlight_search_string(
*val = Value::string(
highlight_search_string(
s,
orig_search_string,
string_style,
highlight_style,
)?,
span: *span,
};
span,
);
return Ok(true);
}
}

View File

@ -159,11 +159,7 @@ pub fn help_aliases(
long_desc = nu_utils::strip_ansi_string_likely(long_desc);
}
Ok(Value::String {
val: long_desc,
span: call.head,
}
.into_pipeline_data())
Ok(Value::string(long_desc, call.head).into_pipeline_data())
}
}

View File

@ -109,11 +109,10 @@ pub fn help_commands(
.collect::<Vec<String>>();
if !output.is_empty() {
Ok(Value::String {
val: output.join("======================\n\n"),
span: call.head,
}
.into_pipeline_data())
Ok(
Value::string(output.join("======================\n\n"), call.head)
.into_pipeline_data(),
)
} else {
Err(ShellError::CommandNotFound(span(&[
rest[0].span,
@ -205,7 +204,7 @@ fn build_help_commands(engine_state: &EngineState, span: Span) -> Vec<Value> {
));
}
Value::List { vals, span }
Value::list(vals, span)
};
// Build the signature input/output table
@ -222,7 +221,7 @@ fn build_help_commands(engine_state: &EngineState, span: Span) -> Vec<Value> {
));
}
Value::List { vals, span }
Value::list(vals, span)
};
let record = record! {

View File

@ -128,11 +128,10 @@ pub fn help_externs(
.collect::<Vec<String>>();
if !output.is_empty() {
Ok(Value::String {
val: output.join("======================\n\n"),
span: call.head,
}
.into_pipeline_data())
Ok(
Value::string(output.join("======================\n\n"), call.head)
.into_pipeline_data(),
)
} else {
Err(ShellError::CommandNotFound(span(&[
rest[0].span,

View File

@ -243,11 +243,7 @@ pub fn help_modules(
long_desc = nu_utils::strip_ansi_string_likely(long_desc);
}
Ok(Value::String {
val: long_desc,
span: call.head,
}
.into_pipeline_data())
Ok(Value::string(long_desc, call.head).into_pipeline_data())
}
}