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()?;
match arg {
Value::Block { span, .. } => {
let contents = engine_state.get_span_contents(&span);
Ok(
Value::string(String::from_utf8_lossy(contents), call.head)
.into_pipeline_data(),
)
Value::Block { val: block_id, .. } => {
let block = engine_state.get_block(block_id);
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 {
Ok(Value::string("<internal command>", call.head).into_pipeline_data())
}
}
Value::String { val, .. } => {
if let Some(decl_id) = engine_state.find_decl(val.as_bytes()) {