Improve enter and fix bugs

This commit is contained in:
Jonathan Turner
2019-08-11 08:18:14 +12:00
parent 357ab46b58
commit 8f78995014
11 changed files with 54 additions and 17 deletions

View File

@@ -51,7 +51,10 @@ pub fn autoview(
let result = table.run(raw.with_input(input), &context.commands).await.unwrap();
result.collect::<Vec<_>>().await;
} else {
println!("TODO!")
let table = context.expect_command("table");
let result = table.run(raw.with_input(input), &context.commands).await.unwrap();
result.collect::<Vec<_>>().await;
//println!("TODO!")
// TODO
// let mut host = context.host.lock().unwrap();
// for i in input.iter() {

View File

@@ -158,13 +158,18 @@ impl InternalCommand {
let full_path = std::path::PathBuf::from(cwd);
let (file_extension, contents, contents_tag, _) =
let (file_extension, contents, contents_tag, span_source) =
crate::commands::open::fetch(
&full_path,
&location,
Span::unknown(),
)?;
if let Some(uuid) = contents_tag.origin {
// If we have loaded something, track its source
context.add_span_source(uuid, span_source);
}
match contents {
Value::Primitive(Primitive::String(string)) => {
let value = crate::commands::open::parse_as_value(
@@ -178,7 +183,7 @@ impl InternalCommand {
}
value => context
.shell_manager
.push(Box::new(ValueShell::new(value.tagged(Tag::unknown())))),
.push(Box::new(ValueShell::new(value.tagged(contents_tag)))),
}
}
}

View File

@@ -226,6 +226,7 @@ pub fn fetch(
}
} else {
cwd.push(Path::new(location));
let cwd = dunce::canonicalize(cwd).unwrap();
match std::fs::read(&cwd) {
Ok(bytes) => match std::str::from_utf8(&bytes) {
Ok(s) => Ok((

View File

@@ -6,9 +6,17 @@ pub fn shells(args: CommandArgs, _registry: &CommandRegistry) -> Result<OutputSt
let mut shells_out = VecDeque::new();
let span = args.call_info.name_span;
for shell in args.shell_manager.shells.lock().unwrap().iter() {
let shells_len = args.shell_manager.shells.lock().unwrap().len();
for (index, shell) in args.shell_manager.shells.lock().unwrap().iter().enumerate() {
let mut dict = TaggedDictBuilder::new(Tag::unknown_origin(span));
dict.insert("name", shell.name());
if index == (shells_len - 1) {
dict.insert(" ", "X".to_string());
} else {
dict.insert(" ", " ".to_string());
}
dict.insert("name", shell.name(&args.call_info.source_map));
dict.insert("path", shell.path());
shells_out.push_back(dict.into_tagged_value());

View File

@@ -15,16 +15,17 @@ pub fn tags(args: CommandArgs, _registry: &CommandRegistry) -> Result<OutputStre
let mut dict = TaggedDictBuilder::new(v.tag());
dict.insert("start", Value::int(span.start as i64));
dict.insert("end", Value::int(span.end as i64));
tags.insert_tagged("span", dict.into_tagged_value());
match origin.map(|x| source_map.get(&x)).flatten() {
Some(SpanSource::File(source)) => {
dict.insert("origin", Value::string(source));
tags.insert("origin", Value::string(source));
}
Some(SpanSource::Url(source)) => {
dict.insert("origin", Value::string(source));
tags.insert("origin", Value::string(source));
}
_ => {}
}
tags.insert_tagged("span", dict.into_tagged_value());
}
tags.into_tagged_value()