Upgrade nu version

main
trivernis 1 year ago
parent a283d435e7
commit 949e270e39
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -10,12 +10,12 @@ authors = ["trivernis <trivernis@proton.me>"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
miette = "5.7.0" miette = "5.9.0"
nu-cmd-lang = "0.78.0" nu-cmd-lang = "0.80.0"
nu-command = "0.78.0" nu-command = "0.80.0"
nu-engine = "0.78.0" nu-engine = "0.80.0"
nu-parser = "0.78.0" nu-parser = "0.80.0"
nu-protocol = "0.78.0" nu-protocol = "0.80.0"
paste = "1.0.12" paste = "1.0.12"
rusty-value = { version = "0.6.0", features = ["derive"] } rusty-value = { version = "0.6.0", features = ["derive"] }
thiserror = "1.0.40" thiserror = "1.0.40"

@ -19,7 +19,6 @@ pub fn bind_core_commands(engine_state: &mut EngineState) -> CrateResult<()> {
Alias, Alias,
Break, Break,
Collect, Collect,
Commandline,
Const, Const,
Continue, Continue,
Def, Def,
@ -157,7 +156,7 @@ pub fn bind_filter_commands(engine_state: &mut EngineState) -> CrateResult<()> {
} }
pub fn bind_misc_commands(engine_state: &mut EngineState) -> CrateResult<()> { pub fn bind_misc_commands(engine_state: &mut EngineState) -> CrateResult<()> {
bind_commands!(engine_state, History, Tutor, HistorySession) bind_commands!(engine_state, Tutor)
} }
pub fn bind_path_commands(engine_state: &mut EngineState) -> CrateResult<()> { pub fn bind_path_commands(engine_state: &mut EngineState) -> CrateResult<()> {
@ -319,12 +318,8 @@ pub fn bind_platform_commands(engine_state: &mut EngineState) -> CrateResult<()>
AnsiStrip, AnsiStrip,
Clear, Clear,
Du, Du,
KeybindingsDefault,
Input, Input,
KeybindingsListen,
Keybindings,
Kill, Kill,
KeybindingsList,
Sleep, Sleep,
TermSize, TermSize,
} }
@ -347,12 +342,7 @@ pub fn bind_date_commands(engine_state: &mut EngineState) -> CrateResult<()> {
pub fn bind_shell_commands(engine_state: &mut EngineState) -> CrateResult<()> { pub fn bind_shell_commands(engine_state: &mut EngineState) -> CrateResult<()> {
bind_commands! { bind_commands! {
engine_state, engine_state,
Enter,
Exit, Exit,
GotoShell,
NextShell,
PrevShell,
Shells,
} }
} }

@ -1,6 +1,8 @@
mod bindings; mod bindings;
mod builder; mod builder;
mod command_group_config; mod command_group_config;
use std::collections::HashMap;
pub use builder::*; pub use builder::*;
pub use command_group_config::CommandGroupConfig; pub use command_group_config::CommandGroupConfig;
use nu_protocol::{ use nu_protocol::{
@ -58,15 +60,11 @@ impl Context {
pub fn get_var<S: AsRef<str>>(&self, name: S) -> Option<nu_protocol::Value> { pub fn get_var<S: AsRef<str>>(&self, name: S) -> Option<nu_protocol::Value> {
let name = name.as_ref(); let name = name.as_ref();
let dollar_name = format!("${name}"); let dollar_name = format!("${name}");
let var_id = self let var_id = self.engine_state.active_overlays(&vec![]).find_map(|o| {
.engine_state o.vars
.active_overlays(&vec![]) .get(dollar_name.as_bytes())
.iter() .or(o.vars.get(name.as_bytes()))
.find_map(|o| { })?;
o.vars
.get(dollar_name.as_bytes())
.or(o.vars.get(name.as_bytes()))
})?;
self.stack.get_var(*var_id, Span::new(0, 0)).ok() self.stack.get_var(*var_id, Span::new(0, 0)).ok()
} }
@ -99,7 +97,7 @@ impl Context {
arguments: args, arguments: args,
redirect_stdout: true, redirect_stdout: true,
redirect_stderr: true, redirect_stderr: true,
parser_info: Vec::new(), parser_info: HashMap::new(),
}; };
let data = nu_engine::eval_call( let data = nu_engine::eval_call(

@ -1,86 +1,20 @@
use miette::Diagnostic; use miette::Diagnostic;
use nu_parser::ParseError; use nu_protocol::{ParseError, ShellError};
use nu_protocol::ShellError;
use thiserror::Error; use thiserror::Error;
pub type CrateResult<T> = std::result::Result<T, CrateError>; pub type CrateResult<T> = std::result::Result<T, CrateError>;
#[derive(Clone, Debug, Error)] #[derive(Clone, Debug, Error, Diagnostic)]
pub enum CrateError { pub enum CrateError {
#[error("Shell Error {0}")] #[error("Shell Error {0}")]
#[diagnostic()]
NuShellError(#[from] ShellError), NuShellError(#[from] ShellError),
#[error("Parse Error {0}")] #[error("Parse Error {0:?}")]
NuParseError(#[from] ParseError), #[diagnostic()]
NuParseErrors(Vec<ParseError>),
#[error("Could not find the function {0}")] #[error("Could not find the function {0}")]
#[diagnostic()]
FunctionNotFound(String), FunctionNotFound(String),
} }
impl Diagnostic for CrateError {
fn code<'a>(&'a self) -> Option<Box<dyn std::fmt::Display + 'a>> {
match self {
CrateError::NuShellError(n) => n.code(),
CrateError::NuParseError(n) => n.code(),
Self::FunctionNotFound(_) => Some(Box::new("embed_nu::fn_not_found")),
}
}
fn severity(&self) -> Option<miette::Severity> {
match self {
CrateError::NuShellError(n) => n.severity(),
CrateError::NuParseError(n) => n.severity(),
_ => None,
}
}
fn help<'a>(&'a self) -> Option<Box<dyn std::fmt::Display + 'a>> {
match self {
CrateError::NuShellError(n) => n.help(),
CrateError::NuParseError(n) => n.help(),
CrateError::FunctionNotFound(_) => Some(Box::new(
"Make sure the function you want to execute is defined at this point.",
)),
}
}
fn url<'a>(&'a self) -> Option<Box<dyn std::fmt::Display + 'a>> {
match self {
CrateError::NuShellError(n) => n.url(),
CrateError::NuParseError(n) => n.url(),
_ => None,
}
}
fn source_code(&self) -> Option<&dyn miette::SourceCode> {
match self {
CrateError::NuShellError(n) => n.source_code(),
CrateError::NuParseError(n) => n.source_code(),
_ => None,
}
}
fn labels(&self) -> Option<Box<dyn Iterator<Item = miette::LabeledSpan> + '_>> {
match self {
CrateError::NuShellError(n) => n.labels(),
CrateError::NuParseError(n) => n.labels(),
_ => None,
}
}
fn related<'a>(&'a self) -> Option<Box<dyn Iterator<Item = &'a dyn Diagnostic> + 'a>> {
match self {
CrateError::NuShellError(n) => n.related(),
CrateError::NuParseError(n) => n.related(),
_ => None,
}
}
fn diagnostic_source(&self) -> Option<&dyn Diagnostic> {
match self {
CrateError::NuShellError(n) => n.diagnostic_source(),
CrateError::NuParseError(n) => n.diagnostic_source(),
_ => None,
}
}
}

