Skip to content

Commit

Permalink
Finish removing profile command and related data (nushell#10807)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubouch authored Oct 22, 2023
1 parent a01ef85 commit a35ecb4
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 150 deletions.
8 changes: 3 additions & 5 deletions crates/nu-cmd-extra/src/extra/formats/to/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,9 @@ fn to_html(
})
.collect();
return Ok(
Value::list(result, head).into_pipeline_data_with_metadata(Box::new(
PipelineMetadata {
data_source: DataSource::HtmlThemes,
},
)),
Value::list(result, head).into_pipeline_data_with_metadata(PipelineMetadata {
data_source: DataSource::HtmlThemes,
}),
);
} else {
let theme_span = match &theme {
Expand Down
28 changes: 8 additions & 20 deletions crates/nu-command/src/debug/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,46 +55,37 @@ impl Command for Metadata {
let origin = stack.get_var_with_origin(*var_id, *span)?;

Ok(
build_metadata_record(&origin, input.metadata().as_deref(), head)
build_metadata_record(&origin, input.metadata().as_ref(), head)
.into_pipeline_data(),
)
}
_ => {
let val: Value = call.req(engine_state, stack, 0)?;
Ok(
build_metadata_record(&val, input.metadata().as_deref(), head)
.into_pipeline_data(),
)
Ok(build_metadata_record(&val, input.metadata().as_ref(), head)
.into_pipeline_data())
}
}
} else {
let val: Value = call.req(engine_state, stack, 0)?;
Ok(
build_metadata_record(&val, input.metadata().as_deref(), head)
.into_pipeline_data(),
)
Ok(build_metadata_record(&val, input.metadata().as_ref(), head)
.into_pipeline_data())
}
}
Some(_) => {
let val: Value = call.req(engine_state, stack, 0)?;
Ok(
build_metadata_record(&val, input.metadata().as_deref(), head)
.into_pipeline_data(),
)
Ok(build_metadata_record(&val, input.metadata().as_ref(), head)
.into_pipeline_data())
}
None => {
let mut record = Record::new();
if let Some(x) = input.metadata().as_deref() {
if let Some(x) = input.metadata().as_ref() {
match x {
PipelineMetadata {
data_source: DataSource::Ls,
} => record.push("source", Value::string("ls", head)),
PipelineMetadata {
data_source: DataSource::HtmlThemes,
} => record.push("source", Value::string("into html --list", head)),
PipelineMetadata {
data_source: DataSource::Profiling(values),
} => record.push("profiling", Value::list(values.clone(), head)),
}
}

Expand Down Expand Up @@ -142,9 +133,6 @@ fn build_metadata_record(arg: &Value, metadata: Option<&PipelineMetadata>, head:
PipelineMetadata {
data_source: DataSource::HtmlThemes,
} => record.push("source", Value::string("into html --list", head)),
PipelineMetadata {
data_source: DataSource::Profiling(values),
} => record.push("profiling", Value::list(values.clone(), head)),
}
}

Expand Down
2 changes: 0 additions & 2 deletions crates/nu-command/src/debug/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ mod info;
mod inspect;
mod inspect_table;
mod metadata;
mod profile;
mod timeit;
mod view;
mod view_files;
Expand All @@ -19,7 +18,6 @@ pub use info::DebugInfo;
pub use inspect::Inspect;
pub use inspect_table::build_table;
pub use metadata::Metadata;
pub use profile::Profile;
pub use timeit::TimeIt;
pub use view::View;
pub use view_files::ViewFiles;
Expand Down
102 changes: 0 additions & 102 deletions crates/nu-command/src/debug/profile.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/nu-command/src/default_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ pub fn add_shell_command_context(mut engine_state: EngineState) -> EngineState {
Explain,
Inspect,
Metadata,
Profile,
TimeIt,
View,
ViewFiles,
Expand Down
4 changes: 2 additions & 2 deletions crates/nu-command/src/filesystem/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ impl Command for Ls {
_ => Some(Value::nothing(call_span)),
})
.into_pipeline_data_with_metadata(
Box::new(PipelineMetadata {
PipelineMetadata {
data_source: DataSource::Ls,
}),
},
engine_state.ctrlc.clone(),
))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/filters/uniq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ pub fn uniq(
call: &Call,
input: Vec<Value>,
item_mapper: Box<dyn Fn(ItemMapperState) -> ValueCounter>,
metadata: Option<Box<PipelineMetadata>>,
metadata: Option<PipelineMetadata>,
) -> Result<PipelineData, ShellError> {
let ctrlc = engine_state.ctrlc.clone();
let head = call.head;
Expand Down
4 changes: 2 additions & 2 deletions crates/nu-command/src/viewers/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,11 @@ fn handle_row_stream(
input: CmdInput<'_>,
cfg: TableConfig,
stream: ListStream,
metadata: Option<Box<PipelineMetadata>>,
metadata: Option<PipelineMetadata>,
) -> Result<PipelineData, ShellError> {
let ctrlc = input.engine_state.ctrlc.clone();

let stream = match metadata.as_deref() {
let stream = match metadata.as_ref() {
// First, `ls` sources:
Some(PipelineMetadata {
data_source: DataSource::Ls,
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-explore/src/nu_common/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn collect_pipeline(input: PipelineData) -> (Vec<String>, Vec<Vec<Value>>) {
metadata,
span,
..
} => collect_external_stream(stdout, stderr, exit_code, metadata.map(|m| *m), span),
} => collect_external_stream(stdout, stderr, exit_code, metadata, span),
}
}

Expand Down
25 changes: 11 additions & 14 deletions crates/nu-protocol/src/pipeline_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,14 @@ const LINE_ENDING_PATTERN: &[char] = &['\r', '\n'];
/// Nushell.
#[derive(Debug)]
pub enum PipelineData {
// Note: the PipelineMetadata is boxed everywhere because the DataSource::Profiling caused
// stack overflow on Windows CI when testing virtualenv
Value(Value, Option<Box<PipelineMetadata>>),
ListStream(ListStream, Option<Box<PipelineMetadata>>),
Value(Value, Option<PipelineMetadata>),
ListStream(ListStream, Option<PipelineMetadata>),
ExternalStream {
stdout: Option<RawStream>,
stderr: Option<RawStream>,
exit_code: Option<ListStream>,
span: Span,
metadata: Option<Box<PipelineMetadata>>,
metadata: Option<PipelineMetadata>,
trim_end_newline: bool,
},
Empty,
Expand All @@ -64,11 +62,10 @@ pub struct PipelineMetadata {
pub enum DataSource {
Ls,
HtmlThemes,
Profiling(Vec<Value>),
}

impl PipelineData {
pub fn new_with_metadata(metadata: Option<Box<PipelineMetadata>>, span: Span) -> PipelineData {
pub fn new_with_metadata(metadata: Option<PipelineMetadata>, span: Span) -> PipelineData {
PipelineData::Value(Value::nothing(span), metadata)
}

Expand All @@ -93,7 +90,7 @@ impl PipelineData {
PipelineData::Empty
}

pub fn metadata(&self) -> Option<Box<PipelineMetadata>> {
pub fn metadata(&self) -> Option<PipelineMetadata> {
match self {
PipelineData::ListStream(_, x) => x.clone(),
PipelineData::ExternalStream { metadata: x, .. } => x.clone(),
Expand All @@ -102,7 +99,7 @@ impl PipelineData {
}
}

pub fn set_metadata(mut self, metadata: Option<Box<PipelineMetadata>>) -> Self {
pub fn set_metadata(mut self, metadata: Option<PipelineMetadata>) -> Self {
match &mut self {
PipelineData::ListStream(_, x) => *x = metadata,
PipelineData::ExternalStream { metadata: x, .. } => *x = metadata,
Expand Down Expand Up @@ -354,7 +351,7 @@ impl PipelineData {
pub fn collect_string_strict(
self,
span: Span,
) -> Result<(String, Span, Option<Box<PipelineMetadata>>), ShellError> {
) -> Result<(String, Span, Option<PipelineMetadata>), ShellError> {
match self {
PipelineData::Empty => Ok((String::new(), span, None)),
PipelineData::Value(Value::String { val, .. }, metadata) => Ok((val, span, metadata)),
Expand Down Expand Up @@ -926,7 +923,7 @@ pub trait IntoPipelineData {

fn into_pipeline_data_with_metadata(
self,
metadata: impl Into<Option<Box<PipelineMetadata>>>,
metadata: impl Into<Option<PipelineMetadata>>,
) -> PipelineData;
}

Expand All @@ -940,7 +937,7 @@ where

fn into_pipeline_data_with_metadata(
self,
metadata: impl Into<Option<Box<PipelineMetadata>>>,
metadata: impl Into<Option<PipelineMetadata>>,
) -> PipelineData {
PipelineData::Value(self.into(), metadata.into())
}
Expand All @@ -950,7 +947,7 @@ pub trait IntoInterruptiblePipelineData {
fn into_pipeline_data(self, ctrlc: Option<Arc<AtomicBool>>) -> PipelineData;
fn into_pipeline_data_with_metadata(
self,
metadata: impl Into<Option<Box<PipelineMetadata>>>,
metadata: impl Into<Option<PipelineMetadata>>,
ctrlc: Option<Arc<AtomicBool>>,
) -> PipelineData;
}
Expand All @@ -973,7 +970,7 @@ where

fn into_pipeline_data_with_metadata(
self,
metadata: impl Into<Option<Box<PipelineMetadata>>>,
metadata: impl Into<Option<PipelineMetadata>>,
ctrlc: Option<Arc<AtomicBool>>,
) -> PipelineData {
PipelineData::ListStream(
Expand Down

0 comments on commit a35ecb4

Please sign in to comment.