mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 21:37:54 +02:00
Spanned Value step 1: span all value cases (#10042)
# Description This doesn't really do much that the user could see, but it helps get us ready to do the steps of the refactor to split the span off of Value, so that values can be spanless. This allows us to have top-level values that can hold both a Value and a Span, without requiring that all values have them. We expect to see significant memory reduction by removing so many unnecessary spans from values. For example, a table of 100,000 rows and 5 columns would have a savings of ~8megs in just spans that are almost always duplicated. # User-Facing Changes Nothing yet # 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 -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `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. -->
This commit is contained in:
@ -278,7 +278,7 @@ pub fn request_set_timeout(
|
||||
if val.is_negative() || val < 1 {
|
||||
return Err(ShellError::TypeMismatch {
|
||||
err_message: "Timeout value must be an integer and larger than 0".to_string(),
|
||||
span: timeout.expect_span(),
|
||||
span: timeout.span(),
|
||||
});
|
||||
}
|
||||
|
||||
@ -316,7 +316,7 @@ pub fn request_add_custom_headers(
|
||||
return Err(ShellError::CantConvert {
|
||||
to_type: "string list or single row".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: headers.span().unwrap_or_else(|_| Span::new(0, 0)),
|
||||
span: headers.span(),
|
||||
help: None,
|
||||
});
|
||||
}
|
||||
@ -335,7 +335,7 @@ pub fn request_add_custom_headers(
|
||||
return Err(ShellError::CantConvert {
|
||||
to_type: "string list or single row".into(),
|
||||
from_type: x.get_type().to_string(),
|
||||
span: headers.span().unwrap_or_else(|_| Span::new(0, 0)),
|
||||
span: headers.span(),
|
||||
help: None,
|
||||
});
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ fn helper(
|
||||
call: &Call,
|
||||
args: Arguments,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let span = args.url.span()?;
|
||||
let span = args.url.span();
|
||||
let ctrl_c = engine_state.ctrlc.clone();
|
||||
let (requested_url, _) = http_parse_url(call, span, args.url)?;
|
||||
|
||||
|
@ -167,7 +167,7 @@ fn helper(
|
||||
call: &Call,
|
||||
args: Arguments,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let span = args.url.span()?;
|
||||
let span = args.url.span();
|
||||
let ctrl_c = engine_state.ctrlc.clone();
|
||||
let (requested_url, _) = http_parse_url(call, span, args.url)?;
|
||||
|
||||
|
@ -141,7 +141,7 @@ fn helper(
|
||||
args: Arguments,
|
||||
ctrlc: Option<Arc<AtomicBool>>,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let span = args.url.span()?;
|
||||
let span = args.url.span();
|
||||
let (requested_url, _) = http_parse_url(call, span, args.url)?;
|
||||
|
||||
let client = http_client(args.insecure);
|
||||
|
@ -156,7 +156,7 @@ fn helper(
|
||||
call: &Call,
|
||||
args: Arguments,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let span = args.url.span()?;
|
||||
let span = args.url.span();
|
||||
let ctrl_c = engine_state.ctrlc.clone();
|
||||
let (requested_url, _) = http_parse_url(call, span, args.url)?;
|
||||
|
||||
|
@ -173,7 +173,7 @@ fn helper(
|
||||
call: &Call,
|
||||
args: Arguments,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let span = args.url.span()?;
|
||||
let span = args.url.span();
|
||||
let ctrl_c = engine_state.ctrlc.clone();
|
||||
let (requested_url, _) = http_parse_url(call, span, args.url)?;
|
||||
|
||||
|
@ -173,7 +173,7 @@ fn helper(
|
||||
call: &Call,
|
||||
args: Arguments,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let span = args.url.span()?;
|
||||
let span = args.url.span();
|
||||
let ctrl_c = engine_state.ctrlc.clone();
|
||||
let (requested_url, _) = http_parse_url(call, span, args.url)?;
|
||||
|
||||
|
@ -173,7 +173,7 @@ fn helper(
|
||||
call: &Call,
|
||||
args: Arguments,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let span = args.url.span()?;
|
||||
let span = args.url.span();
|
||||
let ctrl_c = engine_state.ctrlc.clone();
|
||||
let (requested_url, _) = http_parse_url(call, span, args.url)?;
|
||||
|
||||
|
@ -94,12 +94,12 @@ fn to_url(input: PipelineData, head: Span) -> Result<PipelineData, ShellError> {
|
||||
}
|
||||
}
|
||||
// Propagate existing errors
|
||||
Value::Error { error } => Err(*error),
|
||||
Value::Error { error, .. } => Err(*error),
|
||||
other => Err(ShellError::UnsupportedInput(
|
||||
"Expected a table from pipeline".to_string(),
|
||||
"value originates from here".into(),
|
||||
head,
|
||||
other.expect_span(),
|
||||
other.span(),
|
||||
)),
|
||||
})
|
||||
.collect();
|
||||
|
@ -109,8 +109,9 @@ fn action_all(input: &Value, _arg: &CellPathOnlyArgs, head: Span) -> Value {
|
||||
exp_input_type: "string".into(),
|
||||
wrong_type: input.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: input.expect_span(),
|
||||
src_span: input.span(),
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -130,8 +131,9 @@ fn action(input: &Value, _arg: &CellPathOnlyArgs, head: Span) -> Value {
|
||||
exp_input_type: "string".into(),
|
||||
wrong_type: input.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: input.expect_span(),
|
||||
src_span: input.span(),
|
||||
}),
|
||||
span: head,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -101,12 +101,12 @@ impl Command for SubCommand {
|
||||
|
||||
url_components?.to_url(span)
|
||||
}
|
||||
Value::Error { error } => Err(*error),
|
||||
Value::Error { error, .. } => Err(*error),
|
||||
other => Err(ShellError::UnsupportedInput(
|
||||
"Expected a record from pipeline".to_string(),
|
||||
"value originates from here".into(),
|
||||
head,
|
||||
other.expect_span(),
|
||||
other.span(),
|
||||
)),
|
||||
})
|
||||
.collect();
|
||||
@ -159,12 +159,12 @@ impl UrlComponents {
|
||||
port: Some(val),
|
||||
..self
|
||||
}),
|
||||
Value::Error { error } => Err(*error),
|
||||
Value::Error { error, .. } => Err(*error),
|
||||
other => Err(ShellError::IncompatibleParametersSingle {
|
||||
msg: String::from(
|
||||
"Port parameter should be an unsigned integer or a string representing it",
|
||||
),
|
||||
span: other.expect_span(),
|
||||
span: other.span(),
|
||||
}),
|
||||
};
|
||||
}
|
||||
@ -192,7 +192,7 @@ impl UrlComponents {
|
||||
// if query is present it means that also query_span is set.
|
||||
return Err(ShellError::IncompatibleParameters {
|
||||
left_message: format!("Mismatch, qs from params is: {qs}"),
|
||||
left_span: value.expect_span(),
|
||||
left_span: value.span(),
|
||||
right_message: format!("instead query is: {q}"),
|
||||
right_span: self.query_span.unwrap_or(Span::unknown()),
|
||||
});
|
||||
@ -205,10 +205,10 @@ impl UrlComponents {
|
||||
..self
|
||||
})
|
||||
}
|
||||
Value::Error { error } => Err(*error),
|
||||
Value::Error { error, .. } => Err(*error),
|
||||
other => Err(ShellError::IncompatibleParametersSingle {
|
||||
msg: String::from("Key params has to be a record"),
|
||||
span: other.expect_span(),
|
||||
span: other.span(),
|
||||
}),
|
||||
};
|
||||
}
|
||||
@ -250,7 +250,7 @@ impl UrlComponents {
|
||||
// if query is present it means that also params_span is set.
|
||||
return Err(ShellError::IncompatibleParameters {
|
||||
left_message: format!("Mismatch, query param is: {s}"),
|
||||
left_span: value.expect_span(),
|
||||
left_span: value.span(),
|
||||
right_message: format!("instead qs from params is: {q}"),
|
||||
right_span: self.params_span.unwrap_or(Span::unknown()),
|
||||
});
|
||||
@ -259,7 +259,7 @@ impl UrlComponents {
|
||||
|
||||
Ok(Self {
|
||||
query: Some(format!("?{s}")),
|
||||
query_span: Some(value.expect_span()),
|
||||
query_span: Some(value.span()),
|
||||
..self
|
||||
})
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ fn parse(value: Value, head: Span, engine_state: &EngineState) -> Result<Pipelin
|
||||
let result_url = Url::parse(url_string.as_str());
|
||||
|
||||
// This is the span of the original string, not the call head.
|
||||
let span = value.span()?;
|
||||
let span = value.span();
|
||||
|
||||
match result_url {
|
||||
Ok(url) => {
|
||||
|
Reference in New Issue
Block a user