@ -19,14 +19,14 @@ impl NewEmpty for Span {
pub fn parse_nu_script(engine_state: &mut EngineState, contents: String) -> CrateResult<Block> { pub fn parse_nu_script(engine_state: &mut EngineState, contents: String) -> CrateResult<Block> {
let mut working_set = StateWorkingSet::new(&engine_state); let mut working_set = StateWorkingSet::new(&engine_state);
let (block, err) = nu_parser::parse(&mut working_set, None, &contents.into_bytes(), false, &[]); let block = nu_parser::parse(&mut working_set, None, &contents.into_bytes(), false);
if let Some(err) = err { if working_set.parse_errors.is_empty() {
Err(CrateError::from(err))
} else {
let delta = working_set.render(); let delta = working_set.render();
engine_state.merge_delta(delta)?; engine_state.merge_delta(delta)?;
Ok(block) Ok(block)
} else {
Err(CrateError::NuParseErrors(working_set.parse_errors))
} }
} }

@ -15,6 +15,13 @@ fn it_evals_strings() {
ctx.print_pipeline(pipeline).unwrap() ctx.print_pipeline(pipeline).unwrap()
} }
#[test]
fn it_reports_parse_errors() {
let mut ctx = get_context();
let eval_result = ctx.eval_raw(r#"let a = 1 | 2 | 3"#, PipelineData::empty());
assert!(eval_result.is_err());
}
#[test] #[test]
fn it_returns_variables() { fn it_returns_variables() {
let mut ctx = get_context(); let mut ctx = get_context();

Loading…
Cancel
Save