Define keywords (#13213)

# Description
Some commands in `nu-cmd-lang` are not classified as keywords even
though they should be.

# User-Facing Changes
In the output of `which`, `scope commands`, and `help commands`, some
commands will now have a `type` of `keyword` instead of `built-in`.
This commit is contained in:
Ian Manske
2024-06-26 01:32:54 +00:00
committed by GitHub
parent f241110005
commit 55ee476306
13 changed files with 126 additions and 32 deletions

View File

@ -42,32 +42,44 @@ use crate::{
};
/// These parser keywords can be aliased
pub const ALIASABLE_PARSER_KEYWORDS: &[&[u8]] = &[b"overlay hide", b"overlay new", b"overlay use"];
pub const ALIASABLE_PARSER_KEYWORDS: &[&[u8]] = &[
b"if",
b"match",
b"try",
b"overlay",
b"overlay hide",
b"overlay new",
b"overlay use",
];
pub const RESERVED_VARIABLE_NAMES: [&str; 3] = ["in", "nu", "env"];
/// These parser keywords cannot be aliased (either not possible, or support not yet added)
pub const UNALIASABLE_PARSER_KEYWORDS: &[&[u8]] = &[
b"export",
b"def",
b"export def",
b"for",
b"extern",
b"export extern",
b"alias",
b"export alias",
b"export-env",
b"const",
b"def",
b"extern",
b"module",
b"use",
b"export",
b"export alias",
b"export const",
b"export def",
b"export extern",
b"export module",
b"export use",
b"hide",
// b"overlay",
// b"overlay hide",
// b"overlay new",
// b"overlay use",
b"for",
b"loop",
b"while",
b"return",
b"break",
b"continue",
b"let",
b"const",
b"mut",
b"hide",
b"export-env",
b"source-env",
b"source",
b"where",
b"register",

View File

@ -934,15 +934,12 @@ pub fn parse_internal_call(
let output = signature.get_output_type();
// storing the var ID for later due to borrowing issues
let lib_dirs_var_id = if decl.is_builtin() {
match decl.name() {
"use" | "overlay use" | "source-env" | "nu-check" => {
find_dirs_var(working_set, LIB_DIRS_VAR)
}
_ => None,
let lib_dirs_var_id = match decl.name() {
"use" | "overlay use" | "source-env" if decl.is_keyword() => {
find_dirs_var(working_set, LIB_DIRS_VAR)
}
} else {
None
"nu-check" if decl.is_builtin() => find_dirs_var(working_set, LIB_DIRS_VAR),
_ => None,
};
// The index into the positional parameter in the definition