mirror of
https://github.com/nushell/nushell.git
synced 2024-12-25 00:19:39 +01:00
Merge remote-tracking branch 'upstream/master' into post-headers
This commit is contained in:
commit
ff92123d93
@ -58,7 +58,7 @@ pub fn autoview(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} else if is_single_origined_text_value(&input) {
|
} else if is_single_anchored_text_value(&input) {
|
||||||
let text = context.get_command("textview");
|
let text = context.get_command("textview");
|
||||||
if let Some(text) = text {
|
if let Some(text) = text {
|
||||||
let result = text.run(raw.with_input(input), &context.commands, false);
|
let result = text.run(raw.with_input(input), &context.commands, false);
|
||||||
@ -111,17 +111,17 @@ fn is_single_text_value(input: &Vec<Tagged<Value>>) -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_single_origined_text_value(input: &Vec<Tagged<Value>>) -> bool {
|
fn is_single_anchored_text_value(input: &Vec<Tagged<Value>>) -> bool {
|
||||||
if input.len() != 1 {
|
if input.len() != 1 {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Tagged {
|
if let Tagged {
|
||||||
item: Value::Primitive(Primitive::String(_)),
|
item: Value::Primitive(Primitive::String(_)),
|
||||||
tag: Tag { origin, .. },
|
tag: Tag { anchor, .. },
|
||||||
} = input[0]
|
} = input[0]
|
||||||
{
|
{
|
||||||
origin != uuid::Uuid::nil()
|
anchor != uuid::Uuid::nil()
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
@ -127,8 +127,8 @@ impl InternalCommand {
|
|||||||
CommandAction::ChangePath(path) => {
|
CommandAction::ChangePath(path) => {
|
||||||
context.shell_manager.set_path(path);
|
context.shell_manager.set_path(path);
|
||||||
}
|
}
|
||||||
CommandAction::AddSpanSource(uuid, span_source) => {
|
CommandAction::AddAnchorLocation(uuid, anchor_location) => {
|
||||||
context.add_span_source(uuid, span_source);
|
context.add_anchor_location(uuid, anchor_location);
|
||||||
}
|
}
|
||||||
CommandAction::Exit => std::process::exit(0), // TODO: save history.txt
|
CommandAction::Exit => std::process::exit(0), // TODO: save history.txt
|
||||||
CommandAction::EnterHelpShell(value) => {
|
CommandAction::EnterHelpShell(value) => {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::context::{SourceMap, SpanSource};
|
use crate::context::{AnchorLocation, SourceMap};
|
||||||
use crate::data::Value;
|
use crate::data::Value;
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::evaluate::Scope;
|
use crate::evaluate::Scope;
|
||||||
@ -376,7 +376,7 @@ impl EvaluatedCommandArgs {
|
|||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub enum CommandAction {
|
pub enum CommandAction {
|
||||||
ChangePath(String),
|
ChangePath(String),
|
||||||
AddSpanSource(Uuid, SpanSource),
|
AddAnchorLocation(Uuid, AnchorLocation),
|
||||||
Exit,
|
Exit,
|
||||||
EnterShell(String),
|
EnterShell(String),
|
||||||
EnterValueShell(Tagged<Value>),
|
EnterValueShell(Tagged<Value>),
|
||||||
@ -390,7 +390,7 @@ impl ToDebug for CommandAction {
|
|||||||
fn fmt_debug(&self, f: &mut fmt::Formatter, _source: &str) -> fmt::Result {
|
fn fmt_debug(&self, f: &mut fmt::Formatter, _source: &str) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
CommandAction::ChangePath(s) => write!(f, "action:change-path={}", s),
|
CommandAction::ChangePath(s) => write!(f, "action:change-path={}", s),
|
||||||
CommandAction::AddSpanSource(u, source) => {
|
CommandAction::AddAnchorLocation(u, source) => {
|
||||||
write!(f, "action:add-span-source={}@{:?}", u, source)
|
write!(f, "action:add-span-source={}@{:?}", u, source)
|
||||||
}
|
}
|
||||||
CommandAction::Exit => write!(f, "action:exit"),
|
CommandAction::Exit => write!(f, "action:exit"),
|
||||||
|
@ -67,7 +67,7 @@ impl PerItemCommand for Enter {
|
|||||||
|
|
||||||
let full_path = std::path::PathBuf::from(cwd);
|
let full_path = std::path::PathBuf::from(cwd);
|
||||||
|
|
||||||
let (file_extension, contents, contents_tag, span_source) =
|
let (file_extension, contents, contents_tag, anchor_location) =
|
||||||
crate::commands::open::fetch(
|
crate::commands::open::fetch(
|
||||||
&full_path,
|
&full_path,
|
||||||
&location_clone,
|
&location_clone,
|
||||||
@ -75,11 +75,11 @@ impl PerItemCommand for Enter {
|
|||||||
)
|
)
|
||||||
.await.unwrap();
|
.await.unwrap();
|
||||||
|
|
||||||
if contents_tag.origin != uuid::Uuid::nil() {
|
if contents_tag.anchor != uuid::Uuid::nil() {
|
||||||
// If we have loaded something, track its source
|
// If we have loaded something, track its source
|
||||||
yield ReturnSuccess::action(CommandAction::AddSpanSource(
|
yield ReturnSuccess::action(CommandAction::AddAnchorLocation(
|
||||||
contents_tag.origin,
|
contents_tag.anchor,
|
||||||
span_source,
|
anchor_location,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::commands::UnevaluatedCallInfo;
|
use crate::commands::UnevaluatedCallInfo;
|
||||||
use crate::context::SpanSource;
|
use crate::context::AnchorLocation;
|
||||||
use crate::data::meta::Span;
|
use crate::data::meta::Span;
|
||||||
use crate::data::Value;
|
use crate::data::Value;
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
@ -66,7 +66,7 @@ fn run(
|
|||||||
yield Err(e);
|
yield Err(e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let (file_extension, contents, contents_tag, span_source) = result.unwrap();
|
let (file_extension, contents, contents_tag, anchor_location) = result.unwrap();
|
||||||
|
|
||||||
let file_extension = if has_raw {
|
let file_extension = if has_raw {
|
||||||
None
|
None
|
||||||
@ -76,11 +76,11 @@ fn run(
|
|||||||
file_extension.or(path_str.split('.').last().map(String::from))
|
file_extension.or(path_str.split('.').last().map(String::from))
|
||||||
};
|
};
|
||||||
|
|
||||||
if contents_tag.origin != uuid::Uuid::nil() {
|
if contents_tag.anchor != uuid::Uuid::nil() {
|
||||||
// If we have loaded something, track its source
|
// If we have loaded something, track its source
|
||||||
yield ReturnSuccess::action(CommandAction::AddSpanSource(
|
yield ReturnSuccess::action(CommandAction::AddAnchorLocation(
|
||||||
contents_tag.origin,
|
contents_tag.anchor,
|
||||||
span_source,
|
anchor_location,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ fn run(
|
|||||||
pub async fn fetch(
|
pub async fn fetch(
|
||||||
location: &str,
|
location: &str,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> Result<(Option<String>, Value, Tag, SpanSource), ShellError> {
|
) -> Result<(Option<String>, Value, Tag, AnchorLocation), ShellError> {
|
||||||
if let Err(_) = url::Url::parse(location) {
|
if let Err(_) = url::Url::parse(location) {
|
||||||
return Err(ShellError::labeled_error(
|
return Err(ShellError::labeled_error(
|
||||||
"Incomplete or incorrect url",
|
"Incomplete or incorrect url",
|
||||||
@ -158,9 +158,9 @@ pub async fn fetch(
|
|||||||
})?),
|
})?),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::Url(location.to_string()),
|
AnchorLocation::Url(location.to_string()),
|
||||||
)),
|
)),
|
||||||
(mime::APPLICATION, mime::JSON) => Ok((
|
(mime::APPLICATION, mime::JSON) => Ok((
|
||||||
Some("json".to_string()),
|
Some("json".to_string()),
|
||||||
@ -173,9 +173,9 @@ pub async fn fetch(
|
|||||||
})?),
|
})?),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::Url(location.to_string()),
|
AnchorLocation::Url(location.to_string()),
|
||||||
)),
|
)),
|
||||||
(mime::APPLICATION, mime::OCTET_STREAM) => {
|
(mime::APPLICATION, mime::OCTET_STREAM) => {
|
||||||
let buf: Vec<u8> = r.body_bytes().await.map_err(|_| {
|
let buf: Vec<u8> = r.body_bytes().await.map_err(|_| {
|
||||||
@ -190,9 +190,9 @@ pub async fn fetch(
|
|||||||
Value::binary(buf),
|
Value::binary(buf),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::Url(location.to_string()),
|
AnchorLocation::Url(location.to_string()),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
(mime::IMAGE, mime::SVG) => Ok((
|
(mime::IMAGE, mime::SVG) => Ok((
|
||||||
@ -206,9 +206,9 @@ pub async fn fetch(
|
|||||||
})?),
|
})?),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::Url(location.to_string()),
|
AnchorLocation::Url(location.to_string()),
|
||||||
)),
|
)),
|
||||||
(mime::IMAGE, image_ty) => {
|
(mime::IMAGE, image_ty) => {
|
||||||
let buf: Vec<u8> = r.body_bytes().await.map_err(|_| {
|
let buf: Vec<u8> = r.body_bytes().await.map_err(|_| {
|
||||||
@ -223,9 +223,9 @@ pub async fn fetch(
|
|||||||
Value::binary(buf),
|
Value::binary(buf),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::Url(location.to_string()),
|
AnchorLocation::Url(location.to_string()),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
(mime::TEXT, mime::HTML) => Ok((
|
(mime::TEXT, mime::HTML) => Ok((
|
||||||
@ -239,9 +239,9 @@ pub async fn fetch(
|
|||||||
})?),
|
})?),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::Url(location.to_string()),
|
AnchorLocation::Url(location.to_string()),
|
||||||
)),
|
)),
|
||||||
(mime::TEXT, mime::PLAIN) => {
|
(mime::TEXT, mime::PLAIN) => {
|
||||||
let path_extension = url::Url::parse(location)
|
let path_extension = url::Url::parse(location)
|
||||||
@ -266,9 +266,9 @@ pub async fn fetch(
|
|||||||
})?),
|
})?),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::Url(location.to_string()),
|
AnchorLocation::Url(location.to_string()),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
(ty, sub_ty) => Ok((
|
(ty, sub_ty) => Ok((
|
||||||
@ -276,9 +276,9 @@ pub async fn fetch(
|
|||||||
Value::string(format!("Not yet supported MIME type: {} {}", ty, sub_ty)),
|
Value::string(format!("Not yet supported MIME type: {} {}", ty, sub_ty)),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::Url(location.to_string()),
|
AnchorLocation::Url(location.to_string()),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -287,9 +287,9 @@ pub async fn fetch(
|
|||||||
Value::string(format!("No content type found")),
|
Value::string(format!("No content type found")),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::Url(location.to_string()),
|
AnchorLocation::Url(location.to_string()),
|
||||||
)),
|
)),
|
||||||
},
|
},
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::commands::UnevaluatedCallInfo;
|
use crate::commands::UnevaluatedCallInfo;
|
||||||
use crate::context::SpanSource;
|
use crate::context::AnchorLocation;
|
||||||
use crate::data::meta::Span;
|
use crate::data::meta::Span;
|
||||||
use crate::data::Value;
|
use crate::data::Value;
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
@ -67,7 +67,7 @@ fn run(
|
|||||||
yield Err(e);
|
yield Err(e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let (file_extension, contents, contents_tag, span_source) = result.unwrap();
|
let (file_extension, contents, contents_tag, anchor_location) = result.unwrap();
|
||||||
|
|
||||||
let file_extension = if has_raw {
|
let file_extension = if has_raw {
|
||||||
None
|
None
|
||||||
@ -77,11 +77,11 @@ fn run(
|
|||||||
file_extension.or(path_str.split('.').last().map(String::from))
|
file_extension.or(path_str.split('.').last().map(String::from))
|
||||||
};
|
};
|
||||||
|
|
||||||
if contents_tag.origin != uuid::Uuid::nil() {
|
if contents_tag.anchor != uuid::Uuid::nil() {
|
||||||
// If we have loaded something, track its source
|
// If we have loaded something, track its source
|
||||||
yield ReturnSuccess::action(CommandAction::AddSpanSource(
|
yield ReturnSuccess::action(CommandAction::AddAnchorLocation(
|
||||||
contents_tag.origin,
|
contents_tag.anchor,
|
||||||
span_source,
|
anchor_location,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ pub async fn fetch(
|
|||||||
cwd: &PathBuf,
|
cwd: &PathBuf,
|
||||||
location: &str,
|
location: &str,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> Result<(Option<String>, Value, Tag, SpanSource), ShellError> {
|
) -> Result<(Option<String>, Value, Tag, AnchorLocation), ShellError> {
|
||||||
let mut cwd = cwd.clone();
|
let mut cwd = cwd.clone();
|
||||||
|
|
||||||
cwd.push(Path::new(location));
|
cwd.push(Path::new(location));
|
||||||
@ -147,9 +147,9 @@ pub async fn fetch(
|
|||||||
Value::string(s),
|
Value::string(s),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::File(cwd.to_string_lossy().to_string()),
|
AnchorLocation::File(cwd.to_string_lossy().to_string()),
|
||||||
)),
|
)),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
//Non utf8 data.
|
//Non utf8 data.
|
||||||
@ -166,18 +166,18 @@ pub async fn fetch(
|
|||||||
Value::string(s),
|
Value::string(s),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::File(cwd.to_string_lossy().to_string()),
|
AnchorLocation::File(cwd.to_string_lossy().to_string()),
|
||||||
)),
|
)),
|
||||||
Err(_) => Ok((
|
Err(_) => Ok((
|
||||||
None,
|
None,
|
||||||
Value::binary(bytes),
|
Value::binary(bytes),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::File(cwd.to_string_lossy().to_string()),
|
AnchorLocation::File(cwd.to_string_lossy().to_string()),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -186,9 +186,9 @@ pub async fn fetch(
|
|||||||
Value::binary(bytes),
|
Value::binary(bytes),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::File(cwd.to_string_lossy().to_string()),
|
AnchorLocation::File(cwd.to_string_lossy().to_string()),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -204,18 +204,18 @@ pub async fn fetch(
|
|||||||
Value::string(s),
|
Value::string(s),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::File(cwd.to_string_lossy().to_string()),
|
AnchorLocation::File(cwd.to_string_lossy().to_string()),
|
||||||
)),
|
)),
|
||||||
Err(_) => Ok((
|
Err(_) => Ok((
|
||||||
None,
|
None,
|
||||||
Value::binary(bytes),
|
Value::binary(bytes),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::File(cwd.to_string_lossy().to_string()),
|
AnchorLocation::File(cwd.to_string_lossy().to_string()),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -224,9 +224,9 @@ pub async fn fetch(
|
|||||||
Value::binary(bytes),
|
Value::binary(bytes),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::File(cwd.to_string_lossy().to_string()),
|
AnchorLocation::File(cwd.to_string_lossy().to_string()),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -235,9 +235,9 @@ pub async fn fetch(
|
|||||||
Value::binary(bytes),
|
Value::binary(bytes),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Uuid::new_v4(),
|
anchor: Uuid::new_v4(),
|
||||||
},
|
},
|
||||||
SpanSource::File(cwd.to_string_lossy().to_string()),
|
AnchorLocation::File(cwd.to_string_lossy().to_string()),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::commands::UnevaluatedCallInfo;
|
use crate::commands::UnevaluatedCallInfo;
|
||||||
use crate::context::SpanSource;
|
use crate::context::AnchorLocation;
|
||||||
use crate::data::Value;
|
use crate::data::Value;
|
||||||
use crate::errors::ShellError;
|
use crate::errors::ShellError;
|
||||||
use crate::parser::hir::SyntaxShape;
|
use crate::parser::hir::SyntaxShape;
|
||||||
@ -83,7 +83,7 @@ fn run(
|
|||||||
let headers = get_headers(&call_info)?;
|
let headers = get_headers(&call_info)?;
|
||||||
|
|
||||||
let stream = async_stream! {
|
let stream = async_stream! {
|
||||||
let (file_extension, contents, contents_tag, span_source) =
|
let (file_extension, contents, contents_tag, anchor_location) =
|
||||||
post(&path_str, &body, user, password, &headers, path_span, ®istry, &raw_args).await.unwrap();
|
post(&path_str, &body, user, password, &headers, path_span, ®istry, &raw_args).await.unwrap();
|
||||||
|
|
||||||
let file_extension = if has_raw {
|
let file_extension = if has_raw {
|
||||||
@ -94,11 +94,11 @@ fn run(
|
|||||||
file_extension.or(path_str.split('.').last().map(String::from))
|
file_extension.or(path_str.split('.').last().map(String::from))
|
||||||
};
|
};
|
||||||
|
|
||||||
if contents_tag.origin != uuid::Uuid::nil() {
|
if contents_tag.anchor != uuid::Uuid::nil() {
|
||||||
// If we have loaded something, track its source
|
// If we have loaded something, track its source
|
||||||
yield ReturnSuccess::action(CommandAction::AddSpanSource(
|
yield ReturnSuccess::action(CommandAction::AddAnchorLocation(
|
||||||
contents_tag.origin,
|
contents_tag.anchor,
|
||||||
span_source,
|
anchor_location,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,7 +202,7 @@ pub async fn post(
|
|||||||
tag: Tag,
|
tag: Tag,
|
||||||
registry: &CommandRegistry,
|
registry: &CommandRegistry,
|
||||||
raw_args: &RawCommandArgs,
|
raw_args: &RawCommandArgs,
|
||||||
) -> Result<(Option<String>, Value, Tag, SpanSource), ShellError> {
|
) -> Result<(Option<String>, Value, Tag, AnchorLocation), ShellError> {
|
||||||
let registry = registry.clone();
|
let registry = registry.clone();
|
||||||
let raw_args = raw_args.clone();
|
let raw_args = raw_args.clone();
|
||||||
if location.starts_with("http:") || location.starts_with("https:") {
|
if location.starts_with("http:") || location.starts_with("https:") {
|
||||||
@ -311,7 +311,7 @@ pub async fn post(
|
|||||||
)
|
)
|
||||||
})?),
|
})?),
|
||||||
tag,
|
tag,
|
||||||
SpanSource::Url(location.to_string()),
|
AnchorLocation::Url(location.to_string()),
|
||||||
)),
|
)),
|
||||||
(mime::APPLICATION, mime::JSON) => Ok((
|
(mime::APPLICATION, mime::JSON) => Ok((
|
||||||
Some("json".to_string()),
|
Some("json".to_string()),
|
||||||
@ -323,7 +323,7 @@ pub async fn post(
|
|||||||
)
|
)
|
||||||
})?),
|
})?),
|
||||||
tag,
|
tag,
|
||||||
SpanSource::Url(location.to_string()),
|
AnchorLocation::Url(location.to_string()),
|
||||||
)),
|
)),
|
||||||
(mime::APPLICATION, mime::OCTET_STREAM) => {
|
(mime::APPLICATION, mime::OCTET_STREAM) => {
|
||||||
let buf: Vec<u8> = r.body_bytes().await.map_err(|_| {
|
let buf: Vec<u8> = r.body_bytes().await.map_err(|_| {
|
||||||
@ -337,7 +337,7 @@ pub async fn post(
|
|||||||
None,
|
None,
|
||||||
Value::binary(buf),
|
Value::binary(buf),
|
||||||
tag,
|
tag,
|
||||||
SpanSource::Url(location.to_string()),
|
AnchorLocation::Url(location.to_string()),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
(mime::IMAGE, image_ty) => {
|
(mime::IMAGE, image_ty) => {
|
||||||
@ -352,7 +352,7 @@ pub async fn post(
|
|||||||
Some(image_ty.to_string()),
|
Some(image_ty.to_string()),
|
||||||
Value::binary(buf),
|
Value::binary(buf),
|
||||||
tag,
|
tag,
|
||||||
SpanSource::Url(location.to_string()),
|
AnchorLocation::Url(location.to_string()),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
(mime::TEXT, mime::HTML) => Ok((
|
(mime::TEXT, mime::HTML) => Ok((
|
||||||
@ -365,7 +365,7 @@ pub async fn post(
|
|||||||
)
|
)
|
||||||
})?),
|
})?),
|
||||||
tag,
|
tag,
|
||||||
SpanSource::Url(location.to_string()),
|
AnchorLocation::Url(location.to_string()),
|
||||||
)),
|
)),
|
||||||
(mime::TEXT, mime::PLAIN) => {
|
(mime::TEXT, mime::PLAIN) => {
|
||||||
let path_extension = url::Url::parse(location)
|
let path_extension = url::Url::parse(location)
|
||||||
@ -389,7 +389,7 @@ pub async fn post(
|
|||||||
)
|
)
|
||||||
})?),
|
})?),
|
||||||
tag,
|
tag,
|
||||||
SpanSource::Url(location.to_string()),
|
AnchorLocation::Url(location.to_string()),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
(ty, sub_ty) => Ok((
|
(ty, sub_ty) => Ok((
|
||||||
@ -399,7 +399,7 @@ pub async fn post(
|
|||||||
ty, sub_ty
|
ty, sub_ty
|
||||||
)),
|
)),
|
||||||
tag,
|
tag,
|
||||||
SpanSource::Url(location.to_string()),
|
AnchorLocation::Url(location.to_string()),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -407,7 +407,7 @@ pub async fn post(
|
|||||||
None,
|
None,
|
||||||
Value::string(format!("No content type found")),
|
Value::string(format!("No content type found")),
|
||||||
tag,
|
tag,
|
||||||
SpanSource::Url(location.to_string()),
|
AnchorLocation::Url(location.to_string()),
|
||||||
)),
|
)),
|
||||||
},
|
},
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
|
@ -133,12 +133,12 @@ fn save(
|
|||||||
let stream = async_stream! {
|
let stream = async_stream! {
|
||||||
let input: Vec<Tagged<Value>> = input.values.collect().await;
|
let input: Vec<Tagged<Value>> = input.values.collect().await;
|
||||||
if path.is_none() {
|
if path.is_none() {
|
||||||
// If there is no filename, check the metadata for the origin filename
|
// If there is no filename, check the metadata for the anchor filename
|
||||||
if input.len() > 0 {
|
if input.len() > 0 {
|
||||||
let origin = input[0].origin();
|
let anchor = input[0].anchor();
|
||||||
match source_map.get(&origin) {
|
match source_map.get(&anchor) {
|
||||||
Some(path) => match path {
|
Some(path) => match path {
|
||||||
SpanSource::File(file) => {
|
AnchorLocation::File(file) => {
|
||||||
full_path.push(Path::new(file));
|
full_path.push(Path::new(file));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -35,19 +35,19 @@ fn tags(args: CommandArgs, _registry: &CommandRegistry) -> Result<OutputStream,
|
|||||||
.map(move |v| {
|
.map(move |v| {
|
||||||
let mut tags = TaggedDictBuilder::new(v.tag());
|
let mut tags = TaggedDictBuilder::new(v.tag());
|
||||||
{
|
{
|
||||||
let origin = v.origin();
|
let anchor = v.anchor();
|
||||||
let span = v.tag().span;
|
let span = v.tag().span;
|
||||||
let mut dict = TaggedDictBuilder::new(v.tag());
|
let mut dict = TaggedDictBuilder::new(v.tag());
|
||||||
dict.insert("start", Value::int(span.start as i64));
|
dict.insert("start", Value::int(span.start as i64));
|
||||||
dict.insert("end", Value::int(span.end as i64));
|
dict.insert("end", Value::int(span.end as i64));
|
||||||
tags.insert_tagged("span", dict.into_tagged_value());
|
tags.insert_tagged("span", dict.into_tagged_value());
|
||||||
|
|
||||||
match source_map.get(&origin) {
|
match source_map.get(&anchor) {
|
||||||
Some(SpanSource::File(source)) => {
|
Some(AnchorLocation::File(source)) => {
|
||||||
tags.insert("origin", Value::string(source));
|
tags.insert("anchor", Value::string(source));
|
||||||
}
|
}
|
||||||
Some(SpanSource::Url(source)) => {
|
Some(AnchorLocation::Url(source)) => {
|
||||||
tags.insert("origin", Value::string(source));
|
tags.insert("anchor", Value::string(source));
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
@ -11,21 +11,21 @@ use std::sync::Arc;
|
|||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub enum SpanSource {
|
pub enum AnchorLocation {
|
||||||
Url(String),
|
Url(String),
|
||||||
File(String),
|
File(String),
|
||||||
Source(Text),
|
Source(Text),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct SourceMap(HashMap<Uuid, SpanSource>);
|
pub struct SourceMap(HashMap<Uuid, AnchorLocation>);
|
||||||
|
|
||||||
impl SourceMap {
|
impl SourceMap {
|
||||||
pub fn insert(&mut self, uuid: Uuid, span_source: SpanSource) {
|
pub fn insert(&mut self, uuid: Uuid, anchor_location: AnchorLocation) {
|
||||||
self.0.insert(uuid, span_source);
|
self.0.insert(uuid, anchor_location);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(&self, uuid: &Uuid) -> Option<&SpanSource> {
|
pub fn get(&self, uuid: &Uuid) -> Option<&AnchorLocation> {
|
||||||
self.0.get(uuid)
|
self.0.get(uuid)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,8 +105,8 @@ impl Context {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_span_source(&mut self, uuid: Uuid, span_source: SpanSource) {
|
pub fn add_anchor_location(&mut self, uuid: Uuid, anchor_location: AnchorLocation) {
|
||||||
self.source_map.insert(uuid, span_source);
|
self.source_map.insert(uuid, anchor_location);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn has_command(&self, name: &str) -> bool {
|
pub(crate) fn has_command(&self, name: &str) -> bool {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::context::{SourceMap, SpanSource};
|
use crate::context::{AnchorLocation, SourceMap};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::Text;
|
use crate::Text;
|
||||||
use derive_new::new;
|
use derive_new::new;
|
||||||
@ -39,7 +39,7 @@ pub trait TaggedItem: Sized {
|
|||||||
self,
|
self,
|
||||||
Tag {
|
Tag {
|
||||||
span: Span::unknown(),
|
span: Span::unknown(),
|
||||||
origin: uuid::Uuid::nil(),
|
anchor: uuid::Uuid::nil(),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -90,14 +90,14 @@ impl<T> Tagged<T> {
|
|||||||
self.tag.span
|
self.tag.span
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn origin(&self) -> uuid::Uuid {
|
pub fn anchor(&self) -> uuid::Uuid {
|
||||||
self.tag.origin
|
self.tag.anchor
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn origin_name(&self, source_map: &SourceMap) -> Option<String> {
|
pub fn anchor_name(&self, source_map: &SourceMap) -> Option<String> {
|
||||||
match source_map.get(&self.tag.origin) {
|
match source_map.get(&self.tag.anchor) {
|
||||||
Some(SpanSource::File(file)) => Some(file.clone()),
|
Some(AnchorLocation::File(file)) => Some(file.clone()),
|
||||||
Some(SpanSource::Url(url)) => Some(url.clone()),
|
Some(AnchorLocation::Url(url)) => Some(url.clone()),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -167,14 +167,14 @@ impl From<&std::ops::Range<usize>> for Span {
|
|||||||
Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Serialize, Deserialize, Hash, Getters,
|
Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Serialize, Deserialize, Hash, Getters,
|
||||||
)]
|
)]
|
||||||
pub struct Tag {
|
pub struct Tag {
|
||||||
pub origin: Uuid,
|
pub anchor: Uuid,
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Span> for Tag {
|
impl From<Span> for Tag {
|
||||||
fn from(span: Span) -> Self {
|
fn from(span: Span) -> Self {
|
||||||
Tag {
|
Tag {
|
||||||
origin: uuid::Uuid::nil(),
|
anchor: uuid::Uuid::nil(),
|
||||||
span,
|
span,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -183,25 +183,25 @@ impl From<Span> for Tag {
|
|||||||
impl From<&Span> for Tag {
|
impl From<&Span> for Tag {
|
||||||
fn from(span: &Span) -> Self {
|
fn from(span: &Span) -> Self {
|
||||||
Tag {
|
Tag {
|
||||||
origin: uuid::Uuid::nil(),
|
anchor: uuid::Uuid::nil(),
|
||||||
span: *span,
|
span: *span,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<(usize, usize, Uuid)> for Tag {
|
impl From<(usize, usize, Uuid)> for Tag {
|
||||||
fn from((start, end, origin): (usize, usize, Uuid)) -> Self {
|
fn from((start, end, anchor): (usize, usize, Uuid)) -> Self {
|
||||||
Tag {
|
Tag {
|
||||||
origin,
|
anchor,
|
||||||
span: Span { start, end },
|
span: Span { start, end },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<(usize, usize, Option<Uuid>)> for Tag {
|
impl From<(usize, usize, Option<Uuid>)> for Tag {
|
||||||
fn from((start, end, origin): (usize, usize, Option<Uuid>)) -> Self {
|
fn from((start, end, anchor): (usize, usize, Option<Uuid>)) -> Self {
|
||||||
Tag {
|
Tag {
|
||||||
origin: if let Some(uuid) = origin {
|
anchor: if let Some(uuid) = anchor {
|
||||||
uuid
|
uuid
|
||||||
} else {
|
} else {
|
||||||
uuid::Uuid::nil()
|
uuid::Uuid::nil()
|
||||||
@ -214,7 +214,7 @@ impl From<(usize, usize, Option<Uuid>)> for Tag {
|
|||||||
impl From<nom_locate::LocatedSpanEx<&str, Uuid>> for Tag {
|
impl From<nom_locate::LocatedSpanEx<&str, Uuid>> for Tag {
|
||||||
fn from(input: nom_locate::LocatedSpanEx<&str, Uuid>) -> Tag {
|
fn from(input: nom_locate::LocatedSpanEx<&str, Uuid>) -> Tag {
|
||||||
Tag {
|
Tag {
|
||||||
origin: input.extra,
|
anchor: input.extra,
|
||||||
span: Span {
|
span: Span {
|
||||||
start: input.offset,
|
start: input.offset,
|
||||||
end: input.offset + input.fragment.len(),
|
end: input.offset + input.fragment.len(),
|
||||||
@ -236,23 +236,23 @@ impl From<&Tag> for Span {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Tag {
|
impl Tag {
|
||||||
pub fn unknown_origin(span: Span) -> Tag {
|
pub fn unknown_anchor(span: Span) -> Tag {
|
||||||
Tag {
|
Tag {
|
||||||
origin: uuid::Uuid::nil(),
|
anchor: uuid::Uuid::nil(),
|
||||||
span,
|
span,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unknown_span(origin: Uuid) -> Tag {
|
pub fn unknown_span(anchor: Uuid) -> Tag {
|
||||||
Tag {
|
Tag {
|
||||||
origin,
|
anchor,
|
||||||
span: Span::unknown(),
|
span: Span::unknown(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unknown() -> Tag {
|
pub fn unknown() -> Tag {
|
||||||
Tag {
|
Tag {
|
||||||
origin: uuid::Uuid::nil(),
|
anchor: uuid::Uuid::nil(),
|
||||||
span: Span::unknown(),
|
span: Span::unknown(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -260,8 +260,8 @@ impl Tag {
|
|||||||
pub fn until(&self, other: impl Into<Tag>) -> Tag {
|
pub fn until(&self, other: impl Into<Tag>) -> Tag {
|
||||||
let other = other.into();
|
let other = other.into();
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
self.origin == other.origin,
|
self.anchor == other.anchor,
|
||||||
"Can only merge two tags with the same origin"
|
"Can only merge two tags with the same anchor"
|
||||||
);
|
);
|
||||||
|
|
||||||
Tag {
|
Tag {
|
||||||
@ -269,7 +269,7 @@ impl Tag {
|
|||||||
start: self.span.start,
|
start: self.span.start,
|
||||||
end: other.span.end,
|
end: other.span.end,
|
||||||
},
|
},
|
||||||
origin: self.origin,
|
anchor: self.anchor,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -348,7 +348,7 @@ impl language_reporting::ReportingSpan for Tag {
|
|||||||
start,
|
start,
|
||||||
end: self.span.end,
|
end: self.span.end,
|
||||||
},
|
},
|
||||||
origin: self.origin,
|
anchor: self.anchor,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,7 +358,7 @@ impl language_reporting::ReportingSpan for Tag {
|
|||||||
start: self.span.start,
|
start: self.span.start,
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
origin: self.origin,
|
anchor: self.anchor,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ mod traits;
|
|||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
pub use crate::commands::command::{CallInfo, ReturnSuccess, ReturnValue};
|
pub use crate::commands::command::{CallInfo, ReturnSuccess, ReturnValue};
|
||||||
pub use crate::context::{SourceMap, SpanSource};
|
pub use crate::context::{AnchorLocation, SourceMap};
|
||||||
pub use crate::env::host::BasicHost;
|
pub use crate::env::host::BasicHost;
|
||||||
pub use crate::parser::hir::SyntaxShape;
|
pub use crate::parser::hir::SyntaxShape;
|
||||||
pub use crate::parser::parse::token_tree_builder::TokenTreeBuilder;
|
pub use crate::parser::parse::token_tree_builder::TokenTreeBuilder;
|
||||||
|
@ -21,10 +21,10 @@ pub(crate) use parse::unit::Unit;
|
|||||||
pub(crate) use parse_command::parse_command;
|
pub(crate) use parse_command::parse_command;
|
||||||
pub(crate) use registry::CommandRegistry;
|
pub(crate) use registry::CommandRegistry;
|
||||||
|
|
||||||
pub fn parse(input: &str, origin: uuid::Uuid) -> Result<TokenNode, ShellError> {
|
pub fn parse(input: &str, anchor: uuid::Uuid) -> Result<TokenNode, ShellError> {
|
||||||
let _ = pretty_env_logger::try_init();
|
let _ = pretty_env_logger::try_init();
|
||||||
|
|
||||||
match pipeline(nom_input(input, origin)) {
|
match pipeline(nom_input(input, anchor)) {
|
||||||
Ok((_rest, val)) => Ok(val),
|
Ok((_rest, val)) => Ok(val),
|
||||||
Err(err) => Err(ShellError::parse_error(err)),
|
Err(err) => Err(ShellError::parse_error(err)),
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ impl language_reporting::ReportingFiles for Files {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn file_id(&self, tag: Self::Span) -> Self::FileId {
|
fn file_id(&self, tag: Self::Span) -> Self::FileId {
|
||||||
tag.origin
|
tag.anchor
|
||||||
}
|
}
|
||||||
|
|
||||||
fn file_name(&self, _file: Self::FileId) -> FileName {
|
fn file_name(&self, _file: Self::FileId) -> FileName {
|
||||||
|
@ -26,8 +26,8 @@ use uuid::Uuid;
|
|||||||
|
|
||||||
pub type NomSpan<'a> = LocatedSpanEx<&'a str, Uuid>;
|
pub type NomSpan<'a> = LocatedSpanEx<&'a str, Uuid>;
|
||||||
|
|
||||||
pub fn nom_input(s: &str, origin: Uuid) -> NomSpan<'_> {
|
pub fn nom_input(s: &str, anchor: Uuid) -> NomSpan<'_> {
|
||||||
LocatedSpanEx::new_extra(s, origin)
|
LocatedSpanEx::new_extra(s, anchor)
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! operator {
|
macro_rules! operator {
|
||||||
@ -149,7 +149,7 @@ impl Into<Number> for BigDecimal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn raw_number(input: NomSpan) -> IResult<NomSpan, Tagged<RawNumber>> {
|
pub fn raw_number(input: NomSpan) -> IResult<NomSpan, Tagged<RawNumber>> {
|
||||||
let original = input;
|
let anchoral = input;
|
||||||
let start = input.offset;
|
let start = input.offset;
|
||||||
trace_step(input, "raw_decimal", move |input| {
|
trace_step(input, "raw_decimal", move |input| {
|
||||||
let (input, neg) = opt(tag("-"))(input)?;
|
let (input, neg) = opt(tag("-"))(input)?;
|
||||||
@ -1308,7 +1308,7 @@ mod tests {
|
|||||||
right: usize,
|
right: usize,
|
||||||
) -> TokenNode {
|
) -> TokenNode {
|
||||||
let node = DelimitedNode::new(*delimiter, children);
|
let node = DelimitedNode::new(*delimiter, children);
|
||||||
let spanned = node.tagged((left, right, delimiter.tag.origin));
|
let spanned = node.tagged((left, right, delimiter.tag.anchor));
|
||||||
TokenNode::Delimited(spanned)
|
TokenNode::Delimited(spanned)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1319,7 +1319,7 @@ mod tests {
|
|||||||
Box::new(head),
|
Box::new(head),
|
||||||
tail.into_iter().map(TokenNode::Token).collect(),
|
tail.into_iter().map(TokenNode::Token).collect(),
|
||||||
);
|
);
|
||||||
let spanned = node.tagged((left, right, tag.origin));
|
let spanned = node.tagged((left, right, tag.anchor));
|
||||||
TokenNode::Path(spanned)
|
TokenNode::Path(spanned)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,15 +18,15 @@ pub struct TokenTreeBuilder {
|
|||||||
#[new(default)]
|
#[new(default)]
|
||||||
output: String,
|
output: String,
|
||||||
|
|
||||||
origin: Uuid,
|
anchor: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type CurriedToken = Box<dyn FnOnce(&mut TokenTreeBuilder) -> TokenNode + 'static>;
|
pub type CurriedToken = Box<dyn FnOnce(&mut TokenTreeBuilder) -> TokenNode + 'static>;
|
||||||
pub type CurriedCall = Box<dyn FnOnce(&mut TokenTreeBuilder) -> Tagged<CallNode> + 'static>;
|
pub type CurriedCall = Box<dyn FnOnce(&mut TokenTreeBuilder) -> Tagged<CallNode> + 'static>;
|
||||||
|
|
||||||
impl TokenTreeBuilder {
|
impl TokenTreeBuilder {
|
||||||
pub fn build(origin: Uuid, block: impl FnOnce(&mut Self) -> TokenNode) -> (TokenNode, String) {
|
pub fn build(anchor: Uuid, block: impl FnOnce(&mut Self) -> TokenNode) -> (TokenNode, String) {
|
||||||
let mut builder = TokenTreeBuilder::new(origin);
|
let mut builder = TokenTreeBuilder::new(anchor);
|
||||||
let node = block(&mut builder);
|
let node = block(&mut builder);
|
||||||
(node, builder.output)
|
(node, builder.output)
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ impl TokenTreeBuilder {
|
|||||||
|
|
||||||
let end = b.pos;
|
let end = b.pos;
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_pipeline((out, None), (start, end, b.origin))
|
TokenTreeBuilder::tagged_pipeline((out, None), (start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ impl TokenTreeBuilder {
|
|||||||
|
|
||||||
b.pos = end;
|
b.pos = end;
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_op(input, (start, end, b.origin))
|
TokenTreeBuilder::tagged_op(input, (start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,8 +113,8 @@ impl TokenTreeBuilder {
|
|||||||
b.pos = end;
|
b.pos = end;
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_string(
|
TokenTreeBuilder::tagged_string(
|
||||||
(inner_start, inner_end, b.origin),
|
(inner_start, inner_end, b.anchor),
|
||||||
(start, end, b.origin),
|
(start, end, b.anchor),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -130,7 +130,7 @@ impl TokenTreeBuilder {
|
|||||||
let (start, end) = b.consume(&input);
|
let (start, end) = b.consume(&input);
|
||||||
b.pos = end;
|
b.pos = end;
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_bare((start, end, b.origin))
|
TokenTreeBuilder::tagged_bare((start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +145,7 @@ impl TokenTreeBuilder {
|
|||||||
let (start, end) = b.consume(&input);
|
let (start, end) = b.consume(&input);
|
||||||
b.pos = end;
|
b.pos = end;
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_pattern((start, end, b.origin))
|
TokenTreeBuilder::tagged_pattern((start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ impl TokenTreeBuilder {
|
|||||||
let (start, end) = b.consume(&input);
|
let (start, end) = b.consume(&input);
|
||||||
b.pos = end;
|
b.pos = end;
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_external_word((start, end, b.origin))
|
TokenTreeBuilder::tagged_external_word((start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,8 +180,8 @@ impl TokenTreeBuilder {
|
|||||||
b.pos = end;
|
b.pos = end;
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_number(
|
TokenTreeBuilder::tagged_number(
|
||||||
RawNumber::Int((start, end, b.origin).into()),
|
RawNumber::Int((start, end, b.anchor).into()),
|
||||||
(start, end, b.origin),
|
(start, end, b.anchor),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -194,8 +194,8 @@ impl TokenTreeBuilder {
|
|||||||
b.pos = end;
|
b.pos = end;
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_number(
|
TokenTreeBuilder::tagged_number(
|
||||||
RawNumber::Decimal((start, end, b.origin).into()),
|
RawNumber::Decimal((start, end, b.anchor).into()),
|
||||||
(start, end, b.origin),
|
(start, end, b.anchor),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -214,8 +214,8 @@ impl TokenTreeBuilder {
|
|||||||
b.pos = end_unit;
|
b.pos = end_unit;
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_size(
|
TokenTreeBuilder::tagged_size(
|
||||||
(RawNumber::Int((start_int, end_int, b.origin).into()), unit),
|
(RawNumber::Int((start_int, end_int, b.anchor).into()), unit),
|
||||||
(start_int, end_unit, b.origin),
|
(start_int, end_unit, b.anchor),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -244,7 +244,7 @@ impl TokenTreeBuilder {
|
|||||||
|
|
||||||
let end = b.pos;
|
let end = b.pos;
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_path((head, output), (start, end, b.origin))
|
TokenTreeBuilder::tagged_path((head, output), (start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,7 +259,7 @@ impl TokenTreeBuilder {
|
|||||||
let (start, _) = b.consume("$");
|
let (start, _) = b.consume("$");
|
||||||
let (inner_start, end) = b.consume(&input);
|
let (inner_start, end) = b.consume(&input);
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_var((inner_start, end, b.origin), (start, end, b.origin))
|
TokenTreeBuilder::tagged_var((inner_start, end, b.anchor), (start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,7 +274,7 @@ impl TokenTreeBuilder {
|
|||||||
let (start, _) = b.consume("--");
|
let (start, _) = b.consume("--");
|
||||||
let (inner_start, end) = b.consume(&input);
|
let (inner_start, end) = b.consume(&input);
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_flag((inner_start, end, b.origin), (start, end, b.origin))
|
TokenTreeBuilder::tagged_flag((inner_start, end, b.anchor), (start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,7 +289,7 @@ impl TokenTreeBuilder {
|
|||||||
let (start, _) = b.consume("-");
|
let (start, _) = b.consume("-");
|
||||||
let (inner_start, end) = b.consume(&input);
|
let (inner_start, end) = b.consume(&input);
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_shorthand((inner_start, end, b.origin), (start, end, b.origin))
|
TokenTreeBuilder::tagged_shorthand((inner_start, end, b.anchor), (start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,7 +302,7 @@ impl TokenTreeBuilder {
|
|||||||
|
|
||||||
Box::new(move |b| {
|
Box::new(move |b| {
|
||||||
let (start, end) = b.consume(&input);
|
let (start, end) = b.consume(&input);
|
||||||
TokenTreeBuilder::tagged_member((start, end, b.origin))
|
TokenTreeBuilder::tagged_member((start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,7 +323,7 @@ impl TokenTreeBuilder {
|
|||||||
|
|
||||||
let end = b.pos;
|
let end = b.pos;
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_call(nodes, (start, end, b.origin))
|
TokenTreeBuilder::tagged_call(nodes, (start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -350,7 +350,7 @@ impl TokenTreeBuilder {
|
|||||||
|
|
||||||
let (_, end) = b.consume(")");
|
let (_, end) = b.consume(")");
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_parens(output, (start, end, b.origin))
|
TokenTreeBuilder::tagged_parens(output, (start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,7 +368,7 @@ impl TokenTreeBuilder {
|
|||||||
|
|
||||||
let (_, end) = b.consume("]");
|
let (_, end) = b.consume("]");
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_square(output, (start, end, b.origin))
|
TokenTreeBuilder::tagged_square(output, (start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,7 +386,7 @@ impl TokenTreeBuilder {
|
|||||||
|
|
||||||
let (_, end) = b.consume(" }");
|
let (_, end) = b.consume(" }");
|
||||||
|
|
||||||
TokenTreeBuilder::tagged_brace(output, (start, end, b.origin))
|
TokenTreeBuilder::tagged_brace(output, (start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -397,7 +397,7 @@ impl TokenTreeBuilder {
|
|||||||
pub fn sp() -> CurriedToken {
|
pub fn sp() -> CurriedToken {
|
||||||
Box::new(|b| {
|
Box::new(|b| {
|
||||||
let (start, end) = b.consume(" ");
|
let (start, end) = b.consume(" ");
|
||||||
TokenNode::Whitespace(Tag::from((start, end, b.origin)))
|
TokenNode::Whitespace(Tag::from((start, end, b.anchor)))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -406,7 +406,7 @@ impl TokenTreeBuilder {
|
|||||||
|
|
||||||
Box::new(move |b| {
|
Box::new(move |b| {
|
||||||
let (start, end) = b.consume(&input);
|
let (start, end) = b.consume(&input);
|
||||||
TokenTreeBuilder::tagged_ws((start, end, b.origin))
|
TokenTreeBuilder::tagged_ws((start, end, b.anchor))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -425,6 +425,6 @@ impl TokenTreeBuilder {
|
|||||||
let start = self.pos;
|
let start = self.pos;
|
||||||
self.pos += input.len();
|
self.pos += input.len();
|
||||||
self.output.push_str(input);
|
self.output.push_str(input);
|
||||||
(start, self.pos, self.origin).into()
|
(start, self.pos, self.anchor).into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crossterm::{cursor, terminal, Attribute, RawScreen};
|
use crossterm::{cursor, terminal, Attribute, RawScreen};
|
||||||
use nu::{
|
use nu::{
|
||||||
serve_plugin, CallInfo, Plugin, Primitive, ShellError, Signature, SpanSource, Tagged, Value,
|
serve_plugin, AnchorLocation, CallInfo, Plugin, Primitive, ShellError, Signature, Tagged, Value,
|
||||||
};
|
};
|
||||||
use pretty_hex::*;
|
use pretty_hex::*;
|
||||||
|
|
||||||
@ -21,10 +21,10 @@ impl Plugin for BinaryView {
|
|||||||
|
|
||||||
fn sink(&mut self, call_info: CallInfo, input: Vec<Tagged<Value>>) {
|
fn sink(&mut self, call_info: CallInfo, input: Vec<Tagged<Value>>) {
|
||||||
for v in input {
|
for v in input {
|
||||||
let value_origin = v.origin();
|
let value_anchor = v.anchor();
|
||||||
match v.item {
|
match v.item {
|
||||||
Value::Primitive(Primitive::Binary(b)) => {
|
Value::Primitive(Primitive::Binary(b)) => {
|
||||||
let source = call_info.source_map.get(&value_origin);
|
let source = call_info.source_map.get(&value_anchor);
|
||||||
let _ = view_binary(&b, source, call_info.args.has("lores"));
|
let _ = view_binary(&b, source, call_info.args.has("lores"));
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
@ -35,7 +35,7 @@ impl Plugin for BinaryView {
|
|||||||
|
|
||||||
fn view_binary(
|
fn view_binary(
|
||||||
b: &[u8],
|
b: &[u8],
|
||||||
source: Option<&SpanSource>,
|
source: Option<&AnchorLocation>,
|
||||||
lores_mode: bool,
|
lores_mode: bool,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
if b.len() > 3 {
|
if b.len() > 3 {
|
||||||
@ -254,7 +254,7 @@ fn load_from_jpg_buffer(buffer: &[u8]) -> Option<(RawImageBuffer)> {
|
|||||||
|
|
||||||
pub fn view_contents(
|
pub fn view_contents(
|
||||||
buffer: &[u8],
|
buffer: &[u8],
|
||||||
_source: Option<&SpanSource>,
|
_source: Option<&AnchorLocation>,
|
||||||
lores_mode: bool,
|
lores_mode: bool,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let mut raw_image_buffer = load_from_png_buffer(buffer);
|
let mut raw_image_buffer = load_from_png_buffer(buffer);
|
||||||
@ -341,12 +341,12 @@ pub fn view_contents(
|
|||||||
#[cfg(feature = "rawkey")]
|
#[cfg(feature = "rawkey")]
|
||||||
pub fn view_contents_interactive(
|
pub fn view_contents_interactive(
|
||||||
buffer: &[u8],
|
buffer: &[u8],
|
||||||
source: Option<&SpanSource>,
|
source: Option<&AnchorLocation>,
|
||||||
lores_mode: bool,
|
lores_mode: bool,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
use rawkey::{KeyCode, RawKey};
|
use rawkey::{KeyCode, RawKey};
|
||||||
|
|
||||||
let sav_path = if let Some(SpanSource::File(f)) = source {
|
let sav_path = if let Some(AnchorLocation::File(f)) = source {
|
||||||
let mut path = std::path::PathBuf::from(f);
|
let mut path = std::path::PathBuf::from(f);
|
||||||
path.set_extension("sav");
|
path.set_extension("sav");
|
||||||
Some(path)
|
Some(path)
|
||||||
|
@ -186,15 +186,15 @@ mod tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct CallStub {
|
struct CallStub {
|
||||||
origin: uuid::Uuid,
|
anchor: uuid::Uuid,
|
||||||
positionals: Vec<Tagged<Value>>,
|
positionals: Vec<Tagged<Value>>,
|
||||||
flags: IndexMap<String, Tagged<Value>>,
|
flags: IndexMap<String, Tagged<Value>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CallStub {
|
impl CallStub {
|
||||||
fn new(origin: uuid::Uuid) -> CallStub {
|
fn new(anchor: uuid::Uuid) -> CallStub {
|
||||||
CallStub {
|
CallStub {
|
||||||
origin,
|
anchor,
|
||||||
positionals: vec![],
|
positionals: vec![],
|
||||||
flags: indexmap::IndexMap::new(),
|
flags: indexmap::IndexMap::new(),
|
||||||
}
|
}
|
||||||
@ -210,7 +210,7 @@ mod tests {
|
|||||||
|
|
||||||
fn with_parameter(&mut self, name: &str) -> &mut Self {
|
fn with_parameter(&mut self, name: &str) -> &mut Self {
|
||||||
self.positionals
|
self.positionals
|
||||||
.push(Value::string(name.to_string()).tagged(Tag::unknown_span(self.origin)));
|
.push(Value::string(name.to_string()).tagged(Tag::unknown_span(self.anchor)));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ mod tests {
|
|||||||
CallInfo {
|
CallInfo {
|
||||||
args: EvaluatedArgs::new(Some(self.positionals.clone()), Some(self.flags.clone())),
|
args: EvaluatedArgs::new(Some(self.positionals.clone()), Some(self.flags.clone())),
|
||||||
source_map: SourceMap::new(),
|
source_map: SourceMap::new(),
|
||||||
name_tag: Tag::unknown_span(self.origin),
|
name_tag: Tag::unknown_span(self.anchor),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -204,7 +204,7 @@ mod tests {
|
|||||||
use num_bigint::BigInt;
|
use num_bigint::BigInt;
|
||||||
|
|
||||||
struct CallStub {
|
struct CallStub {
|
||||||
origin: uuid::Uuid,
|
anchor: uuid::Uuid,
|
||||||
positionals: Vec<Tagged<Value>>,
|
positionals: Vec<Tagged<Value>>,
|
||||||
flags: IndexMap<String, Tagged<Value>>,
|
flags: IndexMap<String, Tagged<Value>>,
|
||||||
}
|
}
|
||||||
@ -212,7 +212,7 @@ mod tests {
|
|||||||
impl CallStub {
|
impl CallStub {
|
||||||
fn new() -> CallStub {
|
fn new() -> CallStub {
|
||||||
CallStub {
|
CallStub {
|
||||||
origin: uuid::Uuid::nil(),
|
anchor: uuid::Uuid::nil(),
|
||||||
positionals: vec![],
|
positionals: vec![],
|
||||||
flags: indexmap::IndexMap::new(),
|
flags: indexmap::IndexMap::new(),
|
||||||
}
|
}
|
||||||
@ -236,7 +236,7 @@ mod tests {
|
|||||||
CallInfo {
|
CallInfo {
|
||||||
args: EvaluatedArgs::new(Some(self.positionals.clone()), Some(self.flags.clone())),
|
args: EvaluatedArgs::new(Some(self.positionals.clone()), Some(self.flags.clone())),
|
||||||
source_map: SourceMap::new(),
|
source_map: SourceMap::new(),
|
||||||
name_tag: Tag::unknown_span(self.origin),
|
name_tag: Tag::unknown_span(self.anchor),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crossterm::{cursor, terminal, RawScreen};
|
use crossterm::{cursor, terminal, RawScreen};
|
||||||
use crossterm::{InputEvent, KeyEvent};
|
use crossterm::{InputEvent, KeyEvent};
|
||||||
use nu::{
|
use nu::{
|
||||||
serve_plugin, CallInfo, Plugin, Primitive, ShellError, Signature, SourceMap, SpanSource,
|
serve_plugin, AnchorLocation, CallInfo, Plugin, Primitive, ShellError, Signature, SourceMap,
|
||||||
Tagged, Value,
|
Tagged, Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -216,18 +216,18 @@ fn scroll_view(s: &str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn view_text_value(value: &Tagged<Value>, source_map: &SourceMap) {
|
fn view_text_value(value: &Tagged<Value>, source_map: &SourceMap) {
|
||||||
let value_origin = value.origin();
|
let value_anchor = value.anchor();
|
||||||
match value.item {
|
match value.item {
|
||||||
Value::Primitive(Primitive::String(ref s)) => {
|
Value::Primitive(Primitive::String(ref s)) => {
|
||||||
let source = source_map.get(&value_origin);
|
let source = source_map.get(&value_anchor);
|
||||||
|
|
||||||
if let Some(source) = source {
|
if let Some(source) = source {
|
||||||
let extension: Option<String> = match source {
|
let extension: Option<String> = match source {
|
||||||
SpanSource::File(file) => {
|
AnchorLocation::File(file) => {
|
||||||
let path = Path::new(file);
|
let path = Path::new(file);
|
||||||
path.extension().map(|x| x.to_string_lossy().to_string())
|
path.extension().map(|x| x.to_string_lossy().to_string())
|
||||||
}
|
}
|
||||||
SpanSource::Url(url) => {
|
AnchorLocation::Url(url) => {
|
||||||
let url = url::Url::parse(url);
|
let url = url::Url::parse(url);
|
||||||
if let Ok(url) = url {
|
if let Ok(url) = url {
|
||||||
let url = url.clone();
|
let url = url.clone();
|
||||||
@ -246,7 +246,7 @@ fn view_text_value(value: &Tagged<Value>, source_map: &SourceMap) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//FIXME: this probably isn't correct
|
//FIXME: this probably isn't correct
|
||||||
SpanSource::Source(_source) => None,
|
AnchorLocation::Source(_source) => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
match extension {
|
match extension {
|
||||||
|
@ -54,7 +54,7 @@ pub(crate) use crate::commands::command::{
|
|||||||
pub(crate) use crate::commands::PerItemCommand;
|
pub(crate) use crate::commands::PerItemCommand;
|
||||||
pub(crate) use crate::commands::RawCommandArgs;
|
pub(crate) use crate::commands::RawCommandArgs;
|
||||||
pub(crate) use crate::context::CommandRegistry;
|
pub(crate) use crate::context::CommandRegistry;
|
||||||
pub(crate) use crate::context::{Context, SpanSource};
|
pub(crate) use crate::context::{AnchorLocation, Context};
|
||||||
pub(crate) use crate::data::base as value;
|
pub(crate) use crate::data::base as value;
|
||||||
pub(crate) use crate::data::meta::{Tag, Tagged, TaggedItem};
|
pub(crate) use crate::data::meta::{Tag, Tagged, TaggedItem};
|
||||||
pub(crate) use crate::data::types::ExtractType;
|
pub(crate) use crate::data::types::ExtractType;
|
||||||
|
@ -99,10 +99,10 @@ impl HelpShell {
|
|||||||
|
|
||||||
impl Shell for HelpShell {
|
impl Shell for HelpShell {
|
||||||
fn name(&self, source_map: &SourceMap) -> String {
|
fn name(&self, source_map: &SourceMap) -> String {
|
||||||
let origin_name = self.value.origin_name(source_map);
|
let anchor_name = self.value.anchor_name(source_map);
|
||||||
format!(
|
format!(
|
||||||
"{}",
|
"{}",
|
||||||
match origin_name {
|
match anchor_name {
|
||||||
Some(x) => format!("{{{}}}", x),
|
Some(x) => format!("{{{}}}", x),
|
||||||
None => format!("<{}>", self.value.item.type_name(),),
|
None => format!("<{}>", self.value.item.type_name(),),
|
||||||
}
|
}
|
||||||
|
@ -73,10 +73,10 @@ impl ValueShell {
|
|||||||
|
|
||||||
impl Shell for ValueShell {
|
impl Shell for ValueShell {
|
||||||
fn name(&self, source_map: &SourceMap) -> String {
|
fn name(&self, source_map: &SourceMap) -> String {
|
||||||
let origin_name = self.value.origin_name(source_map);
|
let anchor_name = self.value.anchor_name(source_map);
|
||||||
format!(
|
format!(
|
||||||
"{}",
|
"{}",
|
||||||
match origin_name {
|
match anchor_name {
|
||||||
Some(x) => format!("{{{}}}", x),
|
Some(x) => format!("{{{}}}", x),
|
||||||
None => format!("<{}>", self.value.item.type_name(),),
|
None => format!("<{}>", self.value.item.type_name(),),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user