Add a config variable with engine support (#332)

* Add a config variable with engine support

* Add a config variable with engine support

* Oops, cleanup
This commit is contained in:
JT
2021-11-15 08:25:57 +13:00
committed by GitHub
parent e76451866d
commit 0f107b2830
30 changed files with 333 additions and 96 deletions

View File

@ -1,7 +1,7 @@
use nu_protocol::{
ast::{Block, Call, Expr, Expression, ImportPattern, ImportPatternMember, Pipeline, Statement},
engine::StateWorkingSet,
span, DeclId, Span, SyntaxShape, Type,
span, DeclId, Span, SyntaxShape, Type, CONFIG_VARIABLE_ID,
};
use std::path::Path;
@ -800,7 +800,9 @@ pub fn parse_let(
.expect("internal error: expected variable");
let rhs_type = call.positional[1].ty.clone();
working_set.set_variable_type(var_id, rhs_type);
if var_id != CONFIG_VARIABLE_ID {
working_set.set_variable_type(var_id, rhs_type);
}
}
return (

View File

@ -12,6 +12,7 @@ use nu_protocol::{
},
engine::StateWorkingSet,
span, Flag, PositionalArg, Signature, Span, Spanned, SyntaxShape, Type, Unit, VarId,
CONFIG_VARIABLE_ID,
};
use crate::parse_keywords::{
@ -1201,6 +1202,16 @@ pub fn parse_variable_expr(
},
None,
);
} else if contents == b"$config" {
return (
Expression {
expr: Expr::Var(nu_protocol::CONFIG_VARIABLE_ID),
span,
ty: Type::Unknown,
custom_completion: None,
},
None,
);
}
let (id, err) = parse_variable(working_set, span);
@ -1909,6 +1920,16 @@ pub fn parse_var_with_opt_type(
Some(ParseError::MissingType(spans[*spans_idx])),
)
}
} else if bytes == b"$config" || bytes == b"config" {
(
Expression {
expr: Expr::Var(CONFIG_VARIABLE_ID),
span: spans[*spans_idx],
ty: Type::Unknown,
custom_completion: None,
},
None,
)
} else {
let id = working_set.add_variable(bytes, Type::Unknown);