Allow NU_LIBS_DIR and friends to be const (#8538)

This commit is contained in:
StevenDoesStuffs
2023-04-05 11:56:48 -05:00
committed by GitHub
parent d18cf19a3f
commit 1134c2f16c
13 changed files with 279 additions and 136 deletions

View File

@ -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,