mirror of
https://github.com/nushell/nushell.git
synced 2025-08-17 20:27:20 +02:00
Allow NU_LIBS_DIR and friends to be const (#8538)
This commit is contained in:
@ -8,6 +8,7 @@ use crate::{
|
||||
ParseError, Token, TokenContents,
|
||||
};
|
||||
|
||||
use nu_engine::DIR_VAR_PARSER_INFO;
|
||||
use nu_protocol::{
|
||||
ast::{
|
||||
Argument, Assignment, Bits, Block, Boolean, Call, CellPath, Comparison, Expr, Expression,
|
||||
@ -20,10 +21,10 @@ use nu_protocol::{
|
||||
};
|
||||
|
||||
use crate::parse_keywords::{
|
||||
is_unaliasable_parser_keyword, parse_alias, parse_def, parse_def_predecl,
|
||||
find_dirs_var, is_unaliasable_parser_keyword, parse_alias, parse_def, parse_def_predecl,
|
||||
parse_export_in_block, parse_extern, parse_for, parse_hide, parse_keyword, parse_let_or_const,
|
||||
parse_module, parse_old_alias, parse_overlay_hide, parse_overlay_new, parse_overlay_use,
|
||||
parse_source, parse_use, parse_where, parse_where_expr,
|
||||
parse_source, parse_use, parse_where, parse_where_expr, LIB_DIRS_VAR,
|
||||
};
|
||||
|
||||
use itertools::Itertools;
|
||||
@ -809,6 +810,25 @@ pub struct ParsedInternalCall {
|
||||
pub error: Option<ParseError>,
|
||||
}
|
||||
|
||||
fn attach_parser_info_builtin(working_set: &StateWorkingSet, name: &str, call: &mut Call) {
|
||||
match name {
|
||||
"use" | "overlay use" | "source-env" | "nu-check" => {
|
||||
if let Some(var_id) = find_dirs_var(working_set, LIB_DIRS_VAR) {
|
||||
call.set_parser_info(
|
||||
DIR_VAR_PARSER_INFO.to_owned(),
|
||||
Expression {
|
||||
expr: Expr::Var(var_id),
|
||||
span: call.head,
|
||||
ty: Type::Any,
|
||||
custom_completion: None,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_internal_call(
|
||||
working_set: &mut StateWorkingSet,
|
||||
command_span: Span,
|
||||
@ -828,6 +848,10 @@ pub fn parse_internal_call(
|
||||
let signature = decl.signature();
|
||||
let output = signature.output_type.clone();
|
||||
|
||||
if decl.is_builtin() {
|
||||
attach_parser_info_builtin(working_set, decl.name(), &mut call);
|
||||
}
|
||||
|
||||
// The index into the positional parameter in the definition
|
||||
let mut positional_idx = 0;
|
||||
|
||||
@ -5686,7 +5710,7 @@ pub fn parse_expression(
|
||||
arguments,
|
||||
redirect_stdout: true,
|
||||
redirect_stderr: false,
|
||||
parser_info: vec![],
|
||||
parser_info: HashMap::new(),
|
||||
}));
|
||||
|
||||
(
|
||||
@ -6577,7 +6601,7 @@ fn wrap_expr_with_collect(working_set: &mut StateWorkingSet, expr: &Expression)
|
||||
decl_id,
|
||||
redirect_stdout: true,
|
||||
redirect_stderr: false,
|
||||
parser_info: vec![],
|
||||
parser_info: HashMap::new(),
|
||||
})),
|
||||
span,
|
||||
ty: Type::String,
|
||||
|
Reference in New Issue
Block a user