Improve external output in subexprs (#294)

This commit is contained in:
JT
2021-11-06 18:50:33 +13:00
committed by GitHub
parent c7d159a0f3
commit 02b8027749
50 changed files with 320 additions and 136 deletions

View File

@ -37,16 +37,16 @@ pub enum PipelineData {
}
impl PipelineData {
pub fn new() -> PipelineData {
PipelineData::Value(Value::nothing())
pub fn new(span: Span) -> PipelineData {
PipelineData::Value(Value::Nothing { span })
}
pub fn into_value(self) -> Value {
pub fn into_value(self, span: Span) -> Value {
match self {
PipelineData::Value(v) => v,
PipelineData::Stream(s) => Value::List {
vals: s.collect(),
span: Span::unknown(), // FIXME?
span, // FIXME?
},
}
}
@ -140,11 +140,11 @@ impl PipelineData {
}
}
impl Default for PipelineData {
fn default() -> Self {
PipelineData::new()
}
}
// impl Default for PipelineData {
// fn default() -> Self {
// PipelineData::new()
// }
// }
pub struct PipelineIterator(PipelineData);

View File

@ -82,7 +82,7 @@ pub enum ShellError {
#[error("Can't convert to {0}.")]
#[diagnostic(code(nu::shell::cant_convert), url(docsrs))]
CantConvert(String, #[label("can't convert to {0}")] Span),
CantConvert(String, String, #[label("can't convert {1} to {0}")] Span),
#[error("Division by zero.")]
#[diagnostic(code(nu::shell::division_by_zero), url(docsrs))]

View File

@ -87,7 +87,14 @@ impl Value {
pub fn as_string(&self) -> Result<String, ShellError> {
match self {
Value::String { val, .. } => Ok(val.to_string()),
_ => Err(ShellError::CantConvert("string".into(), self.span()?)),
x => {
println!("{:?}", x);
Err(ShellError::CantConvert(
"string".into(),
x.get_type().to_string(),
self.span()?,
))
}
}
}
@ -225,10 +232,8 @@ impl Value {
}
/// Create a new `Nothing` value
pub fn nothing() -> Value {
Value::Nothing {
span: Span::unknown(),
}
pub fn nothing(span: Span) -> Value {
Value::Nothing { span }
}
/// Follow a given column path into the value: for example accessing nth elements in a stream or list
@ -425,7 +430,9 @@ impl Value {
impl Default for Value {
fn default() -> Self {
Value::nothing()
Value::Nothing {
span: Span::unknown(),
}
}
}