From 3484e0defd76ae35ee569e6c021028401184b601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Sat, 26 Mar 2022 21:22:45 +0200 Subject: [PATCH] Add parser keyword note to help and $nu.scope (#4978) --- crates/nu-command/src/core_commands/alias.rs | 9 +++++ crates/nu-command/src/core_commands/def.rs | 9 +++++ .../nu-command/src/core_commands/def_env.rs | 9 +++++ crates/nu-command/src/core_commands/export.rs | 9 +++++ .../src/core_commands/export_alias.rs | 9 +++++ .../src/core_commands/export_def.rs | 9 +++++ .../src/core_commands/export_def_env.rs | 9 +++++ .../src/core_commands/export_env.rs | 9 +++++ .../src/core_commands/export_extern.rs | 9 +++++ .../nu-command/src/core_commands/extern_.rs | 9 +++++ crates/nu-command/src/core_commands/for_.rs | 9 +++++ crates/nu-command/src/core_commands/help.rs | 35 ++++++++++++++----- crates/nu-command/src/core_commands/hide.rs | 10 +++++- crates/nu-command/src/core_commands/if_.rs | 9 +++++ crates/nu-command/src/core_commands/let_.rs | 9 +++++ crates/nu-command/src/core_commands/module.rs | 9 +++++ .../nu-command/src/core_commands/register.rs | 9 +++++ crates/nu-command/src/core_commands/source.rs | 9 +++++ crates/nu-command/src/core_commands/use_.rs | 9 +++++ crates/nu-engine/src/eval.rs | 6 ++++ crates/nu-protocol/src/engine/command.rs | 5 +++ 21 files changed, 200 insertions(+), 9 deletions(-) diff --git a/crates/nu-command/src/core_commands/alias.rs b/crates/nu-command/src/core_commands/alias.rs index b0a9adb16..36aa4e723 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 2cb64739c..f89d2ea6b 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 00a42b3eb..1b29a3da0 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 92cb6593d..383dce86c 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 456bb7dc3..3af266dd9 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 1444cab98..024ae2643 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 d724f44a3..267b1eb95 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 883519c33..fb6e5d029 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 7cc4489e7..ddab0ad51 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 d28f259b6..0c7b7692a 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 96052b314..52d1d434b 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 f0aa18114..dc47a00ed 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 c2bd9b518..c35bad3c1 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 5b0fe0b29..a26fbdc78 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 69a560ca6..9327fab1d 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 f96519796..c1c1ec5ec 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 b80610286..2ff4e2c08 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 80f12b66f..f1d340fb9 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 0dae9b8bc..5a6fe80af 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 93c927475..1247ea58e 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 8a90405c8..681c822e3 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)> {