"Add plugin arg errors. Bring remaining errors to parity"

This commit is contained in:
Jonathan Turner
2019-07-14 04:59:59 +12:00
parent b2d48566ba
commit 7e555a0ef2
16 changed files with 47 additions and 60 deletions

View File

@ -99,8 +99,6 @@ pub trait Command {
named: indexmap::IndexMap::new(),
is_filter: true,
is_sink: false,
can_load: vec![],
can_save: vec![],
}
}
}
@ -117,8 +115,6 @@ pub trait Sink {
named: indexmap::IndexMap::new(),
is_filter: false,
is_sink: true,
can_load: vec![],
can_save: vec![],
}
}
}

View File

@ -36,8 +36,6 @@ impl Command for Config {
named,
is_sink: true,
is_filter: false,
can_load: vec![],
can_save: vec![],
}
}
}

View File

@ -14,8 +14,6 @@ impl Command for Enter {
name: self.name().to_string(),
positional: vec![PositionalType::mandatory_block("path")],
rest_positional: false,
can_load: vec![],
can_save: vec![],
is_filter: false,
is_sink: false,
named: indexmap::IndexMap::new(),

View File

@ -65,7 +65,7 @@ pub fn get(args: CommandArgs) -> Result<OutputStream, ShellError> {
}
}
Ok(x) => result.push_back(ReturnSuccess::value(x.clone())),
Err(_) => {}
Err(x) => result.push_back(Err(x)),
}
}

View File

@ -48,8 +48,6 @@ macro_rules! command {
name: self.name().to_string(),
positional: vec![$($mandatory_positional)*],
rest_positional: false,
can_load: vec![],
can_save: vec![],
is_filter: false,
is_sink: false,

View File

@ -43,11 +43,32 @@ pub fn filter_plugin(path: String, args: CommandArgs) -> Result<OutputStream, Sh
let stdin = child.stdin.as_mut().expect("Failed to open stdin");
let stdout = child.stdout.as_mut().expect("Failed to open stdout");
let _reader = BufReader::new(stdout);
let mut reader = BufReader::new(stdout);
let request = JsonRpc::new("begin_filter", args.args);
let request_raw = serde_json::to_string(&request).unwrap();
stdin.write(format!("{}\n", request_raw).as_bytes())?;
let mut input = String::new();
match reader.read_line(&mut input) {
Ok(_) => {
let response = serde_json::from_str::<NuResult>(&input);
match response {
Ok(NuResult::response { params }) => match params {
Ok(_) => {}
Err(e) => {
return Err(e);
}
},
Err(e) => {
return Err(ShellError::string(format!(
"Error while processing input: {:?} {}",
e, input
)));
}
}
}
_ => {}
}
}
let mut eos: VecDeque<Spanned<Value>> = VecDeque::new();

View File

@ -21,8 +21,6 @@ impl Command for SkipWhile {
named: indexmap::IndexMap::new(),
is_filter: true,
is_sink: false,
can_load: vec![],
can_save: vec![],
}
}
}

View File

@ -5,7 +5,7 @@ use crate::parser::{Span, Spanned};
use ansi_term::Color;
use derive_new::new;
use language_reporting::{Diagnostic, Label, Severity};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde::{Deserialize, Serialize};
#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Serialize, Deserialize)]
pub enum Description {
@ -203,7 +203,7 @@ impl ShellError {
}
}
crate fn labeled_error(
pub fn labeled_error(
msg: impl Into<String>,
label: impl Into<String>,
span: Span,
@ -214,7 +214,7 @@ impl ShellError {
)
}
crate fn maybe_labeled_error(
pub fn maybe_labeled_error(
msg: impl Into<String>,
label: impl Into<String>,
span: Option<Span>,
@ -272,7 +272,7 @@ impl ProximateShellError {
}
}
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ShellDiagnostic {
crate diagnostic: Diagnostic<Span>,
}
@ -315,28 +315,6 @@ impl std::cmp::Ord for ShellDiagnostic {
}
}
impl Serialize for ShellDiagnostic {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
"<diagnostic>".serialize(serializer)
}
}
impl Deserialize<'de> for ShellDiagnostic {
fn deserialize<D>(_deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
Ok(ShellDiagnostic {
diagnostic: Diagnostic::new(
language_reporting::Severity::Error,
"deserialize not implemented for ShellDiagnostic",
),
})
}
}
#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, new, Clone, Serialize, Deserialize)]
pub struct StringError {
title: String,

View File

@ -82,8 +82,6 @@ pub struct CommandConfig {
pub named: IndexMap<String, NamedType>,
pub is_filter: bool,
pub is_sink: bool,
pub can_load: Vec<String>,
pub can_save: Vec<String>,
}
#[derive(Debug, Default, new, Serialize, Deserialize)]

View File

@ -33,7 +33,11 @@ pub fn serve_plugin(plugin: &mut dyn Plugin) {
send_response(plugin.config());
}
Ok(NuCommand::begin_filter { params }) => {
let _ = plugin.begin_filter(params);
send_response(
plugin
.begin_filter(params)
.map(|_| Vec::<ReturnValue>::new()),
);
}
Ok(NuCommand::filter { params }) => {
send_response(plugin.filter(params));
@ -66,7 +70,11 @@ pub fn serve_plugin(plugin: &mut dyn Plugin) {
send_response(plugin.config());
}
Ok(NuCommand::begin_filter { params }) => {
let _ = plugin.begin_filter(params);
send_response(
plugin
.begin_filter(params)
.map(|_| Vec::<ReturnValue>::new()),
);
}
Ok(NuCommand::filter { params }) => {
send_response(plugin.filter(params));

View File

@ -16,8 +16,6 @@ impl Plugin for BinaryView {
Ok(CommandConfig {
name: "binaryview".to_string(),
positional: vec![],
can_load: vec![],
can_save: vec![],
is_filter: false,
is_sink: true,
named: IndexMap::new(),

View File

@ -18,8 +18,6 @@ impl Plugin for Inc {
Ok(CommandConfig {
name: "inc".to_string(),
positional: vec![PositionalType::mandatory("Increment")],
can_load: vec![],
can_save: vec![],
is_filter: true,
is_sink: false,
named: IndexMap::new(),

View File

@ -18,8 +18,6 @@ impl Plugin for NewSkip {
Ok(CommandConfig {
name: "skip".to_string(),
positional: vec![],
can_load: vec![],
can_save: vec![],
is_filter: true,
is_sink: false,
named: IndexMap::new(),
@ -36,7 +34,7 @@ impl Plugin for NewSkip {
} => {
self.skip_amount = i;
}
_ => return Err(ShellError::string("Unrecognized type in params")),
_ => return Err(ShellError::labeled_error("Unrecognized type in params", "expected an integer", arg.span)),
}
}
}

View File

@ -85,8 +85,6 @@ impl Plugin for TreeViewer {
Ok(CommandConfig {
name: "tree".to_string(),
positional: vec![],
can_load: vec![],
can_save: vec![],
is_filter: false,
is_sink: true,
named: IndexMap::new(),