diff --git a/crates/nu-command/src/debug/view_source.rs b/crates/nu-command/src/debug/view_source.rs index 417da5ec1e..2aadd4d361 100644 --- a/crates/nu-command/src/debug/view_source.rs +++ b/crates/nu-command/src/debug/view_source.rs @@ -33,6 +33,22 @@ impl Command for ViewSource { let arg_span = arg.span(); let source = match arg { + Value::Int { val, .. } => { + let block = engine_state.get_block(nu_protocol::BlockId::new(val as usize)); + if let Some(span) = block.span { + let contents = engine_state.get_span_contents(span); + Ok(Value::string(String::from_utf8_lossy(contents), call.head) + .into_pipeline_data()) + } else { + Err(ShellError::GenericError { + error: "Cannot view int value".to_string(), + msg: "the block does not have a viewable span".to_string(), + span: Some(arg_span), + help: None, + inner: vec![], + }) + } + } Value::String { val, .. } => { if let Some(decl_id) = engine_state.find_decl(val.as_bytes(), &[]) { // arg is a command @@ -130,7 +146,7 @@ impl Command for ViewSource { Ok(Value::string(final_contents, call.head).into_pipeline_data()) } else { Err(ShellError::GenericError { - error: "Cannot view value".to_string(), + error: "Cannot view string value".to_string(), msg: "the command does not have a viewable block span".to_string(), span: Some(arg_span), help: None, @@ -139,7 +155,7 @@ impl Command for ViewSource { } } else { Err(ShellError::GenericError { - error: "Cannot view value".to_string(), + error: "Cannot view string decl value".to_string(), msg: "the command does not have a viewable block".to_string(), span: Some(arg_span), help: None, @@ -155,7 +171,7 @@ impl Command for ViewSource { .into_pipeline_data()) } else { Err(ShellError::GenericError { - error: "Cannot view value".to_string(), + error: "Cannot view string module value".to_string(), msg: "the module does not have a viewable block".to_string(), span: Some(arg_span), help: None, @@ -164,7 +180,7 @@ impl Command for ViewSource { } } else { Err(ShellError::GenericError { - error: "Cannot view value".to_string(), + error: "Cannot view string value".to_string(), msg: "this name does not correspond to a viewable value".to_string(), span: Some(arg_span), help: None,