mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 07:16:05 +02:00
allow str from to convert more things to string (#2977)
* allow str from to convert more things to string * fixed FileSize so it reports with units configured * added tests
This commit is contained in:
@ -12,7 +12,7 @@ use derive_new::new;
|
||||
|
||||
use nu_errors::ParseError;
|
||||
use nu_source::{
|
||||
b, DebugDocBuilder, HasSpan, PrettyDebug, PrettyDebugRefineKind, PrettyDebugWithSource,
|
||||
DbgDocBldr, DebugDocBuilder, HasSpan, PrettyDebug, PrettyDebugRefineKind, PrettyDebugWithSource,
|
||||
};
|
||||
use nu_source::{IntoSpanned, Span, Spanned, SpannedItem, Tag};
|
||||
|
||||
@ -390,9 +390,9 @@ impl Member {
|
||||
impl PrettyDebugWithSource for Member {
|
||||
fn pretty_debug(&self, source: &str) -> DebugDocBuilder {
|
||||
match self {
|
||||
Member::String(outer, _) => b::value(outer.slice(source)),
|
||||
Member::Int(int, _) => b::value(format!("{}", int)),
|
||||
Member::Bare(span) => b::value(span.span.slice(source)),
|
||||
Member::String(outer, _) => DbgDocBldr::value(outer.slice(source)),
|
||||
Member::Int(int, _) => DbgDocBldr::value(format!("{}", int)),
|
||||
Member::Bare(span) => DbgDocBldr::value(span.span.slice(source)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -416,8 +416,8 @@ pub enum Number {
|
||||
impl PrettyDebug for Number {
|
||||
fn pretty(&self) -> DebugDocBuilder {
|
||||
match self {
|
||||
Number::Int(int) => b::primitive(int),
|
||||
Number::Decimal(decimal) => b::primitive(decimal),
|
||||
Number::Int(int) => DbgDocBldr::primitive(int),
|
||||
Number::Decimal(decimal) => DbgDocBldr::primitive(decimal),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -508,7 +508,7 @@ impl ToBigInt for Number {
|
||||
|
||||
impl PrettyDebug for Unit {
|
||||
fn pretty(&self) -> DebugDocBuilder {
|
||||
b::keyword(self.as_str())
|
||||
DbgDocBldr::keyword(self.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
@ -715,31 +715,35 @@ impl PrettyDebugWithSource for SpannedExpression {
|
||||
.into_spanned(self.span)
|
||||
.refined_pretty_debug(refine, source),
|
||||
Expression::ExternalWord => {
|
||||
b::delimit("e\"", b::primitive(self.span.slice(source)), "\"").group()
|
||||
DbgDocBldr::delimit("e\"", DbgDocBldr::primitive(self.span.slice(source)), "\"")
|
||||
.group()
|
||||
}
|
||||
Expression::Synthetic(s) => match s {
|
||||
Synthetic::String(_) => {
|
||||
b::delimit("s\"", b::primitive(self.span.slice(source)), "\"").group()
|
||||
}
|
||||
Synthetic::String(_) => DbgDocBldr::delimit(
|
||||
"s\"",
|
||||
DbgDocBldr::primitive(self.span.slice(source)),
|
||||
"\"",
|
||||
)
|
||||
.group(),
|
||||
},
|
||||
Expression::Variable(_, _) => b::keyword(self.span.slice(source)),
|
||||
Expression::Variable(_, _) => DbgDocBldr::keyword(self.span.slice(source)),
|
||||
Expression::Binary(binary) => binary.pretty_debug(source),
|
||||
Expression::Range(range) => range.pretty_debug(source),
|
||||
Expression::Block(_) => b::opaque("block"),
|
||||
Expression::Invocation(_) => b::opaque("invocation"),
|
||||
Expression::Garbage => b::opaque("garbage"),
|
||||
Expression::List(list) => b::delimit(
|
||||
Expression::Block(_) => DbgDocBldr::opaque("block"),
|
||||
Expression::Invocation(_) => DbgDocBldr::opaque("invocation"),
|
||||
Expression::Garbage => DbgDocBldr::opaque("garbage"),
|
||||
Expression::List(list) => DbgDocBldr::delimit(
|
||||
"[",
|
||||
b::intersperse(
|
||||
DbgDocBldr::intersperse(
|
||||
list.iter()
|
||||
.map(|item| item.refined_pretty_debug(refine, source)),
|
||||
b::space(),
|
||||
DbgDocBldr::space(),
|
||||
),
|
||||
"]",
|
||||
),
|
||||
Expression::Table(_headers, cells) => b::delimit(
|
||||
Expression::Table(_headers, cells) => DbgDocBldr::delimit(
|
||||
"[",
|
||||
b::intersperse(
|
||||
DbgDocBldr::intersperse(
|
||||
cells
|
||||
.iter()
|
||||
.map(|row| {
|
||||
@ -747,19 +751,21 @@ impl PrettyDebugWithSource for SpannedExpression {
|
||||
.map(|item| item.refined_pretty_debug(refine, source))
|
||||
})
|
||||
.flatten(),
|
||||
b::space(),
|
||||
DbgDocBldr::space(),
|
||||
),
|
||||
"]",
|
||||
),
|
||||
Expression::Path(path) => path.pretty_debug(source),
|
||||
Expression::FilePath(path) => b::typed("path", b::primitive(path.display())),
|
||||
Expression::ExternalCommand(external) => {
|
||||
b::keyword("^") + b::keyword(external.name.span.slice(source))
|
||||
Expression::FilePath(path) => {
|
||||
DbgDocBldr::typed("path", DbgDocBldr::primitive(path.display()))
|
||||
}
|
||||
Expression::Command => b::keyword(self.span.slice(source)),
|
||||
Expression::ExternalCommand(external) => {
|
||||
DbgDocBldr::keyword("^") + DbgDocBldr::keyword(external.name.span.slice(source))
|
||||
}
|
||||
Expression::Command => DbgDocBldr::keyword(self.span.slice(source)),
|
||||
Expression::Boolean(boolean) => match boolean {
|
||||
true => b::primitive("$yes"),
|
||||
false => b::primitive("$no"),
|
||||
true => DbgDocBldr::primitive("$yes"),
|
||||
false => DbgDocBldr::primitive("$no"),
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -770,47 +776,54 @@ impl PrettyDebugWithSource for SpannedExpression {
|
||||
Expression::Literal(literal) => {
|
||||
literal.clone().into_spanned(self.span).pretty_debug(source)
|
||||
}
|
||||
Expression::ExternalWord => {
|
||||
b::typed("external word", b::primitive(self.span.slice(source)))
|
||||
}
|
||||
Expression::ExternalWord => DbgDocBldr::typed(
|
||||
"external word",
|
||||
DbgDocBldr::primitive(self.span.slice(source)),
|
||||
),
|
||||
Expression::Synthetic(s) => match s {
|
||||
Synthetic::String(s) => b::typed("synthetic", b::primitive(format!("{:?}", s))),
|
||||
Synthetic::String(s) => {
|
||||
DbgDocBldr::typed("synthetic", DbgDocBldr::primitive(format!("{:?}", s)))
|
||||
}
|
||||
},
|
||||
Expression::Variable(_, _) => b::keyword(self.span.slice(source)),
|
||||
Expression::Variable(_, _) => DbgDocBldr::keyword(self.span.slice(source)),
|
||||
Expression::Binary(binary) => binary.pretty_debug(source),
|
||||
Expression::Range(range) => range.pretty_debug(source),
|
||||
Expression::Block(_) => b::opaque("block"),
|
||||
Expression::Invocation(_) => b::opaque("invocation"),
|
||||
Expression::Garbage => b::opaque("garbage"),
|
||||
Expression::List(list) => b::delimit(
|
||||
Expression::Block(_) => DbgDocBldr::opaque("block"),
|
||||
Expression::Invocation(_) => DbgDocBldr::opaque("invocation"),
|
||||
Expression::Garbage => DbgDocBldr::opaque("garbage"),
|
||||
Expression::List(list) => DbgDocBldr::delimit(
|
||||
"[",
|
||||
b::intersperse(
|
||||
DbgDocBldr::intersperse(
|
||||
list.iter().map(|item| item.pretty_debug(source)),
|
||||
b::space(),
|
||||
DbgDocBldr::space(),
|
||||
),
|
||||
"]",
|
||||
),
|
||||
Expression::Table(_headers, cells) => b::delimit(
|
||||
Expression::Table(_headers, cells) => DbgDocBldr::delimit(
|
||||
"[",
|
||||
b::intersperse(
|
||||
DbgDocBldr::intersperse(
|
||||
cells
|
||||
.iter()
|
||||
.map(|row| row.iter().map(|item| item.pretty_debug(source)))
|
||||
.flatten(),
|
||||
b::space(),
|
||||
DbgDocBldr::space(),
|
||||
),
|
||||
"]",
|
||||
),
|
||||
Expression::Path(path) => path.pretty_debug(source),
|
||||
Expression::FilePath(path) => b::typed("path", b::primitive(path.display())),
|
||||
Expression::ExternalCommand(external) => b::typed(
|
||||
Expression::FilePath(path) => {
|
||||
DbgDocBldr::typed("path", DbgDocBldr::primitive(path.display()))
|
||||
}
|
||||
Expression::ExternalCommand(external) => DbgDocBldr::typed(
|
||||
"command",
|
||||
b::keyword("^") + b::primitive(external.name.span.slice(source)),
|
||||
DbgDocBldr::keyword("^") + DbgDocBldr::primitive(external.name.span.slice(source)),
|
||||
),
|
||||
Expression::Command => b::typed("command", b::primitive(self.span.slice(source))),
|
||||
Expression::Command => {
|
||||
DbgDocBldr::typed("command", DbgDocBldr::primitive(self.span.slice(source)))
|
||||
}
|
||||
Expression::Boolean(boolean) => match boolean {
|
||||
true => b::primitive("$yes"),
|
||||
false => b::primitive("$no"),
|
||||
true => DbgDocBldr::primitive("$yes"),
|
||||
false => DbgDocBldr::primitive("$no"),
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -846,12 +859,12 @@ pub struct Binary {
|
||||
|
||||
impl PrettyDebugWithSource for Binary {
|
||||
fn pretty_debug(&self, source: &str) -> DebugDocBuilder {
|
||||
b::delimit(
|
||||
DbgDocBldr::delimit(
|
||||
"<",
|
||||
self.left.pretty_debug(source)
|
||||
+ b::space()
|
||||
+ b::keyword(self.op.span.slice(source))
|
||||
+ b::space()
|
||||
+ DbgDocBldr::space()
|
||||
+ DbgDocBldr::keyword(self.op.span.slice(source))
|
||||
+ DbgDocBldr::space()
|
||||
+ self.right.pretty_debug(source),
|
||||
">",
|
||||
)
|
||||
@ -881,15 +894,15 @@ pub struct Range {
|
||||
|
||||
impl PrettyDebugWithSource for Range {
|
||||
fn pretty_debug(&self, source: &str) -> DebugDocBuilder {
|
||||
b::delimit(
|
||||
DbgDocBldr::delimit(
|
||||
"<",
|
||||
(if let Some(left) = &self.left {
|
||||
left.pretty_debug(source)
|
||||
} else {
|
||||
DebugDocBuilder::blank()
|
||||
}) + b::space()
|
||||
+ b::keyword(self.operator.span().slice(source))
|
||||
+ b::space()
|
||||
}) + DbgDocBldr::space()
|
||||
+ DbgDocBldr::keyword(self.operator.span().slice(source))
|
||||
+ DbgDocBldr::space()
|
||||
+ (if let Some(right) = &self.right {
|
||||
right.pretty_debug(source)
|
||||
} else {
|
||||
@ -955,13 +968,15 @@ impl PrettyDebugWithSource for SpannedLiteral {
|
||||
PrettyDebugRefineKind::WithContext => match &self.literal {
|
||||
Literal::Number(number) => number.pretty(),
|
||||
Literal::Size(number, unit) => (number.pretty() + unit.pretty()).group(),
|
||||
Literal::String(string) => b::primitive(format!("{:?}", string)), //string.slice(source))),
|
||||
Literal::GlobPattern(pattern) => b::primitive(pattern),
|
||||
Literal::String(string) => DbgDocBldr::primitive(format!("{:?}", string)), //string.slice(source))),
|
||||
Literal::GlobPattern(pattern) => DbgDocBldr::primitive(pattern),
|
||||
Literal::ColumnPath(path) => {
|
||||
b::intersperse_with_source(path.iter(), b::space(), source)
|
||||
DbgDocBldr::intersperse_with_source(path.iter(), DbgDocBldr::space(), source)
|
||||
}
|
||||
Literal::Bare(bare) => b::delimit("b\"", b::primitive(bare), "\""),
|
||||
Literal::Operator(operator) => b::primitive(format!("{:?}", operator)),
|
||||
Literal::Bare(bare) => {
|
||||
DbgDocBldr::delimit("b\"", DbgDocBldr::primitive(bare), "\"")
|
||||
}
|
||||
Literal::Operator(operator) => DbgDocBldr::primitive(format!("{:?}", operator)),
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -970,20 +985,22 @@ impl PrettyDebugWithSource for SpannedLiteral {
|
||||
match &self.literal {
|
||||
Literal::Number(number) => number.pretty(),
|
||||
Literal::Size(number, unit) => {
|
||||
b::typed("size", (number.pretty() + unit.pretty()).group())
|
||||
DbgDocBldr::typed("size", (number.pretty() + unit.pretty()).group())
|
||||
}
|
||||
Literal::String(string) => b::typed(
|
||||
Literal::String(string) => DbgDocBldr::typed(
|
||||
"string",
|
||||
b::primitive(format!("{:?}", string)), //string.slice(source))),
|
||||
DbgDocBldr::primitive(format!("{:?}", string)), //string.slice(source))),
|
||||
),
|
||||
Literal::GlobPattern(pattern) => b::typed("pattern", b::primitive(pattern)),
|
||||
Literal::ColumnPath(path) => b::typed(
|
||||
Literal::GlobPattern(pattern) => {
|
||||
DbgDocBldr::typed("pattern", DbgDocBldr::primitive(pattern))
|
||||
}
|
||||
Literal::ColumnPath(path) => DbgDocBldr::typed(
|
||||
"column path",
|
||||
b::intersperse_with_source(path.iter(), b::space(), source),
|
||||
DbgDocBldr::intersperse_with_source(path.iter(), DbgDocBldr::space(), source),
|
||||
),
|
||||
Literal::Bare(bare) => b::typed("bare", b::primitive(bare)),
|
||||
Literal::Bare(bare) => DbgDocBldr::typed("bare", DbgDocBldr::primitive(bare)),
|
||||
Literal::Operator(operator) => {
|
||||
b::typed("operator", b::primitive(format!("{:?}", operator)))
|
||||
DbgDocBldr::typed("operator", DbgDocBldr::primitive(format!("{:?}", operator)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -998,8 +1015,11 @@ pub struct Path {
|
||||
impl PrettyDebugWithSource for Path {
|
||||
fn pretty_debug(&self, source: &str) -> DebugDocBuilder {
|
||||
self.head.pretty_debug(source)
|
||||
+ b::operator(".")
|
||||
+ b::intersperse(self.tail.iter().map(|m| m.pretty()), b::operator("."))
|
||||
+ DbgDocBldr::operator(".")
|
||||
+ DbgDocBldr::intersperse(
|
||||
self.tail.iter().map(|m| m.pretty()),
|
||||
DbgDocBldr::operator("."),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1225,9 +1245,13 @@ impl NamedValue {
|
||||
impl PrettyDebugWithSource for NamedValue {
|
||||
fn pretty_debug(&self, source: &str) -> DebugDocBuilder {
|
||||
match self {
|
||||
NamedValue::AbsentSwitch => b::typed("switch", b::description("absent")),
|
||||
NamedValue::PresentSwitch(_) => b::typed("switch", b::description("present")),
|
||||
NamedValue::AbsentValue => b::description("absent"),
|
||||
NamedValue::AbsentSwitch => {
|
||||
DbgDocBldr::typed("switch", DbgDocBldr::description("absent"))
|
||||
}
|
||||
NamedValue::PresentSwitch(_) => {
|
||||
DbgDocBldr::typed("switch", DbgDocBldr::description("present"))
|
||||
}
|
||||
NamedValue::AbsentValue => DbgDocBldr::description("absent"),
|
||||
NamedValue::Value(_, value) => value.pretty_debug(source),
|
||||
}
|
||||
}
|
||||
@ -1236,9 +1260,9 @@ impl PrettyDebugWithSource for NamedValue {
|
||||
match refine {
|
||||
PrettyDebugRefineKind::ContextFree => self.pretty_debug(source),
|
||||
PrettyDebugRefineKind::WithContext => match self {
|
||||
NamedValue::AbsentSwitch => b::value("absent"),
|
||||
NamedValue::PresentSwitch(_) => b::value("present"),
|
||||
NamedValue::AbsentValue => b::value("absent"),
|
||||
NamedValue::AbsentSwitch => DbgDocBldr::value("absent"),
|
||||
NamedValue::PresentSwitch(_) => DbgDocBldr::value("present"),
|
||||
NamedValue::AbsentValue => DbgDocBldr::value("absent"),
|
||||
NamedValue::Value(_, value) => value.refined_pretty_debug(refine, source),
|
||||
},
|
||||
}
|
||||
@ -1324,22 +1348,22 @@ impl PrettyDebugWithSource for Call {
|
||||
PrettyDebugRefineKind::WithContext => {
|
||||
self.head
|
||||
.refined_pretty_debug(PrettyDebugRefineKind::WithContext, source)
|
||||
+ b::preceded_option(
|
||||
Some(b::space()),
|
||||
+ DbgDocBldr::preceded_option(
|
||||
Some(DbgDocBldr::space()),
|
||||
self.positional.as_ref().map(|pos| {
|
||||
b::intersperse(
|
||||
DbgDocBldr::intersperse(
|
||||
pos.iter().map(|expr| {
|
||||
expr.refined_pretty_debug(
|
||||
PrettyDebugRefineKind::WithContext,
|
||||
source,
|
||||
)
|
||||
}),
|
||||
b::space(),
|
||||
DbgDocBldr::space(),
|
||||
)
|
||||
}),
|
||||
)
|
||||
+ b::preceded_option(
|
||||
Some(b::space()),
|
||||
+ DbgDocBldr::preceded_option(
|
||||
Some(DbgDocBldr::space()),
|
||||
self.named.as_ref().map(|named| {
|
||||
named.refined_pretty_debug(PrettyDebugRefineKind::WithContext, source)
|
||||
}),
|
||||
@ -1349,7 +1373,7 @@ impl PrettyDebugWithSource for Call {
|
||||
}
|
||||
|
||||
fn pretty_debug(&self, source: &str) -> DebugDocBuilder {
|
||||
b::typed(
|
||||
DbgDocBldr::typed(
|
||||
"call",
|
||||
self.refined_pretty_debug(PrettyDebugRefineKind::WithContext, source),
|
||||
)
|
||||
@ -1538,19 +1562,19 @@ impl PrettyDebugWithSource for NamedArguments {
|
||||
fn refined_pretty_debug(&self, refine: PrettyDebugRefineKind, source: &str) -> DebugDocBuilder {
|
||||
match refine {
|
||||
PrettyDebugRefineKind::ContextFree => self.pretty_debug(source),
|
||||
PrettyDebugRefineKind::WithContext => b::intersperse(
|
||||
PrettyDebugRefineKind::WithContext => DbgDocBldr::intersperse(
|
||||
self.named.iter().map(|(key, value)| {
|
||||
b::key(key)
|
||||
+ b::equals()
|
||||
DbgDocBldr::key(key)
|
||||
+ DbgDocBldr::equals()
|
||||
+ value.refined_pretty_debug(PrettyDebugRefineKind::WithContext, source)
|
||||
}),
|
||||
b::space(),
|
||||
DbgDocBldr::space(),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
fn pretty_debug(&self, source: &str) -> DebugDocBuilder {
|
||||
b::delimit(
|
||||
DbgDocBldr::delimit(
|
||||
"(",
|
||||
self.refined_pretty_debug(PrettyDebugRefineKind::WithContext, source),
|
||||
")",
|
||||
@ -1573,11 +1597,11 @@ pub struct Flag {
|
||||
impl PrettyDebugWithSource for Flag {
|
||||
fn pretty_debug(&self, source: &str) -> DebugDocBuilder {
|
||||
let prefix = match self.kind {
|
||||
FlagKind::Longhand => b::description("--"),
|
||||
FlagKind::Shorthand => b::description("-"),
|
||||
FlagKind::Longhand => DbgDocBldr::description("--"),
|
||||
FlagKind::Shorthand => DbgDocBldr::description("-"),
|
||||
};
|
||||
|
||||
prefix + b::description(self.name.slice(source))
|
||||
prefix + DbgDocBldr::description(self.name.slice(source))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::value::Value;
|
||||
use nu_errors::ShellError;
|
||||
use nu_source::{b, DebugDocBuilder, PrettyDebug};
|
||||
use nu_source::{DbgDocBldr, DebugDocBuilder, PrettyDebug};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// The inner set of actions for the command processor. Each denotes a way to change state in the processor without changing it directly from the command itself.
|
||||
@ -34,19 +34,23 @@ impl PrettyDebug for CommandAction {
|
||||
/// Get a command action ready to be pretty-printed
|
||||
fn pretty(&self) -> DebugDocBuilder {
|
||||
match self {
|
||||
CommandAction::ChangePath(path) => b::typed("change path", b::description(path)),
|
||||
CommandAction::Exit => b::description("exit"),
|
||||
CommandAction::Error(_) => b::error("error"),
|
||||
CommandAction::AutoConvert(_, extension) => {
|
||||
b::typed("auto convert", b::description(extension))
|
||||
CommandAction::ChangePath(path) => {
|
||||
DbgDocBldr::typed("change path", DbgDocBldr::description(path))
|
||||
}
|
||||
CommandAction::EnterShell(s) => b::typed("enter shell", b::description(s)),
|
||||
CommandAction::EnterValueShell(v) => b::typed("enter value shell", v.pretty()),
|
||||
CommandAction::EnterHelpShell(v) => b::typed("enter help shell", v.pretty()),
|
||||
CommandAction::AddPlugins(..) => b::description("add plugins"),
|
||||
CommandAction::PreviousShell => b::description("previous shell"),
|
||||
CommandAction::NextShell => b::description("next shell"),
|
||||
CommandAction::LeaveShell => b::description("leave shell"),
|
||||
CommandAction::Exit => DbgDocBldr::description("exit"),
|
||||
CommandAction::Error(_) => DbgDocBldr::error("error"),
|
||||
CommandAction::AutoConvert(_, extension) => {
|
||||
DbgDocBldr::typed("auto convert", DbgDocBldr::description(extension))
|
||||
}
|
||||
CommandAction::EnterShell(s) => {
|
||||
DbgDocBldr::typed("enter shell", DbgDocBldr::description(s))
|
||||
}
|
||||
CommandAction::EnterValueShell(v) => DbgDocBldr::typed("enter value shell", v.pretty()),
|
||||
CommandAction::EnterHelpShell(v) => DbgDocBldr::typed("enter help shell", v.pretty()),
|
||||
CommandAction::AddPlugins(..) => DbgDocBldr::description("add plugins"),
|
||||
CommandAction::PreviousShell => DbgDocBldr::description("previous shell"),
|
||||
CommandAction::NextShell => DbgDocBldr::description("next shell"),
|
||||
CommandAction::LeaveShell => DbgDocBldr::description("leave shell"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -66,9 +70,9 @@ impl PrettyDebug for ReturnSuccess {
|
||||
/// Get a return success ready to be pretty-printed
|
||||
fn pretty(&self) -> DebugDocBuilder {
|
||||
match self {
|
||||
ReturnSuccess::Value(value) => b::typed("value", value.pretty()),
|
||||
ReturnSuccess::DebugValue(value) => b::typed("debug value", value.pretty()),
|
||||
ReturnSuccess::Action(action) => b::typed("action", action.pretty()),
|
||||
ReturnSuccess::Value(value) => DbgDocBldr::typed("value", value.pretty()),
|
||||
ReturnSuccess::DebugValue(value) => DbgDocBldr::typed("debug value", value.pretty()),
|
||||
ReturnSuccess::Action(action) => DbgDocBldr::typed("action", action.pretty()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::syntax_shape::SyntaxShape;
|
||||
use crate::type_shape::Type;
|
||||
use indexmap::IndexMap;
|
||||
use nu_source::{b, DebugDocBuilder, PrettyDebug, PrettyDebugWithSource};
|
||||
use nu_source::{DbgDocBldr, DebugDocBuilder, PrettyDebug, PrettyDebugWithSource};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// The types of named parameter that a command can have
|
||||
@ -39,12 +39,17 @@ impl PrettyDebug for PositionalType {
|
||||
fn pretty(&self) -> DebugDocBuilder {
|
||||
match self {
|
||||
PositionalType::Mandatory(string, shape) => {
|
||||
b::description(string) + b::delimit("(", shape.pretty(), ")").into_kind().group()
|
||||
DbgDocBldr::description(string)
|
||||
+ DbgDocBldr::delimit("(", shape.pretty(), ")")
|
||||
.into_kind()
|
||||
.group()
|
||||
}
|
||||
PositionalType::Optional(string, shape) => {
|
||||
b::description(string)
|
||||
+ b::operator("?")
|
||||
+ b::delimit("(", shape.pretty(), ")").into_kind().group()
|
||||
DbgDocBldr::description(string)
|
||||
+ DbgDocBldr::operator("?")
|
||||
+ DbgDocBldr::delimit("(", shape.pretty(), ")")
|
||||
.into_kind()
|
||||
.group()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -165,16 +170,16 @@ impl Signature {
|
||||
impl PrettyDebugWithSource for Signature {
|
||||
/// Prepare a Signature for pretty-printing
|
||||
fn pretty_debug(&self, source: &str) -> DebugDocBuilder {
|
||||
b::typed(
|
||||
DbgDocBldr::typed(
|
||||
"signature",
|
||||
b::description(&self.name)
|
||||
+ b::preceded(
|
||||
b::space(),
|
||||
b::intersperse(
|
||||
DbgDocBldr::description(&self.name)
|
||||
+ DbgDocBldr::preceded(
|
||||
DbgDocBldr::space(),
|
||||
DbgDocBldr::intersperse(
|
||||
self.positional
|
||||
.iter()
|
||||
.map(|(ty, _)| ty.pretty_debug(source)),
|
||||
b::space(),
|
||||
DbgDocBldr::space(),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_source::{b, DebugDocBuilder, PrettyDebug};
|
||||
use nu_source::{DbgDocBldr, DebugDocBuilder, PrettyDebug};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// The syntactic shapes that values must match to be passed into a command. You can think of this as the type-checking that occurs when you call a function.
|
||||
@ -40,7 +40,7 @@ pub enum SyntaxShape {
|
||||
impl PrettyDebug for SyntaxShape {
|
||||
/// Prepare SyntaxShape for pretty-printing
|
||||
fn pretty(&self) -> DebugDocBuilder {
|
||||
b::kind(match self {
|
||||
DbgDocBldr::kind(match self {
|
||||
SyntaxShape::Any => "any",
|
||||
SyntaxShape::String => "string",
|
||||
SyntaxShape::FullColumnPath => "column path (with variable)",
|
||||
|
@ -10,7 +10,7 @@ use crate::value::range::RangeInclusion;
|
||||
use crate::value::{UntaggedValue, Value};
|
||||
use derive_new::new;
|
||||
use indexmap::map::IndexMap;
|
||||
use nu_source::{b, DebugDoc, DebugDocBuilder, PrettyDebug};
|
||||
use nu_source::{DbgDocBldr, DebugDoc, DebugDocBuilder, PrettyDebug};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::cmp::Ordering;
|
||||
use std::fmt::Debug;
|
||||
@ -197,22 +197,22 @@ impl PrettyDebug for Type {
|
||||
let (left, left_inclusion) = &range.from;
|
||||
let (right, right_inclusion) = &range.to;
|
||||
|
||||
let left_bracket = b::delimiter(match left_inclusion {
|
||||
let left_bracket = DbgDocBldr::delimiter(match left_inclusion {
|
||||
RangeInclusion::Exclusive => "(",
|
||||
RangeInclusion::Inclusive => "[",
|
||||
});
|
||||
|
||||
let right_bracket = b::delimiter(match right_inclusion {
|
||||
let right_bracket = DbgDocBldr::delimiter(match right_inclusion {
|
||||
RangeInclusion::Exclusive => ")",
|
||||
RangeInclusion::Inclusive => "]",
|
||||
});
|
||||
|
||||
b::typed(
|
||||
DbgDocBldr::typed(
|
||||
"range",
|
||||
(left_bracket
|
||||
+ left.pretty()
|
||||
+ b::operator(",")
|
||||
+ b::space()
|
||||
+ DbgDocBldr::operator(",")
|
||||
+ DbgDocBldr::space()
|
||||
+ right.pretty()
|
||||
+ right_bracket)
|
||||
.group(),
|
||||
@ -229,20 +229,20 @@ impl PrettyDebug for Type {
|
||||
Type::Duration => ty("duration"),
|
||||
Type::FilePath => ty("path"),
|
||||
Type::Binary => ty("binary"),
|
||||
Type::Error => b::error("error"),
|
||||
Type::BeginningOfStream => b::keyword("beginning-of-stream"),
|
||||
Type::EndOfStream => b::keyword("end-of-stream"),
|
||||
Type::Row(row) => (b::kind("row")
|
||||
+ b::space()
|
||||
+ b::intersperse(
|
||||
Type::Error => DbgDocBldr::error("error"),
|
||||
Type::BeginningOfStream => DbgDocBldr::keyword("beginning-of-stream"),
|
||||
Type::EndOfStream => DbgDocBldr::keyword("end-of-stream"),
|
||||
Type::Row(row) => (DbgDocBldr::kind("row")
|
||||
+ DbgDocBldr::space()
|
||||
+ DbgDocBldr::intersperse(
|
||||
row.map.iter().map(|(key, ty)| {
|
||||
(b::key(match key {
|
||||
(DbgDocBldr::key(match key {
|
||||
Column::String(string) => string.clone(),
|
||||
Column::Value => "".to_string(),
|
||||
}) + b::delimit("(", ty.pretty(), ")").into_kind())
|
||||
}) + DbgDocBldr::delimit("(", ty.pretty(), ")").into_kind())
|
||||
.nest()
|
||||
}),
|
||||
b::space(),
|
||||
DbgDocBldr::space(),
|
||||
)
|
||||
.nest())
|
||||
.nest(),
|
||||
@ -254,34 +254,35 @@ impl PrettyDebug for Type {
|
||||
group.add(item.to_doc(), i);
|
||||
}
|
||||
|
||||
(b::kind("table") + b::space() + b::keyword("of")).group()
|
||||
+ b::space()
|
||||
(DbgDocBldr::kind("table") + DbgDocBldr::space() + DbgDocBldr::keyword("of"))
|
||||
.group()
|
||||
+ DbgDocBldr::space()
|
||||
+ (if group.len() == 1 {
|
||||
let (doc, _) = group.into_iter().collect::<Vec<_>>()[0].clone();
|
||||
DebugDocBuilder::from_doc(doc)
|
||||
} else {
|
||||
b::intersperse(
|
||||
DbgDocBldr::intersperse(
|
||||
group.into_iter().map(|(doc, rows)| {
|
||||
(b::intersperse(
|
||||
(DbgDocBldr::intersperse(
|
||||
rows.iter().map(|(from, to)| {
|
||||
if from == to {
|
||||
b::description(from)
|
||||
DbgDocBldr::description(from)
|
||||
} else {
|
||||
(b::description(from)
|
||||
+ b::space()
|
||||
+ b::keyword("to")
|
||||
+ b::space()
|
||||
+ b::description(to))
|
||||
(DbgDocBldr::description(from)
|
||||
+ DbgDocBldr::space()
|
||||
+ DbgDocBldr::keyword("to")
|
||||
+ DbgDocBldr::space()
|
||||
+ DbgDocBldr::description(to))
|
||||
.group()
|
||||
}
|
||||
}),
|
||||
b::description(", "),
|
||||
) + b::description(":")
|
||||
+ b::space()
|
||||
DbgDocBldr::description(", "),
|
||||
) + DbgDocBldr::description(":")
|
||||
+ DbgDocBldr::space()
|
||||
+ DebugDocBuilder::from_doc(doc))
|
||||
.nest()
|
||||
}),
|
||||
b::space(),
|
||||
DbgDocBldr::space(),
|
||||
)
|
||||
})
|
||||
}
|
||||
@ -300,16 +301,16 @@ struct DebugEntry<'a> {
|
||||
impl<'a> PrettyDebug for DebugEntry<'a> {
|
||||
/// Prepare debug entries for pretty-printing
|
||||
fn pretty(&self) -> DebugDocBuilder {
|
||||
b::key(match self.key {
|
||||
DbgDocBldr::key(match self.key {
|
||||
Column::String(string) => string.clone(),
|
||||
Column::Value => "".to_string(),
|
||||
}) + b::delimit("(", self.value.pretty(), ")").into_kind()
|
||||
}) + DbgDocBldr::delimit("(", self.value.pretty(), ")").into_kind()
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper to create a pretty-print for the type
|
||||
fn ty(name: impl std::fmt::Display) -> DebugDocBuilder {
|
||||
b::kind(format!("{}", name))
|
||||
DbgDocBldr::kind(format!("{}", name))
|
||||
}
|
||||
|
||||
pub trait GroupedValue: Debug + Clone {
|
||||
|
@ -1,8 +1,8 @@
|
||||
use derive_new::new;
|
||||
use getset::Getters;
|
||||
use nu_source::{
|
||||
b, span_for_spanned_list, DebugDocBuilder, HasFallibleSpan, PrettyDebug, Span, Spanned,
|
||||
SpannedItem,
|
||||
span_for_spanned_list, DbgDocBldr, DebugDocBuilder, HasFallibleSpan, PrettyDebug, Span,
|
||||
Spanned, SpannedItem,
|
||||
};
|
||||
use num_bigint::BigInt;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -38,8 +38,8 @@ impl PrettyDebug for &PathMember {
|
||||
/// Gets the PathMember ready to be pretty-printed
|
||||
fn pretty(&self) -> DebugDocBuilder {
|
||||
match &self.unspanned {
|
||||
UnspannedPathMember::String(string) => b::primitive(format!("{:?}", string)),
|
||||
UnspannedPathMember::Int(int) => b::primitive(format!("{}", int)),
|
||||
UnspannedPathMember::String(string) => DbgDocBldr::primitive(format!("{:?}", string)),
|
||||
UnspannedPathMember::Int(int) => DbgDocBldr::primitive(format!("{}", int)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -96,9 +96,11 @@ impl PrettyDebug for ColumnPath {
|
||||
let members: Vec<DebugDocBuilder> =
|
||||
self.members.iter().map(|member| member.pretty()).collect();
|
||||
|
||||
b::delimit(
|
||||
DbgDocBldr::delimit(
|
||||
"(",
|
||||
b::description("path") + b::equals() + b::intersperse(members, b::space()),
|
||||
DbgDocBldr::description("path")
|
||||
+ DbgDocBldr::equals()
|
||||
+ DbgDocBldr::intersperse(members, DbgDocBldr::space()),
|
||||
")",
|
||||
)
|
||||
.nest()
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::type_name::PrettyType;
|
||||
use crate::value::primitive::Primitive;
|
||||
use crate::value::{UntaggedValue, Value};
|
||||
use nu_source::{b, DebugDocBuilder, PrettyDebug};
|
||||
use nu_source::{DbgDocBldr, DebugDocBuilder, PrettyDebug};
|
||||
|
||||
impl PrettyDebug for &Value {
|
||||
/// Get a borrowed Value ready to be pretty-printed
|
||||
@ -16,11 +16,14 @@ impl PrettyDebug for Value {
|
||||
match &self.value {
|
||||
UntaggedValue::Primitive(p) => p.pretty(),
|
||||
UntaggedValue::Row(row) => row.pretty_builder().nest(1).group().into(),
|
||||
UntaggedValue::Table(table) => {
|
||||
b::delimit("[", b::intersperse(table, b::space()), "]").nest()
|
||||
}
|
||||
UntaggedValue::Error(_) => b::error("error"),
|
||||
UntaggedValue::Block(_) => b::opaque("block"),
|
||||
UntaggedValue::Table(table) => DbgDocBldr::delimit(
|
||||
"[",
|
||||
DbgDocBldr::intersperse(table, DbgDocBldr::space()),
|
||||
"]",
|
||||
)
|
||||
.nest(),
|
||||
UntaggedValue::Error(_) => DbgDocBldr::error("error"),
|
||||
UntaggedValue::Block(_) => DbgDocBldr::opaque("block"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -42,8 +45,8 @@ impl PrettyType for Primitive {
|
||||
Primitive::Duration(_) => ty("duration"),
|
||||
Primitive::FilePath(_) => ty("path"),
|
||||
Primitive::Binary(_) => ty("binary"),
|
||||
Primitive::BeginningOfStream => b::keyword("beginning-of-stream"),
|
||||
Primitive::EndOfStream => b::keyword("end-of-stream"),
|
||||
Primitive::BeginningOfStream => DbgDocBldr::keyword("beginning-of-stream"),
|
||||
Primitive::EndOfStream => DbgDocBldr::keyword("end-of-stream"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -52,19 +55,19 @@ impl PrettyDebug for Primitive {
|
||||
/// Get a Primitive value ready to be pretty-printed
|
||||
fn pretty(&self) -> DebugDocBuilder {
|
||||
match self {
|
||||
Primitive::Nothing => b::primitive("nothing"),
|
||||
Primitive::Nothing => DbgDocBldr::primitive("nothing"),
|
||||
Primitive::Int(int) => prim(format_args!("{}", int)),
|
||||
Primitive::Decimal(decimal) => prim(format_args!("{}", decimal)),
|
||||
Primitive::Range(range) => {
|
||||
let (left, left_inclusion) = &range.from;
|
||||
let (right, right_inclusion) = &range.to;
|
||||
|
||||
b::typed(
|
||||
DbgDocBldr::typed(
|
||||
"range",
|
||||
(left_inclusion.debug_left_bracket()
|
||||
+ left.pretty()
|
||||
+ b::operator(",")
|
||||
+ b::space()
|
||||
+ DbgDocBldr::operator(",")
|
||||
+ DbgDocBldr::space()
|
||||
+ right.pretty()
|
||||
+ right_inclusion.debug_right_bracket())
|
||||
.group(),
|
||||
@ -75,27 +78,28 @@ impl PrettyDebug for Primitive {
|
||||
Primitive::ColumnPath(path) => path.pretty(),
|
||||
Primitive::GlobPattern(pattern) => primitive_doc(pattern, "pattern"),
|
||||
Primitive::Boolean(boolean) => match boolean {
|
||||
true => b::primitive("$yes"),
|
||||
false => b::primitive("$no"),
|
||||
true => DbgDocBldr::primitive("$yes"),
|
||||
false => DbgDocBldr::primitive("$no"),
|
||||
},
|
||||
Primitive::Date(date) => primitive_doc(date, "date"),
|
||||
Primitive::Duration(duration) => primitive_doc(duration, "nanoseconds"),
|
||||
Primitive::FilePath(path) => primitive_doc(path, "path"),
|
||||
Primitive::Binary(_) => b::opaque("binary"),
|
||||
Primitive::BeginningOfStream => b::keyword("beginning-of-stream"),
|
||||
Primitive::EndOfStream => b::keyword("end-of-stream"),
|
||||
Primitive::Binary(_) => DbgDocBldr::opaque("binary"),
|
||||
Primitive::BeginningOfStream => DbgDocBldr::keyword("beginning-of-stream"),
|
||||
Primitive::EndOfStream => DbgDocBldr::keyword("end-of-stream"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn prim(name: impl std::fmt::Debug) -> DebugDocBuilder {
|
||||
b::primitive(format!("{:?}", name))
|
||||
DbgDocBldr::primitive(format!("{:?}", name))
|
||||
}
|
||||
|
||||
fn primitive_doc(name: impl std::fmt::Debug, ty: impl Into<String>) -> DebugDocBuilder {
|
||||
b::primitive(format!("{:?}", name)) + b::delimit("(", b::kind(ty.into()), ")")
|
||||
DbgDocBldr::primitive(format!("{:?}", name))
|
||||
+ DbgDocBldr::delimit("(", DbgDocBldr::kind(ty.into()), ")")
|
||||
}
|
||||
|
||||
fn ty(name: impl std::fmt::Debug) -> DebugDocBuilder {
|
||||
b::kind(format!("{:?}", name))
|
||||
DbgDocBldr::kind(format!("{:?}", name))
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use crate::value::{UntaggedValue, Value};
|
||||
use derive_new::new;
|
||||
use getset::Getters;
|
||||
use indexmap::IndexMap;
|
||||
use nu_source::{b, DebugDocBuilder, PrettyDebug, Spanned, SpannedItem, Tag};
|
||||
use nu_source::{DbgDocBldr, DebugDocBuilder, PrettyDebug, Spanned, SpannedItem, Tag};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::cmp::{Ord, Ordering, PartialOrd};
|
||||
use std::hash::{Hash, Hasher};
|
||||
@ -78,20 +78,23 @@ struct DebugEntry<'a> {
|
||||
impl<'a> PrettyDebug for DebugEntry<'a> {
|
||||
/// Build the the information to pretty-print the DebugEntry
|
||||
fn pretty(&self) -> DebugDocBuilder {
|
||||
(b::key(self.key.to_string()) + b::equals() + self.value.pretty().into_value()).group()
|
||||
(DbgDocBldr::key(self.key.to_string())
|
||||
+ DbgDocBldr::equals()
|
||||
+ self.value.pretty().into_value())
|
||||
.group()
|
||||
}
|
||||
}
|
||||
|
||||
impl PrettyDebug for Dictionary {
|
||||
/// Get a Dictionary ready to be pretty-printed
|
||||
fn pretty(&self) -> DebugDocBuilder {
|
||||
b::delimit(
|
||||
DbgDocBldr::delimit(
|
||||
"(",
|
||||
b::intersperse(
|
||||
DbgDocBldr::intersperse(
|
||||
self.entries()
|
||||
.iter()
|
||||
.map(|(key, value)| DebugEntry::new(key, value)),
|
||||
b::space(),
|
||||
DbgDocBldr::space(),
|
||||
),
|
||||
")",
|
||||
)
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::value::Primitive;
|
||||
use derive_new::new;
|
||||
use nu_source::{b, DebugDocBuilder, Spanned};
|
||||
use nu_source::{DbgDocBldr, DebugDocBuilder, Spanned};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// The two types of ways to include a range end. Inclusive means to include the value (eg 1..3 inclusive would include the 3 value).
|
||||
@ -14,7 +14,7 @@ pub enum RangeInclusion {
|
||||
impl RangeInclusion {
|
||||
/// Get a RangeInclusion left bracket ready for pretty printing
|
||||
pub fn debug_left_bracket(self) -> DebugDocBuilder {
|
||||
b::delimiter(match self {
|
||||
DbgDocBldr::delimiter(match self {
|
||||
RangeInclusion::Exclusive => "(",
|
||||
RangeInclusion::Inclusive => "[",
|
||||
})
|
||||
@ -22,7 +22,7 @@ impl RangeInclusion {
|
||||
|
||||
/// Get a RangeInclusion right bracket ready for pretty printing
|
||||
pub fn debug_right_bracket(self) -> DebugDocBuilder {
|
||||
b::delimiter(match self {
|
||||
DbgDocBldr::delimiter(match self {
|
||||
RangeInclusion::Exclusive => ")",
|
||||
RangeInclusion::Inclusive => "]",
|
||||
})
|
||||
|
Reference in New Issue
Block a user