ListStream touchup (#12524)

# Description

Does some misc changes to `ListStream`:
- Moves it into its own module/file separate from `RawStream`.
- `ListStream`s now have an associated `Span`.
- This required changes to `ListStreamInfo` in `nu-plugin`. Note sure if
this is a breaking change for the plugin protocol.
- Hides the internals of `ListStream` but also adds a few more methods.
- This includes two functions to more easily alter a stream (these take
a `ListStream` and return a `ListStream` instead of having to go through
the whole `into_pipeline_data(..)` route).
  -  `map`: takes a `FnMut(Value) -> Value`
  - `modify`: takes a function to modify the inner stream.
This commit is contained in:
Ian Manske
2024-05-05 16:00:59 +00:00
committed by GitHub
parent 3143ded374
commit e879d4ecaf
106 changed files with 957 additions and 874 deletions

View File

@ -34,16 +34,14 @@ impl Command for Explain {
stack: &mut Stack,
call: &Call,
_input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
) -> Result<PipelineData, ShellError> {
let head = call.head;
// This was all delightfully stolen from benchmark :)
let capture_block: Closure = call.req(engine_state, stack, 0)?;
let block = engine_state.get_block(capture_block.block_id);
let ctrlc = engine_state.ctrlc.clone();
let mut stack = stack.captures_to_stack(capture_block.captures);
let elements = get_pipeline_elements(engine_state, &mut stack, block, call.head);
Ok(elements.into_pipeline_data(ctrlc))
let elements = get_pipeline_elements(engine_state, &mut stack, block, head);
Ok(Value::list(elements, head).into_pipeline_data())
}
fn examples(&self) -> Vec<Example> {

View File

@ -47,13 +47,21 @@ impl Command for MetadataSet {
let metadata = PipelineMetadata {
data_source: DataSource::FilePath(path.into()),
};
Ok(input.into_pipeline_data_with_metadata(metadata, engine_state.ctrlc.clone()))
Ok(input.into_pipeline_data_with_metadata(
head,
engine_state.ctrlc.clone(),
metadata,
))
}
(None, true) => {
let metadata = PipelineMetadata {
data_source: DataSource::Ls,
};
Ok(input.into_pipeline_data_with_metadata(metadata, engine_state.ctrlc.clone()))
Ok(input.into_pipeline_data_with_metadata(
head,
engine_state.ctrlc.clone(),
metadata,
))
}
_ => Err(ShellError::IncorrectValue {
msg: "Expected either --datasource-ls(-l) or --datasource-filepath(-f)".to_string(),