mirror of
https://github.com/nushell/nushell.git
synced 2025-01-24 23:29:52 +01:00
commit
25c7d8ead6
39
.github/workflows/ci.yml
vendored
Normal file
39
.github/workflows/ci.yml
vendored
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
on: push
|
||||||
|
|
||||||
|
name: Continuous integration
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
ci:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
rust:
|
||||||
|
- stable
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
profile: minimal
|
||||||
|
toolchain: ${{ matrix.rust }}
|
||||||
|
override: true
|
||||||
|
components: rustfmt, clippy
|
||||||
|
|
||||||
|
- uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: build
|
||||||
|
|
||||||
|
- uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: test
|
||||||
|
|
||||||
|
- uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: fmt
|
||||||
|
args: --all -- --check
|
||||||
|
|
||||||
|
- uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: clippy
|
||||||
|
args: -- -D warnings
|
@ -26,7 +26,7 @@ impl Command for Do {
|
|||||||
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
|
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
|
||||||
let block = &call.positional[0];
|
let block = &call.positional[0];
|
||||||
|
|
||||||
let out = eval_expression(context, &block)?;
|
let out = eval_expression(context, block)?;
|
||||||
|
|
||||||
match out {
|
match out {
|
||||||
Value::Block { val: block_id, .. } => {
|
Value::Block { val: block_id, .. } => {
|
||||||
|
@ -48,7 +48,7 @@ impl Command for Each {
|
|||||||
let block = engine_state.get_block(block);
|
let block = engine_state.get_block(block);
|
||||||
|
|
||||||
let state = context.enter_scope();
|
let state = context.enter_scope();
|
||||||
state.add_var(var_id, x.clone());
|
state.add_var(var_id, x);
|
||||||
|
|
||||||
//FIXME: DON'T UNWRAP
|
//FIXME: DON'T UNWRAP
|
||||||
eval_block(&state, block, Value::nothing()).unwrap()
|
eval_block(&state, block, Value::nothing()).unwrap()
|
||||||
@ -63,7 +63,7 @@ impl Command for Each {
|
|||||||
let block = engine_state.get_block(block);
|
let block = engine_state.get_block(block);
|
||||||
|
|
||||||
let state = context.enter_scope();
|
let state = context.enter_scope();
|
||||||
state.add_var(var_id, x.clone());
|
state.add_var(var_id, x);
|
||||||
|
|
||||||
//FIXME: DON'T UNWRAP
|
//FIXME: DON'T UNWRAP
|
||||||
eval_block(&state, block, Value::nothing()).unwrap()
|
eval_block(&state, block, Value::nothing()).unwrap()
|
||||||
|
@ -60,7 +60,7 @@ impl Command for For {
|
|||||||
let block = engine_state.get_block(block);
|
let block = engine_state.get_block(block);
|
||||||
|
|
||||||
let state = context.enter_scope();
|
let state = context.enter_scope();
|
||||||
state.add_var(var_id, x.clone());
|
state.add_var(var_id, x);
|
||||||
|
|
||||||
//FIXME: DON'T UNWRAP
|
//FIXME: DON'T UNWRAP
|
||||||
eval_block(&state, block, Value::nothing()).unwrap()
|
eval_block(&state, block, Value::nothing()).unwrap()
|
||||||
@ -76,7 +76,7 @@ impl Command for For {
|
|||||||
let block = engine_state.get_block(block);
|
let block = engine_state.get_block(block);
|
||||||
|
|
||||||
let state = context.enter_scope();
|
let state = context.enter_scope();
|
||||||
state.add_var(var_id, x.clone());
|
state.add_var(var_id, x);
|
||||||
|
|
||||||
//FIXME: DON'T UNWRAP
|
//FIXME: DON'T UNWRAP
|
||||||
eval_block(&state, block, Value::nothing()).unwrap()
|
eval_block(&state, block, Value::nothing()).unwrap()
|
||||||
|
@ -247,8 +247,7 @@ fn calculate_end_span(
|
|||||||
&& spans.len() > (signature.required_positional.len() - positional_idx)
|
&& spans.len() > (signature.required_positional.len() - positional_idx)
|
||||||
{
|
{
|
||||||
spans.len() - (signature.required_positional.len() - positional_idx - 1)
|
spans.len() - (signature.required_positional.len() - positional_idx - 1)
|
||||||
} else {
|
} else if signature.num_positionals_after(positional_idx) == 0 {
|
||||||
if signature.num_positionals_after(positional_idx) == 0 {
|
|
||||||
spans.len()
|
spans.len()
|
||||||
} else {
|
} else {
|
||||||
spans_idx + 1
|
spans_idx + 1
|
||||||
@ -256,7 +255,6 @@ fn calculate_end_span(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_multispan_value(
|
fn parse_multispan_value(
|
||||||
working_set: &mut StateWorkingSet,
|
working_set: &mut StateWorkingSet,
|
||||||
@ -496,7 +494,7 @@ pub fn parse_call(
|
|||||||
let cmd_start = pos;
|
let cmd_start = pos;
|
||||||
|
|
||||||
if expand_aliases {
|
if expand_aliases {
|
||||||
if let Some(expansion) = working_set.find_alias(&name) {
|
if let Some(expansion) = working_set.find_alias(name) {
|
||||||
let orig_span = spans[pos];
|
let orig_span = spans[pos];
|
||||||
//let mut spans = spans.to_vec();
|
//let mut spans = spans.to_vec();
|
||||||
let mut new_spans: Vec<Span> = vec![];
|
let mut new_spans: Vec<Span> = vec![];
|
||||||
@ -992,7 +990,7 @@ pub fn parse_string(
|
|||||||
|
|
||||||
//TODO: Handle error case
|
//TODO: Handle error case
|
||||||
pub fn parse_shape_name(
|
pub fn parse_shape_name(
|
||||||
working_set: &StateWorkingSet,
|
_working_set: &StateWorkingSet,
|
||||||
bytes: &[u8],
|
bytes: &[u8],
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> (SyntaxShape, Option<ParseError>) {
|
) -> (SyntaxShape, Option<ParseError>) {
|
||||||
@ -1018,7 +1016,7 @@ pub fn parse_shape_name(
|
|||||||
(result, None)
|
(result, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_type(working_set: &StateWorkingSet, bytes: &[u8]) -> Type {
|
pub fn parse_type(_working_set: &StateWorkingSet, bytes: &[u8]) -> Type {
|
||||||
if bytes == b"int" {
|
if bytes == b"int" {
|
||||||
Type::Int
|
Type::Int
|
||||||
} else {
|
} else {
|
||||||
@ -1479,7 +1477,7 @@ pub fn parse_list_expression(
|
|||||||
expr: Expr::List(args),
|
expr: Expr::List(args),
|
||||||
span,
|
span,
|
||||||
ty: Type::List(Box::new(if let Some(ty) = contained_type {
|
ty: Type::List(Box::new(if let Some(ty) = contained_type {
|
||||||
ty.clone()
|
ty
|
||||||
} else {
|
} else {
|
||||||
Type::Unknown
|
Type::Unknown
|
||||||
})),
|
})),
|
||||||
@ -2001,15 +1999,12 @@ pub fn parse_def_predecl(working_set: &mut StateWorkingSet, spans: &[Span]) {
|
|||||||
let signature = sig.as_signature();
|
let signature = sig.as_signature();
|
||||||
working_set.exit_scope();
|
working_set.exit_scope();
|
||||||
|
|
||||||
match (name, signature) {
|
if let (Some(name), Some(mut signature)) = (name, signature) {
|
||||||
(Some(name), Some(mut signature)) => {
|
|
||||||
signature.name = name;
|
signature.name = name;
|
||||||
let decl = signature.predeclare();
|
let decl = signature.predeclare();
|
||||||
|
|
||||||
working_set.add_decl(decl);
|
working_set.add_decl(decl);
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ pub fn type_compatible(lhs: &Type, rhs: &Type) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn math_result_type(
|
pub fn math_result_type(
|
||||||
working_set: &StateWorkingSet,
|
_working_set: &StateWorkingSet,
|
||||||
lhs: &mut Expression,
|
lhs: &mut Expression,
|
||||||
op: &mut Expression,
|
op: &mut Expression,
|
||||||
rhs: &mut Expression,
|
rhs: &mut Expression,
|
||||||
|
@ -119,6 +119,7 @@ impl EngineState {
|
|||||||
.expect("internal error: missing variable")
|
.expect("internal error: missing variable")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::borrowed_box)]
|
||||||
pub fn get_decl(&self, decl_id: DeclId) -> &Box<dyn Command> {
|
pub fn get_decl(&self, decl_id: DeclId) -> &Box<dyn Command> {
|
||||||
self.decls
|
self.decls
|
||||||
.get(decl_id)
|
.get(decl_id)
|
||||||
@ -460,6 +461,7 @@ impl<'a> StateWorkingSet<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::borrowed_box)]
|
||||||
pub fn get_decl(&self, decl_id: DeclId) -> &Box<dyn Command> {
|
pub fn get_decl(&self, decl_id: DeclId) -> &Box<dyn Command> {
|
||||||
let num_permanent_decls = self.permanent_state.num_decls();
|
let num_permanent_decls = self.permanent_state.num_decls();
|
||||||
if decl_id < num_permanent_decls {
|
if decl_id < num_permanent_decls {
|
||||||
|
@ -249,9 +249,8 @@ impl Signature {
|
|||||||
|
|
||||||
pub fn num_positionals_after(&self, idx: usize) -> usize {
|
pub fn num_positionals_after(&self, idx: usize) -> usize {
|
||||||
let mut total = 0;
|
let mut total = 0;
|
||||||
let mut curr = 0;
|
|
||||||
|
|
||||||
for positional in &self.required_positional {
|
for (curr, positional) in self.required_positional.iter().enumerate() {
|
||||||
match positional.shape {
|
match positional.shape {
|
||||||
SyntaxShape::Keyword(..) => {
|
SyntaxShape::Keyword(..) => {
|
||||||
// Keywords have a required argument, so account for that
|
// Keywords have a required argument, so account for that
|
||||||
@ -265,7 +264,6 @@ impl Signature {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
curr += 1;
|
|
||||||
}
|
}
|
||||||
total
|
total
|
||||||
}
|
}
|
||||||
|
@ -9,13 +9,11 @@ pub struct ValueStream(pub Rc<RefCell<dyn Iterator<Item = Value>>>);
|
|||||||
|
|
||||||
impl ValueStream {
|
impl ValueStream {
|
||||||
pub fn into_string(self) -> String {
|
pub fn into_string(self) -> String {
|
||||||
let val: Vec<Value> = self.collect();
|
|
||||||
format!(
|
format!(
|
||||||
"[{}]",
|
"[{}]",
|
||||||
val.into_iter()
|
self.map(|x| x.into_string())
|
||||||
.map(|x| x.into_string())
|
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join(", ".into())
|
.join(", ")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,20 +57,18 @@ pub struct RowStream(Rc<RefCell<dyn Iterator<Item = Vec<Value>>>>);
|
|||||||
|
|
||||||
impl RowStream {
|
impl RowStream {
|
||||||
pub fn into_string(self, headers: Vec<String>) -> String {
|
pub fn into_string(self, headers: Vec<String>) -> String {
|
||||||
let val: Vec<Vec<Value>> = self.collect();
|
|
||||||
format!(
|
format!(
|
||||||
"[{}]\n[{}]",
|
"[{}]\n[{}]",
|
||||||
headers
|
headers
|
||||||
.iter()
|
.iter()
|
||||||
.map(|x| x.to_string())
|
.map(|x| x.to_string())
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join(", ".into()),
|
.join(", "),
|
||||||
val.into_iter()
|
self.map(|x| {
|
||||||
.map(|x| {
|
|
||||||
x.into_iter()
|
x.into_iter()
|
||||||
.map(|x| x.into_string())
|
.map(|x| x.into_string())
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join(", ".into())
|
.join(", ")
|
||||||
})
|
})
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join("\n")
|
.join("\n")
|
||||||
|
Loading…
Reference in New Issue
Block a user