mirror of
https://github.com/nushell/nushell.git
synced 2025-08-10 07:18:19 +02:00
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:
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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! {
|
||||
|
@ -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,
|
||||
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user