diff --git a/crates/nu-command/src/core_commands/alias.rs b/crates/nu-command/src/core_commands/alias.rs index b0a9adb161..36aa4e7231 100644 --- a/crates/nu-command/src/core_commands/alias.rs +++ b/crates/nu-command/src/core_commands/alias.rs @@ -25,6 +25,15 @@ impl Command for Alias { .category(Category::Core) } + fn extra_usage(&self) -> &str { + r#"This command is a parser keyword. For details, check +https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"# + } + + fn is_parser_keyword(&self) -> bool { + true + } + fn run( &self, _engine_state: &EngineState, diff --git a/crates/nu-command/src/core_commands/def.rs b/crates/nu-command/src/core_commands/def.rs index 2cb64739c7..f89d2ea6ba 100644 --- a/crates/nu-command/src/core_commands/def.rs +++ b/crates/nu-command/src/core_commands/def.rs @@ -26,6 +26,15 @@ impl Command for Def { .category(Category::Core) } + fn extra_usage(&self) -> &str { + r#"This command is a parser keyword. For details, check +https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"# + } + + fn is_parser_keyword(&self) -> bool { + true + } + fn run( &self, _engine_state: &EngineState, diff --git a/crates/nu-command/src/core_commands/def_env.rs b/crates/nu-command/src/core_commands/def_env.rs index 00a42b3eb5..1b29a3da0a 100644 --- a/crates/nu-command/src/core_commands/def_env.rs +++ b/crates/nu-command/src/core_commands/def_env.rs @@ -26,6 +26,15 @@ impl Command for DefEnv { .category(Category::Core) } + fn extra_usage(&self) -> &str { + r#"This command is a parser keyword. For details, check +https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"# + } + + fn is_parser_keyword(&self) -> bool { + true + } + fn run( &self, _engine_state: &EngineState, diff --git a/crates/nu-command/src/core_commands/export.rs b/crates/nu-command/src/core_commands/export.rs index 92cb6593d8..383dce86c7 100644 --- a/crates/nu-command/src/core_commands/export.rs +++ b/crates/nu-command/src/core_commands/export.rs @@ -21,6 +21,15 @@ impl Command for ExportCommand { "Export custom commands or environment variables from a module." } + fn extra_usage(&self) -> &str { + r#"This command is a parser keyword. For details, check +https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"# + } + + fn is_parser_keyword(&self) -> bool { + true + } + fn run( &self, engine_state: &EngineState, diff --git a/crates/nu-command/src/core_commands/export_alias.rs b/crates/nu-command/src/core_commands/export_alias.rs index 456bb7dc30..3af266dd9f 100644 --- a/crates/nu-command/src/core_commands/export_alias.rs +++ b/crates/nu-command/src/core_commands/export_alias.rs @@ -25,6 +25,15 @@ impl Command for ExportAlias { .category(Category::Core) } + fn extra_usage(&self) -> &str { + r#"This command is a parser keyword. For details, check +https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"# + } + + fn is_parser_keyword(&self) -> bool { + true + } + fn run( &self, _engine_state: &EngineState, diff --git a/crates/nu-command/src/core_commands/export_def.rs b/crates/nu-command/src/core_commands/export_def.rs index 1444cab98d..024ae26432 100644 --- a/crates/nu-command/src/core_commands/export_def.rs +++ b/crates/nu-command/src/core_commands/export_def.rs @@ -26,6 +26,15 @@ impl Command for ExportDef { .category(Category::Core) } + fn extra_usage(&self) -> &str { + r#"This command is a parser keyword. For details, check +https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"# + } + + fn is_parser_keyword(&self) -> bool { + true + } + fn run( &self, _engine_state: &EngineState, diff --git a/crates/nu-command/src/core_commands/export_def_env.rs b/crates/nu-command/src/core_commands/export_def_env.rs index d724f44a37..267b1eb958 100644 --- a/crates/nu-command/src/core_commands/export_def_env.rs +++ b/crates/nu-command/src/core_commands/export_def_env.rs @@ -26,6 +26,15 @@ impl Command for ExportDefEnv { .category(Category::Core) } + fn extra_usage(&self) -> &str { + r#"This command is a parser keyword. For details, check +https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"# + } + + fn is_parser_keyword(&self) -> bool { + true + } + fn run( &self, _engine_state: &EngineState, diff --git a/crates/nu-command/src/core_commands/export_env.rs b/crates/nu-command/src/core_commands/export_env.rs index 883519c33b..fb6e5d0292 100644 --- a/crates/nu-command/src/core_commands/export_env.rs +++ b/crates/nu-command/src/core_commands/export_env.rs @@ -29,6 +29,15 @@ impl Command for ExportEnv { .category(Category::Core) } + fn extra_usage(&self) -> &str { + r#"This command is a parser keyword. For details, check +https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"# + } + + fn is_parser_keyword(&self) -> bool { + true + } + fn run( &self, _engine_state: &EngineState, diff --git a/crates/nu-command/src/core_commands/export_extern.rs b/crates/nu-command/src/core_commands/export_extern.rs index 7cc4489e77..ddab0ad510 100644 --- a/crates/nu-command/src/core_commands/export_extern.rs +++ b/crates/nu-command/src/core_commands/export_extern.rs @@ -21,6 +21,15 @@ impl Command for ExportExtern { .category(Category::Core) } + fn extra_usage(&self) -> &str { + r#"This command is a parser keyword. For details, check +https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"# + } + + fn is_parser_keyword(&self) -> bool { + true + } + fn run( &self, _engine_state: &EngineState, diff --git a/crates/nu-command/src/core_commands/extern_.rs b/crates/nu-command/src/core_commands/extern_.rs index d28f259b63..0c7b7692a8 100644 --- a/crates/nu-command/src/core_commands/extern_.rs +++ b/crates/nu-command/src/core_commands/extern_.rs @@ -21,6 +21,15 @@ impl Command for Extern { .category(Category::Core) } + fn extra_usage(&self) -> &str { + r#"This command is a parser keyword. For details, check +https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"# + } + + fn is_parser_keyword(&self) -> bool { + true + } + fn run( &self, _engine_state: &EngineState, diff --git a/crates/nu-command/src/core_commands/for_.rs b/crates/nu-command/src/core_commands/for_.rs index 96052b3143..52d1d434be 100644 --- a/crates/nu-command/src/core_commands/for_.rs +++ b/crates/nu-command/src/core_commands/for_.rs @@ -44,6 +44,15 @@ impl Command for For { .category(Category::Core) } + fn extra_usage(&self) -> &str { + r#"This command is a parser keyword. For details, check +https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"# + } + + fn is_parser_keyword(&self) -> bool { + true + } + fn run( &self, engine_state: &EngineState, diff --git a/crates/nu-command/src/core_commands/help.rs b/crates/nu-command/src/core_commands/help.rs index f0aa181143..dc47a00ed2 100644 --- a/crates/nu-command/src/core_commands/help.rs +++ b/crates/nu-command/src/core_commands/help.rs @@ -85,16 +85,19 @@ fn help( let find: Option> = call.get_flag(engine_state, stack, "find")?; let rest: Vec> = call.rest(engine_state, stack, 0)?; - let full_commands = engine_state.get_signatures_with_examples(false); + let commands = engine_state.get_decl_ids_sorted(false); if let Some(f) = find { let search_string = f.item.to_lowercase(); let mut found_cmds_vec = Vec::new(); - for (sig, _, is_plugin, is_custom) in full_commands { + for decl_id in commands { let mut cols = vec![]; let mut vals = vec![]; + let decl = engine_state.get_decl(decl_id); + let sig = decl.signature(); + let key = sig.name.clone(); let c = sig.usage.clone(); let e = sig.extra_usage.clone(); @@ -116,13 +119,19 @@ fn help( cols.push("is_plugin".into()); vals.push(Value::Bool { - val: is_plugin, + val: decl.is_plugin().is_some(), span: head, }); cols.push("is_custom".into()); vals.push(Value::Bool { - val: is_custom, + val: decl.get_block_id().is_some(), + span: head, + }); + + cols.push("is_keyword".into()); + vals.push(Value::Bool { + val: decl.is_parser_keyword(), span: head, }); @@ -149,10 +158,13 @@ fn help( let mut found_cmds_vec = Vec::new(); if rest[0].item == "commands" { - for (sig, _, is_plugin, is_custom) in full_commands { + for decl_id in commands { let mut cols = vec![]; let mut vals = vec![]; + let decl = engine_state.get_decl(decl_id); + let sig = decl.signature(); + let key = sig.name.clone(); let c = sig.usage.clone(); let e = sig.extra_usage.clone(); @@ -171,13 +183,19 @@ fn help( cols.push("is_plugin".into()); vals.push(Value::Bool { - val: is_plugin, + val: decl.is_plugin().is_some(), span: head, }); cols.push("is_custom".into()); vals.push(Value::Bool { - val: is_custom, + val: decl.get_block_id().is_some(), + span: head, + }); + + cols.push("is_keyword".into()); + vals.push(Value::Bool { + val: decl.is_parser_keyword(), span: head, }); @@ -207,7 +225,8 @@ fn help( name.push_str(&r.item); } - let output = full_commands + let output = engine_state + .get_signatures_with_examples(false) .iter() .filter(|(signature, _, _, _)| signature.name == name) .map(|(signature, examples, _, _)| { diff --git a/crates/nu-command/src/core_commands/hide.rs b/crates/nu-command/src/core_commands/hide.rs index c2bd9b5187..c35bad3c16 100644 --- a/crates/nu-command/src/core_commands/hide.rs +++ b/crates/nu-command/src/core_commands/hide.rs @@ -23,7 +23,15 @@ impl Command for Hide { } fn extra_usage(&self) -> &str { - "Symbols are hidden by priority: First aliases, then custom commands, then environment variables." + r#"Symbols are hidden by priority: First aliases, then custom commands, then environment variables. + +This command is a parser keyword. For details, check +https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages + "# + } + + fn is_parser_keyword(&self) -> bool { + true } fn run( diff --git a/crates/nu-command/src/core_commands/if_.rs b/crates/nu-command/src/core_commands/if_.rs index 5b0fe0b298..a26fbdc784 100644 --- a/crates/nu-command/src/core_commands/if_.rs +++ b/crates/nu-command/src/core_commands/if_.rs @@ -34,6 +34,15 @@ impl Command for If { .category(Category::Core) } + fn extra_usage(&self) -> &str { + r#"This command is a parser keyword. For details, check +https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"# + } + + fn is_parser_keyword(&self) -> bool { + true + } + fn run( &self, engine_state: &EngineState, diff --git a/crates/nu-command/src/core_commands/let_.rs b/crates/nu-command/src/core_commands/let_.rs index 69a560ca6c..9327fab1d4 100644 --- a/crates/nu-command/src/core_commands/let_.rs +++ b/crates/nu-command/src/core_commands/let_.rs @@ -26,6 +26,15 @@ impl Command for Let { .category(Category::Core) } + fn extra_usage(&self) -> &str { + r#"This command is a parser keyword. For details, check +https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"# + } + + fn is_parser_keyword(&self) -> bool { + true + } + fn run( &self, engine_state: &EngineState, diff --git a/crates/nu-command/src/core_commands/module.rs b/crates/nu-command/src/core_commands/module.rs index f96519796d..c1c1ec5ec6 100644 --- a/crates/nu-command/src/core_commands/module.rs +++ b/crates/nu-command/src/core_commands/module.rs @@ -25,6 +25,15 @@ impl Command for Module { .category(Category::Core) } + fn extra_usage(&self) -> &str { + r#"This command is a parser keyword. For details, check +https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"# + } + + fn is_parser_keyword(&self) -> bool { + true + } + fn run( &self, _engine_state: &EngineState, diff --git a/crates/nu-command/src/core_commands/register.rs b/crates/nu-command/src/core_commands/register.rs index b806102865..2ff4e2c08e 100644 --- a/crates/nu-command/src/core_commands/register.rs +++ b/crates/nu-command/src/core_commands/register.rs @@ -41,6 +41,15 @@ impl Command for Register { .category(Category::Core) } + fn extra_usage(&self) -> &str { + r#"This command is a parser keyword. For details, check +https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"# + } + + fn is_parser_keyword(&self) -> bool { + true + } + fn run( &self, _engine_state: &EngineState, diff --git a/crates/nu-command/src/core_commands/source.rs b/crates/nu-command/src/core_commands/source.rs index 80f12b66f5..f1d340fb99 100644 --- a/crates/nu-command/src/core_commands/source.rs +++ b/crates/nu-command/src/core_commands/source.rs @@ -26,6 +26,15 @@ impl Command for Source { "Runs a script file in the current context." } + fn extra_usage(&self) -> &str { + r#"This command is a parser keyword. For details, check +https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"# + } + + fn is_parser_keyword(&self) -> bool { + true + } + fn run( &self, engine_state: &EngineState, diff --git a/crates/nu-command/src/core_commands/use_.rs b/crates/nu-command/src/core_commands/use_.rs index 0dae9b8bc8..5a6fe80af5 100644 --- a/crates/nu-command/src/core_commands/use_.rs +++ b/crates/nu-command/src/core_commands/use_.rs @@ -23,6 +23,15 @@ impl Command for Use { .category(Category::Core) } + fn extra_usage(&self) -> &str { + r#"This command is a parser keyword. For details, check +https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-different-stages"# + } + + fn is_parser_keyword(&self) -> bool { + true + } + fn run( &self, engine_state: &EngineState, diff --git a/crates/nu-engine/src/eval.rs b/crates/nu-engine/src/eval.rs index 93c927475d..1247ea58e0 100644 --- a/crates/nu-engine/src/eval.rs +++ b/crates/nu-engine/src/eval.rs @@ -1002,6 +1002,12 @@ pub fn create_scope( span, }); + cols.push("is_keyword".into()); + vals.push(Value::Bool { + val: decl.is_parser_keyword(), + span, + }); + cols.push("is_extern".to_string()); vals.push(Value::Bool { val: decl.is_known_external(), diff --git a/crates/nu-protocol/src/engine/command.rs b/crates/nu-protocol/src/engine/command.rs index 8a90405c8b..681c822e35 100644 --- a/crates/nu-protocol/src/engine/command.rs +++ b/crates/nu-protocol/src/engine/command.rs @@ -46,6 +46,11 @@ pub trait Command: Send + Sync + CommandClone { self.name().contains(' ') } + // Is a parser keyword (source, def, etc.) + fn is_parser_keyword(&self) -> bool { + false + } + // Is a plugin command (returns plugin's path, encoding and type of shell // if the declaration is a plugin) fn is_plugin(&self) -> Option<(&PathBuf, &str, &Option)> {