adding span to value encoding

This commit is contained in:
Fernando Herrera 2021-11-01 08:16:56 +00:00
parent c56a233808
commit 1f4c34fa04
2 changed files with 10 additions and 9 deletions

View File

@ -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),
}
}
}

View File

@ -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<Value, PluginError> {
@ -95,10 +99,7 @@ mod tests {
let mut builder = message.init_root::<value::Builder>();
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()))