From 1f4c34fa04f85ae4724a66fb1bbafed06f75c227 Mon Sep 17 00:00:00 2001 From: Fernando Herrera Date: Mon, 1 Nov 2021 08:16:56 +0000 Subject: [PATCH] adding span to value encoding --- crates/nu-plugin/src/plugin.rs | 4 ++-- crates/nu-plugin/src/serializers/value.rs | 15 ++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/crates/nu-plugin/src/plugin.rs b/crates/nu-plugin/src/plugin.rs index 8803db70fa..672c648463 100644 --- a/crates/nu-plugin/src/plugin.rs +++ b/crates/nu-plugin/src/plugin.rs @@ -187,7 +187,7 @@ impl Command for PluginDeclaration { } // Deserialize response from plugin to extract the resulting value - let signature = if let Some(stdout_reader) = child.stdout.take() { + let pipeline_data = if let Some(stdout_reader) = child.stdout.take() { let mut buf_read = BufReader::with_capacity(OUTPUT_BUFFER_SIZE, stdout_reader); let response = plugin_call::decode_response(&mut buf_read) .map_err(|err| ShellError::PluginError(err.to_string()))?; @@ -208,7 +208,7 @@ impl Command for PluginDeclaration { match child.wait() { Err(err) => Err(ShellError::PluginError(format!("{}", err))), - Ok(_) => Ok(signature), + Ok(_) => Ok(pipeline_data), } } } diff --git a/crates/nu-plugin/src/serializers/value.rs b/crates/nu-plugin/src/serializers/value.rs index d2a641ddb2..d5e1bef7d9 100644 --- a/crates/nu-plugin/src/serializers/value.rs +++ b/crates/nu-plugin/src/serializers/value.rs @@ -2,8 +2,8 @@ use crate::plugin::PluginError; use crate::plugin_capnp::value; use nu_protocol::{Span, Value}; -pub(crate) fn serialize_value(value: &Value, mut builder: value::Builder) -> Span { - match value { +pub(crate) fn serialize_value(value: &Value, mut builder: value::Builder) { + let value_span = match value { Value::Nothing { span } => { builder.set_void(()); *span @@ -38,7 +38,11 @@ pub(crate) fn serialize_value(value: &Value, mut builder: value::Builder) -> Spa // we have to define the encoding for that object in this match Span::unknown() } - } + }; + + let mut span = builder.reborrow().init_span(); + span.set_start(value_span.start as u64); + span.set_end(value_span.end as u64); } pub(crate) fn deserialize_value(reader: value::Reader) -> Result { @@ -95,10 +99,7 @@ mod tests { let mut builder = message.init_root::(); - let value_span = serialize_value(value, builder.reborrow()); - let mut span = builder.reborrow().init_span(); - span.set_start(value_span.start as u64); - span.set_end(value_span.end as u64); + serialize_value(value, builder.reborrow()); serialize_packed::write_message(writer, &message) .map_err(|e| PluginError::EncodingError(e.to_string()))