Compare commits

...

4 Commits

@ -1,6 +1,6 @@
[package]
name = "embed-nu"
version = "0.6.0"
version = "0.8.0"
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/Trivernis/embed-nu"
@ -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
[dependencies]
miette = "5.7.0"
nu-cmd-lang = "0.78.0"
nu-command = "0.78.0"
nu-engine = "0.78.0"
nu-parser = "0.78.0"
nu-protocol = "0.78.0"
miette = "5.9.0"
nu-cmd-lang = "0.80.0"
nu-command = "0.80.0"
nu-engine = "0.80.0"
nu-parser = "0.80.0"
nu-protocol = "0.80.0"
paste = "1.0.12"
rusty-value = { version = "0.6.0", features = ["derive"] }
thiserror = "1.0.40"

@ -19,7 +19,6 @@ pub fn bind_core_commands(engine_state: &mut EngineState) -> CrateResult<()> {
Alias,
Break,
Collect,
Commandline,
Const,
Continue,
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<()> {
bind_commands!(engine_state, History, Tutor, HistorySession)
bind_commands!(engine_state, Tutor)
}
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,
Clear,
Du,
KeybindingsDefault,
Input,
KeybindingsListen,
Keybindings,
Kill,
KeybindingsList,
Sleep,
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<()> {
bind_commands! {
engine_state,
Enter,
Exit,
GotoShell,
NextShell,
PrevShell,
Shells,
}
}

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

@ -1,86 +1,20 @@
use miette::Diagnostic;
use nu_parser::ParseError;
use nu_protocol::ShellError;
use nu_protocol::{ParseError, ShellError};
use thiserror::Error;
pub type CrateResult<T> = std::result::Result<T, CrateError>;
#[derive(Clone, Debug, Error)]
#[derive(Clone, Debug, Error, Diagnostic)]
pub enum CrateError {
#[error("Shell Error {0}")]
#[diagnostic()]
NuShellError(#[from] ShellError),
#[error("Parse Error {0}")]
NuParseError(#[from] ParseError),
#[error("Parse Error {0:?}")]
#[diagnostic()]
NuParseErrors(#[related] Vec<ParseError>),
#[error("Could not find the function {0}")]
#[diagnostic()]
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> {
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 {
Err(CrateError::from(err))
} else {
if working_set.parse_errors.is_empty() {
let delta = working_set.render();
engine_state.merge_delta(delta)?;
Ok(block)
} else {
Err(CrateError::NuParseErrors(working_set.parse_errors))
}
}

@ -15,6 +15,13 @@ fn it_evals_strings() {
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]
fn it_returns_variables() {
let mut ctx = get_context();

Loading…
Cancel
Save