From 48cf103439f229274de5d78be76ee6ce5d37c781 Mon Sep 17 00:00:00 2001 From: pwygab <88221256+merelymyself@users.noreply.github.com> Date: Wed, 4 May 2022 19:35:09 +0800 Subject: [PATCH] Allowed for view-source to include entire custom command definition (#5435) * allowed for view-source to include entire custom command definition * fmt * clippy --- .../src/experimental/view_source.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/crates/nu-command/src/experimental/view_source.rs b/crates/nu-command/src/experimental/view_source.rs index 06fdccd22b..83eea4ca9b 100644 --- a/crates/nu-command/src/experimental/view_source.rs +++ b/crates/nu-command/src/experimental/view_source.rs @@ -50,12 +50,27 @@ impl Command for ViewSource { if let Some(decl_id) = engine_state.find_decl(val.as_bytes()) { // arg is a command let decl = engine_state.get_decl(decl_id); + let sig = decl.signature(); + let vec_of_required = &sig.required_positional; + // gets vector of positionals. if let Some(block_id) = decl.get_block_id() { let block = engine_state.get_block(block_id); if let Some(block_span) = block.span { let contents = engine_state.get_span_contents(&block_span); - Ok(Value::string(String::from_utf8_lossy(contents), call.head) - .into_pipeline_data()) + let mut final_contents = String::from("def "); + final_contents.push_str(&val); + // The name of the function... + final_contents.push_str(" [ "); + for n in vec_of_required { + final_contents.push_str(&n.name); + // name of positional arg + final_contents.push(':'); + final_contents.push_str(&n.shape.to_string()); + final_contents.push(' '); + } + final_contents.push_str("] "); + final_contents.push_str(&String::from_utf8_lossy(contents)); + Ok(Value::string(final_contents, call.head).into_pipeline_data()) } else { Err(ShellError::GenericError( "Cannot view value".to_string(),