Fix view-source command (#4486)

This commit is contained in:
JT 2022-02-15 17:03:06 -05:00 committed by GitHub
parent f824388f63
commit df07e8e410
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -35,12 +35,16 @@ impl Command for ViewSource {
let arg_span = arg.span()?; let arg_span = arg.span()?;
match arg { match arg {
Value::Block { span, .. } => { Value::Block { val: block_id, .. } => {
let contents = engine_state.get_span_contents(&span); let block = engine_state.get_block(block_id);
Ok(
Value::string(String::from_utf8_lossy(contents), call.head) if let Some(span) = block.span {
.into_pipeline_data(), let contents = engine_state.get_span_contents(&span);
) Ok(Value::string(String::from_utf8_lossy(contents), call.head)
.into_pipeline_data())
} else {
Ok(Value::string("<internal command>", call.head).into_pipeline_data())
}
} }
Value::String { val, .. } => { Value::String { val, .. } => {
if let Some(decl_id) = engine_state.find_decl(val.as_bytes()) { if let Some(decl_id) = engine_state.find_decl(val.as_bytes()) {