mirror of
https://github.com/nushell/nushell.git
synced 2025-07-02 23:51:49 +02:00
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:
@ -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 (
|
||||
|
@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user